mdbx: backport - add db-copy testcase.

Change-Id: Ib554880ebbabcb5dfc55bdb3c71767d0fa1630fd
This commit is contained in:
Leonid Yuriev 2018-11-04 18:57:36 +03:00
parent 3d59c9f9e7
commit ee0c8bb249
13 changed files with 95 additions and 32 deletions

View File

@ -3,6 +3,7 @@ README-RU.md
pcrf_test/CMakeLists.txt pcrf_test/CMakeLists.txt
src/tools/CMakeLists.txt src/tools/CMakeLists.txt
test/CMakeLists.txt test/CMakeLists.txt
test/copy.cc
tutorial/CMakeLists.txt tutorial/CMakeLists.txt
tutorial/sample-mdbx.c tutorial/sample-mdbx.c
AUTHORS AUTHORS

3
mdbx.h
View File

@ -100,6 +100,7 @@ typedef DWORD mdbx_tid_t;
#define MDBX_EIO ERROR_WRITE_FAULT #define MDBX_EIO ERROR_WRITE_FAULT
#define MDBX_EPERM ERROR_INVALID_FUNCTION #define MDBX_EPERM ERROR_INVALID_FUNCTION
#define MDBX_EINTR ERROR_CANCELLED #define MDBX_EINTR ERROR_CANCELLED
#define MDBX_ENOFILE ERROR_FILE_NOT_FOUND
#else #else
@ -120,6 +121,8 @@ typedef pthread_t mdbx_tid_t;
#define MDBX_EIO EIO #define MDBX_EIO EIO
#define MDBX_EPERM EPERM #define MDBX_EPERM EPERM
#define MDBX_EINTR EINTR #define MDBX_EINTR EINTR
#define MDBX_ENOFILE ENOENT
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -1,4 +1,4 @@
set(TARGET mdbx_test) set(TARGET mdbx_test)
project(${TARGET}) project(${TARGET})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations")
@ -11,6 +11,7 @@ add_executable(${TARGET}
chrono.h chrono.h
config.cc config.cc
config.h config.h
copy.cc
dead.cc dead.cc
hill.cc hill.cc
jitter.cc jitter.cc

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -68,6 +68,7 @@ void testcase_setup(const char *casename, actor_params &params,
configure_actor(last_space_id, ac_jitter, nullptr, params); configure_actor(last_space_id, ac_jitter, nullptr, params);
configure_actor(last_space_id, ac_hill, nullptr, params); configure_actor(last_space_id, ac_hill, nullptr, params);
configure_actor(last_space_id, ac_try, nullptr, params); configure_actor(last_space_id, ac_try, nullptr, params);
configure_actor(last_space_id, ac_copy, nullptr, params);
log_notice("<<< testcase_setup(%s): done", casename); log_notice("<<< testcase_setup(%s): done", casename);
} else { } else {
failure("unknown testcase `%s`", casename); failure("unknown testcase `%s`", casename);

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -26,7 +26,8 @@ enum actor_testcase {
ac_deadread, ac_deadread,
ac_deadwrite, ac_deadwrite,
ac_jitter, ac_jitter,
ac_try ac_try,
ac_copy
}; };
enum actor_status { enum actor_status {

26
test/copy.cc Normal file
View File

@ -0,0 +1,26 @@
#include "test.h"
void testcase_copy::copy_db(const bool with_compaction) {
int err = osal_removefile(copy_pathname);
if (err != MDBX_SUCCESS && err != MDBX_ENOFILE)
failure_perror("mdbx_removefile()", err);
err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
with_compaction ? MDBX_CP_COMPACT : 0);
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;
}

View File

@ -337,6 +337,10 @@ int main(int argc, char *const argv[]) {
configure_actor(last_space_id, ac_deadwrite, value, params); configure_actor(last_space_id, ac_deadwrite, value, params);
continue; continue;
} }
if (config::parse_option(argc, argv, narg, "copy", nullptr)) {
configure_actor(last_space_id, ac_copy, value, params);
continue;
}
if (config::parse_option(argc, argv, narg, "failfast", if (config::parse_option(argc, argv, narg, "failfast",
global::config::failfast)) global::config::failfast))
continue; continue;

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -301,3 +301,7 @@ std::string osal_tempdir(void) {
return "/dev/shm/"; return "/dev/shm/";
return ""; return "";
} }
int osal_removefile(const std::string &pathname) {
return unlink(pathname.c_str()) ? errno : MDBX_SUCCESS;
}

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -405,3 +405,7 @@ std::string osal_tempdir(void) {
DWORD len = GetTempPathA(sizeof(buf), buf); DWORD len = GetTempPathA(sizeof(buf), buf);
return std::string(buf, len); return std::string(buf, len);
} }
int osal_removefile(const std::string &pathname) {
return DeleteFileA(pathname.c_str()) ? MDBX_SUCCESS : GetLastError();
}

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -32,6 +32,7 @@ void osal_udelay(unsigned us);
void osal_yield(void); void osal_yield(void);
bool osal_istty(int fd); bool osal_istty(int fd);
std::string osal_tempdir(void); std::string osal_tempdir(void);
int osal_removefile(const std::string &pathname);
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef STDIN_FILENO #ifndef STDIN_FILENO

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -31,6 +31,8 @@ const char *testcase2str(const actor_testcase testcase) {
return "jitter"; return "jitter";
case ac_try: case ac_try:
return "try"; return "try";
case ac_copy:
return "copy";
} }
} }
@ -443,6 +445,9 @@ bool test_execute(const actor_config &config) {
case ac_try: case ac_try:
test.reset(new testcase_try(config, pid)); test.reset(new testcase_try(config, pid));
break; break;
case ac_copy:
test.reset(new testcase_copy(config, pid));
break;
default: default:
test.reset(new testcase(config, pid)); test.reset(new testcase(config, pid));
break; break;

View File

@ -203,3 +203,14 @@ public:
bool run(); bool run();
bool teardown(); bool teardown();
}; };
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();
};

View File

@ -184,6 +184,7 @@
<ClCompile Include="cases.cc" /> <ClCompile Include="cases.cc" />
<ClCompile Include="chrono.cc" /> <ClCompile Include="chrono.cc" />
<ClCompile Include="config.cc" /> <ClCompile Include="config.cc" />
<ClCompile Include="copy.cc" />
<ClCompile Include="dead.cc" /> <ClCompile Include="dead.cc" />
<ClCompile Include="hill.cc" /> <ClCompile Include="hill.cc" />
<ClCompile Include="try.cc" /> <ClCompile Include="try.cc" />