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, 2025 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 : gdk_export bat getBBPsize(void); /* current occupied size of BBP array */ 62 : gdk_export unsigned BBPheader(FILE *fp, int *lineno, bat *bbpsize, lng *logno, bool allow_hge_upgrade); 63 : gdk_export int BBPreadBBPline(FILE *fp, unsigned bbpversion, int *lineno, BAT *bn, 64 : #ifdef GDKLIBRARY_HASHASH 65 : int *hashash, 66 : #endif 67 : char *batname, char *filename, char **options); 68 : 69 : /* global calls */ 70 : gdk_export gdk_return BBPaddfarm(const char *dirname, uint32_t rolemask, bool logerror); 71 : 72 : /* update interface */ 73 : gdk_export gdk_return BBPsave(BAT *b); 74 : gdk_export int BBPrename(BAT *b, const char *nme); 75 : 76 : /* query interface */ 77 : gdk_export bat BBPindex(const char *nme); 78 : 79 : /* swapping interface */ 80 : gdk_export int BBPfix(bat b); 81 : gdk_export int BBPunfix(bat b); 82 : static inline void 83 74601320 : BBPreclaim(BAT *b) 84 : { 85 71090101 : if (b != NULL) 86 68004491 : BBPunfix(b->batCacheid); 87 1747944 : } 88 : gdk_export int BBPretain(bat b); 89 : gdk_export int BBPrelease(bat b); 90 : gdk_export void BBPkeepref(BAT *b) 91 : __attribute__((__nonnull__(1))); 92 : gdk_export void BBPcold(bat i); 93 : gdk_export void BBPrelinquishbats(void); 94 : #ifdef GDKLIBRARY_JSON 95 : typedef gdk_return ((*json_storage_conversion)(char **, const char **)); 96 : gdk_export gdk_return BBPjson_upgrade(json_storage_conversion); 97 : #endif 98 : #define BBP_status_set(bid, mode) \ 99 : ATOMIC_SET(&BBP_record(bid).status, mode) 100 : 101 : #define BBP_status_on(bid, flags) \ 102 : ATOMIC_OR(&BBP_record(bid).status, flags) 103 : 104 : #define BBP_status_off(bid, flags) \ 105 : ATOMIC_AND(&BBP_record(bid).status, ~(flags)) 106 : 107 : #define BBPswappable(b) ((b) && (b)->batCacheid && BBP_refs((b)->batCacheid) == 0) 108 : #define BBPtrimmable(b) (BBPswappable(b) && isVIEW(b) == 0 && (BBP_status((b)->batCacheid)&BBPWAITING) == 0) 109 : 110 : #endif /* _GDK_BBP_H_ */