From ccecd5996a7b5c5b3281860186b30048a2ee4763 Mon Sep 17 00:00:00 2001 From: Smilencer <527646889@qq.com> Date: Wed, 30 Sep 2020 04:21:23 -0500 Subject: [PATCH] feat(hotkey): Add an interface of on_detect_hotkey (#634) --- include/dsn/dist/replication/replication_app_base.h | 7 +++++++ src/replica/replica.cpp | 6 ++++++ src/replica/replica.h | 2 ++ src/replica/replica_stub.cpp | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/dsn/dist/replication/replication_app_base.h b/include/dsn/dist/replication/replication_app_base.h index dbe35f24c9..b22cf98b11 100644 --- a/include/dsn/dist/replication/replication_app_base.h +++ b/include/dsn/dist/replication/replication_app_base.h @@ -242,6 +242,13 @@ class replication_app_base : public replica_base virtual ingestion_status::type get_ingestion_status() { return ingestion_status::IS_INVALID; } + virtual void on_detect_hotkey(const detect_hotkey_request &req, + /*out*/ detect_hotkey_response &resp) + { + resp.err = dsn::ERR_OBJECT_NOT_FOUND; + resp.__set_err_hint("on_detect_hotkey implementation not found"); + } + public: // // utility functions to be used by app diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp index e0de73e2e5..17f5a54773 100644 --- a/src/replica/replica.cpp +++ b/src/replica/replica.cpp @@ -459,5 +459,11 @@ void replica::init_table_level_latency_counters() } } } + +void replica::on_detect_hotkey(const detect_hotkey_request &req, detect_hotkey_response &resp) +{ + _app->on_detect_hotkey(req, resp); +} + } // namespace replication } // namespace dsn diff --git a/src/replica/replica.h b/src/replica/replica.h index 83dd756d19..a031aad721 100644 --- a/src/replica/replica.h +++ b/src/replica/replica.h @@ -383,6 +383,8 @@ class replica : public serverlet, public ref_counter, public replica_ba void init_table_level_latency_counters(); + void on_detect_hotkey(const detect_hotkey_request &req, /*out*/ detect_hotkey_response &resp); + private: friend class ::dsn::replication::test::test_checker; friend class ::dsn::replication::mutation_queue; diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index 4d98671013..fe126db68c 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -2784,7 +2784,7 @@ void replica_stub::on_detect_hotkey(detect_hotkey_rpc rpc) replica_ptr rep = get_replica(request.pid); if (rep != nullptr) { - response.err = ERR_OK; + rep->on_detect_hotkey(request, response); } else { response.err = ERR_OBJECT_NOT_FOUND; response.err_hint = fmt::format("not find the replica {} \n", request.pid);