1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#ifndef _GDK_BBP_H_
10#define _GDK_BBP_H_
11
12#define BBPLOADED 1 /* set if bat in memory */
13#define BBPSWAPPED 2 /* set if dirty bat is not in memory */
14#define BBPTMP 4 /* set if non-persistent bat has image on disk */
15
16/* These 4 symbols indicate what the persistence state is of a bat.
17 * - If the bat was persistent at the last commit (or at startup
18 * before the first commit), BBPEXISTING or BBPDELETED is set.
19 * - If the bat is to be persistent after the next commit, BBPEXISTING
20 * or BBPNEW is set (i.e. (status&BBPPERSISTENT) != 0).
21 * - If the bat was transient at the last commit (or didn't exist),
22 * BBPNEW is set, or none of these flag values is set.
23 * - If the bat is to be transient at the next commit, BBPDELETED is
24 * set, or none of these flag values is set.
25 * BATmode() switches between BBPDELETED and BBPEXISTING (bat was
26 * persistent at last commit), or between BBPNEW and 0 (bat was
27 * transient or didn't exist at last commit).
28 * Committing a bat switches from BBPNEW to BBPEXISTING, or turns off
29 * BBPDELETED.
30 * In any case, only at most one of BBPDELETED, BBPEXISTING, and
31 * BBPNEW may be set at any one time.
32 *
33 * In short,
34 * BBPEXISTING -- bat was and should remain persistent;
35 * BBPDELETED -- bat was persistent at last commit and should be transient;
36 * BBPNEW -- bat was transient at last commit and should be persistent;
37 * none of the above -- bat was and should remain transient.
38 */
39#define BBPDELETED 16 /* set if bat persistent at last commit is now transient */
40#define BBPEXISTING 32 /* set if bat was already persistent at end of last commit */
41#define BBPNEW 64 /* set if bat has become persistent since last commit */
42#define BBPPERSISTENT (BBPEXISTING|BBPNEW) /* mask for currently persistent bats */
43
44#define BBPSTATUS 127
45
46#define BBPUNLOADING 128 /* set while we are unloading */
47#define BBPLOADING 256 /* set while we are loading */
48#define BBPSAVING 512 /* set while we are saving */
49#define BBPRENAMED 1024 /* set when bat is renamed in this transaction */
50#define BBPDELETING 2048 /* set while we are deleting (special case in module unload) */
51#define BBPUNSTABLE (BBPUNLOADING|BBPDELETING) /* set while we are unloading */
52#define BBPWAITING (BBPUNLOADING|BBPLOADING|BBPSAVING|BBPDELETING)
53
54#define BBPTRIM_ALL (((size_t)1) << (sizeof(size_t)*8 - 2)) /* very large positive size_t */
55
56gdk_export bat getBBPsize(void); /* current occupied size of BBP array */
57
58/* global calls */
59gdk_export gdk_return BBPaddfarm(const char *dirname, int rolemask);
60
61/* update interface */
62gdk_export void BBPclear(bat bid);
63gdk_export int BBPreclaim(BAT *b);
64gdk_export gdk_return BBPsave(BAT *b);
65gdk_export int BBPrename(bat bid, const char *nme);
66
67/* query interface */
68gdk_export bat BBPindex(const char *nme);
69gdk_export BAT *BBPdescriptor(bat b);
70
71/* swapping interface */
72gdk_export gdk_return BBPsync(int cnt, bat *subcommit);
73gdk_export int BBPfix(bat b);
74gdk_export int BBPunfix(bat b);
75gdk_export int BBPretain(bat b);
76gdk_export int BBPrelease(bat b);
77gdk_export void BBPkeepref(bat i);
78gdk_export void BBPshare(bat b);
79
80#define BBPtmpcheck(s) (strncmp(s, "tmp_", 4) == 0)
81
82#define BBP_status_set(bid, mode, nme) \
83 do { \
84 BBP_status(bid) = mode; \
85 } while (0)
86
87#define BBP_status_on(bid, flags, nme) \
88 BBP_status_set(bid, BBP_status(bid) | flags, nme)
89
90#define BBP_status_off(bid, flags, nme) \
91 BBP_status_set(bid, BBP_status(bid) & ~(flags), nme)
92
93#define BBPswappable(b) ((b) && (b)->batCacheid && BBP_refs((b)->batCacheid) == 0)
94#define BBPtrimmable(b) (BBPswappable(b) && isVIEW(b) == 0 && (BBP_status((b)->batCacheid)&BBPWAITING) == 0)
95
96#endif /* _GDK_BBP_H_ */
97