Skip to content

Commit

Permalink
fix: fix bug in function_test/test_restore (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao liwei authored May 29, 2020
1 parent bdd21a0 commit 072e5c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rdsn
Submodule rdsn updated 79 files
+3 −0 include/dsn/cpp/rpc_holder.h
+1 −0 include/dsn/dist/replication/replication.codes.h
+2 −0 include/dsn/tool-api/file_io.h
+2 −2 include/dsn/tool-api/global_config.h
+4 −9 include/dsn/tool-api/task.h
+0 −3 include/dsn/tool_api.h
+2 −0 include/dsn/utility/filesystem.h
+1 −1 scripts/linux/build.sh
+1 −0 src/core/CMakeLists.txt
+17 −0 src/core/aio/CMakeLists.txt
+2 −11 src/core/aio/aio_provider.cpp
+0 −2 src/core/aio/aio_provider.h
+57 −0 src/core/aio/aio_task.cpp
+11 −25 src/core/aio/disk_engine.cpp
+11 −14 src/core/aio/disk_engine.h
+12 −8 src/core/aio/file_io.cpp
+7 −13 src/core/aio/native_linux_aio_provider.cpp
+2 −4 src/core/aio/native_linux_aio_provider.h
+5 −13 src/core/aio/sim_aio_provider.cpp
+4 −13 src/core/aio/sim_aio_provider.h
+33 −0 src/core/core/filesystem.cpp
+3 −0 src/core/core/global_config.cpp
+0 −1 src/core/core/service_api_c.cpp
+2 −19 src/core/core/service_engine.cpp
+0 −5 src/core/core/service_engine.h
+5 −51 src/core/core/task.cpp
+0 −7 src/core/core/tool_api.cpp
+1 −0 src/core/tests/CMakeLists.txt
+0 −13 src/core/tests/aio.cpp
+0 −1 src/core/tests/async_call.cpp
+0 −1 src/core/tests/lpc.cpp
+10 −9 src/core/tests/netprovider.cpp
+2 −0 src/core/tools/common/asio_net_provider.cpp
+1 −0 src/core/tools/common/dsn_message_parser.cpp
+2 −2 src/core/tools/common/nativerun.cpp
+0 −3 src/core/tools/common/providers.common.cpp
+1 −1 src/core/tools/hpc/hpc_task_queue.h
+3 −4 src/core/tools/simulator/simulator.cpp
+9 −14 src/dist/block_service/fds/fds_service.cpp
+1 −1 src/dist/nfs/CMakeLists.txt
+55 −0 src/dist/nfs/nfs_client_impl.cpp
+11 −2 src/dist/nfs/nfs_client_impl.h
+1 −1 src/dist/nfs/nfs_server_impl.h
+1 −1 src/dist/nfs/test/CMakeLists.txt
+17 −1 src/dist/replication/common/replication_common.cpp
+6 −1 src/dist/replication/common/replication_common.h
+7 −0 src/dist/replication/lib/CMakeLists.txt
+440 −0 src/dist/replication/lib/bulk_load/replica_bulk_loader.cpp
+120 −0 src/dist/replication/lib/bulk_load/replica_bulk_loader.h
+23 −0 src/dist/replication/lib/bulk_load/test/CMakeLists.txt
+75 −0 src/dist/replication/lib/bulk_load/test/config-test.ini
+39 −0 src/dist/replication/lib/bulk_load/test/main.cpp
+332 −0 src/dist/replication/lib/bulk_load/test/replica_bulk_loader_test.cpp
+11 −0 src/dist/replication/lib/bulk_load/test/run.sh
+4 −0 src/dist/replication/lib/replica.cpp
+21 −25 src/dist/replication/lib/replica.h
+0 −212 src/dist/replication/lib/replica_bulk_load.cpp
+9 −0 src/dist/replication/lib/replica_context.cpp
+2 −11 src/dist/replication/lib/replica_context.h
+152 −0 src/dist/replication/lib/replica_file_provider.cpp
+1 −1 src/dist/replication/lib/replica_split.cpp
+40 −3 src/dist/replication/lib/replica_stub.cpp
+7 −0 src/dist/replication/lib/replica_stub.h
+1 −0 src/dist/replication/meta_server/CMakeLists.txt
+8 −1 src/dist/replication/meta_server/duplication/meta_duplication_service.cpp
+177 −2 src/dist/replication/meta_server/meta_bulk_load_service.cpp
+44 −0 src/dist/replication/meta_server/meta_bulk_load_service.h
+17 −12 src/dist/replication/meta_server/meta_service.cpp
+3 −1 src/dist/replication/meta_server/meta_service.h
+1 −0 src/dist/replication/test/meta_test/unit_test/CMakeLists.txt
+5 −0 src/dist/replication/test/meta_test/unit_test/config-test.ini
+3 −0 src/dist/replication/test/meta_test/unit_test/meta_bulk_load_service_test.cpp
+4 −0 src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp
+5 −1 src/dist/replication/test/replica_test/unit_test/config-test.ini
+16 −0 src/dist/replication/test/replica_test/unit_test/mock_utils.h
+0 −148 src/dist/replication/test/replica_test/unit_test/replica_bulk_load_test.cpp
+96 −0 src/dist/replication/test/replica_test/unit_test/replica_file_provider_test.cpp
+11 −0 thirdparty/build-thirdparty.sh
+10 −0 thirdparty/download-thirdparty.sh
51 changes: 32 additions & 19 deletions src/test/function_test/test_restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ class restore_test : public testing::Test
virtual void SetUp() override
{
pegasus_root_dir = global_env::instance()._pegasus_root;
working_root_dir = global_env::instance()._working_dir;

chdir(pegasus_root_dir.c_str());
cluster_name = dsn::utils::filesystem::path_combine(pegasus_root_dir, backup_data_dir);
system("pwd");

// modify the config to enable backup, and restart onebox
Expand All @@ -39,9 +37,22 @@ class restore_test : public testing::Test
system("./run.sh start_onebox --config_path config-server-test-restore.ini");
std::this_thread::sleep_for(std::chrono::seconds(3));

// First of all, we are in the path of pegasus root, for example: /home/mi/pegasus.
// And we can get the provider_dir which actually is `block_service/local_service`,
// from config-server-test-restore.ini.
// With cluster_name = mycluster and policy_name = policy_1, we can get the absolute
// path of policy: /home/mi/pegasus/onebox/block_service/local_service/mycluster/policy_1
cmd = "grep -A 5 block_service." + backup_provider_name +
" config-server-test-restore.ini | grep args | cut -f2,3 -d'/'";
std::stringstream ss;
assert(dsn::utils::pipe_execute(cmd.c_str(), ss) == 0);
std::string provider_dir = ss.str().substr(0, ss.str().length() - 1);
policy_dir = "onebox/" + provider_dir + '/' +
dsn::utils::filesystem::path_combine(cluster_name, policy_name);

std::vector<dsn::rpc_address> meta_list;
replica_helper::load_meta_servers(
meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "mycluster");
meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), cluster_name.c_str());

