Changeset: 7c042c27748f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7c042c27748f
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_cat.c
        sql/backends/monet5/sql_result.c
        sql/include/sql_catalog.h
        sql/server/sql_mvc.c
        sql/server/sql_partition.c
        sql/server/sql_privileges.c
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        sql/storage/bat/bat_table.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: nospare
Log Message:

mvcc using a single catalog tree with chains of versions (ie objects can be 
chained (most recent object first), and content (delta storage) is chained)


diffs (truncated from 6164 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -5363,8 +5363,6 @@ sql_truncate(backend *be, sql_table *t, 
                                                        error = 1;
                                                        goto finalize;
                                                }
-                                               seq->base.wtime = 
sche->base.wtime = tr->wtime = tr->wstime;
-                                               tr->schema_updates++;
                                        }
                                }
                        }
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -959,7 +959,7 @@ mvc_getVersion(lng *version, const int *
                return msg;
        *version = -1;
        if (m->session->tr)
-               *version = m->session->tr->stime;
+               *version = (lng)m->session->tr->ts;
        return MAL_SUCCEED;
 }
 
@@ -1350,13 +1350,9 @@ mvc_insert_delta_values(mvc *m, BAT *col
                return createException(SQL,"sql.delta", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
        }
        /* compute level using global transaction */
-       if (gtrans) {
-               sql_column *oc = tr_find_column(gtrans, c);
-
-               if (oc) {
-                       for(sql_delta *d = oc->data; d; d = d->next)
+       if (c) {
+                       for(sql_delta *d = c->data; d; d = d->next)
                                level++;
-               }
        }
        if (BUNappend(col7, &level, false) != GDK_SUCCEED) {
                return createException(SQL,"sql.delta", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -921,7 +921,6 @@ alter_table(Client cntxt, mvc *sql, char
                if (c->storage_type != nc->storage_type) {
                        if (c->t->access == TABLE_WRITABLE)
                                throw(SQL,"sql.alter_table", SQLSTATE(40002) 
"ALTER TABLE: SET STORAGE for column %s.%s only allowed on READ or INSERT ONLY 
tables", c->t->base.name, c->base.name);
-                       nc->base.rtime = nc->base.wtime = 
sql->session->tr->wtime;
                        mvc_storage(sql, nc, c->storage_type);
                }
        }
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -851,7 +851,6 @@ mvc_import_table(Client cntxt, BAT ***ba
                                BAT *b = 
store->storage_api.bind_col(m->session->tr, c, RDONLY);
                                sql_delta *d = c->data;
 
-                               c->base.wtime = t->base.wtime = 
t->s->base.wtime = m->session->tr->wtime = m->session->tr->wstime;
                                if ( b == NULL)
                                        sql_error(m, 500, "failed to bind to 
delta column");
                                else {
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
@@ -197,14 +197,13 @@ typedef enum commit_action_t {
 typedef int sqlid;
 
 typedef struct sql_base {
-       int wtime;
-       int rtime;
-       int stime;
        int allocated;
        int flags;
        int refcnt;
        sqlid id;
        char *name;
+       ulng ts;                                /* transaction start timestamp 
*/
+       struct sql_base *next;  /* older versions */
 } sql_base;
 
 #define newFlagSet(x)     ((x & TR_NEW) == TR_NEW)
@@ -267,14 +266,13 @@ typedef struct sql_catalog {
 
 typedef struct sql_trans {
        char *name;
-       int ts;                         /* transaction timestamp */
-       sql_store store;        /* keep link into the global store */
+
+       ulng ts;                /* transaction start timestamp */
+       ulng tid;               /* transaction id */
 
-       int stime;              /* start of transaction */
-       int wstime;             /* first write transaction time stamp */
-       int wtime;              /* timestamp of latest write performed in 
transaction*/
-       int schema_number;      /* schema timestamp */
-       int schema_updates;     /* set on schema changes */
+       sql_store store;        /* keep link into the global store */
+       list *changes;  /* list of changes */
+
        int active;             /* active transaction */
        int status;             /* status of the last query */
        list *dropped;          /* protection against recursive cascade action*/
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
@@ -445,7 +445,7 @@ void
 mvc_cancel_session(mvc *m)
 {
        store_lock(m->store);
-       sql_trans_end(m->session, 0);
+       (void)sql_trans_end(m->session, 0);
        store_unlock(m->store);
 }
 
@@ -466,7 +466,7 @@ mvc_trans(mvc *m)
                        /* TODO Change into recreate all */
                        m->qc = qc_create(m->pa, m->clientid, seqnr);
                        if (!m->qc) {
-                               sql_trans_end(m->session, 0);
+                               (void)sql_trans_end(m->session, 0);
                                store_unlock(m->store);
                                return -1;
                        }
@@ -481,7 +481,7 @@ mvc_commit(mvc *m, int chain, const char
 {
        sql_trans *cur, *tr = m->session->tr, *ctr;
        int ok = SQL_OK;
-       str msg, other;
+       str msg = NULL, other;
        char operation[BUFSIZ];
 
        assert(tr);
@@ -527,6 +527,18 @@ mvc_commit(mvc *m, int chain, const char
                return msg;
        }
 
+       if (!tr->parent && !name) {
+               store_lock(m->store);
+               if (sql_trans_end(m->session, 1) != SQL_OK) {
+                       store_unlock(m->store);
+                       /* transaction conflict */
+                       msg = createException(SQL, "sql.commit", 
SQLSTATE(40000) "%s transaction is aborted because of concurrency conflicts, 
will ROLLBACK instead", operation);
+                       return msg;
+               }
+               store_unlock(m->store);
+               return msg;
+       }
+
        /* first release all intermediate savepoints */
        ctr = cur = tr;
        tr = tr->parent;
@@ -548,9 +560,9 @@ mvc_commit(mvc *m, int chain, const char
 
        store_lock(m->store);
        /* if there is nothing to commit reuse the current transaction */
-       if (tr->wtime == 0) {
+       if (tr->changes == NULL) {
                if (!chain)
-                       sql_trans_end(m->session, 1);
+                       (void)sql_trans_end(m->session, 1);
                m->type = Q_TRANS;
                msg = WLCcommit(m->clientid);
                store_unlock(m->store);
@@ -564,26 +576,8 @@ mvc_commit(mvc *m, int chain, const char
                return msg;
        }
 
-       /* validation phase */
-       bool valid = sql_trans_validate(tr);
-       if (valid) {
-               store_unlock(m->store);
-               if (sql_save_snapshots(tr) != SQL_OK) {
-                       GDKfatal("%s transaction commit failed (perhaps your 
disk is full?) exiting (kernel error: %s)", operation, GDKerrbuf);
-               }
-               store_lock(m->store);
-       }
-       valid = sql_trans_validate(tr);
-       if (valid) {
-               if ((ok = sql_trans_commit(tr)) != SQL_OK) {
-                       GDKfatal("%s transaction commit failed (perhaps your 
disk is full?) exiting (kernel error: %s)", operation, GDKerrbuf);
-               }
-       } else {
-               store_unlock(m->store);
-               msg = createException(SQL, "sql.commit", SQLSTATE(40000) "%s 
transaction is aborted because of concurrency conflicts, will ROLLBACK 
instead", operation);
-               if ((other = mvc_rollback(m, chain, name, false)) != 
MAL_SUCCEED)
-                       freeException(other);
-               return msg;
+       if ((ok = sql_trans_commit(tr)) != SQL_OK) {
+               GDKfatal("%s transaction commit failed (perhaps your disk is 
full?) exiting (kernel error: %s)", operation, GDKerrbuf);
        }
        msg = WLCcommit(m->clientid);
        if (msg != MAL_SUCCEED) {
@@ -592,7 +586,7 @@ mvc_commit(mvc *m, int chain, const char
                        freeException(other);
                return msg;
        }
-       sql_trans_end(m->session, 1);
+       (void)sql_trans_end(m->session, 1);
        if (chain)
                sql_trans_begin(m->session);
        store_unlock(m->store);
@@ -625,7 +619,7 @@ mvc_rollback(mvc *m, int chain, const ch
                tr = m->session->tr;
                while (!tr->name || strcmp(tr->name, name) != 0) {
                        /* make sure we do not reuse changed data */
-                       if (tr->wtime)
+                       if (tr->changes)
                                tr->status = 1;
                        tr = sql_trans_destroy(tr);
                }
@@ -641,9 +635,9 @@ mvc_rollback(mvc *m, int chain, const ch
                }
                m->session-> tr = tr;
                /* make sure we do not reuse changed data */
-               if (tr->wtime)
+               if (tr->changes)
                        tr->status = 1;
-               sql_trans_end(m->session, 0);
+               (void)sql_trans_end(m->session, 0);
                if (chain)
                        sql_trans_begin(m->session);
        }
@@ -657,7 +651,7 @@ mvc_rollback(mvc *m, int chain, const ch
        TRC_INFO(SQL_TRANS,
                "Commit%s%s rolled back%s\n",
                name ? " " : "", name ? name : "",
-               tr->wtime == 0 ? " (no changes)" : "");
+               !tr->changes ? " (no changes)" : "");
        return msg;
 }
 
@@ -858,7 +852,7 @@ mvc_destroy(mvc *m)
        store_lock(m->store);
        if (tr) {
                if (m->session->tr->active)
-                       sql_trans_end(m->session, 0);
+                       (void)sql_trans_end(m->session, 0);
                while (tr->parent)
                        tr = sql_trans_destroy(tr);
                m->session->tr = NULL;
diff --git a/sql/server/sql_partition.c b/sql/server/sql_partition.c
--- a/sql/server/sql_partition.c
+++ b/sql/server/sql_partition.c
@@ -418,7 +418,6 @@ initialize_sql_parts(mvc *sql, sql_table
                }
                for (node *n = new->h; n; n = n->next) {
                        sql_part *next = (sql_part*) n->data;
-                       sql_table *pt = find_sql_table_id(mt->s, next->base.id);
                        sql_part *err = NULL;
 
                        cs_add(&mt->s->parts, next, TR_NEW);
@@ -435,14 +434,8 @@ initialize_sql_parts(mvc *sql, sql_table
                                                                          
SQLSTATE(42000) "Internal error while bootstrapping partitioned tables");
                                goto finish;
                        }
-                       pt->s->base.wtime = pt->base.wtime = tr->wtime = 
tr->wstime;
-                       if (isGlobal(pt))
-                               tr->schema_updates++;
                }
        }
-       mt->s->base.wtime = mt->base.wtime = tr->wtime = tr->wstime;
-       if (isGlobal(mt))
-               tr->schema_updates++;
 finish:
        return res;
 }
diff --git a/sql/server/sql_privileges.c b/sql/server/sql_privileges.c
--- a/sql/server/sql_privileges.c
+++ b/sql/server/sql_privileges.c
@@ -104,7 +104,6 @@ schema_privs(sqlid grantor, sql_schema *
 str
 sql_grant_global_privs( mvc *sql, char *grantee, int privs, int grant, sqlid 
grantor)
 {
-       sql_trans *tr = sql->session->tr;
        bool allowed;
        sqlid grantee_id;
 
@@ -123,14 +122,12 @@ sql_grant_global_privs( mvc *sql, char *
        if ((sql_privilege(sql, grantee_id, GLOBAL_OBJID, privs) >= 0))
                throw(SQL,"sql.grant_global",SQLSTATE(01007) "GRANT: User/role 
'%s' already has this privilege", grantee);
        sql_insert_priv(sql, grantee_id, GLOBAL_OBJID, privs, grantor, grant);
-       tr->schema_updates++;
        return MAL_SUCCEED;
 }
 
 char *
 sql_grant_table_privs( mvc *sql, char *grantee, int privs, char *sname, char 
*tname, char *cname, int grant, sqlid grantor)
 {
-       sql_trans *tr = sql->session->tr;
        sql_table *t = NULL;
        sql_column *c = NULL;
        bool allowed;
@@ -182,14 +179,12 @@ sql_grant_table_privs( mvc *sql, char *g
        } else {
                sql_insert_priv(sql, grantee_id, c->base.id, privs, grantor, 
grant);
        }
-       tr->schema_updates++;
        return NULL;
 }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to