Changeset: ba31d0f46901 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ba31d0f46901
Modified Files:
        gdk/gdk_align.c
        gdk/gdk_bbp.c
Branch: Jan2022
Log Message:

Improve some view manipulation.
Don't unload views when refs goes down to zero.
Delete any heap files when a partial view (shared vheap, private tail)
is destroyed.
And a little cleanup.


diffs (115 lines):

diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -381,12 +381,18 @@ VIEWdestroy(BAT *b)
        VIEWunlink(b);
 
        MT_lock_set(&b->theaplock);
+       /* heaps that are left after VIEWunlink are ours, so need to be
+        * destroyed (and files deleted) */
        if (b->theap) {
-               HEAPdecref(b->theap, false);
+               HEAPdecref(b->theap, true);
                b->theap = NULL;
        }
        if (b->tvheap) {
-               HEAPdecref(b->tvheap, false);
+               /* should never happen: if this heap exists, then it was
+                * our own (not a view), and then it doesn't make sense
+                * that the offset heap was a view (at least one of them
+                * had to be) */
+               HEAPdecref(b->tvheap, true);
                b->tvheap = NULL;
        }
        MT_lock_unset(&b->theaplock);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1378,6 +1378,7 @@ BBPtrim(bool aggressive)
                    BBP_lrefs(bid) != 0 &&
                    (b = BBP_cache(bid)) != NULL &&
                    b->batSharecnt == 0 &&
+                   !isVIEW(b) &&
                    (!BATdirty(b) || (aggressive && b->theap->storage == 
STORE_MMAP && (b->tvheap == NULL || b->tvheap->storage == STORE_MMAP))) &&
                    !(BBP_status(bid) & flag) /*&&
                    (BBP_status(bid) & BBPPERSISTENT ||
@@ -1764,28 +1765,24 @@ BBPexit(void)
                                                skipped = true;
                                                continue;
                                        }
-                                       if (isVIEW(b)) {
-                                               /* "manually"
-                                                * decrement parent
-                                                * references, since
-                                                * VIEWdestroy doesn't
-                                                * (and can't here due
-                                                * to locks) do it */
-                                               bat tp = VIEWtparent(b);
-                                               bat vtp = VIEWvtparent(b);
-                                               if (tp) {
-                                                       
BBP_desc(tp)->batSharecnt--;
-                                                       --BBP_lrefs(tp);
-                                               }
-                                               if (vtp) {
-                                                       
BBP_desc(vtp)->batSharecnt--;
-                                                       --BBP_lrefs(vtp);
-                                               }
-                                               VIEWdestroy(b);
-                                       } else {
-                                               PROPdestroy(b);
-                                               BATfree(b);
+                                       MT_lock_set(&b->theaplock);
+                                       bat tp = VIEWtparent(b);
+                                       if (tp != 0) {
+                                               BBP_desc(tp)->batSharecnt--;
+                                               --BBP_lrefs(tp);
+                                               HEAPdecref(b->theap, false);
+                                               b->theap = NULL;
                                        }
+                                       tp = VIEWvtparent(b);
+                                       if (tp != 0) {
+                                               BBP_desc(tp)->batSharecnt--;
+                                               --BBP_lrefs(tp);
+                                               HEAPdecref(b->tvheap, false);
+                                               b->tvheap = NULL;
+                                       }
+                                       MT_lock_unset(&b->theaplock);
+                                       PROPdestroy(b);
+                                       BATfree(b);
                                }
                                BBP_pid(i) = 0;
                                BBPuncacheit(i, true);
@@ -3171,7 +3168,7 @@ BBPreclaim(BAT *b)
 
        assert(BBP_refs(i) == 1);
 
-       return decref(i, false, false, lock, __func__) <0;
+       return decref(i, false, false, lock, __func__) < 0;
 }
 
 /*
@@ -3346,20 +3343,16 @@ BBPfree(BAT *b)
 
        assert(bid > 0);
        assert(BBPswappable(b));
+       assert(!isVIEW(b));
 
        BBP_unload_inc();
-       /* write dirty BATs before being unloaded */
+       /* write dirty BATs before unloading */
        ret = BBPsave(b);
        if (ret == GDK_SUCCEED) {
-               if (isVIEW(b)) {        /* physical view */
-                       VIEWdestroy(b);
-               } else {
-                       if (BBP_cache(bid))
-                               BATfree(b);     /* free memory */
-               }
+               if (BBP_cache(bid))
+                       BATfree(b);     /* free memory */
                BBPuncacheit(bid, false);
        }
-       /* clearing bits can be done without the lock */
        TRC_DEBUG(BAT_, "turn off unloading %d\n", bid);
        BBP_status_off(bid, BBPUNLOADING);
        BBP_unload_dec();
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to