Skip to content

Commit

Permalink
Verify client dbstore only on master
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hannum <[email protected]>
  • Loading branch information
markhannum committed Dec 2, 2024
1 parent df44f1c commit 7be2427
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 11 deletions.
5 changes: 3 additions & 2 deletions bdb/llmeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ static const uint8_t *llmeta_tablename_alias_data_get(
return p_buf;
}

int gbl_llmeta_pagesize = 0;
/* opens the low level meta table, if this is not called, any calls to
* bdb_get_file_version* will return successfully but with a 0 version_number
* any calls to bdb_new_file_version will fail */
Expand All @@ -1274,8 +1275,8 @@ int bdb_llmeta_open(char name[], char dir[], bdb_state_type *parent_bdb_handle,
return 0;
}

llmeta_bdb_state = bdb_open_more_lite(
name, dir, 0, LLMETA_IXLEN, 0, parent_bdb_handle, NULL, 0, bdberr);
llmeta_bdb_state =
bdb_open_more_lite(name, dir, 0, LLMETA_IXLEN, gbl_llmeta_pagesize, parent_bdb_handle, NULL, 0, bdberr);

BDB_RELLOCK();

Expand Down
2 changes: 2 additions & 0 deletions db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ extern int gbl_fdb_push_remote;
extern int gbl_goslow;
extern int gbl_heartbeat_send;
extern int gbl_keycompr;
extern int gbl_llmeta_pagesize;
extern int gbl_largepages;
extern int gbl_loghist;
extern int gbl_loghist_verbose;
Expand Down Expand Up @@ -145,6 +146,7 @@ extern int diffstat_thresh;
extern int reqltruncate;
extern int analyze_max_comp_threads;
extern int analyze_max_table_threads;
extern int gbl_always_reload_analyze;
extern int gbl_block_set_commit_genid_trace;
extern int gbl_random_prepare_commit;
extern int gbl_all_prepare_commit;
Expand Down
9 changes: 4 additions & 5 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ REGISTER_TUNABLE("analyze_tbl_threads",
"generating index statistics. (Default: 5)",
TUNABLE_INTEGER, &analyze_max_table_threads, READONLY, NULL,
NULL, analyze_set_max_table_threads, NULL);
REGISTER_TUNABLE("always_reload_analyze", "Reload analyze data on every query. (Default: off)", TUNABLE_BOOLEAN,
&gbl_always_reload_analyze, 0, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("badwrite_intvl", NULL, TUNABLE_INTEGER,
&gbl_test_badwrite_intvl, READONLY, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("bbenv", NULL, TUNABLE_BOOLEAN, &gbl_bbenv,
Expand Down Expand Up @@ -974,11 +976,8 @@ REGISTER_TUNABLE(
"Perform table scans in page order and not row order. (Default: off)",
TUNABLE_BOOLEAN, &gbl_page_order_table_scan, NOARG, NULL, NULL,
page_order_table_scan_update, NULL);
/*
REGISTER_TUNABLE("pagesize", NULL, TUNABLE_INTEGER,
&placeholder, DEPRECATED_TUNABLE|READONLY, NULL, NULL, NULL,
NULL);
*/
REGISTER_TUNABLE("llmeta_pagesize", "Init-option for llmeta and metadb pagesizes. (Default: 4096)", TUNABLE_INTEGER,
&gbl_llmeta_pagesize, READONLY | READEARLY, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("parallel_recovery", NULL, TUNABLE_INTEGER,
&gbl_parallel_recovery_threads, READONLY, NULL, NULL, NULL,
NULL);
Expand Down
16 changes: 14 additions & 2 deletions db/sqlglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -12941,13 +12941,25 @@ int verify_dbstore_client_function(const char *dbstore)
int rc = 0;
strbuf *sql;

/* This deadlocks in replication. On the master, this is called
* from do_schema_change_tran_thd (prior to finalize). This thread
* calls do_alter_table with tran set to NULL, no self-deadlock. */
if (!bdb_iam_master(thedb->bdb_env) || gbl_is_physical_replicant) {
return 0;
}

sql = strbuf_new();
strbuf_appendf(sql, "TESTDEFAULT (%s)", dbstore);

rc = run_verify_dbstore_function((char *)strbuf_buf(sql));
struct errstat err = {0};
run_sql_return_ll((char *)strbuf_buf(sql), &err);
if (err.errval != 0) {
logmsg(LOGMSG_ERROR, "error verifying dbstore expression (%s): %s\n", dbstore, err.errstr);
rc = -1;
}

strbuf_free(sql);
return rc ? -1 : 0;
return rc;
}

/* Verify all CHECK constraints against this record.
Expand Down
4 changes: 3 additions & 1 deletion db/sqlinterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,8 @@ static int reload_analyze(struct sqlthdstate *thd, struct sqlclntstate *clnt,
thd->dbopen_gen, bdb_get_dbopen_gen(), thd->analyze_gen, \
cached_analyze_gen, thd->views_gen, gbl_views_gen);

int gbl_always_reload_analyze = 0;

// Call with schema_lk held and in_sqlite_init == 1
static int check_thd_gen(struct sqlthdstate *thd, struct sqlclntstate *clnt, int flags)
{
Expand All @@ -2640,7 +2642,7 @@ static int check_thd_gen(struct sqlthdstate *thd, struct sqlclntstate *clnt, int
TRK;
return SQLITE_SCHEMA;
}
if (thd->analyze_gen != cached_analyze_gen) {
if ((thd->analyze_gen != cached_analyze_gen) || gbl_always_reload_analyze) {
int ret;
TRK;
stmt_cache_reset(thd->stmt_cache);
Expand Down
4 changes: 4 additions & 0 deletions tests/sc_dbstore_func.test/lrl.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Force large pages in llmeta
llmeta_pagesize 65536
always_reload_analyze 1

21 changes: 20 additions & 1 deletion tests/sc_dbstore_func.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bash -n "$0" | exit 1

dbnm=$1

cat << EOF | cdb2sql ${CDB2_OPTIONS} -tabs -s $dbnm default - >output.actual 2>&1
cat << EOF | timeout -s 9 60s cdb2sql ${CDB2_OPTIONS} -tabs -s $dbnm default - >output.actual 2>&1
SELECT "- Testing dbstore now() -"
CREATE TABLE t1 { tag ondisk { int i } }\$\$
INSERT INTO t1 VALUES (1)
Expand Down Expand Up @@ -40,6 +40,25 @@ EOF

diff output.actual output.expected

function verify_all_replicants()
{
if [[ -z "$CLUSTER" ]]; then
return 0
fi

for node in $CLUSTER ; do
x=$(timeout -s 9 10s cdb2sql ${CDB2_OPTIONS} -tabs -s ${DBNAME} --host $node "select 1")
if [[ $? -ne 0 || "$x" != "1" ]]; then
echo "Failed to connect to $node"
exit 1
fi
done
}

# Alter again, and verify that we do not hang on replicants
timeout -s 9 20s cdb2sql ${CDB2_OPTIONS} -tabs $dbnm default "ALTER TABLE t1 { `cat t1_hang.csc2` }"
verify_all_replicants

# Make sure we can create a new db which specifies a client-function dbstore,
# but that we fail to create a new db which has an invalid dbstore function.
function create_database_with_table()
Expand Down
7 changes: 7 additions & 0 deletions tests/sc_dbstore_func.test/t1_hang.csc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
schema {
cstring s[33] dbstore={hex(GUID())}
datetime t dbstore={now()} null=yes
datetime t3 dbstore={now()} null=yes
datetime t4 dbstore={now()} null=yes
cstring s2[33] dbstore={hex(GUID())} null=yes
}
3 changes: 3 additions & 0 deletions tests/sc_dbstore_func.test/testdb.lrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name testdb
dir /home/ubuntu/comdb2/tests/sc_dbstore_func.test/testdb

2 changes: 2 additions & 0 deletions tests/tunables.test/t00_all_tunables.expected
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(name='allow_user_schema', description='Enable to allow per-user schemas. (Default: off)', type='BOOLEAN', value='OFF', read_only='Y')
(name='already_aborted_trace', description='Print trace when dd_abort skips an 'already-aborted' locker', type='BOOLEAN', value='OFF', read_only='N')
(name='alternate_verify_fail', description='alternate_verify_fail', type='BOOLEAN', value='OFF', read_only='N')
(name='always_reload_analyze', description='Reload analyze data on every query. (Default: off)', type='BOOLEAN', value='OFF', read_only='N')
(name='always_send_cnonce', description='Always send cnonce to master. (Default: on)', type='BOOLEAN', value='ON', read_only='N')
(name='analyze_comp_threads', description='Number of thread to use when generating samples for computing index statistics. (Default: 10)', type='INTEGER', value='10', read_only='Y')
(name='analyze_comp_threshold', description='Index file size above which we'll do sampling, rather than scan the entire index. (Default: 104857600)', type='INTEGER', value='104857600', read_only='Y')
Expand Down Expand Up @@ -442,6 +443,7 @@
(name='lkr_part', description='', type='INTEGER', value='23', read_only='Y')
(name='llmeta', description='', type='BOOLEAN', value='ON', read_only='N')
(name='llmeta_deadlock_poll', description='Max poll for llmeta on deadlock. (Default: 0ms)', type='INTEGER', value='0', read_only='N')
(name='llmeta_pagesize', description='Init-option for llmeta and metadb pagesizes. (Default: 4096)', type='INTEGER', value='0', read_only='Y')
(name='load_cache_max_pages', description='Maximum number of pages that will load into cache. Setting to 0 means that there is no limit. (Default: 0)', type='INTEGER', value='0', read_only='N')
(name='load_cache_threads', description='Number of threads loading pages to cache. (Default: 8)', type='INTEGER', value='8', read_only='N')
(name='loadcache.dump_on_full', description='Dump status on full queue.', type='BOOLEAN', value='OFF', read_only='N')
Expand Down

0 comments on commit 7be2427

Please sign in to comment.