From 6b3d69e0a71774a9163105accb143a42bccab5fd Mon Sep 17 00:00:00 2001 From: HeYuchen <377710264@qq.com> Date: Mon, 1 Feb 2021 11:15:32 +0800 Subject: [PATCH] fix(split): add flush_memtable for copy_checkpoint_to_dir (#729) --- include/dsn/dist/replication/replication_app_base.h | 3 ++- src/replica/split/replica_split_manager.cpp | 6 +++--- src/replica/storage/simple_kv/simple_kv.server.impl.h | 3 ++- src/replica/storage/simple_kv/test/simple_kv.server.impl.h | 3 ++- src/replica/test/mock_utils.h | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/dsn/dist/replication/replication_app_base.h b/include/dsn/dist/replication/replication_app_base.h index a007ce6e7e..8a4846fd1a 100644 --- a/include/dsn/dist/replication/replication_app_base.h +++ b/include/dsn/dist/replication/replication_app_base.h @@ -197,7 +197,8 @@ class replication_app_base : public replica_base // must be thread safe // virtual ::dsn::error_code copy_checkpoint_to_dir(const char *checkpoint_dir, - /*output*/ int64_t *last_decree) = 0; + /*output*/ int64_t *last_decree, + bool flush_memtable = false) = 0; // // Query methods. diff --git a/src/replica/split/replica_split_manager.cpp b/src/replica/split/replica_split_manager.cpp index 463587e0e5..3a5c88d97b 100644 --- a/src/replica/split/replica_split_manager.cpp +++ b/src/replica/split/replica_split_manager.cpp @@ -175,7 +175,7 @@ void replica_split_manager::parent_prepare_states(const std::string &dir) // on learn_state parent_states; int64_t checkpoint_decree; // generate checkpoint - error_code ec = _replica->_app->copy_checkpoint_to_dir(dir.c_str(), &checkpoint_decree); + error_code ec = _replica->_app->copy_checkpoint_to_dir(dir.c_str(), &checkpoint_decree, true); if (ec == ERR_OK) { ddebug_replica("prepare checkpoint succeed: checkpoint dir = {}, checkpoint decree = {}", dir, @@ -207,8 +207,8 @@ void replica_split_manager::parent_prepare_states(const std::string &dir) // on plist->truncate(last_committed_decree()); dcheck_eq(last_committed_decree(), checkpoint_decree); - dcheck_gt(mutation_list.size(), 0); - dcheck_gt(files.size(), 0); + dcheck_ge(mutation_list.size(), 0); + dcheck_ge(files.size(), 0); ddebug_replica("prepare state succeed: {} mutations, {} private log files, total file size = " "{}, last_committed_decree = {}", mutation_list.size(), diff --git a/src/replica/storage/simple_kv/simple_kv.server.impl.h b/src/replica/storage/simple_kv/simple_kv.server.impl.h index dd491dd56a..599321ec8e 100644 --- a/src/replica/storage/simple_kv/simple_kv.server.impl.h +++ b/src/replica/storage/simple_kv/simple_kv.server.impl.h @@ -70,7 +70,8 @@ class simple_kv_service_impl : public simple_kv_service virtual ::dsn::error_code async_checkpoint(bool flush_memtable) override; virtual ::dsn::error_code copy_checkpoint_to_dir(const char *checkpoint_dir, - int64_t *last_decree) override + int64_t *last_decree, + bool flush_memtable = false) override { return ERR_NOT_IMPLEMENTED; } diff --git a/src/replica/storage/simple_kv/test/simple_kv.server.impl.h b/src/replica/storage/simple_kv/test/simple_kv.server.impl.h index b6fc5dda7d..86894b40ae 100644 --- a/src/replica/storage/simple_kv/test/simple_kv.server.impl.h +++ b/src/replica/storage/simple_kv/test/simple_kv.server.impl.h @@ -72,7 +72,8 @@ class simple_kv_service_impl : public application::simple_kv_service virtual ::dsn::error_code async_checkpoint(bool flush_memtable) override; virtual ::dsn::error_code copy_checkpoint_to_dir(const char *checkpoint_dir, - int64_t *last_decree) override + int64_t *last_decree, + bool flush_memtable = false) override { return ERR_NOT_IMPLEMENTED; } diff --git a/src/replica/test/mock_utils.h b/src/replica/test/mock_utils.h index 66498f6bdb..9e678593cc 100644 --- a/src/replica/test/mock_utils.h +++ b/src/replica/test/mock_utils.h @@ -56,7 +56,8 @@ class mock_replication_app_base : public replication_app_base return ERR_OK; } error_code copy_checkpoint_to_dir(const char *checkpoint_dir, - /*output*/ int64_t *last_decree) override + /*output*/ int64_t *last_decree, + bool flush_memtable = false) override { if (last_decree != nullptr) { *last_decree = _decree;