mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx-test: добавление проверки mdbx_dbi_rename()
.
This commit is contained in:
parent
c9c02dddfb
commit
c216e1afb7
@ -39,6 +39,12 @@ bool testcase_jitter::run() {
|
|||||||
if (upper_limit < 1)
|
if (upper_limit < 1)
|
||||||
upper_limit = config.params.size_now * 2;
|
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()) {
|
while (should_continue()) {
|
||||||
jitter_delay();
|
jitter_delay();
|
||||||
db_open();
|
db_open();
|
||||||
@ -48,6 +54,15 @@ bool testcase_jitter::run() {
|
|||||||
txn_begin(false);
|
txn_begin(false);
|
||||||
dbi = db_table_open(true);
|
dbi = db_table_open(true);
|
||||||
check_dbi_error(MDBX_SUCCESS, "created-uncommitted");
|
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
|
// note: here and below the 4-byte length keys and value are used
|
||||||
// to be compatible with any Db-flags given from command line.
|
// to be compatible with any Db-flags given from command line.
|
||||||
MDBX_val k = {(void *)"k000", 4}, v = {(void *)"v001", 4};
|
MDBX_val k = {(void *)"k000", 4}, v = {(void *)"v001", 4};
|
||||||
@ -75,7 +90,17 @@ bool testcase_jitter::run() {
|
|||||||
failure_perror("jitter.put-2", err);
|
failure_perror("jitter.put-2", err);
|
||||||
check_dbi_error(MDBX_BAD_DBI, "dropped-recreated-aborted");
|
check_dbi_error(MDBX_BAD_DBI, "dropped-recreated-aborted");
|
||||||
// restore DBI
|
// 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");
|
check_dbi_error(MDBX_SUCCESS, "dropped-recreated-aborted+reopened");
|
||||||
v = {(void *)"v003", 4};
|
v = {(void *)"v003", 4};
|
||||||
err = mdbx_put(txn_guard.get(), dbi, &k, &v, MDBX_UPSERT);
|
err = mdbx_put(txn_guard.get(), dbi, &k, &v, MDBX_UPSERT);
|
||||||
|
@ -537,29 +537,43 @@ int testcase::db_open__begin__table_create_open_clean(MDBX_dbi &handle) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDBX_dbi testcase::db_table_open(bool create) {
|
const char *testcase::db_tablename(tablename_buf &buffer,
|
||||||
log_trace(">> testcase::db_table_create");
|
const char *suffix) const {
|
||||||
|
|
||||||
char tablename_buf[16];
|
|
||||||
const char *tablename = nullptr;
|
const char *tablename = nullptr;
|
||||||
if (config.space_id) {
|
if (config.space_id) {
|
||||||
int rc = snprintf(tablename_buf, sizeof(tablename_buf), "TBL%04u",
|
int rc =
|
||||||
config.space_id);
|
snprintf(buffer, sizeof(buffer), "TBL%04u%s", config.space_id, suffix);
|
||||||
if (rc < 4 || rc >= (int)sizeof(tablename_buf) - 1)
|
if (rc < 4 || rc >= (int)sizeof(tablename_buf) - 1)
|
||||||
failure("snprintf(tablename): %d", rc);
|
failure("snprintf(tablename): %d", rc);
|
||||||
tablename = tablename_buf;
|
tablename = buffer;
|
||||||
}
|
}
|
||||||
log_debug("use %s table", tablename ? tablename : "MAINDB");
|
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;
|
MDBX_dbi handle = 0;
|
||||||
int rc = mdbx_dbi_open(txn_guard.get(), tablename,
|
int rc = mdbx_dbi_open(
|
||||||
(create ? MDBX_CREATE : MDBX_DB_DEFAULTS) |
|
txn_guard.get(), tablename,
|
||||||
config.params.table_flags,
|
create ? (MDBX_CREATE | config.params.table_flags)
|
||||||
&handle);
|
: (flipcoin() ? MDBX_DB_ACCEDE
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
: MDBX_DB_DEFAULTS | config.params.table_flags),
|
||||||
failure_perror("mdbx_dbi_open()", rc);
|
&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;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,10 @@ protected:
|
|||||||
MDBX_val expected_valued);
|
MDBX_val expected_valued);
|
||||||
unsigned txn_underutilization_x256(MDBX_txn *txn) const;
|
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_drop(MDBX_dbi handle);
|
||||||
void db_table_clear(MDBX_dbi handle, MDBX_txn *txn = nullptr);
|
void db_table_clear(MDBX_dbi handle, MDBX_txn *txn = nullptr);
|
||||||
void db_table_close(MDBX_dbi handle);
|
void db_table_close(MDBX_dbi handle);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user