Changeset: 06f20b2c802e for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/06f20b2c802e Added Files: sql/test/BugTracker-2024/Tests/7512-concurrent-globaltmp-instantiate-crash.test Modified Files: sql/scripts/52_describe.sql sql/storage/sql_catalog.c sql/storage/store.c sql/test/BugTracker-2024/Tests/All Branch: Dec2023 Log Message:
fixed bug #7512, protect concurrent instantiation of the global temps diffs (99 lines): diff --git a/sql/scripts/52_describe.sql b/sql/scripts/52_describe.sql --- a/sql/scripts/52_describe.sql +++ b/sql/scripts/52_describe.sql @@ -315,7 +315,6 @@ CREATE VIEW sys.describe_foreign_keys AS AND ((fkk."action" >> 8) & 255) = ou.id ORDER BY fkk.name, fkkc.nr; ---TODO: CRASHES when this function gets inlined into describe_tables CREATE FUNCTION sys.get_merge_table_partition_expressions(tid INT) RETURNS STRING BEGIN RETURN diff --git a/sql/storage/sql_catalog.c b/sql/storage/sql_catalog.c --- a/sql/storage/sql_catalog.c +++ b/sql/storage/sql_catalog.c @@ -253,13 +253,20 @@ find_sql_table(sql_trans *tr, sql_schema } if (t && isTempTable(t) && tr->tmp == s) { + sqlstore *store = tr->store; assert(isGlobal(t)); sql_table* lt = (sql_table*) os_find_name(tr->localtmps, tr, tname); if (lt) return lt; + MT_lock_set(&store->table_locks[t->base.id&(NR_TABLE_LOCKS-1)]); - t = globaltmp_instantiate(tr, t); + lt = (sql_table*) os_find_name(tr->localtmps, tr, tname); + if (!lt) + t = globaltmp_instantiate(tr, t); + else + t = lt; + MT_lock_unset(&store->table_locks[t->base.id&(NR_TABLE_LOCKS-1)]); return t; } @@ -276,13 +283,19 @@ find_sql_table_id(sql_trans *tr, sql_sch } if (t && isTempTable(t) && tr->tmp == s) { + sqlstore *store = tr->store; assert(isGlobal(t)); sql_table* lt = (sql_table*) os_find_id(tr->localtmps, tr, id); if (lt) return lt; - - t = globaltmp_instantiate(tr, t); + MT_lock_set(&store->table_locks[id&(NR_TABLE_LOCKS-1)]); + lt = (sql_table*) os_find_id(tr->localtmps, tr, id); + if (!lt) + t = globaltmp_instantiate(tr, t); + else + t = lt; + MT_lock_unset(&store->table_locks[id&(NR_TABLE_LOCKS-1)]); return t; } return t; diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -3197,9 +3197,6 @@ table_dup(sql_trans *tr, sql_table *ot, t->sz = ot->sz; ATOMIC_PTR_INIT(&t->data, NULL); - if ((res = os_add(isLocalTemp(t) ? tr->localtmps : t->s->tables, tr, t->base.name, &t->base))) - goto cleanup; - if (isPartitionedByExpressionTable(ot)) { t->part.pexp = ZNEW(sql_expression); t->part.pexp->exp =_STRDUP(ot->part.pexp->exp); @@ -3257,6 +3254,8 @@ table_dup(sql_trans *tr, sql_table *ot, ATOMIC_PTR_SET(&t->data, store->storage_api.del_dup(ot)); } } + if ((res = os_add(isLocalTemp(t) ? tr->localtmps : t->s->tables, tr, t->base.name, &t->base))) + goto cleanup; cleanup: if (res) { diff --git a/sql/test/BugTracker-2024/Tests/7512-concurrent-globaltmp-instantiate-crash.test b/sql/test/BugTracker-2024/Tests/7512-concurrent-globaltmp-instantiate-crash.test new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2024/Tests/7512-concurrent-globaltmp-instantiate-crash.test @@ -0,0 +1,5 @@ +statement error conversion of string '' to type int failed. +SELECT GET_MERGE_TABLE_PARTITION_EXPRESSIONS('') + +statement ok +SELECT GET_MERGE_TABLE_PARTITION_EXPRESSIONS(0) diff --git a/sql/test/BugTracker-2024/Tests/All b/sql/test/BugTracker-2024/Tests/All --- a/sql/test/BugTracker-2024/Tests/All +++ b/sql/test/BugTracker-2024/Tests/All @@ -53,4 +53,5 @@ rel2bin_select-Bug-7496 multicolumn_IN_value_list-Bug-7497 field-arg-error-Bug-7506 7511-password-hash-missing-error +7512-concurrent-globaltmp-instantiate-crash 7513-uri-authority-parse-issue _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org