Changeset: a0a7e29ca2b6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a0a7e29ca2b6
Modified Files:
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_storage.c
        sql/storage/sql_storage.h
Branch: Jan2022
Log Message:

Lock column while vacuuming. Cleanup


diffs (160 lines):

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
@@ -4787,35 +4787,18 @@ finalize:
 }
 
 static str
-do_str_column_vacuum(sql_trans *tr, sql_column *c, int access, char *sname, 
char *tname, char *cname) {
+do_str_column_vacuum(sql_trans *tr, sql_column *c, char *sname, char *tname, 
char *cname)
+{
        int res;
-       BAT* b = NULL;
-       BAT* bn = NULL;
        sqlstore *store = tr->store;
 
-       if ((b = store->storage_api.bind_col(tr, c, access)) == NULL)
-               throw(SQL, "do_str_column_vacuum", SQLSTATE(42S22) 
"storage_api.bind_col failed for %s.%s.%s", sname, tname, cname);
-       // vacuum only string bats
-       if (ATOMstorage(b->ttype) == TYPE_str) {
-               // TODO check for num of updates on the BAT against some 
threshold
-               // and decide whether to proceed
-               if ((bn = COLcopy(b, b->ttype, true, b->batRole)) == NULL) {
-                       BBPunfix(b->batCacheid);
-                       throw(SQL, "do_str_column_vacuum", SQLSTATE(42S22) 
"COLcopy failed for %s.%s.%s", sname, tname, cname);
-               }
-               if ((res = (int) store->storage_api.swap_bats(tr, c, bn)) != 
LOG_OK) {
-                       BBPreclaim(bn);
-                       BBPunfix(b->batCacheid);
-                       if (res == LOG_CONFLICT)
-                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(25S01) "TRANSACTION CONFLICT in storage_api.swap_bats %s.%s.%s", 
sname, tname, cname);
-                       if (res == LOG_ERR)
-                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(HY000) "LOG ERROR in storage_api.swap_bats %s.%s.%s", sname, tname, 
cname);
-                       throw(SQL, "do_str_column_vacuum", SQLSTATE(HY000) 
"ERROR in storage_api.swap_bats %s.%s.%s", sname, tname, cname);
-               }
-       }
-       BBPunfix(b->batCacheid);
-       if (bn)
-               BBPunfix(bn->batCacheid);
+       if ((res = store->storage_api.swap_bats(tr, c)) != LOG_OK) {
+               if (res == LOG_CONFLICT)
+                       throw(SQL, "do_str_column_vacuum", SQLSTATE(25S01) 
"TRANSACTION CONFLICT in storage_api.swap_bats %s.%s.%s", sname, tname, cname);
+               if (res == LOG_ERR)
+                       throw(SQL, "do_str_column_vacuum", SQLSTATE(HY000) "LOG 
ERROR in storage_api.swap_bats %s.%s.%s", sname, tname, cname);
+               throw(SQL, "do_str_column_vacuum", SQLSTATE(HY000) "ERROR in 
storage_api.swap_bats %s.%s.%s", sname, tname, cname);
+       }
        return MAL_SUCCEED;
 }
 
@@ -4824,7 +4807,6 @@ SQLstr_column_vacuum(Client cntxt, MalBl
 {
        mvc *m = NULL;
        str msg = NULL;
-       int access = 0;
        char *sname = *getArgReference_str(stk, pci, 1);
        char *tname = *getArgReference_str(stk, pci, 2);
        char *cname = *getArgReference_str(stk, pci, 3);
@@ -4855,7 +4837,7 @@ SQLstr_column_vacuum(Client cntxt, MalBl
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42S22) "Column not 
found %s.%s",sname,tname);
 
-       return do_str_column_vacuum(tr, c, access, sname, tname, cname);
+       return do_str_column_vacuum(tr, c, sname, tname, cname);
 }
 
 
@@ -4870,7 +4852,6 @@ str_column_vacuum_callback(int argc, voi
        sql_schema *s = NULL;
        sql_table *t = NULL;
        sql_column *c = NULL;
-       int access = 0;
        char *msg;
        gdk_return res = GDK_SUCCEED;
 
@@ -4913,7 +4894,7 @@ str_column_vacuum_callback(int argc, voi
                        break;
                }
 
-               if((msg=do_str_column_vacuum(session->tr, c, access, sname, 
tname, cname)) != MAL_SUCCEED) {
+               if((msg=do_str_column_vacuum(session->tr, c, sname, tname, 
cname)) != MAL_SUCCEED) {
                        TRC_ERROR((component_t) SQL, 
"[str_column_vacuum_callback] -- %s", msg);
                        res = GDK_FAIL;
                }
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
@@ -4357,34 +4357,53 @@ temp_del_tab(sql_trans *tr, sql_table *t
 }
 
 static int
-swap_bats(sql_trans *tr, sql_column *col, BAT *bn)
+swap_bats(sql_trans *tr, sql_column *col)
 {
+       BAT *b = NULL, *bn = NULL;
        bool update_conflict = false;
-       int in_transaction = segments_in_transaction(tr, col->t);
-
-       if (in_transaction)
+       int in_transaction = 0;
+       sql_delta *d = NULL, *odelta;
+
+       if (ATOMstorage(col->type.type->localtype) != TYPE_str) /* only swap 
strings */
+               return LOG_OK;
+
+       if ((in_transaction = segments_in_transaction(tr, col->t)))
                return LOG_CONFLICT;
 
-       sql_delta *d = NULL, *odelta = ATOMIC_PTR_GET(&col->data);
-
        if ((d = bind_col_data(tr, col, &update_conflict)) == NULL)
                return update_conflict ? LOG_CONFLICT : LOG_ERR;
        assert(d && d->cs.ts == tr->tid);
+       odelta = ATOMIC_PTR_GET(&col->data);
        if ((!inTransaction(tr, col->t) && (odelta != d || isTempTable(col->t)) 
&& isGlobal(col->t)) || (!isNew(col->t) && isLocalTemp(col->t)))
                trans_add(tr, &col->base, d, &tc_gc_col, &commit_update_col, 
&log_update_col);
-       if (d->cs.bid)
-               temp_destroy(d->cs.bid);
+
+       lock_column(tr->store, col->base.id);
+       if (!(b = temp_descriptor(d->cs.bid))) {
+               unlock_column(tr->store, col->base.id);
+               return LOG_ERR;
+       }
+       // TODO check for num of updates on the BAT against some threshold
+       // and decide whether to proceed
+       if (!(bn = COLcopy(b, b->ttype, true, b->batRole))) {
+               bat_destroy(b);
+               unlock_column(tr->store, col->base.id);
+               return LOG_ERR;
+       }
+       bat_destroy(b);
+       temp_destroy(d->cs.bid);
+       d->cs.bid = temp_create(bn);
+       bat_destroy(bn);
        if (d->cs.uibid)
                temp_destroy(d->cs.uibid);
        if (d->cs.uvbid)
                temp_destroy(d->cs.uvbid);
-       d->cs.bid = temp_create(bn);
        d->cs.uibid = 0;
        d->cs.uvbid = 0;
        d->cs.ucnt = 0;
        d->cs.cleared = 0;
        d->cs.ts = tr->tid;
        d->cs.refcnt = 1;
+       unlock_column(tr->store, col->base.id);
        return LOG_OK;
 }
 
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -176,7 +176,7 @@ typedef void *(*del_dup_fptr) (sql_table
 typedef int (*upgrade_col_fptr) (sql_trans *tr, sql_column *c);
 typedef int (*upgrade_idx_fptr) (sql_trans *tr, sql_idx *i);
 typedef int (*upgrade_del_fptr) (sql_trans *tr, sql_table *t);
-typedef int (*swap_bats_fptr) (sql_trans *tr, sql_column *c, BAT *b);
+typedef int (*swap_bats_fptr) (sql_trans *tr, sql_column *c);
 
 /*
 -- free the storage resources for columns, indices and tables
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to