Changeset: c04c9d6d5856 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c04c9d6d5856
Modified Files:
        gdk/gdk_bat.c
        gdk/gdk_string.c
        monetdb5/modules/mal/mat.c
Branch: ustr
Log Message:

Fix deadlock; allow ustr on transient; keep ustr for longer (mat.packIncrement).


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
@@ -809,8 +809,7 @@ COLcopy2(BAT *b, int tt, bool writable, 
                goto bunins_failed;
        }
        if (b->ustr &&
-           mayshare &&
-           role == PERSISTENT) {
+           mayshare) {
                BAT *bu = BATdescriptor(b->ustr);
                gdk_return rc = BATconvert2ustr(bn, bu);
                BBPreclaim(bu);
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -181,7 +181,6 @@ ustrPut(BAT *b, var_t *dst, const char *
        }
 
        BAT *ustrbat = BBP_desc(b->ustr);
-       assert(ustrbat->tvkey);
 
        /* this function is the ONLY place where ustrbat may be changed
         * (inserted into), and we're holding the ustrbat->theaplock, so we are
@@ -189,6 +188,7 @@ ustrPut(BAT *b, var_t *dst, const char *
        (void) BATcheckhash(ustrbat); /* load hash table */
        MT_rwlock_wrlock(&ustrbat->thashlock);
        MT_lock_set(&ustrbat->theaplock);
+       assert(ustrbat->tvkey);
        BUN p = BUN_NONE;
        if (ustrbat->batCount != 0) {
                BATiter ui = bat_iterator_nolock(ustrbat);
@@ -283,11 +283,6 @@ BATconvert2ustr(BAT *b, BAT *bu)
                GDKerror("BAT must be a string BAT to convert to ustr\n");
                return GDK_FAIL;
        }
-       if (b->batRole != PERSISTENT) {
-               MT_lock_unset(&b->theaplock);
-               GDKerror("BAT must be in persistent farm to convert to ustr\n");
-               return GDK_FAIL;
-       }
        MT_lock_set(&bu->theaplock);
        if (!bu->tvkey) {
                MT_lock_unset(&b->theaplock);
@@ -301,14 +296,15 @@ BATconvert2ustr(BAT *b, BAT *bu)
                GDKerror("USTR BAT must not itself be ustr\n");
                return GDK_FAIL;
        }
-       BBPfix(bu->batCacheid);
+       assert(bu->tvheap->parentid == bu->batCacheid);
        b->ustr = bu->batCacheid;
        Heap *vh = b->tvheap;
        b->tvheap = bu->tvheap;
        HEAPincref(b->tvheap);
-       BBPretain(b->tvheap->parentid);
        MT_lock_unset(&bu->theaplock);
        MT_lock_unset(&b->theaplock);
+       BBPfix(bu->batCacheid);
+       BBPretain(bu->batCacheid);
        if (vh)
                HEAPdecref(vh, true);
        return GDK_SUCCEED;
diff --git a/monetdb5/modules/mal/mat.c b/monetdb5/modules/mal/mat.c
--- a/monetdb5/modules/mal/mat.c
+++ b/monetdb5/modules/mal/mat.c
@@ -143,6 +143,15 @@ MATpackIncrement(Client cntxt, MalBlkPtr
                        BBPunfix(b->batCacheid);
                        throw(MAL, "mat.pack", SQLSTATE(HY013) MAL_MALLOC_FAIL);
                }
+               if (tt == TYPE_str && b->ustr) {
+                       MT_thread_setalgorithm("convert to ustr");
+                       BAT *bu = BATdescriptor(b->ustr);
+                       gdk_return rc = BATconvert2ustr(bn, bu);
+                       BBPreclaim(bu);
+                       if (rc != GDK_SUCCEED)
+                               TRC_WARNING(GDK, "convert to ustr failed");
+               }
+
                /* allocate enough space for the vheap, but not for strings,
                 * since BATappend does clever things for strings, and not for
                 * vheap views since they may well get shared */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to