From c216e1afb7b9bbe76bcee2d51d573b92ccbe5fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 1 Nov 2023 11:04:00 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-test:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B8=20`mdbx=5Fdbi=5Frename()`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/jitter.c++ | 27 ++++++++++++++++++++++++++- test/test.c++ | 42 ++++++++++++++++++++++++++++-------------- test/test.h++ | 5 ++++- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/test/jitter.c++ b/test/jitter.c++ index b25599b0..993631e8 100644 --- a/test/jitter.c++ +++ b/test/jitter.c++ @@ -39,6 +39,12 @@ bool testcase_jitter::run() { if (upper_limit < 1) upper_limit = config.params.size_now * 2; + tablename_buf buffer; + const char *const tablename = db_tablename(buffer); + tablename_buf buffer_renamed; + const char *const tablename_renamed = + db_tablename(buffer_renamed, ".renamed"); + while (should_continue()) { jitter_delay(); db_open(); @@ -48,6 +54,15 @@ bool testcase_jitter::run() { txn_begin(false); dbi = db_table_open(true); check_dbi_error(MDBX_SUCCESS, "created-uncommitted"); + + bool renamed = false; + if (flipcoin()) { + err = mdbx_dbi_rename(txn_guard.get(), dbi, tablename_renamed); + if (err != MDBX_SUCCESS) + failure_perror("jitter.rename-1", err); + renamed = true; + } + // note: here and below the 4-byte length keys and value are used // to be compatible with any Db-flags given from command line. MDBX_val k = {(void *)"k000", 4}, v = {(void *)"v001", 4}; @@ -75,7 +90,17 @@ bool testcase_jitter::run() { failure_perror("jitter.put-2", err); check_dbi_error(MDBX_BAD_DBI, "dropped-recreated-aborted"); // restore DBI - dbi = db_table_open(false); + dbi = db_table_open(false, renamed); + if (renamed) { + err = mdbx_dbi_open( + txn_guard.get(), tablename_renamed, + flipcoin() ? MDBX_DB_ACCEDE : config.params.table_flags, &dbi); + if (unlikely(err != MDBX_SUCCESS)) + failure_perror("open-renamed", err); + err = mdbx_dbi_rename(txn_guard.get(), dbi, tablename); + if (err != MDBX_SUCCESS) + failure_perror("jitter.rename-2", err); + } check_dbi_error(MDBX_SUCCESS, "dropped-recreated-aborted+reopened"); v = {(void *)"v003", 4}; err = mdbx_put(txn_guard.get(), dbi, &k, &v, MDBX_UPSERT); diff --git a/test/test.c++ b/test/test.c++ index 77c90c0a..e590d3ce 100644 --- a/test/test.c++ +++ b/test/test.c++ @@ -537,29 +537,43 @@ int testcase::db_open__begin__table_create_open_clean(MDBX_dbi &handle) { return err; } -MDBX_dbi testcase::db_table_open(bool create) { - log_trace(">> testcase::db_table_create"); - - char tablename_buf[16]; +const char *testcase::db_tablename(tablename_buf &buffer, + const char *suffix) const { const char *tablename = nullptr; if (config.space_id) { - int rc = snprintf(tablename_buf, sizeof(tablename_buf), "TBL%04u", - config.space_id); + int rc = + snprintf(buffer, sizeof(buffer), "TBL%04u%s", config.space_id, suffix); if (rc < 4 || rc >= (int)sizeof(tablename_buf) - 1) failure("snprintf(tablename): %d", rc); - tablename = tablename_buf; + tablename = buffer; } log_debug("use %s table", tablename ? tablename : "MAINDB"); + return tablename; +} + +MDBX_dbi testcase::db_table_open(bool create, bool expect_failure) { + log_trace(">> testcase::db_table_%s%s", create ? "create" : "open", + expect_failure ? "(expect_failure)" : ""); + + tablename_buf buffer; + const char *tablename = db_tablename(buffer); MDBX_dbi handle = 0; - int rc = mdbx_dbi_open(txn_guard.get(), tablename, - (create ? MDBX_CREATE : MDBX_DB_DEFAULTS) | - config.params.table_flags, - &handle); - if (unlikely(rc != MDBX_SUCCESS)) - failure_perror("mdbx_dbi_open()", rc); + int rc = mdbx_dbi_open( + txn_guard.get(), tablename, + create ? (MDBX_CREATE | config.params.table_flags) + : (flipcoin() ? MDBX_DB_ACCEDE + : MDBX_DB_DEFAULTS | config.params.table_flags), + &handle); + if (unlikely(expect_failure != (rc != MDBX_SUCCESS))) { + char act[64]; + snprintf(act, sizeof(act), "mdbx_dbi_open(create=%s,expect_failure=%s)", + create ? "true" : "false", expect_failure ? "true" : "false"); + failure_perror(act, rc); + } - log_trace("<< testcase::db_table_create, handle %u", handle); + log_trace("<< testcase::db_table_%s%s, handle %u", create ? "create" : "open", + expect_failure ? "(expect_failure)" : "", handle); return handle; } diff --git a/test/test.h++ b/test/test.h++ index 6158ba66..96d93a7c 100644 --- a/test/test.h++ +++ b/test/test.h++ @@ -265,7 +265,10 @@ protected: MDBX_val expected_valued); unsigned txn_underutilization_x256(MDBX_txn *txn) const; - MDBX_dbi db_table_open(bool create); + using tablename_buf = char[32]; + const char *db_tablename(tablename_buf &buffer, + const char *suffix = "") const; + MDBX_dbi db_table_open(bool create, bool expect_failure = false); void db_table_drop(MDBX_dbi handle); void db_table_clear(MDBX_dbi handle, MDBX_txn *txn = nullptr); void db_table_close(MDBX_dbi handle);