Line data Source code
1 : /* 2 : * SPDX-License-Identifier: MPL-2.0 3 : * 4 : * This Source Code Form is subject to the terms of the Mozilla Public 5 : * License, v. 2.0. If a copy of the MPL was not distributed with this 6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 : * 8 : * Copyright 2024 MonetDB Foundation; 9 : * Copyright August 2008 - 2023 MonetDB B.V.; 10 : * Copyright 1997 - July 2008 CWI. 11 : */ 12 : 13 : #ifndef _GDK_BBP_H_ 14 : #define _GDK_BBP_H_ 15 : 16 : #define BBPLOADED 1 /* set if bat in memory */ 17 : #define BBPSWAPPED 2 /* set if dirty bat is not in memory */ 18 : #define BBPTMP 4 /* set if non-persistent bat has image on disk */ 19 : 20 : /* These 4 symbols indicate what the persistence state is of a bat. 21 : * - If the bat was persistent at the last commit (or at startup 22 : * before the first commit), BBPEXISTING or BBPDELETED is set. 23 : * - If the bat is to be persistent after the next commit, BBPEXISTING 24 : * or BBPNEW is set (i.e. (status&BBPPERSISTENT) != 0). 25 : * - If the bat was transient at the last commit (or didn't exist), 26 : * BBPNEW is set, or none of these flag values is set. 27 : * - If the bat is to be transient at the next commit, BBPDELETED is 28 : * set, or none of these flag values is set. 29 : * BATmode() switches between BBPDELETED and BBPEXISTING (bat was 30 : * persistent at last commit), or between BBPNEW and 0 (bat was 31 : * transient or didn't exist at last commit). 32 : * Committing a bat switches from BBPNEW to BBPEXISTING, or turns off 33 : * BBPDELETED. 34 : * In any case, only at most one of BBPDELETED, BBPEXISTING, and 35 : * BBPNEW may be set at any one time. 36 : * 37 : * In short, 38 : * BBPEXISTING -- bat was and should remain persistent; 39 : * BBPDELETED -- bat was persistent at last commit and should be transient; 40 : * BBPNEW -- bat was transient at last commit and should be persistent; 41 : * none of the above -- bat was and should remain transient. 42 : */ 43 : #define BBPDELETED 16 /* set if bat persistent at last commit is now transient */ 44 : #define BBPEXISTING 32 /* set if bat was already persistent at end of last commit */ 45 : #define BBPNEW 64 /* set if bat has become persistent since last commit */ 46 : #define BBPPERSISTENT (BBPEXISTING|BBPNEW) /* mask for currently persistent bats */ 47 : 48 : #define BBPSTATUS 127 49 : 50 : #define BBPUNLOADING 128 /* set while we are unloading */ 51 : #define BBPLOADING 256 /* set while we are loading */ 52 : #define BBPSAVING 512 /* set while we are saving */ 53 : #define BBPRENAMED 1024 /* set when bat is renamed in this transaction */ 54 : #define BBPDELETING 2048 /* set while we are deleting (special case in module unload) */ 55 : #define BBPHOT 4096 /* bat is "hot", i.e. is still in active use */ 56 : #define BBPSYNCING 8192 /* bat between creating backup and saving */ 57 : 58 : #define BBPUNSTABLE (BBPUNLOADING|BBPDELETING) /* set while we are unloading */ 59 : #define BBPWAITING (BBPUNLOADING|BBPLOADING|BBPSAVING|BBPDELETING|BBPSYNCING) 60 : 61 : #define BBPTRIM_ALL (((size_t)1) << (sizeof(size_t)*8 - 2)) /* very large positive size_t */ 62 : 63 : gdk_export bat getBBPsize(void); /* current occupied size of BBP array */ 64 : gdk_export unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, bool allow_hge_upgrade); 65 : gdk_export int BBPreadBBPline(FILE *fp, unsigned bbpversion, int *lineno, BAT *bn, 66 : #ifdef GDKLIBRARY_HASHASH 67 : int *hashash, 68 : #endif 69 : char *batname, char *filename, char **options); 70 : 71 : /* global calls */ 72 : gdk_export gdk_return BBPaddfarm(const char *dirname, uint32_t rolemask, bool logerror); 73 : 74 : /* update interface */ 75 : gdk_export gdk_return BBPsave(BAT *b); 76 : gdk_export int BBPrename(BAT *b, const char *nme); 77 : 78 : /* query interface */ 79 : gdk_export bat BBPindex(const char *nme); 80 : 81 : /* swapping interface */ 82 : gdk_export int BBPfix(bat b); 83 : gdk_export int BBPunfix(bat b); 84 : static inline void 85 61716927 : BBPreclaim(BAT *b) 86 : { 87 59325260 : if (b != NULL) 88 58159612 : BBPunfix(b->batCacheid); 89 1630273 : } 90 : gdk_export int BBPretain(bat b); 91 : gdk_export int BBPrelease(bat b); 92 : gdk_export void BBPkeepref(BAT *b) 93 : __attribute__((__nonnull__(1))); 94 : gdk_export void BBPcold(bat i); 95 : gdk_export void BBPrelinquishbats(void); 96 : #ifdef GDKLIBRARY_JSON 97 : typedef gdk_return ((*json_storage_conversion)(char **, const char **)); 98 : gdk_export gdk_return BBPjson_upgrade(json_storage_conversion); 99 : #endif 100 : #define BBP_status_set(bid, mode) \ 101 : ATOMIC_SET(&BBP_record(bid).status, mode) 102 : 103 : #define BBP_status_on(bid, flags) \ 104 : ATOMIC_OR(&BBP_record(bid).status, flags) 105 : 106 : #define BBP_status_off(bid, flags) \ 107 : ATOMIC_AND(&BBP_record(bid).status, ~(flags)) 108 : 109 : #define BBPswappable(b) ((b) && (b)->batCacheid && BBP_refs((b)->batCacheid) == 0) 110 : #define BBPtrimmable(b) (BBPswappable(b) && isVIEW(b) == 0 && (BBP_status((b)->batCacheid)&BBPWAITING) == 0) 111 : 112 : #endif /* _GDK_BBP_H_ */