This is an automated email from the ASF dual-hosted git repository.
yuchenhe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 51578db feat(hotkey): add an interface to query hotkey on the
specified partition (#662)
51578db is described below
commit 51578db98da9f1c7278148d6df08b5d4c220b553
Author: Smilencer <[email protected]>
AuthorDate: Mon Dec 28 13:28:44 2020 +0800
feat(hotkey): add an interface to query hotkey on the specified partition
(#662)
---
rdsn | 2 +-
src/server/hotkey_collector.cpp | 18 ++++++++++++++++++
src/server/hotkey_collector.h | 1 +
src/server/pegasus_server_impl.cpp | 3 ++-
src/server/test/hotkey_collector_test.cpp | 6 ++++++
5 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/rdsn b/rdsn
index 67e06d2..29c6ccc 160000
--- a/rdsn
+++ b/rdsn
@@ -1 +1 @@
-Subproject commit 67e06d2c5022e82984b0c7e6651876b5b0e7410d
+Subproject commit 29c6ccca84873f4735c690dc8a616b8ef93377eb
diff --git a/src/server/hotkey_collector.cpp b/src/server/hotkey_collector.cpp
index 60263f6..23aa21a 100644
--- a/src/server/hotkey_collector.cpp
+++ b/src/server/hotkey_collector.cpp
@@ -168,6 +168,7 @@ inline void hotkey_collector::change_state_by_result()
case hotkey_collector_state::FINE_DETECTING:
if (!_result.hot_hash_key.empty()) {
change_state_to_finished();
+ derror_replica("Find the hotkey: {}", _result.hot_hash_key);
}
break;
default:
@@ -185,6 +186,9 @@ void hotkey_collector::handle_rpc(const
dsn::replication::detect_hotkey_request
case dsn::replication::detect_action::STOP:
on_stop_detect(resp);
return;
+ case dsn::replication::detect_action::QUERY:
+ query_result(resp);
+ return;
default:
std::string hint = fmt::format("{}: can't find this detect action",
req.action);
resp.err = dsn::ERR_INVALID_STATE;
@@ -272,6 +276,20 @@ void
hotkey_collector::on_stop_detect(dsn::replication::detect_hotkey_response &
ddebug_replica(hint);
}
+void hotkey_collector::query_result(dsn::replication::detect_hotkey_response
&resp)
+{
+ if (_state != hotkey_collector_state::FINISHED) {
+ resp.err = dsn::ERR_BUSY;
+ std::string hint = fmt::format("hotkey is detecting now, now state:
{}",
+ dsn::enum_to_string(_hotkey_type));
+ resp.__set_err_hint(hint);
+ ddebug_replica(hint);
+ } else {
+ resp.err = dsn::ERR_OK;
+ resp.__set_hotkey_result(_result.hot_hash_key);
+ }
+}
+
bool hotkey_collector::terminate_if_timeout()
{
if (dsn_now_s() >= _collector_start_time_second.load() +
FLAGS_max_seconds_to_detect_hotkey) {
diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h
index a54f019..bdc7fcb 100644
--- a/src/server/hotkey_collector.h
+++ b/src/server/hotkey_collector.h
@@ -98,6 +98,7 @@ public:
private:
void on_start_detect(dsn::replication::detect_hotkey_response &resp);
void on_stop_detect(dsn::replication::detect_hotkey_response &resp);
+ void query_result(dsn::replication::detect_hotkey_response &resp);
void change_state_to_stopped();
void change_state_to_coarse_detecting();
diff --git a/src/server/pegasus_server_impl.cpp
b/src/server/pegasus_server_impl.cpp
index 949eead..5c3d5c7 100644
--- a/src/server/pegasus_server_impl.cpp
+++ b/src/server/pegasus_server_impl.cpp
@@ -2841,7 +2841,8 @@ void pegasus_server_impl::on_detect_hotkey(const
dsn::replication::detect_hotkey
{
if (dsn_unlikely(req.action != dsn::replication::detect_action::START &&
- req.action != dsn::replication::detect_action::STOP)) {
+ req.action != dsn::replication::detect_action::STOP &&
+ req.action != dsn::replication::detect_action::QUERY)) {
resp.err = dsn::ERR_INVALID_PARAMETERS;
resp.__set_err_hint("invalid detect_action");
return;
diff --git a/src/server/test/hotkey_collector_test.cpp
b/src/server/test/hotkey_collector_test.cpp
index 5eea0d8..99913a4 100644
--- a/src/server/test/hotkey_collector_test.cpp
+++ b/src/server/test/hotkey_collector_test.cpp
@@ -305,6 +305,12 @@ TEST_F(hotkey_collector_test, state_transform)
ASSERT_EQ(result->hot_hash_key, "ThisisahotkeyThisisahotkey");
on_detect_hotkey(generate_control_rpc(dsn::replication::hotkey_type::READ,
+
dsn::replication::detect_action::QUERY),
+ resp);
+ ASSERT_EQ(resp.err, dsn::ERR_OK);
+ ASSERT_EQ(resp.hotkey_result, "ThisisahotkeyThisisahotkey");
+
+ on_detect_hotkey(generate_control_rpc(dsn::replication::hotkey_type::READ,
dsn::replication::detect_action::STOP),
resp);
ASSERT_EQ(resp.err, dsn::ERR_OK);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]