From e8b02b124eb8caa8db034cbb359c39372aef2c5a Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Mon, 23 Mar 2020 13:13:16 +0800 Subject: [PATCH] feat(dup): rename change_dup_status to modify_dup (#423) --- .../dsn/dist/replication/duplication_common.h | 3 +- .../dsn/dist/replication/replication.codes.h | 2 +- .../dist/replication/replication_ddl_client.h | 4 +- .../dsn/dist/replication/replication_types.h | 74 ++++++++-------- .../replication/common/replication_types.cpp | 88 +++++++++---------- .../ddl_lib/replication_ddl_client.cpp | 9 +- .../duplication/duplication_info.cpp | 10 ++- .../duplication/duplication_info.h | 11 +-- .../duplication/meta_duplication_service.cpp | 22 ++--- .../duplication/meta_duplication_service.h | 8 +- .../replication/meta_server/meta_service.cpp | 9 +- .../replication/meta_server/meta_service.h | 2 +- src/dist/replication/replication.thrift | 6 +- .../meta_duplication_service_test.cpp | 10 +-- 14 files changed, 125 insertions(+), 133 deletions(-) diff --git a/include/dsn/dist/replication/duplication_common.h b/include/dsn/dist/replication/duplication_common.h index fcfaeb16ef..e2ea759ded 100644 --- a/include/dsn/dist/replication/duplication_common.h +++ b/include/dsn/dist/replication/duplication_common.h @@ -33,8 +33,7 @@ namespace dsn { namespace replication { -typedef rpc_holder - duplication_status_change_rpc; +typedef rpc_holder duplication_modify_rpc; typedef rpc_holder duplication_add_rpc; typedef rpc_holder duplication_query_rpc; typedef rpc_holder duplication_sync_rpc; diff --git a/include/dsn/dist/replication/replication.codes.h b/include/dsn/dist/replication/replication.codes.h index 45687c25ea..7f50081e90 100644 --- a/include/dsn/dist/replication/replication.codes.h +++ b/include/dsn/dist/replication/replication.codes.h @@ -96,7 +96,7 @@ MAKE_EVENT_CODE(LPC_QUERY_PN_DECREE, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_REPORT_RESTORE_STATUS, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_QUERY_RESTORE_STATUS, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_ADD_DUPLICATION, TASK_PRIORITY_COMMON) -MAKE_EVENT_CODE_RPC(RPC_CM_CHANGE_DUPLICATION_STATUS, TASK_PRIORITY_COMMON) +MAKE_EVENT_CODE_RPC(RPC_CM_MODIFY_DUPLICATION, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_QUERY_DUPLICATION, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_DUPLICATION_SYNC, TASK_PRIORITY_COMMON) MAKE_EVENT_CODE_RPC(RPC_CM_UPDATE_APP_ENV, TASK_PRIORITY_COMMON) diff --git a/include/dsn/dist/replication/replication_ddl_client.h b/include/dsn/dist/replication/replication_ddl_client.h index c6dc3d3efb..dd87fab3a9 100644 --- a/include/dsn/dist/replication/replication_ddl_client.h +++ b/include/dsn/dist/replication/replication_ddl_client.h @@ -115,8 +115,10 @@ class replication_ddl_client error_with add_dup(std::string app_name, std::string remote_address, bool freezed); - error_with + + error_with change_dup_status(std::string app_name, int dupid, duplication_status::type status); + error_with query_dup(std::string app_name); dsn::error_code do_restore(const std::string &backup_provider_name, diff --git a/include/dsn/dist/replication/replication_types.h b/include/dsn/dist/replication/replication_types.h index 85a4144908..3ace35e104 100644 --- a/include/dsn/dist/replication/replication_types.h +++ b/include/dsn/dist/replication/replication_types.h @@ -306,9 +306,9 @@ class duplication_add_request; class duplication_add_response; -class duplication_status_change_request; +class duplication_modify_request; -class duplication_status_change_response; +class duplication_modify_response; class duplication_entry; @@ -5015,31 +5015,29 @@ inline std::ostream &operator<<(std::ostream &out, const duplication_add_respons return out; } -typedef struct _duplication_status_change_request__isset +typedef struct _duplication_modify_request__isset { - _duplication_status_change_request__isset() : app_name(false), dupid(false), status(false) {} + _duplication_modify_request__isset() : app_name(false), dupid(false), status(false) {} bool app_name : 1; bool dupid : 1; bool status : 1; -} _duplication_status_change_request__isset; +} _duplication_modify_request__isset; -class duplication_status_change_request +class duplication_modify_request { public: - duplication_status_change_request(const duplication_status_change_request &); - duplication_status_change_request(duplication_status_change_request &&); - duplication_status_change_request &operator=(const duplication_status_change_request &); - duplication_status_change_request &operator=(duplication_status_change_request &&); - duplication_status_change_request() : app_name(), dupid(0), status((duplication_status::type)0) - { - } + duplication_modify_request(const duplication_modify_request &); + duplication_modify_request(duplication_modify_request &&); + duplication_modify_request &operator=(const duplication_modify_request &); + duplication_modify_request &operator=(duplication_modify_request &&); + duplication_modify_request() : app_name(), dupid(0), status((duplication_status::type)0) {} - virtual ~duplication_status_change_request() throw(); + virtual ~duplication_modify_request() throw(); std::string app_name; int32_t dupid; duplication_status::type status; - _duplication_status_change_request__isset __isset; + _duplication_modify_request__isset __isset; void __set_app_name(const std::string &val); @@ -5047,19 +5045,21 @@ class duplication_status_change_request void __set_status(const duplication_status::type val); - bool operator==(const duplication_status_change_request &rhs) const + bool operator==(const duplication_modify_request &rhs) const { if (!(app_name == rhs.app_name)) return false; if (!(dupid == rhs.dupid)) return false; - if (!(status == rhs.status)) + if (__isset.status != rhs.__isset.status) + return false; + else if (__isset.status && !(status == rhs.status)) return false; return true; } - bool operator!=(const duplication_status_change_request &rhs) const { return !(*this == rhs); } + bool operator!=(const duplication_modify_request &rhs) const { return !(*this == rhs); } - bool operator<(const duplication_status_change_request &) const; + bool operator<(const duplication_modify_request &) const; uint32_t read(::apache::thrift::protocol::TProtocol *iprot); uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; @@ -5067,41 +5067,41 @@ class duplication_status_change_request virtual void printTo(std::ostream &out) const; }; -void swap(duplication_status_change_request &a, duplication_status_change_request &b); +void swap(duplication_modify_request &a, duplication_modify_request &b); -inline std::ostream &operator<<(std::ostream &out, const duplication_status_change_request &obj) +inline std::ostream &operator<<(std::ostream &out, const duplication_modify_request &obj) { obj.printTo(out); return out; } -typedef struct _duplication_status_change_response__isset +typedef struct _duplication_modify_response__isset { - _duplication_status_change_response__isset() : err(false), appid(false) {} + _duplication_modify_response__isset() : err(false), appid(false) {} bool err : 1; bool appid : 1; -} _duplication_status_change_response__isset; +} _duplication_modify_response__isset; -class duplication_status_change_response +class duplication_modify_response { public: - duplication_status_change_response(const duplication_status_change_response &); - duplication_status_change_response(duplication_status_change_response &&); - duplication_status_change_response &operator=(const duplication_status_change_response &); - duplication_status_change_response &operator=(duplication_status_change_response &&); - duplication_status_change_response() : appid(0) {} + duplication_modify_response(const duplication_modify_response &); + duplication_modify_response(duplication_modify_response &&); + duplication_modify_response &operator=(const duplication_modify_response &); + duplication_modify_response &operator=(duplication_modify_response &&); + duplication_modify_response() : appid(0) {} - virtual ~duplication_status_change_response() throw(); + virtual ~duplication_modify_response() throw(); ::dsn::error_code err; int32_t appid; - _duplication_status_change_response__isset __isset; + _duplication_modify_response__isset __isset; void __set_err(const ::dsn::error_code &val); void __set_appid(const int32_t val); - bool operator==(const duplication_status_change_response &rhs) const + bool operator==(const duplication_modify_response &rhs) const { if (!(err == rhs.err)) return false; @@ -5109,9 +5109,9 @@ class duplication_status_change_response return false; return true; } - bool operator!=(const duplication_status_change_response &rhs) const { return !(*this == rhs); } + bool operator!=(const duplication_modify_response &rhs) const { return !(*this == rhs); } - bool operator<(const duplication_status_change_response &) const; + bool operator<(const duplication_modify_response &) const; uint32_t read(::apache::thrift::protocol::TProtocol *iprot); uint32_t write(::apache::thrift::protocol::TProtocol *oprot) const; @@ -5119,9 +5119,9 @@ class duplication_status_change_response virtual void printTo(std::ostream &out) const; }; -void swap(duplication_status_change_response &a, duplication_status_change_response &b); +void swap(duplication_modify_response &a, duplication_modify_response &b); -inline std::ostream &operator<<(std::ostream &out, const duplication_status_change_response &obj) +inline std::ostream &operator<<(std::ostream &out, const duplication_modify_response &obj) { obj.printTo(out); return out; diff --git a/src/dist/replication/common/replication_types.cpp b/src/dist/replication/common/replication_types.cpp index 7a338dfb6f..6f7c053c97 100644 --- a/src/dist/replication/common/replication_types.cpp +++ b/src/dist/replication/common/replication_types.cpp @@ -11734,21 +11734,19 @@ void duplication_add_response::printTo(std::ostream &out) const out << ")"; } -duplication_status_change_request::~duplication_status_change_request() throw() {} +duplication_modify_request::~duplication_modify_request() throw() {} -void duplication_status_change_request::__set_app_name(const std::string &val) -{ - this->app_name = val; -} +void duplication_modify_request::__set_app_name(const std::string &val) { this->app_name = val; } -void duplication_status_change_request::__set_dupid(const int32_t val) { this->dupid = val; } +void duplication_modify_request::__set_dupid(const int32_t val) { this->dupid = val; } -void duplication_status_change_request::__set_status(const duplication_status::type val) +void duplication_modify_request::__set_status(const duplication_status::type val) { this->status = val; + __isset.status = true; } -uint32_t duplication_status_change_request::read(::apache::thrift::protocol::TProtocol *iprot) +uint32_t duplication_modify_request::read(::apache::thrift::protocol::TProtocol *iprot) { apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); @@ -11805,12 +11803,11 @@ uint32_t duplication_status_change_request::read(::apache::thrift::protocol::TPr return xfer; } -uint32_t -duplication_status_change_request::write(::apache::thrift::protocol::TProtocol *oprot) const +uint32_t duplication_modify_request::write(::apache::thrift::protocol::TProtocol *oprot) const { uint32_t xfer = 0; apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("duplication_status_change_request"); + xfer += oprot->writeStructBegin("duplication_modify_request"); xfer += oprot->writeFieldBegin("app_name", ::apache::thrift::protocol::T_STRING, 1); xfer += oprot->writeString(this->app_name); @@ -11820,16 +11817,17 @@ duplication_status_change_request::write(::apache::thrift::protocol::TProtocol * xfer += oprot->writeI32(this->dupid); xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("status", ::apache::thrift::protocol::T_I32, 3); - xfer += oprot->writeI32((int32_t)this->status); - xfer += oprot->writeFieldEnd(); - + if (this->__isset.status) { + xfer += oprot->writeFieldBegin("status", ::apache::thrift::protocol::T_I32, 3); + xfer += oprot->writeI32((int32_t)this->status); + xfer += oprot->writeFieldEnd(); + } xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); return xfer; } -void swap(duplication_status_change_request &a, duplication_status_change_request &b) +void swap(duplication_modify_request &a, duplication_modify_request &b) { using ::std::swap; swap(a.app_name, b.app_name); @@ -11838,24 +11836,22 @@ void swap(duplication_status_change_request &a, duplication_status_change_reques swap(a.__isset, b.__isset); } -duplication_status_change_request::duplication_status_change_request( - const duplication_status_change_request &other499) +duplication_modify_request::duplication_modify_request(const duplication_modify_request &other499) { app_name = other499.app_name; dupid = other499.dupid; status = other499.status; __isset = other499.__isset; } -duplication_status_change_request::duplication_status_change_request( - duplication_status_change_request &&other500) +duplication_modify_request::duplication_modify_request(duplication_modify_request &&other500) { app_name = std::move(other500.app_name); dupid = std::move(other500.dupid); status = std::move(other500.status); __isset = std::move(other500.__isset); } -duplication_status_change_request &duplication_status_change_request:: -operator=(const duplication_status_change_request &other501) +duplication_modify_request &duplication_modify_request:: +operator=(const duplication_modify_request &other501) { app_name = other501.app_name; dupid = other501.dupid; @@ -11863,8 +11859,8 @@ operator=(const duplication_status_change_request &other501) __isset = other501.__isset; return *this; } -duplication_status_change_request &duplication_status_change_request:: -operator=(duplication_status_change_request &&other502) +duplication_modify_request &duplication_modify_request:: +operator=(duplication_modify_request &&other502) { app_name = std::move(other502.app_name); dupid = std::move(other502.dupid); @@ -11872,28 +11868,26 @@ operator=(duplication_status_change_request &&other502) __isset = std::move(other502.__isset); return *this; } -void duplication_status_change_request::printTo(std::ostream &out) const +void duplication_modify_request::printTo(std::ostream &out) const { using ::apache::thrift::to_string; - out << "duplication_status_change_request("; + out << "duplication_modify_request("; out << "app_name=" << to_string(app_name); out << ", " << "dupid=" << to_string(dupid); out << ", " - << "status=" << to_string(status); + << "status="; + (__isset.status ? (out << to_string(status)) : (out << "")); out << ")"; } -duplication_status_change_response::~duplication_status_change_response() throw() {} +duplication_modify_response::~duplication_modify_response() throw() {} -void duplication_status_change_response::__set_err(const ::dsn::error_code &val) -{ - this->err = val; -} +void duplication_modify_response::__set_err(const ::dsn::error_code &val) { this->err = val; } -void duplication_status_change_response::__set_appid(const int32_t val) { this->appid = val; } +void duplication_modify_response::__set_appid(const int32_t val) { this->appid = val; } -uint32_t duplication_status_change_response::read(::apache::thrift::protocol::TProtocol *iprot) +uint32_t duplication_modify_response::read(::apache::thrift::protocol::TProtocol *iprot) { apache::thrift::protocol::TInputRecursionTracker tracker(*iprot); @@ -11940,12 +11934,11 @@ uint32_t duplication_status_change_response::read(::apache::thrift::protocol::TP return xfer; } -uint32_t -duplication_status_change_response::write(::apache::thrift::protocol::TProtocol *oprot) const +uint32_t duplication_modify_response::write(::apache::thrift::protocol::TProtocol *oprot) const { uint32_t xfer = 0; apache::thrift::protocol::TOutputRecursionTracker tracker(*oprot); - xfer += oprot->writeStructBegin("duplication_status_change_response"); + xfer += oprot->writeStructBegin("duplication_modify_response"); xfer += oprot->writeFieldBegin("err", ::apache::thrift::protocol::T_STRUCT, 1); xfer += this->err.write(oprot); @@ -11960,7 +11953,7 @@ duplication_status_change_response::write(::apache::thrift::protocol::TProtocol return xfer; } -void swap(duplication_status_change_response &a, duplication_status_change_response &b) +void swap(duplication_modify_response &a, duplication_modify_response &b) { using ::std::swap; swap(a.err, b.err); @@ -11968,40 +11961,39 @@ void swap(duplication_status_change_response &a, duplication_status_change_respo swap(a.__isset, b.__isset); } -duplication_status_change_response::duplication_status_change_response( - const duplication_status_change_response &other503) +duplication_modify_response::duplication_modify_response( + const duplication_modify_response &other503) { err = other503.err; appid = other503.appid; __isset = other503.__isset; } -duplication_status_change_response::duplication_status_change_response( - duplication_status_change_response &&other504) +duplication_modify_response::duplication_modify_response(duplication_modify_response &&other504) { err = std::move(other504.err); appid = std::move(other504.appid); __isset = std::move(other504.__isset); } -duplication_status_change_response &duplication_status_change_response:: -operator=(const duplication_status_change_response &other505) +duplication_modify_response &duplication_modify_response:: +operator=(const duplication_modify_response &other505) { err = other505.err; appid = other505.appid; __isset = other505.__isset; return *this; } -duplication_status_change_response &duplication_status_change_response:: -operator=(duplication_status_change_response &&other506) +duplication_modify_response &duplication_modify_response:: +operator=(duplication_modify_response &&other506) { err = std::move(other506.err); appid = std::move(other506.appid); __isset = std::move(other506.__isset); return *this; } -void duplication_status_change_response::printTo(std::ostream &out) const +void duplication_modify_response::printTo(std::ostream &out) const { using ::apache::thrift::to_string; - out << "duplication_status_change_response("; + out << "duplication_modify_response("; out << "err=" << to_string(err); out << ", " << "appid=" << to_string(appid); diff --git a/src/dist/replication/ddl_lib/replication_ddl_client.cpp b/src/dist/replication/ddl_lib/replication_ddl_client.cpp index 9b45e4b49e..3f184ae8d6 100644 --- a/src/dist/replication/ddl_lib/replication_ddl_client.cpp +++ b/src/dist/replication/ddl_lib/replication_ddl_client.cpp @@ -1354,15 +1354,14 @@ replication_ddl_client::add_dup(std::string app_name, std::string remote_cluster return call_rpc_sync(duplication_add_rpc(std::move(req), RPC_CM_ADD_DUPLICATION)); } -error_with replication_ddl_client::change_dup_status( +error_with replication_ddl_client::change_dup_status( std::string app_name, int dupid, duplication_status::type status) { - auto req = make_unique(); + auto req = make_unique(); req->app_name = std::move(app_name); req->dupid = dupid; - req->status = status; - return call_rpc_sync( - duplication_status_change_rpc(std::move(req), RPC_CM_CHANGE_DUPLICATION_STATUS)); + req->__set_status(status); + return call_rpc_sync(duplication_modify_rpc(std::move(req), RPC_CM_MODIFY_DUPLICATION)); } error_with replication_ddl_client::query_dup(std::string app_name) diff --git a/src/dist/replication/meta_server/duplication/duplication_info.cpp b/src/dist/replication/meta_server/duplication/duplication_info.cpp index 10d7c0eee4..9569dd0dd6 100644 --- a/src/dist/replication/meta_server/duplication/duplication_info.cpp +++ b/src/dist/replication/meta_server/duplication/duplication_info.cpp @@ -64,7 +64,7 @@ namespace replication { } // lock held -error_code duplication_info::do_alter_status(duplication_status::type to_status) +error_code duplication_info::alter_status(duplication_status::type to_status) { if (_is_altering) { return ERR_BUSY; @@ -78,11 +78,13 @@ error_code duplication_info::do_alter_status(duplication_status::type to_status) return ERR_INVALID_PARAMETERS; } - if (_status != to_status) { - _is_altering = true; - _next_status = to_status; + if (_status == to_status) { + return ERR_OK; } + zauto_write_lock l(_lock); + _is_altering = true; + _next_status = to_status; return ERR_OK; } diff --git a/src/dist/replication/meta_server/duplication/duplication_info.h b/src/dist/replication/meta_server/duplication/duplication_info.h index 7ab6ccab9f..549ca10153 100644 --- a/src/dist/replication/meta_server/duplication/duplication_info.h +++ b/src/dist/replication/meta_server/duplication/duplication_info.h @@ -77,16 +77,15 @@ class duplication_info // change current status to `to_status`. // error will be returned if this state transition is not allowed. - error_code alter_status(duplication_status::type to_status) - { - zauto_write_lock l(_lock); - return do_alter_status(to_status); - } + error_code alter_status(duplication_status::type to_status); // persist current status to `next_status` // call this function after data has been persisted on meta storage. void persist_status(); + // not thread-safe + duplication_status::type status() const { return _status; } + // if this duplication is in valid status. bool is_valid() const { return is_duplication_status_valid(_status); } @@ -151,8 +150,6 @@ class duplication_info friend class duplication_info_test; friend class meta_duplication_service_test; - error_code do_alter_status(duplication_status::type to_status); - // Whether there's ongoing meta storage update. bool _is_altering{false}; diff --git a/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp b/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp index 0ac4921d0b..8e28b6c20f 100644 --- a/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp +++ b/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp @@ -60,14 +60,14 @@ void meta_duplication_service::query_duplication_info(const duplication_query_re } // ThreadPool(WRITE): THREAD_POOL_META_STATE -void meta_duplication_service::change_duplication_status(duplication_status_change_rpc rpc) +void meta_duplication_service::modify_duplication(duplication_modify_rpc rpc) { const auto &request = rpc.request(); auto &response = rpc.response(); - ddebug_f("change status of duplication({}) to {} for app({})", + ddebug_f("modify duplication({}) to {} for app({})", request.dupid, - duplication_status_to_string(request.status), + request.__isset.status ? duplication_status_to_string(request.status) : "nil", request.app_name); dupid_t dupid = request.dupid; @@ -78,13 +78,15 @@ void meta_duplication_service::change_duplication_status(duplication_status_chan return; } - duplication_info_s_ptr dup = app->duplications[dupid]; - if (dup == nullptr) { + auto it = app->duplications.find(dupid); + if (it == app->duplications.end()) { response.err = ERR_OBJECT_NOT_FOUND; return; } - response.err = dup->alter_status(request.status); + duplication_info_s_ptr dup = it->second; + auto to_status = request.__isset.status ? request.status : dup->status(); + response.err = dup->alter_status(to_status); if (response.err != ERR_OK) { return; } @@ -93,13 +95,13 @@ void meta_duplication_service::change_duplication_status(duplication_status_chan } // validation passed - do_change_duplication_status(app, dup, rpc); + do_modify_duplication(app, dup, rpc); } // ThreadPool(WRITE): THREAD_POOL_META_STATE -void meta_duplication_service::do_change_duplication_status(std::shared_ptr &app, - duplication_info_s_ptr &dup, - duplication_status_change_rpc &rpc) +void meta_duplication_service::do_modify_duplication(std::shared_ptr &app, + duplication_info_s_ptr &dup, + duplication_modify_rpc &rpc) { // store the duplication in requested status. blob value = dup->to_json_blob(); diff --git a/src/dist/replication/meta_server/duplication/meta_duplication_service.h b/src/dist/replication/meta_server/duplication/meta_duplication_service.h index b368e6d8e1..83ebae1a78 100644 --- a/src/dist/replication/meta_server/duplication/meta_duplication_service.h +++ b/src/dist/replication/meta_server/duplication/meta_duplication_service.h @@ -60,7 +60,7 @@ class meta_duplication_service void add_duplication(duplication_add_rpc rpc); - void change_duplication_status(duplication_status_change_rpc rpc); + void modify_duplication(duplication_modify_rpc rpc); void duplication_sync(duplication_sync_rpc rpc); @@ -72,9 +72,9 @@ class meta_duplication_service duplication_info_s_ptr &dup, duplication_add_rpc &rpc); - void do_change_duplication_status(std::shared_ptr &app, - duplication_info_s_ptr &dup, - duplication_status_change_rpc &rpc); + void do_modify_duplication(std::shared_ptr &app, + duplication_info_s_ptr &dup, + duplication_modify_rpc &rpc); void do_restore_duplication(dupid_t dup_id, std::shared_ptr app); diff --git a/src/dist/replication/meta_server/meta_service.cpp b/src/dist/replication/meta_server/meta_service.cpp index 5e9b590a69..a8c29b95a7 100644 --- a/src/dist/replication/meta_server/meta_service.cpp +++ b/src/dist/replication/meta_server/meta_service.cpp @@ -805,7 +805,7 @@ void meta_service::on_add_duplication(duplication_add_rpc rpc) server_state::sStateHash); } -void meta_service::on_change_duplication_status(duplication_status_change_rpc rpc) +void meta_service::on_modify_duplication(duplication_modify_rpc rpc) { RPC_CHECK_STATUS(rpc.dsn_request(), rpc.response()); @@ -815,7 +815,7 @@ void meta_service::on_change_duplication_status(duplication_status_change_rpc rp } tasking::enqueue(LPC_META_STATE_NORMAL, tracker(), - [this, rpc]() { _dup_svc->change_duplication_status(std::move(rpc)); }, + [this, rpc]() { _dup_svc->modify_duplication(std::move(rpc)); }, server_state::sStateHash); } @@ -857,9 +857,8 @@ void meta_service::register_duplication_rpc_handlers() { register_rpc_handler_with_rpc_holder( RPC_CM_ADD_DUPLICATION, "add_duplication", &meta_service::on_add_duplication); - register_rpc_handler_with_rpc_holder(RPC_CM_CHANGE_DUPLICATION_STATUS, - "change duplication status", - &meta_service::on_change_duplication_status); + register_rpc_handler_with_rpc_holder( + RPC_CM_MODIFY_DUPLICATION, "modify duplication", &meta_service::on_modify_duplication); register_rpc_handler_with_rpc_holder(RPC_CM_QUERY_DUPLICATION, "query duplication info", &meta_service::on_query_duplication_info); diff --git a/src/dist/replication/meta_server/meta_service.h b/src/dist/replication/meta_server/meta_service.h index eebc6c1aa4..4a1fdb65a5 100644 --- a/src/dist/replication/meta_server/meta_service.h +++ b/src/dist/replication/meta_server/meta_service.h @@ -174,7 +174,7 @@ class meta_service : public serverlet // duplication void on_add_duplication(duplication_add_rpc rpc); - void on_change_duplication_status(duplication_status_change_rpc rpc); + void on_modify_duplication(duplication_modify_rpc rpc); void on_query_duplication_info(duplication_query_rpc rpc); void on_duplication_sync(duplication_sync_rpc rpc); void register_duplication_rpc_handlers(); diff --git a/src/dist/replication/replication.thrift b/src/dist/replication/replication.thrift index 0b86ca701d..79b0bd0809 100644 --- a/src/dist/replication/replication.thrift +++ b/src/dist/replication/replication.thrift @@ -681,14 +681,14 @@ struct duplication_add_response } // This request is sent from client to meta. -struct duplication_status_change_request +struct duplication_modify_request { 1:string app_name; 2:i32 dupid; - 3:duplication_status status; + 3:optional duplication_status status; } -struct duplication_status_change_response +struct duplication_modify_response { // Possible errors: // - ERR_APP_NOT_EXIST: app is not found diff --git a/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp b/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp index dbeb816b1f..9d4f94bd2a 100644 --- a/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp +++ b/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp @@ -71,16 +71,16 @@ class meta_duplication_service_test : public meta_test_base return rpc.response(); } - duplication_status_change_response + duplication_modify_response change_dup_status(const std::string &app_name, dupid_t dupid, duplication_status::type status) { - auto req = make_unique(); + auto req = make_unique(); req->dupid = dupid; req->app_name = app_name; - req->status = status; + req->__set_status(status); - duplication_status_change_rpc rpc(std::move(req), RPC_CM_CHANGE_DUPLICATION_STATUS); - dup_svc().change_duplication_status(rpc); + duplication_modify_rpc rpc(std::move(req), RPC_CM_MODIFY_DUPLICATION); + dup_svc().modify_duplication(rpc); wait_all(); return rpc.response();