2024-05-19 22:07:58 +03:00
|
|
|
/// \author Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> \date 2015-2024
|
|
|
|
/// \copyright SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-11-08 16:17:14 +03:00
|
|
|
#include "test.h++"
|
2018-11-04 18:57:36 +03:00
|
|
|
|
2021-03-15 20:52:18 +03: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 18:57:36 +03:00
|
|
|
void testcase_copy::copy_db(const bool with_compaction) {
|
2020-10-10 00:59:12 +03:00
|
|
|
int err = mdbx_env_delete(copy_pathname.c_str(), MDBX_ENV_JUST_DELETE);
|
|
|
|
if (err != MDBX_SUCCESS && err != MDBX_RESULT_TRUE)
|
2022-08-11 01:03:15 +03:00
|
|
|
failure_perror("osal_removefile()", err);
|
2018-11-04 18:57:36 +03:00
|
|
|
|
2024-08-02 12:13:25 +03:00
|
|
|
if (flipcoin()) {
|
|
|
|
err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
|
|
|
|
with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS);
|
|
|
|
if (unlikely(err != MDBX_SUCCESS))
|
|
|
|
failure_perror(with_compaction ? "mdbx_env_copy(MDBX_CP_COMPACT)"
|
|
|
|
: "mdbx_env_copy(MDBX_CP_ASIS)",
|
|
|
|
err);
|
|
|
|
} else {
|
2024-08-02 23:24:17 +03:00
|
|
|
do {
|
|
|
|
const bool ro = mode_readonly() || flipcoin();
|
|
|
|
const bool throttle = ro && flipcoin();
|
|
|
|
const bool dynsize = flipcoin();
|
|
|
|
const bool flush = flipcoin();
|
|
|
|
const bool enable_renew = flipcoin();
|
|
|
|
const MDBX_copy_flags_t flags =
|
|
|
|
(with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS) |
|
|
|
|
(dynsize ? MDBX_CP_FORCE_DYNAMIC_SIZE : MDBX_CP_DEFAULTS) |
|
|
|
|
(throttle ? MDBX_CP_THROTTLE_MVCC : MDBX_CP_DEFAULTS) |
|
|
|
|
(flush ? MDBX_CP_DEFAULTS : MDBX_CP_DONT_FLUSH) |
|
|
|
|
(enable_renew ? MDBX_CP_RENEW_TXN : MDBX_CP_DEFAULTS);
|
|
|
|
txn_begin(ro);
|
|
|
|
err =
|
|
|
|
mdbx_txn_copy2pathname(txn_guard.get(), copy_pathname.c_str(), flags);
|
|
|
|
if (unlikely(err != MDBX_SUCCESS && (!throttle || err != MDBX_OUSTED) &&
|
|
|
|
(!enable_renew && err != MDBX_MVCC_RETARDED)))
|
|
|
|
failure_perror(with_compaction
|
|
|
|
? "mdbx_txn_copy2pathname(MDBX_CP_COMPACT)"
|
|
|
|
: "mdbx_txn_copy2pathname(MDBX_CP_ASIS)",
|
|
|
|
err);
|
|
|
|
txn_end(err != MDBX_SUCCESS || flipcoin());
|
|
|
|
} while (err != MDBX_SUCCESS);
|
2024-08-02 12:13:25 +03:00
|
|
|
}
|
2018-11-04 18:57:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|