Changeset: 12ac39e52f84 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=12ac39e52f84
Modified Files:
        sql/include/sql_catalog.h
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        sql/storage/store.c
Branch: newstorage
Log Message:

issue solved. ready to benchmark concurrent inserts.


diffs (258 lines):

diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -203,7 +203,7 @@ typedef struct sql_trans {
        int rtime;
        int wtime;
        int btime;              /* begin transaction timestamp */
-       BUN firstclaimed;       /* 1st BAT slot to insert */
+       BUN slot;               /* first BAT slot for inserts */
        int schema_number;      /* schema timestamp */
        int schema_updates;     /* set on schema changes */
        int status;             /* status of the last query */
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
@@ -475,7 +475,7 @@ insert_val2col(sql_trans *tr ,sql_delta 
 
        assert(c->T->heap.storage != STORE_PRIV);
 
-       BUNinplace(c, tr->firstclaimed, c->H, i, TRUE);
+       BUNinplace(c, tr->slot, c->H, i, TRUE);
 
        col->cnt++;
        bat_destroy(c);
@@ -515,25 +515,14 @@ dup_idx(sql_trans *tr, sql_idx *i, sql_i
 static int
 dup_tsbats(sql_trans *tr, sql_timestamps *ots, sql_timestamps *ts, int is_new, 
int temp) {
 
-       if(ots->insbid)
-               ts->insbid = ots->insbid;
-       if(ots->delbid)
-               ts->delbid = ots->delbid;
-       if(ots->cnt)
-               ts->cnt = ots->cnt;
-       if(ots->insname)
-               ts->insname = _STRDUP(ots->insname);
-       if(ots->delname)
-               ts->delname = _STRDUP(ots->delname);
-       if(ots->wtime)
-               ts->wtime = ots->wtime;
-
-       if(ts->insbid && is_new)
-                ots->insbid = temp_copy(ts->insbid, temp);
-
-        if(ts->delbid && is_new)
-                ots->delbid = temp_copy(ts->delbid, temp);
-       (void)tr;
+       (void)is_new; (void)temp; (void)tr;
+
+       ts->insbid = ots->insbid;
+       ts->delbid = ots->delbid;
+       ts->cnt = ots->cnt;
+       ts->insname = _STRDUP(ots->insname);
+       ts->delname = _STRDUP(ots->delname);
+       ts->wtime = ots->wtime;
 
        return LOG_OK;
 }
@@ -558,7 +547,7 @@ timestamps_insert(sql_trans *tr, sql_tab
        wrd i;
        int nts=0;
 
-       BUN first = tr->firstclaimed;
+       BUN first = tr->slot;
 
        assert(!insb || insb->htype == TYPE_void);
        assert(!delb || delb->htype == TYPE_void);
@@ -588,7 +577,7 @@ insert_bat2col(sql_trans *tr, sql_delta 
 
        BAT *c = temp_descriptor(col->bid);
        BUN isz = 0;
-       BUN first = -1;
+       BUN first = tr->slot;
 
        assert(!c || c->htype == TYPE_void);
        assert(c->T->heap.storage != STORE_PRIV);
@@ -598,7 +587,6 @@ insert_bat2col(sql_trans *tr, sql_delta 
                 col->cached = NULL;
         }
 
-       first = tr->firstclaimed;
        isz = BATcount(i);
 
        if(isz==0)
@@ -625,15 +613,14 @@ claim_tab(sql_trans *tr, sql_table *t, w
        // *in;
        //int growF=0;
 
-       BAT *insb, *delb = NULL;
+       BAT *insb;
+       BAT *delb;
 
        if (bat_debug==2)
                printf("#in CLAIM\n");
 
        store_lock();
 
-       //tr->firstclaimed = -1;
-
        if (!t->data || !t->base.allocated) {
                 sql_table *ot = tr_find_table(tr->parent, t);
                 sql_timestamps *ts = t->data = ZNEW(sql_timestamps), *ots = 
timestamp_tsbats(ot->data, tr->stime);
@@ -642,7 +629,35 @@ claim_tab(sql_trans *tr, sql_table *t, w
         }
        ts = t->data;
 
-       //in = t->columns.set->h; /* initial node */
+       insb = temp_descriptor(ts->insbid);
+       delb = temp_descriptor(ts->delbid);
+
+       /* grow insbat */
+       if((BUN)cnt > (BATcapacity(insb) - BUNlast(insb))) {
+               BUN newCap = BUNlast(insb) + (BUN)cnt;
+                BUN grows = BATgrows(insb);
+
+               if (newCap > grows)
+                       grows = newCap;
+                if (BATextend(insb, grows) == NULL)
+                       return;
+        }
+       BATsetcount(insb, (BATcount(insb) + (BUN)cnt));
+       tr->slot = BATcount(insb) - (BUN)cnt;
+       bat_destroy(insb);
+
+       /* grow delbat */
+       if((BUN)cnt > (BATcapacity(delb) - BUNlast(delb))) {
+               BUN newCap = BUNlast(delb) + (BUN)cnt;
+                BUN grows = BATgrows(delb);
+
+               if (newCap > grows)
+                       grows = newCap;
+                if (BATextend(delb, grows) == NULL)
+                        return;
+        }
+       BATsetcount(delb, (BATcount(delb) + (BUN)cnt));
+       bat_destroy(delb);
 
        /* claim # of column buns */
        for (n = t->columns.set->h; n; n = n->next) {
@@ -671,7 +686,6 @@ claim_tab(sql_trans *tr, sql_table *t, w
                                return;
                }
                BATsetcount(cmbat, (BATcount(cmbat) + (BUN)cnt));
-               //cbat->ibase+=(BUN)cnt;
                bat_destroy(cmbat);
        }
 
@@ -705,43 +719,13 @@ claim_tab(sql_trans *tr, sql_table *t, w
                 }
         }
 
-       insb = temp_descriptor(ts->insbid);
-       delb = temp_descriptor(ts->delbid);
-
-       /* grow insbat */
-       if(((BUN)cnt > (BATcapacity(insb) - BUNlast(insb)))/* && growF*/) {
-               BUN newCap = BUNlast(insb) + (BUN)cnt;
-                BUN grows = BATgrows(insb);
-
-               if (newCap > grows)
-                       grows = newCap;
-                if (BATextend(insb, grows) == NULL)
-                       return;
-        }
-       BATsetcount(insb, (BATcount(insb) + (BUN)cnt));
-
-       /* grow delbat */
-       if(((BUN)cnt > (BATcapacity(delb) - BUNlast(delb))) /*&& growF*/) {
-               BUN newCap = BUNlast(delb) + (BUN)cnt;
-                BUN grows = BATgrows(delb);
-
-               if (newCap > grows)
-                       grows = newCap;
-                if (BATextend(delb, grows) == NULL)
-                        return;
-        }
-       BATsetcount(delb, (BATcount(delb) + (BUN)cnt));
-
-       tr->firstclaimed = BATcount(insb) - (BUN)cnt;
-
-       bat_destroy(insb);
-       bat_destroy(delb);
-
        ts->wtime /*= t->base.wtime = t->s->base.wtime */= tr->wtime = 
tr->wstime;
 
+       /* fill-in ts bats */
+       timestamps_insert(tr, t, ts, cnt);
+
        store_unlock();
 
-       timestamps_insert(tr, t, ts, cnt);
 }
 
 static void 
@@ -1969,7 +1953,7 @@ clear_timestamps(sql_trans *tr, sql_tabl
        if(!t->data || !t->base.allocated) {
                sql_table *ot = tr_find_table(tr->parent, t);
                sql_timestamps *ts = t->data = ZNEW(sql_timestamps), *ots = 
timestamp_tsbats(ot->data, tr->stime);
-               dup_tsbats(tr, ts, ots, isNew(ot), isTempTable(t));
+               dup_tsbats(tr, ots, ts, isNew(ot), isTempTable(t));
                t->base.allocated = 1;
        }
 
diff --git a/sql/storage/bat/bat_storage.h b/sql/storage/bat/bat_storage.h
--- a/sql/storage/bat/bat_storage.h
+++ b/sql/storage/bat/bat_storage.h
@@ -27,7 +27,6 @@ typedef struct sql_delta {
        char *name;             /* name of the main bat */
        int bid;
        oid ibase;              /* ibase: first id of inserts */
-       //int ibid;             /* bat with inserts */
        int ubid;               /* bat with updates */
        size_t cnt;             /* number of tuples (including the deletes) */
        size_t ucnt;            /* number of updates */
@@ -36,14 +35,6 @@ typedef struct sql_delta {
        struct sql_delta *next; /* possibly older version of the same 
column/idx */
 } sql_delta;
 
-//typedef struct sql_dbat {
-//     char *dname;            /* name of the persistent deletes bat */
-//     int dbid;               /* bat with deletes */
-//     size_t cnt;
-//     int wtime;              /* time stamp */
-//     struct sql_dbat *next;  /* possibly older version of the same deletes */
-//} sql_dbat;
-
 typedef struct sql_timestamps {
        char *delname;
        int delbid;
@@ -51,6 +42,7 @@ typedef struct sql_timestamps {
        int insbid;
        int wtime;
        size_t cnt;
+       //BUN slot;             /* 1st BAT slot claimed for insert */
        struct sql_timestamps *next;
 } sql_timestamps;
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -940,7 +940,7 @@ create_trans(sql_allocator *sa, backend_
        t->btime = btimestamp();
        t->schema_updates = 0;
        t->status = 0;
-       t->firstclaimed = -1;
+       t->slot = -1;
 
        t->parent = NULL;
        t->stk = stk;
@@ -2274,7 +2274,7 @@ trans_init(sql_trans *t, backend_stack s
        t->wtime = t->rtime = 0;
        t->stime = ot->wtime;
        t->wstime = timestamp();
-       t->firstclaimed = -1;
+       t->slot = -1;
 
        t->btime = btimestamp();
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to