From 4c0290b5764985f426e696876b2d997da5d0c97f 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: Fri, 2 Aug 2024 12:13:25 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-testing:=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`mdbx=5Ftxn=5Fcopy2pathname()`?= =?UTF-8?q?=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdbx.h | 8 ++++---- test/copy.c++ | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/mdbx.h b/mdbx.h index 0d04c73f..aa2989c5 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1719,16 +1719,16 @@ typedef enum MDBX_copy_flags { MDBX_CP_DONT_FLUSH = 4u, /** Use read transaction parking during copying MVCC-snapshot - * \see mdbx_txn_park() */ + * \see mdbx_txn_park() */ MDBX_CP_THROTTLE_MVCC = 8u, /** Abort/dispose passed transaction after copy - * \see mdbx_txn_copy2fd() \see mdbx_txn_copy2pathname() */ + * \see mdbx_txn_copy2fd() \see mdbx_txn_copy2pathname() */ MDBX_CP_DISPOSE_TXN = 16u, /** Enable renew/restart read transaction in case it use outdated - * MVCC shapshot, otherwise the \ref MDBX_MVCC_RETARDED will be returned - * \see mdbx_txn_copy2fd() \see mdbx_txn_copy2pathname() */ + * MVCC shapshot, otherwise the \ref MDBX_MVCC_RETARDED will be returned + * \see mdbx_txn_copy2fd() \see mdbx_txn_copy2pathname() */ MDBX_CP_RENEW_TXN = 32u } MDBX_copy_flags_t; diff --git a/test/copy.c++ b/test/copy.c++ index 7ab96c24..9ca4fe9c 100644 --- a/test/copy.c++ +++ b/test/copy.c++ @@ -20,12 +20,34 @@ void testcase_copy::copy_db(const bool with_compaction) { if (err != MDBX_SUCCESS && err != MDBX_RESULT_TRUE) failure_perror("osal_removefile()", err); - 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); + 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 { + 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()); + } } bool testcase_copy::run() {