2019-09-09 18:40:24 +08:00
|
|
|
#include "test.h"
|
2018-11-04 23:57:36 +08:00
|
|
|
|
2021-03-16 01:52:18 +08:00
|
|
|
class testcase_copy : public testcase {
|
|
|
|
const std::string copy_pathname;
|
|
|
|
void copy_db(const bool with_compaction);
|
|
|
|
|
|
|
|
public:
|
|
|
|
testcase_copy(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
: testcase(config, pid),
|
|
|
|
copy_pathname(config.params.pathname_db + "-copy") {}
|
|
|
|
bool run() override;
|
|
|
|
};
|
|
|
|
REGISTER_TESTCASE(copy);
|
|
|
|
|
2018-11-04 23:57:36 +08:00
|
|
|
void testcase_copy::copy_db(const bool with_compaction) {
|
2020-10-10 05:59:12 +08:00
|
|
|
int err = mdbx_env_delete(copy_pathname.c_str(), MDBX_ENV_JUST_DELETE);
|
|
|
|
if (err != MDBX_SUCCESS && err != MDBX_RESULT_TRUE)
|
2018-11-04 23:57:36 +08:00
|
|
|
failure_perror("mdbx_removefile()", err);
|
|
|
|
|
|
|
|
err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
|
2020-08-04 06:06:01 +08:00
|
|
|
with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS);
|
2018-11-04 23:57:36 +08:00
|
|
|
if (unlikely(err != MDBX_SUCCESS))
|
|
|
|
failure_perror(with_compaction ? "mdbx_env_copy(MDBX_CP_COMPACT)"
|
|
|
|
: "mdbx_env_copy(MDBX_CP_ASIS)",
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool testcase_copy::run() {
|
|
|
|
jitter_delay();
|
|
|
|
db_open();
|
|
|
|
assert(!txn_guard);
|
|
|
|
const bool order = flipcoin();
|
|
|
|
jitter_delay();
|
|
|
|
copy_db(order);
|
|
|
|
jitter_delay();
|
|
|
|
copy_db(!order);
|
|
|
|
return true;
|
|
|
|
}
|