ddl_client = std::make_shared<replication_ddl_client>(meta_list);
error_code err =
Expand All @@ -56,7 +67,8 @@ class restore_test : public testing::Test
old_app_id = app_id;
}
ASSERT_GE(app_id, 0);
pg_client = pegasus::pegasus_client_factory::get_client("mycluster", app_name.c_str());
pg_client =
pegasus::pegasus_client_factory::get_client(cluster_name.c_str(), app_name.c_str());
ASSERT_NE(pg_client, nullptr);

write_data();
Expand All @@ -78,8 +90,6 @@ class restore_test : public testing::Test
chdir(global_env::instance()._pegasus_root.c_str());
system("./run.sh clear_onebox");
system("./run.sh start_onebox -w");
std::string cmd = "rm -rf " + backup_data_dir;
system(cmd.c_str());
chdir(global_env::instance()._working_dir.c_str());
}

Expand Down Expand Up @@ -108,17 +118,24 @@ class restore_test : public testing::Test
int err = PERR_OK;
std::cout << "start to get " << kv_pair_cnt << " key-value pairs, using get()..."
<< std::endl;
new_pg_client =
pegasus::pegasus_client_factory::get_client(cluster_name.c_str(), new_app_name.c_str());
if (nullptr == new_pg_client) {
std::cout << "error to create client for " << new_app_name << std::endl;
return false;
}

