From 41234d8f60d6f67994d03100908999d639b6dc56 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Tue, 13 Oct 2020 14:36:04 +0800 Subject: [PATCH 01/10] add codes --- src/server/hotkey_collector.h | 6 +++ src/server/hotkey_state_machine.h | 72 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/server/hotkey_state_machine.h diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h index 57c7482aa0..b0d01b53d7 100644 --- a/src/server/hotkey_collector.h +++ b/src/server/hotkey_collector.h @@ -19,6 +19,9 @@ #include #include +#include +#include +#include "hotkey_state_machine.h" namespace pegasus { namespace server { @@ -69,6 +72,9 @@ class hotkey_collector void capture_hash_key(const dsn::blob &hash_key, int64_t weight); void handle_rpc(const dsn::replication::detect_hotkey_request &req, /*out*/ dsn::replication::detect_hotkey_response &resp); + +private: + std::atomic _state; }; } // namespace server diff --git a/src/server/hotkey_state_machine.h b/src/server/hotkey_state_machine.h new file mode 100644 index 0000000000..bd7ecf99ce --- /dev/null +++ b/src/server/hotkey_state_machine.h @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include + +// hotkey_collector +// state machine +// +--------+ +// data has been cleared, | | +// ready to start | STOP <-----------+ +// | | | +// +---+----+ | +// | | +// Receive start rpc Time out +// | | +// +---v----+ | +// is running coarse | | | +// capture and analysis | COARSE +-----------^ +// | | | +// +---+----+ | +// | | +// Find a hot bucket Time out +// | | +// +---v----+ | +// is running fine | | | +// capture and analysis | FINE +-----------+ +// | | +// +---+----+ +// | +// Find a hotkey +// | +// +---v----+ +// capture and analyse | | +// is done, ready to get | FINISH | +// the result | | +// +--------+ +namespace pegasus { +namespace server { + +enum class collector_state +{ + STOP, + COARSE, + FINE, + FINISH +}; + +ENUM_BEGIN2(collector_state, collector_state, collector_state::STOP) +ENUM_REG(collector_state::STOP) +ENUM_REG(collector_state::COARSE) +ENUM_REG(collector_state::FINE) +ENUM_REG(collector_state::FINISH) +ENUM_END2(collector_state, collector_state) + +} // namespace server +} // namespace pegasus From 96a0e7f582bef54fef229aeae85b4788ed211157 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Tue, 13 Oct 2020 14:41:15 +0800 Subject: [PATCH 02/10] delete headers --- src/server/hotkey_collector.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h index b0d01b53d7..aa70215c3f 100644 --- a/src/server/hotkey_collector.h +++ b/src/server/hotkey_collector.h @@ -19,8 +19,6 @@ #include #include -#include -#include #include "hotkey_state_machine.h" namespace pegasus { From 40cfbb488ccc44b441b8267ec06b573456029c5f Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Tue, 13 Oct 2020 15:25:59 +0800 Subject: [PATCH 03/10] update comments --- src/server/hotkey_state_machine.h | 63 ++++++++++++++++--------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/server/hotkey_state_machine.h b/src/server/hotkey_state_machine.h index bd7ecf99ce..f05489ebd7 100644 --- a/src/server/hotkey_state_machine.h +++ b/src/server/hotkey_state_machine.h @@ -19,40 +19,41 @@ #include -// hotkey_collector -// state machine -// +--------+ -// data has been cleared, | | -// ready to start | STOP <-----------+ -// | | | -// +---+----+ | -// | | -// Receive start rpc Time out -// | | -// +---v----+ | -// is running coarse | | | -// capture and analysis | COARSE +-----------^ -// | | | -// +---+----+ | -// | | -// Find a hot bucket Time out -// | | -// +---v----+ | -// is running fine | | | -// capture and analysis | FINE +-----------+ -// | | -// +---+----+ -// | -// Find a hotkey -// | -// +---v----+ -// capture and analyse | | -// is done, ready to get | FINISH | -// the result | | -// +--------+ namespace pegasus { namespace server { +// hotkey_collector +// state machine +// +--------+ +// data has been cleared, | | +// ready to start | STOP <-----------+-------------+ +// | | | | +// +---+----+ | | +// + + | +// Receive START rpc Time out | +// + + | +// +---v----+ | | +// is running coarse | | | | +// capture and analysis | COARSE +-----------> Receive STOP rpc +// | | | | +// +---+----+ | | +// + + | +// Find a hot bucket Time out | +// + + | +// +---v----+ | | +// is running fine | | | | +// capture and analysis | FINE +-----------+ | +// | | | +// +---+----+ | +// + | +// Find a hotkey | +// + | +// +---v----+ | +// capture and analyse | | | +// is done, ready to get | FINISH +-------------------------+ +// the result | | +// +--------+ + enum class collector_state { STOP, From beebec784362a2b076b986259744912080c978a1 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Tue, 13 Oct 2020 15:30:30 +0800 Subject: [PATCH 04/10] update comments --- src/server/hotkey_state_machine.h | 36 ++++++++++++------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/server/hotkey_state_machine.h b/src/server/hotkey_state_machine.h index f05489ebd7..708d8d5314 100644 --- a/src/server/hotkey_state_machine.h +++ b/src/server/hotkey_state_machine.h @@ -24,35 +24,27 @@ namespace server { // hotkey_collector // state machine -// +--------+ -// data has been cleared, | | +// data has been cleared, +--------+ // ready to start | STOP <-----------+-------------+ -// | | | | // +---+----+ | | -// + + | -// Receive START rpc Time out | -// + + | -// +---v----+ | | -// is running coarse | | | | -// capture and analysis | COARSE +-----------> Receive STOP rpc -// | | | | +// | | | +// Receive START RPC Time out | +// | + | +// is running coarse +---v----+ | | +// capture and analysis | COARSE +-----------^ Receive STOP RPC // +---+----+ | | -// + + | -// Find a hot bucket Time out | -// + + | -// +---v----+ | | -// is running fine | | | | +// | + | +// Find a hot bucket Time out | +// | + | +// is running fine +---v----+ | | // capture and analysis | FINE +-----------+ | -// | | | // +---+----+ | -// + | +// | | // Find a hotkey | -// + | -// +---v----+ | -// capture and analyse | | | +// | | +// capture and analyse +---v----+ | // is done, ready to get | FINISH +-------------------------+ -// the result | | -// +--------+ +// the result +--------+ enum class collector_state { From 0e38fd593876918acf8d45974a460d387a7b8fa6 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Tue, 13 Oct 2020 17:37:09 +0800 Subject: [PATCH 05/10] change class name --- src/server/hotkey_collector.h | 2 +- src/server/hotkey_state_machine.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h index aa70215c3f..b04beb4a37 100644 --- a/src/server/hotkey_collector.h +++ b/src/server/hotkey_collector.h @@ -72,7 +72,7 @@ class hotkey_collector /*out*/ dsn::replication::detect_hotkey_response &resp); private: - std::atomic _state; + std::atomic _state; }; } // namespace server diff --git a/src/server/hotkey_state_machine.h b/src/server/hotkey_state_machine.h index 708d8d5314..8b19dd2ba0 100644 --- a/src/server/hotkey_state_machine.h +++ b/src/server/hotkey_state_machine.h @@ -46,7 +46,7 @@ namespace server { // is done, ready to get | FINISH +-------------------------+ // the result +--------+ -enum class collector_state +enum class hotkey_collector_state { STOP, COARSE, @@ -54,12 +54,12 @@ enum class collector_state FINISH }; -ENUM_BEGIN2(collector_state, collector_state, collector_state::STOP) -ENUM_REG(collector_state::STOP) -ENUM_REG(collector_state::COARSE) -ENUM_REG(collector_state::FINE) -ENUM_REG(collector_state::FINISH) -ENUM_END2(collector_state, collector_state) +ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOP) +ENUM_REG(hotkey_collector_state::STOP) +ENUM_REG(hotkey_collector_state::COARSE) +ENUM_REG(hotkey_collector_state::FINE) +ENUM_REG(hotkey_collector_state::FINISH) +ENUM_END2(hotkey_collector_state, hotkey_collector_state) } // namespace server } // namespace pegasus From e060bc49ed6c5dc90ef79ab4ce68b969eefcfdd4 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Wed, 14 Oct 2020 10:43:45 +0800 Subject: [PATCH 06/10] rename --- src/server/hotkey_collector.h | 2 +- src/server/{hotkey_state_machine.h => hotkey_collector_state.h} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/server/{hotkey_state_machine.h => hotkey_collector_state.h} (98%) diff --git a/src/server/hotkey_collector.h b/src/server/hotkey_collector.h index b04beb4a37..a1818d391e 100644 --- a/src/server/hotkey_collector.h +++ b/src/server/hotkey_collector.h @@ -19,7 +19,7 @@ #include #include -#include "hotkey_state_machine.h" +#include "hotkey_collector_state.h" namespace pegasus { namespace server { diff --git a/src/server/hotkey_state_machine.h b/src/server/hotkey_collector_state.h similarity index 98% rename from src/server/hotkey_state_machine.h rename to src/server/hotkey_collector_state.h index 8b19dd2ba0..19f01d189d 100644 --- a/src/server/hotkey_state_machine.h +++ b/src/server/hotkey_collector_state.h @@ -23,7 +23,7 @@ namespace pegasus { namespace server { // hotkey_collector -// state machine +// collector state // data has been cleared, +--------+ // ready to start | STOP <-----------+-------------+ // +---+----+ | | From 815ff5e78e4d06d5b06b569f99b324a88fc8d310 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Wed, 14 Oct 2020 14:14:35 +0800 Subject: [PATCH 07/10] rename state --- src/server/hotkey_collector_state.h | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/server/hotkey_collector_state.h b/src/server/hotkey_collector_state.h index 19f01d189d..8a2ba68d65 100644 --- a/src/server/hotkey_collector_state.h +++ b/src/server/hotkey_collector_state.h @@ -22,43 +22,43 @@ namespace pegasus { namespace server { -// hotkey_collector -// collector state -// data has been cleared, +--------+ -// ready to start | STOP <-----------+-------------+ -// +---+----+ | | -// | | | -// Receive START RPC Time out | -// | + | -// is running coarse +---v----+ | | -// capture and analysis | COARSE +-----------^ Receive STOP RPC -// +---+----+ | | -// | + | -// Find a hot bucket Time out | -// | + | -// is running fine +---v----+ | | -// capture and analysis | FINE +-----------+ | -// +---+----+ | -// | | -// Find a hotkey | -// | | -// capture and analyse +---v----+ | -// is done, ready to get | FINISH +-------------------------+ -// the result +--------+ +// hotkey_collector +// state +// data has been cleared, +--------------+ +// ready to start | STOPED |<--------------+------------+ +// +------+-------+ | | +// | | | +// Receive START RPC Time out | +// | + | +// is running COARSE +------v-------+ | | +// capture and analysis |COARSE_FINDING+---------------^ Receive STOPED RPC +// +------+-------+ | | +// | + | +// Find a hot bucket Time out | +// | + | +// is running FINE +------v-------+ | | +// capture and analysis | FINE_FINDING |+--------------+ | +// +------+-------+ | +// | | +// Find a hotkey | +// | | +// capture and analyse +------v-------+ | +// is done, ready to get | FINISHED |+---------------------------+ +// the result +--------------+ enum class hotkey_collector_state { - STOP, - COARSE, - FINE, - FINISH + STOPED, + COARSE_FINDING, + FINE_FINDING, + FINISHED }; -ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOP) -ENUM_REG(hotkey_collector_state::STOP) -ENUM_REG(hotkey_collector_state::COARSE) -ENUM_REG(hotkey_collector_state::FINE) -ENUM_REG(hotkey_collector_state::FINISH) +ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOPED) +ENUM_REG(hotkey_collector_state::STOPED) +ENUM_REG(hotkey_collector_state::COARSE_FINDING) +ENUM_REG(hotkey_collector_state::FINE_FINDING) +ENUM_REG(hotkey_collector_state::FINISHED) ENUM_END2(hotkey_collector_state, hotkey_collector_state) } // namespace server From 542b91fb398e5f179b46fc8c0cf9dfc0a86ab4e0 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Wed, 14 Oct 2020 14:15:35 +0800 Subject: [PATCH 08/10] fix --- src/server/hotkey_collector_state.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/hotkey_collector_state.h b/src/server/hotkey_collector_state.h index 8a2ba68d65..1a86f472b7 100644 --- a/src/server/hotkey_collector_state.h +++ b/src/server/hotkey_collector_state.h @@ -28,13 +28,13 @@ namespace server { // ready to start | STOPED |<--------------+------------+ // +------+-------+ | | // | | | -// Receive START RPC Time out | +// Receive START RPC Timeout | // | + | // is running COARSE +------v-------+ | | // capture and analysis |COARSE_FINDING+---------------^ Receive STOPED RPC // +------+-------+ | | // | + | -// Find a hot bucket Time out | +// Find a hot bucket Timeout | // | + | // is running FINE +------v-------+ | | // capture and analysis | FINE_FINDING |+--------------+ | From d271916c159d77d2da00ae9beef2e7d56a7a72e1 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Wed, 14 Oct 2020 15:17:01 +0800 Subject: [PATCH 09/10] replace finding --- src/server/hotkey_collector_state.h | 54 ++++++++++++++--------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/server/hotkey_collector_state.h b/src/server/hotkey_collector_state.h index 1a86f472b7..7dafa5ae00 100644 --- a/src/server/hotkey_collector_state.h +++ b/src/server/hotkey_collector_state.h @@ -22,42 +22,42 @@ namespace pegasus { namespace server { -// hotkey_collector -// state -// data has been cleared, +--------------+ -// ready to start | STOPED |<--------------+------------+ -// +------+-------+ | | -// | | | -// Receive START RPC Timeout | -// | + | -// is running COARSE +------v-------+ | | -// capture and analysis |COARSE_FINDING+---------------^ Receive STOPED RPC -// +------+-------+ | | -// | + | -// Find a hot bucket Timeout | -// | + | -// is running FINE +------v-------+ | | -// capture and analysis | FINE_FINDING |+--------------+ | -// +------+-------+ | -// | | -// Find a hotkey | -// | | -// capture and analyse +------v-------+ | -// is done, ready to get | FINISHED |+---------------------------+ -// the result +--------------+ +// hotkey_collector +// state +// data has been cleared, +----------------+ +// ready to start | STOPED |<--------------+------------+ +// +-------+--------+ | | +// | | | +// Receive START RPC Timeout | +// | + | +// is running COARSE +-------v--------+ | | +// capture and analysis |COARSE_DETECTING+---------------^ Receive STOPED RPC +// +-------+--------+ | | +// | + | +// Find a hot bucket Timeout | +// | + | +// is running FINE +-------v--------+ | | +// capture and analysis | FINE_DETECTING |+--------------+ | +// +-------+--------+ | +// | | +// Find a hotkey | +// | | +// capture and analyse +-------v--------+ | +// is done, ready to get | FINISHED |+---------------------------+ +// the result +----------------+ enum class hotkey_collector_state { STOPED, - COARSE_FINDING, - FINE_FINDING, + COARSE_DETECTING, + FINE_DETECTING, FINISHED }; ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOPED) ENUM_REG(hotkey_collector_state::STOPED) -ENUM_REG(hotkey_collector_state::COARSE_FINDING) -ENUM_REG(hotkey_collector_state::FINE_FINDING) +ENUM_REG(hotkey_collector_state::COARSE_DETECTING) +ENUM_REG(hotkey_collector_state::FINE_DETECTING) ENUM_REG(hotkey_collector_state::FINISHED) ENUM_END2(hotkey_collector_state, hotkey_collector_state) From 0d9d5be5b5d2c1d2894b9a3519293ec578a58ec3 Mon Sep 17 00:00:00 2001 From: tangyanzhao Date: Wed, 14 Oct 2020 15:24:16 +0800 Subject: [PATCH 10/10] STOPPED --- src/server/hotkey_collector_state.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/hotkey_collector_state.h b/src/server/hotkey_collector_state.h index 7dafa5ae00..315ac7cdd3 100644 --- a/src/server/hotkey_collector_state.h +++ b/src/server/hotkey_collector_state.h @@ -25,13 +25,13 @@ namespace server { // hotkey_collector // state // data has been cleared, +----------------+ -// ready to start | STOPED |<--------------+------------+ +// ready to start | STOPPED |<--------------+------------+ // +-------+--------+ | | // | | | // Receive START RPC Timeout | // | + | // is running COARSE +-------v--------+ | | -// capture and analysis |COARSE_DETECTING+---------------^ Receive STOPED RPC +// capture and analysis |COARSE_DETECTING+---------------^ Receive STOPPED RPC // +-------+--------+ | | // | + | // Find a hot bucket Timeout | @@ -48,14 +48,14 @@ namespace server { enum class hotkey_collector_state { - STOPED, + STOPPED, COARSE_DETECTING, FINE_DETECTING, FINISHED }; -ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOPED) -ENUM_REG(hotkey_collector_state::STOPED) +ENUM_BEGIN2(hotkey_collector_state, hotkey_collector_state, hotkey_collector_state::STOPPED) +ENUM_REG(hotkey_collector_state::STOPPED) ENUM_REG(hotkey_collector_state::COARSE_DETECTING) ENUM_REG(hotkey_collector_state::FINE_DETECTING) ENUM_REG(hotkey_collector_state::FINISHED)