You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by GitBox <gi...@apache.org> on 2020/10/16 02:53:44 UTC

[GitHub] [incubator-pegasus] acelyc111 commented on a change in pull request #621: feat(hotkey): implement the RPC handler in hotkey_collector

acelyc111 commented on a change in pull request #621:
URL: https://github.com/apache/incubator-pegasus/pull/621#discussion_r506002202



##########
File path: src/server/hotkey_collector.h
##########
@@ -19,6 +19,8 @@
 
 #include <dsn/utility/string_view.h>
 #include <dsn/dist/replication/replication_types.h>
+#include <dsn/dist/replication/replica_base.h>
+#include <dsn/dist/fmt_logging.h>

Review comment:
       Move this line to cpp file

##########
File path: src/server/hotkey_collector.cpp
##########
@@ -16,14 +16,34 @@
 // under the License.
 
 #include "hotkey_collector.h"
+#include <dsn/dist/replication/replication_enums.h>
 
 namespace pegasus {
 namespace server {
 
-// TODO: (Tangyanzhao) implement these functions
+hotkey_collector::hotkey_collector(dsn::replication::hotkey_type::type hotkey_type,
+                                   dsn::replication::replica_base *r_base)
+    : replica_base(r_base), _state(hotkey_collector_state::STOPPED), _hotkey_type(hotkey_type)
+{
+}
+
 void hotkey_collector::handle_rpc(const dsn::replication::detect_hotkey_request &req,
                                   dsn::replication::detect_hotkey_response &resp)
 {
+    if (req.action == dsn::replication::detect_action::START) {

Review comment:
       Use `switch..case..`

##########
File path: src/server/hotkey_collector.cpp
##########
@@ -33,5 +53,40 @@ void hotkey_collector::capture_raw_key(const dsn::blob &raw_key, int64_t weight)
 
 void hotkey_collector::capture_hash_key(const dsn::blob &hash_key, int64_t weight) {}
 
+bool hotkey_collector::start_detect(std::string &err_hint)
+{
+    auto now_state = _state.load();
+    switch (_state.load()) {

Review comment:
       ```suggestion
       switch (now_state) {
   ```

##########
File path: src/server/hotkey_collector.cpp
##########
@@ -16,14 +16,34 @@
 // under the License.
 
 #include "hotkey_collector.h"
+#include <dsn/dist/replication/replication_enums.h>
 
 namespace pegasus {
 namespace server {
 
-// TODO: (Tangyanzhao) implement these functions
+hotkey_collector::hotkey_collector(dsn::replication::hotkey_type::type hotkey_type,
+                                   dsn::replication::replica_base *r_base)
+    : replica_base(r_base), _state(hotkey_collector_state::STOPPED), _hotkey_type(hotkey_type)
+{
+}
+
 void hotkey_collector::handle_rpc(const dsn::replication::detect_hotkey_request &req,
                                   dsn::replication::detect_hotkey_response &resp)
 {
+    if (req.action == dsn::replication::detect_action::START) {
+        std::string err_hint;
+        if (start_detect(err_hint)) {
+            resp.err = dsn::ERR_OK;

Review comment:
       You can move this line at first in this function, then it's not needed to reassign it again and again.

##########
File path: src/server/hotkey_collector.cpp
##########
@@ -33,5 +53,40 @@ void hotkey_collector::capture_raw_key(const dsn::blob &raw_key, int64_t weight)
 
 void hotkey_collector::capture_hash_key(const dsn::blob &hash_key, int64_t weight) {}
 
+bool hotkey_collector::start_detect(std::string &err_hint)
+{
+    auto now_state = _state.load();
+    switch (_state.load()) {
+    case hotkey_collector_state::COARSE_DETECTING:
+    case hotkey_collector_state::FINE_DETECTING:
+        err_hint = fmt::format("still detecting {} hotkey, state is {}",
+                               dsn::enum_to_string(_hotkey_type),
+                               enum_to_string(now_state));

Review comment:
       Unify to add or remove `dsn::`

##########
File path: src/server/hotkey_collector.cpp
##########
@@ -33,5 +53,40 @@ void hotkey_collector::capture_raw_key(const dsn::blob &raw_key, int64_t weight)
 
 void hotkey_collector::capture_hash_key(const dsn::blob &hash_key, int64_t weight) {}
 
+bool hotkey_collector::start_detect(std::string &err_hint)
+{
+    auto now_state = _state.load();
+    switch (_state.load()) {
+    case hotkey_collector_state::COARSE_DETECTING:
+    case hotkey_collector_state::FINE_DETECTING:
+        err_hint = fmt::format("still detecting {} hotkey, state is {}",
+                               dsn::enum_to_string(_hotkey_type),
+                               enum_to_string(now_state));
+        ddebug_replica(err_hint);
+        return false;
+    case hotkey_collector_state::FINISHED:
+        err_hint = fmt::format(
+            "{} hotkey result has been found, you can send a stop rpc to restart hotkey detection",
+            dsn::enum_to_string(_hotkey_type));
+        ddebug_replica(err_hint);
+        return false;
+    case hotkey_collector_state::STOPPED:
+        // TODO: (Tangyanzhao) start coarse detecting
+        _state.store(hotkey_collector_state::COARSE_DETECTING);
+        ddebug_replica("starting to detect {} hotkey", dsn::enum_to_string(_hotkey_type));
+        return true;
+    default:
+        err_hint = "invalid collector state";
+        ddebug_replica(err_hint);

Review comment:
       It's not possible to reach here, I think you can assert here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org