int64_t start = dsn_now_ms();
for (int i = 1; i <= kv_pair_cnt; i++) {
std::string index = std::to_string(i);
std::string h_key = hash_key_prefix + "_" + index;
std::string s_key = sort_key_prefix + "_" + index;
std::string value = value_prefix + "_" + index;
std::string value_new;
err = pg_client->get(h_key, s_key, value_new);
err = new_pg_client->get(h_key, s_key, value_new);
if (err != PERR_OK) {
std::cout << "get <" << h_key << ">, <" << s_key
<< "> failed, with err = " << pg_client->get_error_string(err)
<< "> failed, with err = " << new_pg_client->get_error_string(err)
<< std::endl;
return false;
}
Expand All @@ -136,8 +153,6 @@ class restore_test : public testing::Test

bool restore()
{
system("./run.sh clear_onebox");
system("./run.sh start_onebox");
std::this_thread::sleep_for(std::chrono::seconds(3));
time_stamp = get_first_backup_timestamp();
std::cout << "first backup_timestamp = " << time_stamp << std::endl;
Expand All @@ -147,7 +162,7 @@ class restore_test : public testing::Test
time_stamp,
app_name,
old_app_id,
app_name,
new_app_name,
false);
if (err != ERR_OK) {
std::cout << "restore failed, err = " << err.to_string() << std::endl;
Expand Down Expand Up @@ -178,9 +193,9 @@ class restore_test : public testing::Test

p_confs.clear();
app_id = 0, partition_cnt = 0;
err = ddl_client->list_app(app_name, app_id, partition_cnt, p_confs);
err = ddl_client->list_app(new_app_name, app_id, partition_cnt, p_confs);
if (err != ERR_OK) {
std::cout << "list app failed, app_name = " << app_name
std::cout << "list app failed, app_name = " << new_app_name
<< ", with err = " << err.to_string() << std::endl;
continue;
}
Expand Down Expand Up @@ -232,7 +247,6 @@ class restore_test : public testing::Test

int64_t get_first_backup_timestamp()
{
std::string policy_dir = dsn::utils::filesystem::path_combine(cluster_name, policy_name);
std::string cmd = "cd " + policy_dir + "; "
"ls -c > restore_app_from_backup_test_tmp; "
"tail -n 1 restore_app_from_backup_test_tmp; "
Expand All @@ -256,19 +270,20 @@ class restore_test : public testing::Test

bool find_second_backup_timestamp()
{
std::string policy_dir = dsn::utils::filesystem::path_combine(cluster_name, policy_name);
std::vector<std::string> dirs;
::dsn::utils::filesystem::get_subdirectories(policy_dir, dirs, false);
return (dirs.size() >= 2);
}

public:
pegasus_client *pg_client;
pegasus_client *new_pg_client;
std::shared_ptr<replication_ddl_client> ddl_client;
std::string pegasus_root_dir;
std::string working_root_dir;
std::string policy_dir;

std::string cluster_name;
const std::string cluster_name = "mycluster";
const std::string new_app_name = "backup_test_new";
int32_t old_app_id;
int64_t time_stamp;

Expand All @@ -277,7 +292,6 @@ class restore_test : public testing::Test
static const int backup_interval_seconds;
static const int backup_history_count_to_keep;
static const std::string start_time;
static const std::string backup_data_dir;

static const std::string app_name;

Expand All @@ -298,7 +312,6 @@ const std::string restore_test::backup_provider_name = "local_service";
const int restore_test::backup_interval_seconds = 1;
const int restore_test::backup_history_count_to_keep = 6;
const std::string restore_test::start_time = "24:0";
const std::string restore_test::backup_data_dir = "backup_data";

const std::string restore_test::app_name = "backup_test";

Expand Down

0 comments on commit 072e5c9

Please sign in to comment.