Changeset: 159862acbca7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/159862acbca7
Modified Files:
        sql/storage/bat/bat_storage.c
Branch: iso
Log Message:

Merged with Jul2021


diffs (truncated from 321 to 300 lines):

diff --git a/common/stream/stdio_stream.c b/common/stream/stdio_stream.c
--- a/common/stream/stdio_stream.c
+++ b/common/stream/stdio_stream.c
@@ -31,9 +31,8 @@ file_read(stream *restrict s, void *rest
                return -1;
        }
 
-       if (elmsize && cnt && !feof(fp)) {
-               if (ferror(fp) ||
-                   ((rc = fread(buf, elmsize, cnt, fp)) == 0 && ferror(fp))) {
+       if (elmsize && cnt) {
+               if ((rc = fread(buf, elmsize, cnt, fp)) == 0 && ferror(fp)) {
                        mnstr_set_error_errno(s, MNSTR_READ_ERROR, "read 
error");
                        return -1;
                }
@@ -55,7 +54,7 @@ file_write(stream *restrict s, const voi
        if (elmsize && cnt) {
                size_t rc = fwrite(buf, elmsize, cnt, fp);
 
-               if (ferror(fp)) {
+               if (!rc && ferror(fp)) {
                        mnstr_set_error_errno(s, MNSTR_WRITE_ERROR, "write 
error");
                        return -1;
                }
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -2295,6 +2295,8 @@ BATmode(BAT *b, bool transient)
        /* can only make a bat PERSISTENT if its role is already
         * PERSISTENT */
        assert(transient || b->batRole == PERSISTENT);
+       /* cannot make a view PERSISTENT */
+       assert(transient || !isVIEW(b));
 
        if (b->batRole == TRANSIENT && !transient) {
                GDKerror("cannot change mode of BAT in TRANSIENT farm.\n");
@@ -2308,11 +2310,6 @@ BATmode(BAT *b, bool transient)
                        check_type(b->ttype);
                }
 
-               if (!transient && isVIEW(b)) {
-                       if (VIEWreset(b) != GDK_SUCCEED) {
-                               return GDK_FAIL;
-                       }
-               }
                /* persistent BATs get a logical reference */
                if (!transient) {
                        BBPretain(bid);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1800,6 +1800,7 @@ maybeextend(int idx)
                                        BBP_free(m) = BBP_next(i);
                                        BBP_next(i) = 0;
                                        BBP_free(idx) = i;
+                                       GDKclrerr();
                                } else {
                                        /* nothing available */
                                        return GDK_FAIL;
@@ -1885,8 +1886,10 @@ BBPinsert(BAT *bn)
 
        if (*BBP_bak(i) == 0)
                len = snprintf(BBP_bak(i), sizeof(BBP_bak(i)), "tmp_%o", 
(unsigned) i);
-       if (len == -1 || len >= FILENAME_MAX)
+       if (len == -1 || len >= FILENAME_MAX) {
+               GDKerror("impossible error\n");
                return 0;
+       }
        BBP_logical(i) = BBP_bak(i);
 
        /* Keep the physical location around forever */
@@ -2355,6 +2358,17 @@ decref(bat i, bool logical, bool release
                        }
                }
        }
+       if (b && b->batCount > b->batInserted) {
+               /* if batCount is larger than batInserted and the dirty
+                * bits are off, it may be that a (sub)commit happened
+                * in parallel to an update; we must undo the turning
+                * off of the dirty bits */
+               b->batDirtydesc = true;
+               if (b->theap)
+                       b->theap->dirty = true;
+               if (b->tvheap)
+                       b->tvheap->dirty = true;
+       }
 
        /* we destroy transients asap and unload persistent bats only
         * if they have been made cold or are not dirty */
@@ -2497,13 +2511,14 @@ getBBPdescriptor(bat i, bool lock)
 
        assert(i > 0);
        if (!BBPcheck(i, "BBPdescriptor")) {
+               GDKerror("BBPcheck failed for bat id %d\n", i);
                return NULL;
        }
        assert(BBP_refs(i));
-       if ((b = BBP_cache(i)) == NULL) {
-
-               if (lock)
-                       MT_lock_set(&GDKswapLock(i));
+       if (lock)
+               MT_lock_set(&GDKswapLock(i));
+       if ((b = BBP_cache(i)) == NULL || BBP_status(i) & BBPWAITING) {
+
                while (BBP_status(i) & BBPWAITING) {    /* wait for bat to be 
loaded by other thread */
                        if (lock)
                                MT_lock_unset(&GDKswapLock(i));
@@ -2519,9 +2534,9 @@ getBBPdescriptor(bat i, bool lock)
                                BBP_status_on(i, BBPLOADING);
                        }
                }
-               if (lock)
-                       MT_lock_unset(&GDKswapLock(i));
        }
+       if (lock)
+               MT_lock_unset(&GDKswapLock(i));
        if (load) {
                TRC_DEBUG(IO_, "load %s\n", BBPname(i));
 
diff --git a/gdk/gdk_bbp.h b/gdk/gdk_bbp.h
--- a/gdk/gdk_bbp.h
+++ b/gdk/gdk_bbp.h
@@ -48,11 +48,11 @@
 #define BBPSAVING       512    /* set while we are saving */
 #define BBPRENAMED     1024    /* set when bat is renamed in this transaction 
*/
 #define BBPDELETING    2048    /* set while we are deleting (special case in 
module unload) */
-#define BBPUNSTABLE    (BBPUNLOADING|BBPDELETING)      /* set while we are 
unloading */
-#define BBPWAITING      (BBPUNLOADING|BBPLOADING|BBPSAVING|BBPDELETING)
+#define BBPHOT         4096    /* bat is "hot", i.e. is still in active use */
+#define BBPSYNCING     8192    /* bat between creating backup and saving */
 
-#define BBPHOT         4096    /* bat is "hot", i.e. is still in active use */
-#define BBPSYNCING     8192
+#define BBPUNSTABLE    (BBPUNLOADING|BBPDELETING)      /* set while we are 
unloading */
+#define BBPWAITING      
(BBPUNLOADING|BBPLOADING|BBPSAVING|BBPDELETING|BBPSYNCING)
 
 #define BBPTRIM_ALL    (((size_t)1) << (sizeof(size_t)*8 - 2)) /* very large 
positive size_t */
 
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -559,6 +559,7 @@ GDKload(int farmid, const char *nme, con
                                        /* we couldn't read all, error
                                         * already generated */
                                        GDKfree(ret);
+                                       GDKerror("short read from heap %s%s\n", 
nme, ext ? ext : "");
                                        ret = NULL;
                                }
 #ifndef NDEBUG
@@ -640,8 +641,10 @@ DESCload(int i)
 
        b = BBP_desc(i);
 
-       if (b == NULL)
+       if (b == NULL) {
+               GDKerror("no descriptor for BAT %d\n", i);
                return NULL;
+       }
 
        tt = b->ttype;
        if ((tt < 0 && (tt = ATOMindex(s = ATOMunknown_name(tt))) < 0)) {
@@ -779,8 +782,8 @@ BATsave(BAT *bd)
        /* copy the descriptor to a local variable in order to let our
         * messing in the BAT descriptor not affect other threads that
         * only read it. */
+       MT_rwlock_rdlock(&bd->thashlock);
        MT_lock_set(&bd->theaplock);
-       MT_rwlock_rdlock(&bd->thashlock);
        BAT bs = *bd;
        BAT *b = &bs;
        Heap hs = *bd->theap;
diff --git a/gdk/gdk_tm.c b/gdk/gdk_tm.c
--- a/gdk/gdk_tm.c
+++ b/gdk/gdk_tm.c
@@ -205,8 +205,7 @@ TMsubcommit_list(bat *restrict subcommit
                }
        }
        if (prelude(cnt, subcommit, sizes) == GDK_SUCCEED) {    /* save the new 
bats outside the lock */
-               /* lock just prevents BBPtrims, and other global
-                * (sub-)commits */
+               /* lock just prevents other global (sub-)commits */
                MT_lock_set(&GDKtmLock);
                if (BBPsync(cnt, subcommit, sizes, logno, transid) == 
GDK_SUCCEED) { /* write BBP.dir (++) */
                        epilogue(cnt, subcommit);
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -315,7 +315,8 @@ segments2cs(sql_trans *tr, segments *seg
        if (nr >= BATcapacity(b) && BATextend(b, nr) != GDK_SUCCEED)
                return LOG_ERR;
 
-       BATsetcount(b, nr);
+       if (nr > BATcount(b))
+               BATsetcount(b, nr);
 
        /* disable all properties here */
        b->tsorted = false;
@@ -330,6 +331,7 @@ segments2cs(sql_trans *tr, segments *seg
        uint32_t *restrict dst;
        for (; s ; s=s->next) {
                if (s->ts == tr->tid && s->end != s->start) {
+                       b->batDirtydesc = true;
                        size_t lnr = s->end-s->start;
                        size_t pos = s->start;
                        dst = ((uint32_t*)Tloc(b, 0)) + (s->start/32);
@@ -1461,6 +1463,7 @@ static int
 delta_append_bat(sql_trans *tr, sql_delta *bat, sqlid id, BAT *offsets, BAT *i)
 {
        BAT *b, *oi = i;
+       int err = 0;
 
        assert(BATcount(offsets) == BATcount(i));
        if (!BATcount(i))
@@ -1476,19 +1479,18 @@ delta_append_bat(sql_trans *tr, sql_delt
                        bat_destroy(oi);
                return LOG_ERR;
        }
-       if (BATupdate(b, offsets, oi, true) != GDK_SUCCEED) {
-               bat_destroy(b);
-               unlock_column(tr->store, id);
-               if (oi != i)
-                       bat_destroy(oi);
-               return LOG_ERR;
+       if ((BATtdense(offsets) && offsets->tseqbase == 
(b->hseqbase+BATcount(b)))) {
+               if (BATappend(b, oi, NULL, true) != GDK_SUCCEED)
+                       err = 1;
+       } else if (BATupdate(b, offsets, oi, true) != GDK_SUCCEED) {
+                       err = 1;
        }
        bat_destroy(b);
        unlock_column(tr->store, id);
 
        if (oi != i)
                bat_destroy(oi);
-       return LOG_OK;
+       return (err)?LOG_ERR:LOG_OK;
 }
 
 static int
@@ -2825,6 +2827,8 @@ tr_log_cs( sql_trans *tr, sql_table *t, 
        sqlstore *store = tr->store;
        gdk_return ok = GDK_SUCCEED;
 
+       (void) t;
+       (void) segs;
        if (GDKinmemory(0))
                return LOG_OK;
 
@@ -2836,31 +2840,16 @@ tr_log_cs( sql_trans *tr, sql_table *t, 
        if (cs->cleared) {
                assert(cs->ucnt == 0);
                BAT *ins = temp_descriptor(cs->bid);
-               if (isEbat(ins)) {
-                       assert(0);
-                       temp_destroy(cs->bid);
-                       cs->bid = temp_copy(ins->batCacheid, false);
-                       bat_destroy(ins);
-                       ins = temp_descriptor(cs->bid);
-               }
+               if (!ins)
+                       return LOG_ERR;
+               assert(!isEbat(ins));
                bat_set_access(ins, BAT_READ);
                ok = log_bat_persists(store->logger, ins, id);
                bat_destroy(ins);
                return ok == GDK_SUCCEED ? LOG_OK : LOG_ERR;
        }
 
-       if (isTempTable(t)) {
-               assert(0);
-       for (; segs; segs=segs->next) {
-               if (segs->ts == tr->tid) {
-                       BAT *ins = temp_descriptor(cs->bid);
-                       assert(ins);
-                       assert(BATcount(ins) >= segs->end);
-                       ok = log_bat(store->logger, ins, id, segs->start, 
segs->end-segs->start);
-                       bat_destroy(ins);
-               }
-       }
-       }
+       assert(!isTempTable(t));
 
        if (ok == GDK_SUCCEED && cs->ucnt && cs->uibid) {
                BAT *ui = temp_descriptor(cs->uibid);
diff --git a/sql/storage/bat/bat_utils.c b/sql/storage/bat/bat_utils.c
--- a/sql/storage/bat/bat_utils.c
+++ b/sql/storage/bat/bat_utils.c
@@ -91,20 +91,6 @@ temp_copy(log_bid b, int temp)
        return r;
 }
 
-BUN
-append_inserted(BAT *b, BAT *i )
-{
-       BUN nr = 0, r;
-       BATiter ii = bat_iterator(i);
-
-       for (r = i->batInserted; r < BUNlast(i); r++) {
-               if (BUNappend(b, BUNtail(ii,r), true) != GDK_SUCCEED)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to