Changeset: 60aac578a655 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/60aac578a655
Modified Files:
        gdk/ChangeLog
        gdk/gdk.h
        gdk/gdk_aggr.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_group.c
        gdk/gdk_rtree.c
        gdk/gdk_select.c
        gdk/gdk_storage.c
        gdk/gdk_tm.c
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/mal/bbp.c
Branch: default
Log Message:

Removed BBP_cache.  Use BBP_status(bid)&BBPLOADED to see whether loaded 
(cached).


diffs (truncated from 438 to 300 lines):

diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -1,6 +1,12 @@
 # ChangeLog file for GDK
 # This file is updated with Maddlog
 
+* Tue Mar 26 2024 Sjoerd Mullender <sjo...@acm.org>
+- Removed macro BBP_cache and its associated code.  Checking whether a
+  BAT is cached (loaded in memory) can be done by checking the BBPLOADED
+  bit in the BBP_status value.  Getting a pointer to the BAT descriptor
+  can be done by using BBP_desc.
+
 * Tue Feb  6 2024 Sjoerd Mullender <sjo...@acm.org>
 - The SQL transaction ID is no longer saved in the BBP.dir file.
 
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -956,7 +956,6 @@ gdk_export void HEAPincref(Heap *h);
  * field.
  */
 typedef struct {
-       BAT *cache;             /* if loaded: BAT* handle */
        char *logical;          /* logical name (may point at bak) */
        char bak[16];           /* logical name backup (tmp_%o) */
        BAT *desc;              /* the BAT descriptor */
@@ -993,7 +992,6 @@ gdk_export BBPrec *BBP[N_BBPINIT];
 
 /* fast defines without checks; internal use only  */
 #define BBP_record(i)  BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)]
-#define BBP_cache(i)   BBP_record(i).cache
 #define BBP_logical(i) BBP_record(i).logical
 #define BBP_bak(i)     BBP_record(i).bak
 #define BBP_next(i)    BBP_record(i).next
@@ -1005,7 +1003,7 @@ gdk_export BBPrec *BBP[N_BBPINIT];
 #define BBP_status(i)  ((unsigned) ATOMIC_GET(&BBP_record(i).status))
 #define BBP_pid(i)     BBP_record(i).pid
 #define BATgetId(b)    BBP_logical((b)->batCacheid)
-#define BBPvalid(i)    (BBP_logical(i) != NULL && *BBP_logical(i) != '.')
+#define BBPvalid(i)    (BBP_logical(i) != NULL)
 
 #define BBPRENAME_ALREADY      (-1)
 #define BBPRENAME_ILLEGAL      (-2)
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -3675,7 +3675,6 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
                                if ((pb == NULL || bi.count == BATcount(pb)) &&
                                    BATcheckimprints(b)) {
                                        if (pb != NULL) {
-                                               BAT *pb = 
BBP_cache(VIEWtparent(b));
                                                MT_lock_set(&pb->batIdxLock);
                                                imprints = pb->timprints;
                                                if (imprints != NULL)
@@ -3842,7 +3841,6 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
                                if ((pb == NULL || BATcount(b) == BATcount(pb)) 
&&
                                    BATcheckimprints(b)) {
                                        if (pb != NULL) {
-                                               BAT *pb = 
BBP_cache(VIEWtparent(b));
                                                MT_lock_set(&pb->batIdxLock);
                                                imprints = pb->timprints;
                                                if (imprints != NULL)
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2686,7 +2686,7 @@ BATassertProps(BAT *b)
        assert(b != NULL);
        assert(b->batCacheid > 0);
        assert(b->batCacheid < getBBPsize());
-       assert(b == BBP_cache(b->batCacheid));
+       assert(b == BBP_desc(b->batCacheid));
        assert(b->batCount >= b->batInserted);
 
        /* headless */
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -2154,7 +2154,7 @@ BATordered(BAT *b)
        bat pbid = VIEWtparent(b);
        MT_lock_unset(&b->theaplock);
        if (pbid) {
-               BAT *pb = BBP_cache(pbid);
+               BAT *pb = BBP_desc(pbid);
                MT_lock_set(&pb->theaplock);
                if (bi.count == BATcount(pb) &&
                    bi.h == pb->theap &&
@@ -2273,7 +2273,7 @@ BATordered_rev(BAT *b)
        bat pbid = VIEWtparent(b);
        MT_lock_unset(&b->theaplock);
        if (pbid) {
-               BAT *pb = BBP_cache(pbid);
+               BAT *pb = BBP_desc(pbid);
                MT_lock_set(&pb->theaplock);
                if (bi.count == BATcount(pb) &&
                    bi.h == pb->theap &&
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1757,10 +1757,10 @@ BBPtrim(bool aggressive, bat nbat)
                MT_lock_set(&GDKswapLock(bid));
                BAT *b = NULL;
                bool swap = false;
-               if (!(BBP_status(bid) & flag) &&
+               if ((BBP_status(bid) & (flag | BBPLOADED)) == BBPLOADED &&
                    BBP_refs(bid) == 0 &&
                    BBP_lrefs(bid) != 0 &&
-                   (b = BBP_cache(bid)) != NULL) {
+                   (b = BBP_desc(bid)) != NULL) {
                        MT_lock_set(&b->theaplock);
                        if (!BATshared(b) &&
                            !isVIEW(b) &&
@@ -2561,7 +2561,7 @@ BBPdump(void)
                       BBP_refs(i),
                       BBP_lrefs(i),
                       status,
-                      BBP_cache(i) ? "" : " not cached");
+                      status & BBPLOADED ? "" : " not cached");
                if (b == NULL) {
                        printf(", no descriptor\n");
                        continue;
@@ -2762,7 +2762,6 @@ BBPinsert(BAT *bn)
 
        MT_lock_set(&GDKswapLock(i));
        BBP_status_set(i, BBPDELETING|BBPHOT);
-       BBP_cache(i) = NULL;
        BBP_desc(i) = bn;
        BBP_refs(i) = 1;        /* new bats have 1 pin */
        BBP_lrefs(i) = 0;       /* ie. no logical refs */
@@ -2802,8 +2801,6 @@ BBPcacheit(BAT *bn, bool lock)
        mode = (BBP_status(i) | BBPLOADED) & ~(BBPLOADING | BBPDELETING | 
BBPSWAPPED);
 
        /* cache it! */
-       BBP_cache(i) = bn;
-
        BBP_status_set(i, mode);
 
        if (lock)
@@ -2828,13 +2825,11 @@ BBPuncacheit(bat i, bool unloaddesc)
                assert(unloaddesc || BBP_refs(i) == 0);
 
                if (b) {
-                       if (BBP_cache(i)) {
+                       if (BBP_status(i) & BBPLOADED) {
                                TRC_DEBUG(BAT_, "uncache %d (%s)\n", (int) i, 
BBP_logical(i));
 
                                /* clearing bits can be done without the lock */
                                BBP_status_off(i, BBPLOADED);
-
-                               BBP_cache(i) = NULL;
                        }
                        if (unloaddesc) {
                                BBP_desc(i) = NULL;
@@ -3184,7 +3179,7 @@ decref(bat i, bool logical, bool lock, c
                        MT_lock_set(&GDKswapLock(i));
        }
 
-       b = BBP_cache(i);
+       b = (BBP_status(i) & BBPLOADED) ? BBP_desc(i) : NULL;
 
        /* decrement references by one */
        if (logical) {
@@ -3357,14 +3352,15 @@ BATdescriptor(bat i)
                        }
                }
                if (incref(i, false, false) > 0) {
-                       b = BBP_cache(i);
-                       if (b == NULL) {
+                       if ((BBP_status(i) & BBPLOADED) == 0) {
                                b = getBBPdescriptor(i);
                                if (b == NULL) {
                                        /* if loading failed, we need to
                                         * compensate for the incref */
                                        decref(i, false, false, __func__);
                                }
+                       } else {
+                               b = BBP_desc(i);
                        }
                }
                if (lock)
@@ -3390,16 +3386,16 @@ getBBPdescriptor(bat i)
                return NULL;
        }
        assert(BBP_refs(i));
-       if ((b = BBP_cache(i)) == NULL || BBP_status(i) & BBPWAITING) {
-
+       unsigned status = BBP_status(i);
+       b = BBP_desc(i);
+       if ((status & BBPLOADED) == 0 || status & BBPWAITING) {
                while (BBP_status(i) & BBPWAITING) {    /* wait for bat to be 
loaded by other thread */
                        MT_lock_unset(&GDKswapLock(i));
                        BBPspin(i, __func__, BBPWAITING);
                        MT_lock_set(&GDKswapLock(i));
                }
                if (BBPvalid(i)) {
-                       b = BBP_cache(i);
-                       if (b == NULL) {
+                       if ((BBP_status(i) & BBPLOADED) == 0) {
                                load = true;
                                TRC_DEBUG(BAT_, "set to loading BAT %d\n", i);
                                BBP_status_on(i, BBPLOADING);
@@ -3411,7 +3407,6 @@ getBBPdescriptor(bat i)
 
                b = BATload_intern(i, false);
 
-               /* clearing bits can be done without the lock */
                BBP_status_off(i, BBPLOADING);
                CHECKDEBUG if (b != NULL)
                        BATassertProps(b);
@@ -3541,7 +3536,7 @@ BBPfree(BAT *b)
        /* write dirty BATs before unloading */
        ret = BBPsave(b);
        if (ret == GDK_SUCCEED) {
-               if (BBP_cache(bid))
+               if (BBP_status(bid) & BBPLOADED)
                        BATfree(b);     /* free memory */
                BBPuncacheit(bid, false);
        }
@@ -3597,8 +3592,8 @@ dirty_bat(bat *i, bool subcommit)
        if (BBPvalid(*i)) {
                BAT *b;
                BBPspin(*i, __func__, BBPSAVING);
-               b = BBP_cache(*i);
-               if (b != NULL) {
+               if (BBP_status(*i) & BBPLOADED) {
+                       b = BBP_desc(*i);
                        MT_lock_set(&b->theaplock);
                        if ((BBP_status(*i) & BBPNEW) &&
                            BATcheckmodes(b, false) != GDK_SUCCEED) /* check 
mmap modes */
@@ -4503,9 +4498,9 @@ static bool
 persistent_bat(bat bid)
 {
        if (bid >= 0 && bid < (bat) ATOMIC_GET(&BBPsize) && BBPvalid(bid)) {
-               BAT *b = BBP_cache(bid);
-
-               if (b == NULL || b->batCopiedtodisk) {
+               BAT *b;
+               if ((BBP_status(bid) & BBPLOADED) == 0 ||
+                   ((b = BBP_desc(bid)) != NULL && b->batCopiedtodisk)) {
                        return true;
                }
        }
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -1040,7 +1040,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                    (/* DISABLES CODE */ (0) &&
                     (parent = VIEWtparent(b)) != 0 &&
 /* if enabled, need to fix/unfix parent bat */
-                    BATcheckhash(BBP_cache(parent))))) {
+                    BATcheckhash(BBP_desc(parent))))) {
                /* we already have a hash table on b, or b is
                 * persistent and we could create a hash table, or b
                 * is a view on a bat that already has a hash table;
@@ -1058,7 +1058,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                         * calculate the bounds [lo, lo+BATcount(b))
                         * in the parent that b uses */
 /* if enabled, need to fix/unfix parent bat */
-                       BAT *b2 = BBP_cache(parent);
+                       BAT *b2 = BBP_desc(parent);
                        MT_rwlock_rdunlock(&b->thashlock);
                        lo = b->tbaseoff - b2->tbaseoff;
                        b = b2;
diff --git a/gdk/gdk_rtree.c b/gdk/gdk_rtree.c
--- a/gdk/gdk_rtree.c
+++ b/gdk/gdk_rtree.c
@@ -162,7 +162,7 @@ RTREEexists(BAT *b)
        BAT *pb;
        bool ret;
        if (VIEWtparent(b)) {
-               pb = BBP_cache(VIEWtparent(b));
+               pb = BBP_desc(VIEWtparent(b));
                assert(pb);
        } else {
                pb = b;
@@ -198,7 +198,7 @@ BATrtree(BAT *wkb, BAT *mbr)
 
        //Check for a parent BAT of wkb, load if exists
        if (VIEWtparent(wkb)) {
-               pb = BBP_cache(VIEWtparent(wkb));
+               pb = BBP_desc(VIEWtparent(wkb));
                assert(pb);
        } else {
                pb = wkb;
@@ -254,7 +254,7 @@ RTREEfree(BAT *b)
 {
        BAT *pb;
        if (VIEWtparent(b)) {
-               pb = BBP_cache(VIEWtparent(b));
+               pb = BBP_desc(VIEWtparent(b));
                assert(pb);
        } else {
                pb = b;
@@ -275,7 +275,7 @@ RTREEdestroy(BAT *b)
 {
        BAT *pb;
        if (VIEWtparent(b)) {
-               pb = BBP_cache(VIEWtparent(b));
+               pb = BBP_desc(VIEWtparent(b));
                assert(pb);
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to