Changeset: 479eaf929a72 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/479eaf929a72
Modified Files:
        gdk/gdk_bat.c
        gdk/gdk_heap.c
Branch: default
Log Message:

Use BATextend to extend string offset heap when not widening.
Also check heap ref count when extending to see whether we can do it
"in place".


diffs (81 lines):

diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -517,6 +517,7 @@ gdk_return
 BATextend(BAT *b, BUN newcap)
 {
        size_t theap_size;
+       gdk_return rc = GDK_SUCCEED;
 
        assert(newcap <= BUN_MAX);
        BATcheck(b, GDK_FAIL);
@@ -544,17 +545,21 @@ BATextend(BAT *b, BUN newcap)
        if (b->theap->base) {
                TRC_DEBUG(HEAP, "HEAPgrow in BATextend %s %zu %zu\n",
                          b->theap->filename, b->theap->size, theap_size);
-               if (b->ttype == TYPE_str)
-                       return GDKupgradevarheap(b, GDK_VAROFFSET, newcap, 
false);
-               Heap *h = HEAPgrow(b->theap, theap_size);
-               if (h == NULL)
-                       return GDK_FAIL;
                MT_lock_set(&b->theaplock);
-               HEAPdecref(b->theap, false);
-               b->theap = h;
+               if (ATOMIC_GET(&b->theap->refs) == 1) {
+                       rc = HEAPextend(b->theap, theap_size, true);
+               } else {
+                       MT_lock_unset(&b->theaplock);
+                       Heap *h = HEAPgrow(b->theap, theap_size);
+                       if (h == NULL)
+                               return GDK_FAIL;
+                       MT_lock_set(&b->theaplock);
+                       HEAPdecref(b->theap, false);
+                       b->theap = h;
+               }
                MT_lock_unset(&b->theaplock);
        }
-       return GDK_SUCCEED;
+       return rc;
 }
 
 
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -432,12 +432,13 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
                newsize = cap << shift;
        else
                newsize = (old->size >> b->tshift) << shift;
-       if (b->twidth == width && newsize <= old->size) {
-               /* nothing to do */
-               return GDK_SUCCEED;
+       if (b->twidth == width) {
+               if (newsize <= old->size) {
+                       /* nothing to do */
+                       return GDK_SUCCEED;
+               }
+               return BATextend(b, newsize >> shift);
        }
-       if (width > b->twidth)
-               MT_thread_setalgorithm("widen offset heap");
 
        /* if copyall is set, we need to convert the whole heap, since
         * we may be in the middle of an insert loop that adjusts the
@@ -445,6 +446,8 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
         * indicated by the "free" pointer */
        n = (copyall ? old->size : old->free) >> b->tshift;
 
+       if (width > b->twidth)
+               MT_thread_setalgorithm(n ? "widen offset heap" : "widen empty 
offset heap");
        /* Create a backup copy before widening.
         *
         * If the file is memory-mapped, this solves a problem that we
@@ -462,7 +465,7 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
        else
                filename++;
        int exists = 0;
-       if (BBP_status(bid) & (BBPEXISTING|BBPDELETED)) {
+       if (BBP_status(bid) & (BBPEXISTING|BBPDELETED) && width > b->twidth) {
                char fname[sizeof(old->filename)];
                char *p = strrchr(old->filename, DIR_SEP);
                strcpy_len(fname, p ? p + 1 : old->filename, sizeof(fname));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to