Changeset: 961c22e43a32 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=961c22e43a32
Modified Files:
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: unlock
Log Message:

fixed issues with truncate/delete all (use proper delta structure too base 
changes on)


diffs (truncated from 633 to 300 lines):

diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -601,11 +601,13 @@ SQLinit(Client c)
        if ((sqllogthread = THRcreate((void (*)(void *)) mvc_logmanager, NULL, 
MT_THR_DETACHED, "logmanager")) == 0) {
                throw(SQL, "SQLinit", SQLSTATE(42000) "Starting log manager 
failed");
        }
+#if 0
        if (!(SQLdebug&1024)) {
                if ((idlethread = THRcreate((void (*)(void *)) mvc_idlemanager, 
NULL, MT_THR_DETACHED, "idlemanager")) == 0) {
                        throw(SQL, "SQLinit", SQLSTATE(42000) "Starting idle 
manager failed");
                }
        }
+#endif
        if ( wlc_state == WLC_STARTUP)
                return WLCinit();
        return MAL_SUCCEED;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -416,11 +416,13 @@ mvc_logmanager(void)
        store_manager();
 }
 
+/*
 void
 mvc_idlemanager(void)
 {
        idle_manager();
 }
+*/
 
 int
 mvc_status(mvc *m)
diff --git a/sql/server/sql_mvc.h b/sql/server/sql_mvc.h
--- a/sql/server/sql_mvc.h
+++ b/sql/server/sql_mvc.h
@@ -149,7 +149,7 @@ extern sql_table *mvc_init_create_view(m
 extern int mvc_init(int debug, store_type store, int ro, int su, backend_stack 
stk);
 extern void mvc_exit(void);
 extern void mvc_logmanager(void);
-extern void mvc_idlemanager(void);
+//extern void mvc_idlemanager(void);
 
 extern mvc *mvc_create(int clientid, backend_stack stk, int debug, bstream 
*rs, stream *ws);
 extern int mvc_reset(mvc *m, bstream *rs, stream *ws, int debug);
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
@@ -41,6 +41,19 @@ timestamp_dbat( storage *d, int ts)
 }
 
 static size_t
+count_inserts( segment *s, sql_trans *tr)
+{
+       size_t cnt = 0;
+
+       while(s) {
+               if (s->owner == tr)
+                       cnt += s->end - s->start;
+               s = s->next;
+       }
+       return cnt;
+}
+
+static size_t
 count_col(sql_trans *tr, sql_column *c, int access)
 {
        storage *d;
@@ -57,9 +70,9 @@ count_col(sql_trans *tr, sql_column *c, 
                return 0;
        if (access == 2) 
                return d->cs.ucnt;
-       if (access == 1) /* TODO improve */
-               return (d->segs.owner == tr)?d->segs.end - d->segs.start:0;
-       return d->segs.end;
+       if (access == 1)
+               return count_inserts(d->segs->head, tr);
+       return d->end;
 }
 
 static size_t
@@ -99,9 +112,9 @@ count_idx(sql_trans *tr, sql_idx *i, int
                return 0;
        if (access == 2) 
                return d->cs.ucnt;
-       if (access == 1) /* TODO improve */
-               return (d->segs.owner == tr)?d->segs.end - d->segs.start:0;
-       return d->segs.end;
+       if (access == 1)
+               return count_inserts(d->segs->head, tr);
+       return d->end;
 }
 
 static int
@@ -124,7 +137,7 @@ cs_real_update_bats( column_storage *cs,
                    (ui = temp_descriptor(cs->uibid)) == NULL) {
                        bat_destroy(uv);
                        return LOG_ERR;
-       }
+               }
        }
        if (isEbat(uv)){
                temp_destroy(cs->uvbid);
@@ -191,8 +204,8 @@ count_del(sql_trans *tr, sql_table *t, i
                return 0;
        if (access == 2)
                return d->cs.ucnt;
-       if (access == 1) /* TODO improve */
-               return (d->segs.owner == tr)?d->segs.end - d->segs.start:0;
+       if (access == 1)
+               return count_inserts(d->segs->head, tr);
        return count_deletes(d);
 }
 
@@ -303,7 +316,7 @@ bind_del(sql_trans *tr, sql_table *t, in
        if (access == RD_UPD_ID || access == RD_UPD_VAL) {
                return cs_bind_ubat( &s->cs, access, TYPE_bit);
        } else {
-               return cs_bind_bat( &s->cs, access, s->segs.end);
+               return cs_bind_bat( &s->cs, access, s->end);
        }
 }
 
@@ -410,7 +423,7 @@ dup_cs(column_storage *ocs, column_stora
        cs->uvbid = ocs->uvbid;
        cs->ucnt = ocs->ucnt;
        cs->wtime = ocs->wtime;
-       cs->cleared = ocs->cleared;
+       //cs->cleared = ocs->cleared;
 
        if (temp) {
                cs->bid = temp_copy(cs->bid, 1);
@@ -654,14 +667,54 @@ dup_idx(sql_trans *tr, sql_idx *i, sql_i
        return ok;
 }
 
+static segments*
+dup_segments(segments *s)
+{
+       sql_ref_inc(&s->r);
+       return s;
+}
+
+static segment *
+new_segment(segment *o, sql_trans *tr, size_t cnt)
+{
+       segment *n = (segment*)GDKmalloc(sizeof(segment));
+
+       if (n) {
+               n->owner = tr?tr:0;
+               n->start = o?o->end:0;
+               n->end = n->start + cnt;
+               n->next = o;
+       } 
+       return n;
+}
+
+static segments *
+new_segments(size_t cnt) 
+{
+       segments *n = (segments*)GDKmalloc(sizeof(segments));
+
+       if (n) {
+               sql_ref_init(&n->r);
+               n->head = new_segment(NULL, NULL, cnt);
+               n->end = n->head->end;
+       }
+       return n;
+}
+
+
 static int
 dup_dbat(storage *obat, storage *bat, int is_new, int temp)
 {
        if (!obat)
                return LOG_OK;
-       bat->segs.start = obat->segs.start; /* TODO find end */
-       bat->segs.end = obat->segs.end;
-       bat->segs.next = NULL;
+       if (temp) {
+               bat->segs = new_segments(0);
+               bat->end = bat->segs->end;
+       } else {
+               bat->end = obat->end = obat->segs->end;
+               bat->segs = dup_segments(obat->segs);
+               assert(bat->end <= bat->segs->end);
+       }
        return dup_cs(&obat->cs, &bat->cs, TYPE_bit, is_new, temp);
 }
 
@@ -793,141 +846,97 @@ delete_tab(sql_trans *tr, sql_table * t,
        return ok;
 }
 
-static segment *
-new_segment(segment *o)
-{
-       segment *n = (segment*)GDKmalloc(sizeof(segment));
-
-       if (n)
-               *n = *o;
-       return n;
-}
-
+/*
+ * Claim cnt slots to store the tuples. The claim_tab should claim storage on 
the level
+ * of the global transaction and mark the newly added storage slots unused on 
the global
+ * level but used on the local transaction level. Besides this the local 
transaction needs
+ * to update (and mark unused) any slot inbetween the old end and new slots.
+ * */
 static size_t
 claim_tab(sql_trans *tr, sql_table *t, size_t cnt)
 {
        storage *s, *ps = NULL;
-       size_t res = 0;
+       BUN slot = 0;
 
        if (bind_del_data(tr, t) == LOG_ERR)
                return 0;
 
+       /* use (resizeable) array of locks like BBP */
        store_lock();
-       /* use (resizeable) array of locks like BBP */
 
        s = t->data;
        if (isNew(t) || isTempTable(t) || s->cs.cleared) {
                /* a new table ie no competition */
                ps = s;
        } else {
+               /* find parent which knows about the slots to use */
                sql_table *ot = tr_find_base_table(tr->parent, t);
-               ps = ot->data;
+               ps = timestamp_dbat(ot->data, t->base.stime);
        }
-       if (ps->segs.end > 0) {
-               ps->segs.next = new_segment(&ps->segs);
-               ps->segs.start = ps->segs.next->end;
+       if (!ps) 
+               return LOG_ERR;
+
+       slot = ps->end;
+       if (isNew(t) || isTempTable(t) || s->cs.cleared) {
+               ps->end += cnt;
+               if (ps->segs->head)
+                       ps->segs->end = ps->segs->head->end = ps->end;
+       } else {
+               assert(ps->end <= ps->segs->end);
+               ps->segs->head = new_segment(ps->segs->head, tr, cnt);
+               s->end = ps->end = ps->segs->end = ps->segs->head->end;
        }
 
        BAT *b = temp_descriptor(s->cs.bid); /* use s->cs.bid, as its equal 
ps->cs.bid or for cleared tables its a private bid */
-       if (!isTempTable(t) && !s->cs.cleared && BATcount(b) > 
ps->segs.end+cnt){
-               assert(0);
-               //BATreplace();
-       } else {
-               bit deleted = FALSE;  
-               lng i;
+
+       assert(isNew(t) || isTempTable(t) || s->cs.cleared || BATcount(b) == 
slot);
 
-               /* general case, write deleted in the central bat (ie others 
don't see these values) and 
-                * insert rows into the update bats */
-               if (!s->cs.cleared && ps != s && !isTempTable(t)) {
-                       /* add updates */
-                       BAT *ui, *uv;
+       bit deleted = FALSE;  
+       lng i;
 
-                       if (cs_real_update_bats(&s->cs, &ui, &uv) == LOG_ERR) {
-                               assert(0);
-                               store_unlock();
-                               return LOG_ERR;
-                       }
+       /* general case, write deleted in the central bat (ie others don't see 
these values) and 
+        * insert rows into the update bats */
+       if (!s->cs.cleared && ps != s && !isTempTable(t)) {
+               /* add updates */
+               BAT *ui, *uv;
 
-                       oid id = ps->segs.end;
-                       for(i=0; i<(lng)cnt; i++, id++) {
-                               if (BUNappend(ui, &id, true) != GDK_SUCCEED ||
-                                   BUNappend(uv, &deleted, true) != 
GDK_SUCCEED) {
-                                       bat_destroy(ui);
-                                       bat_destroy(uv);
-                                       assert(0);
-                                       store_unlock();
-                                       return LOG_ERR;
-                               }
-                       }
-                       s->cs.ucnt += cnt;
-                       deleted = TRUE;
+               if (cs_real_update_bats(&s->cs, &ui, &uv) == LOG_ERR) {
+                       store_unlock();
+                       return LOG_ERR;
                }
 
-               assert(!s->cs.cleared || BATcount(b) == s->segs.end);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to