Changeset: 67437a75ad04 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/67437a75ad04
Modified Files:
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

Merge with Sep2022 branch.


diffs (truncated from 312 to 300 lines):

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
@@ -524,7 +524,7 @@ temp_dup_delta(ulng tid, int type)
 
        if (!bat)
                return NULL;
-       if (temp_dup_cs(&bat->cs, tid, type)) {
+       if (temp_dup_cs(&bat->cs, tid, type) != LOG_OK) {
                _DELETE(bat);
                return NULL;
        }
@@ -546,7 +546,7 @@ temp_dup_storage(sql_trans *tr)
 
        if (!bat)
                return NULL;
-       if (temp_dup_cs(&bat->cs, tr->tid, TYPE_msk)) {
+       if (temp_dup_cs(&bat->cs, tr->tid, TYPE_msk) != LOG_OK) {
                _DELETE(bat);
                return NULL;
        }
@@ -2136,6 +2136,9 @@ update_col(sql_trans *tr, sql_column *c,
                        return LOG_OK;
        }
 
+       if (c == NULL)
+               return LOG_ERR;
+
        if ((delta = bind_col_data(tr, c, &update_conflict)) == NULL)
                return update_conflict ? LOG_CONFLICT : LOG_ERR;
 
@@ -2208,6 +2211,9 @@ update_idx(sql_trans *tr, sql_idx * i, v
                        return LOG_OK;
        }
 
+       if (i == NULL)
+               return LOG_ERR;
+
        if ((delta = bind_idx_data(tr, i, &update_conflict)) == NULL)
                return update_conflict ? LOG_CONFLICT : LOG_ERR;
 
@@ -2443,8 +2449,8 @@ append_col(sql_trans *tr, sql_column *c,
                        return LOG_OK;
        }
 
-       if (isTempTable(c->t) && isGlobal(c->t))
-               c = find_tmp_column(tr, c);
+       if (isTempTable(c->t) && isGlobal(c->t) && (c = find_tmp_column(tr, c)) 
== NULL)
+               return LOG_ERR;
 
        if ((delta = bind_col_data(tr, c, NULL)) == NULL)
                return LOG_ERR;
@@ -2452,8 +2458,8 @@ append_col(sql_trans *tr, sql_column *c,
        assert(delta->cs.st == ST_DEFAULT || delta->cs.st == ST_DICT || 
delta->cs.st == ST_FOR);
        assert(delta && (!isTempTable(c->t) || delta->cs.ts == tr->tid));
        if (isTempTable(c->t))
-       if ((!inTransaction(tr, c->t) && (odelta != delta || 
!segments_in_transaction(tr, c->t) || isTempTable(c->t)) && isGlobal(c->t)) || 
(!isNew(c->t) && isLocalTemp(c->t)))
-               trans_add(tr, &c->base, delta, &tc_gc_col, &commit_update_col, 
isTempTable(c->t) || isUnloggedTable(c->t) ? NULL : &log_update_col);
+               if ((!inTransaction(tr, c->t) && (odelta != delta || 
!segments_in_transaction(tr, c->t) || isTempTable(c->t)) && isGlobal(c->t)) || 
(!isNew(c->t) && isLocalTemp(c->t)))
+                       trans_add(tr, &c->base, delta, &tc_gc_col, 
&commit_update_col, isTempTable(c->t) || isUnloggedTable(c->t) ? NULL : 
&log_update_col);
 
        odelta = delta;
        if ((res = append_col_execute(tr, &delta, c->base.id, offset, offsets, 
data, cnt, tpe, c->storage_type)) != LOG_OK)
@@ -2483,8 +2489,8 @@ append_idx(sql_trans *tr, sql_idx *i, BU
                        return LOG_OK;
        }
 
-       if (isTempTable(i->t) && isGlobal(i->t))
-               i = find_tmp_idx(tr, i);
+       if (isTempTable(i->t) && isGlobal(i->t) && (i = find_tmp_idx(tr, i)) == 
NULL)
+               return LOG_ERR;
 
        if ((delta = bind_idx_data(tr, i, NULL)) == NULL)
                return LOG_ERR;
@@ -2492,8 +2498,8 @@ append_idx(sql_trans *tr, sql_idx *i, BU
        assert(delta->cs.st == ST_DEFAULT);
        assert(delta && (!isTempTable(i->t) || delta->cs.ts == tr->tid));
        if (isTempTable(i->t))
-       if ((!inTransaction(tr, i->t) && (odelta != delta || 
!segments_in_transaction(tr, i->t) || isTempTable(i->t)) && isGlobal(i->t)) || 
(!isNew(i->t) && isLocalTemp(i->t)))
-               trans_add(tr, &i->base, delta, &tc_gc_idx, &commit_update_idx, 
isTempTable(i->t) || isUnloggedTable(i->t) ? NULL : &log_update_idx);
+               if ((!inTransaction(tr, i->t) && (odelta != delta || 
!segments_in_transaction(tr, i->t) || isTempTable(i->t)) && isGlobal(i->t)) || 
(!isNew(i->t) && isLocalTemp(i->t)))
+                       trans_add(tr, &i->base, delta, &tc_gc_idx, 
&commit_update_idx, isTempTable(i->t) || isUnloggedTable(i->t) ? NULL : 
&log_update_idx);
 
        odelta = delta;
        res = append_col_execute(tr, &delta, i->base.id, offset, offsets, data, 
cnt, tpe, NULL);
@@ -2683,15 +2689,13 @@ destroy_segments(segments *s)
        _DELETE(s);
 }
 
-static int
+static void
 destroy_storage(storage *bat)
 {
-       int ok = LOG_OK;
-
        if (--bat->cs.refcnt > 0)
-               return LOG_OK;
+               return;
        if (bat->next)
-               ok = destroy_storage(bat->next);
+               destroy_storage(bat->next);
        destroy_segments(bat->segs);
        if (bat->cs.uibid)
                temp_destroy(bat->cs.uibid);
@@ -2701,7 +2705,6 @@ destroy_storage(storage *bat)
                temp_destroy(bat->cs.bid);
        bat->cs.bid = bat->cs.uibid = bat->cs.uvbid = 0;
        _DELETE(bat);
-       return ok;
 }
 
 static int
@@ -2795,6 +2798,9 @@ delete_tab(sql_trans *tr, sql_table * t,
        if (tpe == TYPE_bat && !BATcount(b))
                return ok;
 
+       if (t == NULL)
+               return LOG_ERR;
+
        if ((bat = bind_del_data(tr, t, NULL)) == NULL)
                return LOG_ERR;
 
@@ -3226,6 +3232,8 @@ create_col(sql_trans *tr, sql_column *c)
                /* alter ? */
                if (!isTempTable(c->t) && ol_first_node(c->t->columns) && (fc = 
ol_first_node(c->t->columns)->data) != NULL) {
                        storage *s = tab_timestamp_storage(tr, fc->t);
+                       if (s == NULL)
+                               return LOG_ERR;
                        cnt = segs_end(s->segs, tr, c->t);
                }
                if (cnt && fc != c) {
@@ -3354,7 +3362,7 @@ create_idx(sql_trans *tr, sql_idx *ni)
                                        ok = LOG_ERR;
                        }
                } else {
-                       ok = LOG_ERR;
+                       return LOG_ERR;
                }
 
                bat->cs.ucnt = 0;
@@ -3415,8 +3423,10 @@ load_storage(sql_trans *tr, sql_table *t
        }
 
        if (BATcount(b)) {
-               if (ok == LOG_OK && !(s->segs = new_segments(tr, BATcount(ib))))
-                       ok = LOG_ERR;
+               if (ok == LOG_OK && !(s->segs = new_segments(tr, 
BATcount(ib)))) {
+                       bat_destroy(ib);
+                       return LOG_ERR;
+               }
                if (BATtdense(b)) {
                        size_t start = b->tseqbase;
                        size_t cnt = BATcount(b);
@@ -3517,7 +3527,7 @@ create_del(sql_trans *tr, sql_table *t)
        } else if (!bat->cs.bid) {
                assert(!bat->segs);
                if (!(bat->segs = new_segments(tr, 0)))
-                       ok = LOG_ERR;
+                       return LOG_ERR;
 
                b = bat_new(TYPE_msk, t->sz, PERSISTENT);
                if(b != NULL) {
@@ -3525,7 +3535,7 @@ create_del(sql_trans *tr, sql_table *t)
                        bat->cs.bid = temp_create(b);
                        bat_destroy(b);
                } else {
-                       ok = LOG_ERR;
+                       return LOG_ERR;
                }
                if (new)
                        trans_add(tr, &t->base, bat, &tc_gc_del, 
&commit_create_del, isTempTable(t) ? NULL : &log_create_del);
@@ -3622,7 +3632,6 @@ commit_create_del( sql_trans *tr, sql_ch
        if(!isTempTable(t)) {
                storage *dbat = ATOMIC_PTR_GET(&t->data);
                ok = segments2cs(tr, dbat->segs, &dbat->cs);
-               assert(ok == LOG_OK);
                if (ok != LOG_OK)
                        return ok;
                merge_segments(dbat, tr, change, commit_ts, commit_ts/* create 
is we are alone */ /*oldest*/);
@@ -3732,11 +3741,10 @@ static int
 destroy_del(sqlstore *store, sql_table *t)
 {
        (void)store;
-       int ok = LOG_OK;
        if (ATOMIC_PTR_GET(&t->data))
-               ok = destroy_storage(ATOMIC_PTR_GET(&t->data));
+               destroy_storage(ATOMIC_PTR_GET(&t->data));
        ATOMIC_PTR_SET(&t->data, NULL);
-       return ok;
+       return LOG_OK;
 }
 
 static int
@@ -4488,7 +4496,6 @@ commit_update_del( sql_trans *tr, sql_ch
                        dbat->cs.ts = commit_ts;
 
                ok = segments2cs(tr, dbat->segs, &dbat->cs);
-               assert(ok == LOG_OK);
                if (ok == LOG_OK) {
                        merge_segments(dbat, tr, change, commit_ts, oldest);
                        if (oldest == commit_ts)
@@ -4706,27 +4713,30 @@ claim_segmentsV2(sql_trans *tr, sql_tabl
                                slot = s->segs->t->start;
                        }
                }
-               ok = add_offsets(slot, cnt, total, offset, offsets);
+               if (ok == LOG_OK)
+                       ok = add_offsets(slot, cnt, total, offset, offsets);
        }
        if (!locked)
                unlock_table(tr->store, t->base.id);
 
-       /* hard to only add this once per transaction (probably want to change 
to once per new segment) */
-       if ((!inTransaction(tr, t) && (!in_transaction || isTempTable(t)) && 
isGlobal(t)) || (!isNew(t) && isLocalTemp(t))) {
-               trans_add(tr, &t->base, s, &tc_gc_del, &commit_update_del, 
isTempTable(t) || isUnloggedTable(t) ? NULL : &log_update_del);
-               in_transaction = true;
-       }
-       if (in_transaction && !isTempTable(t) && !isUnloggedTable(t))
-               tr->logchanges += (int) total;
-       if (*offsets) {
-               BAT *pos = *offsets;
-               assert(BATcount(pos) == total);
-               BATsetcount(pos, total); /* set other properties */
-               pos->tnil = false;
-               pos->tnonil = true;
-               pos->tkey = true;
-               pos->tsorted = true;
-               pos->trevsorted = false;
+       if (ok == LOG_OK) {
+               /* hard to only add this once per transaction (probably want to 
change to once per new segment) */
+               if ((!inTransaction(tr, t) && (!in_transaction || 
isTempTable(t)) && isGlobal(t)) || (!isNew(t) && isLocalTemp(t))) {
+                       trans_add(tr, &t->base, s, &tc_gc_del, 
&commit_update_del, isTempTable(t) || isUnloggedTable(t) ? NULL : 
&log_update_del);
+                       in_transaction = true;
+               }
+               if (in_transaction && !isTempTable(t) && !isUnloggedTable(t))
+                       tr->logchanges += (int) total;
+               if (*offsets) {
+                       BAT *pos = *offsets;
+                       assert(BATcount(pos) == total);
+                       BATsetcount(pos, total); /* set other properties */
+                       pos->tnil = false;
+                       pos->tnonil = true;
+                       pos->tkey = true;
+                       pos->tsorted = true;
+                       pos->trevsorted = false;
+               }
        }
        return ok;
 }
@@ -4760,8 +4770,10 @@ claim_segments(sql_trans *tr, sql_table 
                                        break;
                                }
                                /* we claimed part of the old segment, the 
split off part needs to stay deleted */
-                               if ((seg=split_segment(s->segs, seg, p, tr, 
seg->start, cnt, false)) == NULL)
+                               if ((seg=split_segment(s->segs, seg, p, tr, 
seg->start, cnt, false)) == NULL) {
                                        ok = LOG_ERR;
+                                       break;
+                               }
                        }
                        seg->ts = tr->tid;
                        seg->deleted = false;
@@ -4787,18 +4799,17 @@ claim_segments(sql_trans *tr, sql_table 
        if (!locked)
                unlock_table(tr->store, t->base.id);
 
-       /* hard to only add this once per transaction (probably want to change 
to once per new segment) */
-       if ((!inTransaction(tr, t) && (!in_transaction || isTempTable(t)) && 
isGlobal(t)) || (!isNew(t) && isLocalTemp(t))) {
-               trans_add(tr, &t->base, s, &tc_gc_del, &commit_update_del, 
isTempTable(t) || isUnloggedTable(t) ? NULL : &log_update_del);
-               in_transaction = true;
+       if (ok == LOG_OK) {
+               /* hard to only add this once per transaction (probably want to 
change to once per new segment) */
+               if ((!inTransaction(tr, t) && (!in_transaction || 
isTempTable(t)) && isGlobal(t)) || (!isNew(t) && isLocalTemp(t))) {
+                       trans_add(tr, &t->base, s, &tc_gc_del, 
&commit_update_del, isTempTable(t) || isUnloggedTable(t) ? NULL : 
&log_update_del);
+                       in_transaction = true;
+               }
+               if (in_transaction && !isTempTable(t) && !isUnloggedTable(t))
+                       tr->logchanges += (int) cnt;
+               *offset = slot;
        }
-       if (in_transaction && !isTempTable(t) && !isUnloggedTable(t))
-               tr->logchanges += (int) cnt;
-       if (ok == LOG_OK) {
-               *offset = slot;
-               return LOG_OK;
-       }
-       return LOG_ERR;
+       return ok;
 }
 
 /*
@@ -4812,8 +4823,8 @@ claim_tab(sql_trans *tr, sql_table *t, s
 {
        storage *s;
 
-       if (isTempTable(t) && isGlobal(t))
-               t = find_tmp_table(tr, t);
+       if (isTempTable(t) && isGlobal(t) && (t = find_tmp_table(tr, t)) == 
NULL)
+               return LOG_ERR;
 
        /* we have a single segment structure for each persistent table
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to