Changeset: 6a013fec3b56 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/6a013fec3b56 Modified Files: gdk/gdk_bbp.c sql/backends/monet5/sql_scenario.c sql/backends/monet5/sql_user.c sql/include/sql_catalog.h sql/storage/bat/bat_storage.c sql/storage/store.c Branch: default Log Message:
Merge with Dec2023 branch. diffs (237 lines): diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -1711,6 +1711,9 @@ BBPjson_upgrade(json_storage_conversion const char *nme; nme = ATOMunknown_name(b->ttype); + int tt = ATOMindex(nme); + if (tt >= 0) + b->ttype = tt; if (strcmp(nme, "json") != 0) continue; } else if (b->ttype != JSON_type) { @@ -4065,34 +4068,41 @@ BBPsync(int cnt, bat *restrict subcommit if (lock) MT_lock_set(&GDKswapLock(bid)); } - if (subcommit) { + BAT *b = BBP_desc(bid); + if (subcommit && b->ttype != TYPE_void) { /* move any tail/theap files we find for this bat that * are in the BACKUP directory to the SUBCOMMIT * directory */ char fname[16]; /* plenty big enough */ - if (snprintf(fname, sizeof(fname), "%o", i) < 16) { + if (snprintf(fname, sizeof(fname), "%o", (unsigned) bid) < 16) { /* the snprintf never fails, any of the * below may fail */ - if (GDKmove(0, BAKDIR, fname, "tail", SUBDIR, fname, "tail", false) == GDK_SUCCEED) - TRC_DEBUG(BAT_, "moved %s.tail from %s to %s\n", + uint8_t stpe = ATOMstorage(b->ttype); + if ((b->ttype != TYPE_str || b->twidth >= 8) && + GDKmove(0, BAKDIR, fname, "tail", SUBDIR, fname, "tail", false) == GDK_SUCCEED) + TRC_DEBUG(IO_, "moved %s.tail from %s to %s\n", fname, BAKDIR, SUBDIR); - if (GDKmove(0, BAKDIR, fname, "tail1", SUBDIR, fname, "tail1", false) == GDK_SUCCEED) - TRC_DEBUG(BAT_, "moved %s.tail1 from %s to %s\n", + if (stpe == TYPE_str && + GDKmove(0, BAKDIR, fname, "tail1", SUBDIR, fname, "tail1", false) == GDK_SUCCEED) + TRC_DEBUG(IO_, "moved %s.tail1 from %s to %s\n", fname, BAKDIR, SUBDIR); - if (GDKmove(0, BAKDIR, fname, "tail2", SUBDIR, fname, "tail2", false) == GDK_SUCCEED) - TRC_DEBUG(BAT_, "moved %s.tail2 from %s to %s\n", + if (stpe == TYPE_str && b->twidth >= 2 && + GDKmove(0, BAKDIR, fname, "tail2", SUBDIR, fname, "tail2", false) == GDK_SUCCEED) + TRC_DEBUG(IO_, "moved %s.tail2 from %s to %s\n", fname, BAKDIR, SUBDIR); #if SIZEOF_VAR_T == 8 - if (GDKmove(0, BAKDIR, fname, "tail4", SUBDIR, fname, "tail4", false) == GDK_SUCCEED) - TRC_DEBUG(BAT_, "moved %s.tail4 from %s to %s\n", + if (stpe == TYPE_str && b->twidth >= 4 && + GDKmove(0, BAKDIR, fname, "tail4", SUBDIR, fname, "tail4", false) == GDK_SUCCEED) + TRC_DEBUG(IO_, "moved %s.tail4 from %s to %s\n", fname, BAKDIR, SUBDIR); #endif - if (GDKmove(0, BAKDIR, fname, "theap", SUBDIR, fname, "theap", false) == GDK_SUCCEED) - TRC_DEBUG(BAT_, "moved %s.theap from %s to %s\n", + if (ATOMvarsized(b->ttype) && + GDKmove(0, BAKDIR, fname, "theap", SUBDIR, fname, "theap", false) == GDK_SUCCEED) + TRC_DEBUG(IO_, "moved %s.theap from %s to %s\n", fname, BAKDIR, SUBDIR); } } - BAT *b = dirty_bat(&i, subcommit != NULL); + b = dirty_bat(&i, subcommit != NULL); if (i <= 0) ret = GDK_FAIL; else if (BBP_status(bid) & BBPEXISTING && 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 @@ -819,7 +819,7 @@ SQLtrans(mvc *m) } s = m->session; if (!s->schema) { - switch (monet5_user_get_def_schema(m, m->user_id, &s->schema_name)) { + switch (monet5_user_get_def_schema(m, m->user_id, &s->def_schema_name)) { case -1: mvc_cancel_session(m); throw(SQL, "sql.trans", SQLSTATE(HY013) MAL_MALLOC_FAIL); @@ -832,6 +832,7 @@ SQLtrans(mvc *m) default: break; } + s->schema_name = s->def_schema_name; if (!(s->schema = find_sql_schema(s->tr, s->schema_name))) { mvc_cancel_session(m); throw(SQL, "sql.trans", SQLSTATE(42000) "The session's schema was not found, this session is going to terminate"); diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c --- a/sql/backends/monet5/sql_user.c +++ b/sql/backends/monet5/sql_user.c @@ -849,6 +849,8 @@ monet5_user_set_def_schema(mvc *m, oid u } /* while getting the session's schema, set the search path as well */ + /* new default schema */ + m->session->def_schema_name = schema; if (!(ok = mvc_set_schema(m, schema)) || (path_err = parse_schema_path_str(m, schema_path, true)) != MAL_SUCCEED) { if (m->session->tr->active && (other = mvc_rollback(m, 0, NULL, false)) != MAL_SUCCEED) freeException(other); 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 @@ -757,6 +757,7 @@ typedef struct sql_session { allocator *sa; sql_trans *tr; /* active transaction */ + char *def_schema_name; /* users default schema name */ char *schema_name; /* transaction's schema name */ sql_schema *schema; 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 @@ -4474,10 +4474,10 @@ tc_gc_col( sql_store Store, sql_change * return LOG_OK; /* cannot cleanup yet */ // d is oldest reachable delta - if (d->cs.merged && d->next) // Unreachable can immediately be destroyed. + if (d->cs.merged && d->next) { // Unreachable can immediately be destroyed. destroy_delta(d->next, true); - - d->next = NULL; + d->next = NULL; + } lock_column(store, c->base.id); /* lock for concurrent updates (appends) */ merge_delta(d); unlock_column(store, c->base.id); @@ -4514,10 +4514,10 @@ tc_gc_upd_col( sql_store Store, sql_chan return LOG_OK; /* cannot cleanup yet */ // d is oldest reachable delta - if (d->cs.merged && d->next) // Unreachable can immediately be destroyed. + if (d->cs.merged && d->next) { // Unreachable can immediately be destroyed. destroy_delta(d->next, true); - - d->next = NULL; + d->next = NULL; + } lock_column(store, c->base.id); /* lock for concurrent updates (appends) */ merge_delta(d); unlock_column(store, c->base.id); @@ -4554,10 +4554,10 @@ tc_gc_idx( sql_store Store, sql_change * return LOG_OK; /* cannot cleanup yet */ // d is oldest reachable delta - if (d->cs.merged && d->next) // Unreachable can immediately be destroyed. + if (d->cs.merged && d->next) { // Unreachable can immediately be destroyed. destroy_delta(d->next, true); - - d->next = NULL; + d->next = NULL; + } lock_column(store, i->base.id); /* lock for concurrent updates (appends) */ merge_delta(d); unlock_column(store, i->base.id); @@ -4594,10 +4594,10 @@ tc_gc_upd_idx( sql_store Store, sql_chan return LOG_OK; /* cannot cleanup yet */ // d is oldest reachable delta - if (d->cs.merged && d->next) // Unreachable can immediately be destroyed. + if (d->cs.merged && d->next) { // Unreachable can immediately be destroyed. destroy_delta(d->next, true); - - d->next = NULL; + d->next = NULL; + } lock_column(store, i->base.id); /* lock for concurrent updates (appends) */ merge_delta(d); unlock_column(store, i->base.id); diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -7237,13 +7237,11 @@ sql_session_destroy(sql_session *s) int sql_session_reset(sql_session *s, int ac) { - char *def_schema_name = SA_STRDUP(s->sa, "sys"); - - if (!s->tr || !def_schema_name) + if (!s->tr) return 0; assert(s->tr && s->tr->active == 0); - s->schema_name = def_schema_name; + s->schema_name = s->def_schema_name; s->schema = NULL; s->auto_commit = s->ac_on_commit = ac; s->level = tr_serializable; @@ -7259,7 +7257,11 @@ sql_trans_begin(sql_session *s) store_lock(store); TRC_DEBUG(SQL_STORE, "Enter sql_trans_begin for transaction: " ULLFMT "\n", tr->tid); tr->ts = store_timestamp(store); - if (!(s->schema = find_sql_schema(tr, s->schema_name))) { + if (s->schema_name && !(s->schema = find_sql_schema(tr, s->schema_name))) + s->schema_name = s->def_schema_name; + if (!s->schema_name) + s->schema_name = "sys"; + if (s->schema_name && !(s->schema = find_sql_schema(tr, s->schema_name))) { TRC_DEBUG(SQL_STORE, "Exit sql_trans_begin for transaction: " ULLFMT " with error, the schema %s was not found\n", tr->tid, s->schema_name); store_unlock(store); return -3; @@ -7291,6 +7293,7 @@ sql_trans_end(sql_session *s, int ok) s->tr->active = 0; s->tr->status = 0; s->auto_commit = s->ac_on_commit; + s->schema = NULL; list_remove_data(store->active, NULL, s->tr); ATOMIC_SET(&store->lastactive, GDKusec()); ATOMIC_DEC(&store->nr_active); diff --git a/sql/test/transactions/Tests/All b/sql/test/transactions/Tests/All --- a/sql/test/transactions/Tests/All +++ b/sql/test/transactions/Tests/All @@ -10,3 +10,4 @@ truncate-insert-restart update_drop_crash update_drop_crash2 insert_drop_crash +rollback_and_schema-Bug-7499 diff --git a/sql/test/transactions/Tests/rollback_and_schema-Bug-7499.test b/sql/test/transactions/Tests/rollback_and_schema-Bug-7499.test new file mode 100644 --- /dev/null +++ b/sql/test/transactions/Tests/rollback_and_schema-Bug-7499.test @@ -0,0 +1,14 @@ +statement ok +START TRANSACTION + +statement ok +CREATE SCHEMA test + +statement ok +SET SCHEMA test + +statement ok +ROLLBACK + +statement ok +SET SCHEMA sys _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org