From 6a79f9a5ae3cb64f899a6d72ef96ce6557290351 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Tue, 10 Mar 2020 16:21:38 +0800 Subject: [PATCH 01/16] add --- src/dist/replication/lib/replica_stub.cpp | 15 +++++++++++++++ src/dist/replication/lib/replica_stub.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index aa2c16b0bf..84faaba2d0 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -85,6 +85,12 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _log = nullptr; _primary_address_str[0] = '\0'; install_perf_counters(); + + _abnormal_write_size_threshold = dsn_config_get_value_uint64( + "pegasus.server", + "rocksdb_abnormal_write_size_threshold", + 1000000, + "write operation exceed this threshold will be logged and reject, 0 means no check"); } replica_stub::~replica_stub(void) { close(); } @@ -774,6 +780,15 @@ void replica_stub::on_client_write(gpid id, dsn::message_ex *request) request->header->rpc_name, request->header->client.timeout_ms); } + + if (request->header->body_length > _abnormal_write_size_threshold) { + dwarn_replica("client from {} write request body size exceed threshold: {}, it will be " + "reject!", + request->header->from_address.to_string(), + _abnormal_write_size_threshold); + response_client_write(request, ERR_INVALID_DATA); + } + replica_ptr rep = get_replica(id); if (rep != nullptr) { rep->on_client_write(request); diff --git a/src/dist/replication/lib/replica_stub.h b/src/dist/replication/lib/replica_stub.h index e2a4cc7063..a00937c358 100644 --- a/src/dist/replication/lib/replica_stub.h +++ b/src/dist/replication/lib/replica_stub.h @@ -336,6 +336,9 @@ class replica_stub : public serverlet, public ref_counter // cli service std::unique_ptr _cli_service; + // write body size exceed this threshold will be logged and reject, 0 means no check + uint64_t _abnormal_write_size_threshold; + // performance counters perf_counter_wrapper _counter_replicas_count; perf_counter_wrapper _counter_replicas_opening_count; From c972fec02045272e97c526c0c26adbafeff6e139 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Tue, 10 Mar 2020 20:29:26 +0800 Subject: [PATCH 02/16] add test and counter --- src/dist/replication/lib/replica.h | 1 + src/dist/replication/lib/replica_2pc.cpp | 9 +++ src/dist/replication/lib/replica_stub.cpp | 14 ++--- src/dist/replication/lib/replica_stub.h | 3 + .../replica_test/unit_test/replica_test.cpp | 62 +++++++++++++++++++ 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/dist/replication/test/replica_test/unit_test/replica_test.cpp diff --git a/src/dist/replication/lib/replica.h b/src/dist/replication/lib/replica.h index 1c38df9b86..75d27da306 100644 --- a/src/dist/replication/lib/replica.h +++ b/src/dist/replication/lib/replica.h @@ -55,6 +55,7 @@ #include "prepare_list.h" #include "replica_context.h" #include "throttling_controller.h" +#include namespace dsn { namespace replication { diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index a95ca0bb73..10de27339a 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -44,6 +44,15 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) return; } + if (request->body_size() > _stub->_abnormal_write_size_threshold) { + dwarn_replica("client from {} write request body size exceed threshold = {}, it will be " + "reject!", + request->header->from_address.to_string(), + _stub->_abnormal_write_size_threshold); + _stub->_counter_recent_write_size_exceed_threshold_count->increment(); + response_client_write(request, ERR_INVALID_DATA); + } + task_spec *spec = task_spec::get(request->rpc_code()); if (!_options->allow_non_idempotent_write && !spec->rpc_request_is_write_idempotent) { response_client_write(request, ERR_OPERATION_DISABLED); diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index 84faaba2d0..c67f6a8292 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -328,6 +328,12 @@ void replica_stub::install_perf_counters() "recent.write.busy.count", COUNTER_TYPE_VOLATILE_NUMBER, "write busy count in the recent period"); + + _counter_recent_write_size_exceed_threshold_count.init_app_counter( + "eon.replica_stub", + "recent.write.size.exceed.count", + COUNTER_TYPE_VOLATILE_NUMBER, + "write size exceed threshold count in the recent period"); } void replica_stub::initialize(bool clear /* = false*/) @@ -781,14 +787,6 @@ void replica_stub::on_client_write(gpid id, dsn::message_ex *request) request->header->client.timeout_ms); } - if (request->header->body_length > _abnormal_write_size_threshold) { - dwarn_replica("client from {} write request body size exceed threshold: {}, it will be " - "reject!", - request->header->from_address.to_string(), - _abnormal_write_size_threshold); - response_client_write(request, ERR_INVALID_DATA); - } - replica_ptr rep = get_replica(id); if (rep != nullptr) { rep->on_client_write(request); diff --git a/src/dist/replication/lib/replica_stub.h b/src/dist/replication/lib/replica_stub.h index a00937c358..5c867102a1 100644 --- a/src/dist/replication/lib/replica_stub.h +++ b/src/dist/replication/lib/replica_stub.h @@ -266,6 +266,7 @@ class replica_stub : public serverlet, public ref_counter friend class duplication_sync_timer; friend class duplication_sync_timer_test; friend class replica_duplicator_manager_test; + friend class replica_test; typedef std::unordered_map opening_replicas; typedef std::unordered_map> @@ -398,6 +399,8 @@ class replica_stub : public serverlet, public ref_counter perf_counter_wrapper _counter_recent_read_busy_count; perf_counter_wrapper _counter_recent_write_busy_count; + perf_counter_wrapper _counter_recent_write_size_exceed_threshold_count; + dsn::task_tracker _tracker; }; } // namespace replication diff --git a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp new file mode 100644 index 0000000000..262c66d742 --- /dev/null +++ b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2017-present, Xiaomi, Inc. All rights reserved. +// This source code is licensed under the Apache License Version 2.0, which +// can be found in the LICENSE file in the root directory of this source tree. + +#include + +#include +#include "replica_test_base.h" + +namespace dsn { +namespace replication { + +class replica_test : public replica_test_base +{ +public: + int total_count = 0; + dsn::app_info _app_info; + dsn::gpid pid = gpid(2, 1); + +public: + void SetUp() override + { + stub->install_perf_counters(); + mock_app_info(); + stub->generate_replica(_app_info, pid, partition_status::PS_PRIMARY, 1); + } + + void calc_write_size_exceed_threshold_count() + { + total_count += stub->_counter_recent_write_size_exceed_threshold_count->get_value(); + } + + void mock_app_info() + { + _app_info.app_id = 2; + _app_info.app_name = "replica_test"; + _app_info.app_type = "replica"; + _app_info.is_stateful = true; + _app_info.max_replica_count = 3; + _app_info.partition_count = 8; + } +}; + +TEST_F(replica_test, write_size_limited) +{ + int count = 100; + task_code default_code; + struct dsn::message_header header; + header.body_length = 10000000; + + auto write_request = dsn::message_ex::create_request(default_code); + write_request->header = &header; + while (count-- > 0) { + stub->on_client_write(pid, write_request); + calc_write_size_exceed_threshold_count(); + } + + ASSERT_EQ(total_count, 100); +} + +} // namespace replication +} // namespace dsn \ No newline at end of file From 7f03c6295c08b52cf2a63fa42d9c4032753c91db Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Tue, 10 Mar 2020 20:32:05 +0800 Subject: [PATCH 03/16] add test and counter --- src/dist/replication/lib/replica_stub.cpp | 1 - .../replication/test/replica_test/unit_test/replica_test.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index c67f6a8292..bdeb3388cf 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -786,7 +786,6 @@ void replica_stub::on_client_write(gpid id, dsn::message_ex *request) request->header->rpc_name, request->header->client.timeout_ms); } - replica_ptr rep = get_replica(id); if (rep != nullptr) { rep->on_client_write(request); diff --git a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp index 262c66d742..2ea6253d74 100644 --- a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp +++ b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp @@ -59,4 +59,4 @@ TEST_F(replica_test, write_size_limited) } } // namespace replication -} // namespace dsn \ No newline at end of file +} // namespace dsn From f8078bf75e9d52d936975dc94056de0646d2dcef Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 09:51:26 +0800 Subject: [PATCH 04/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index 10de27339a..5a49020334 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -44,7 +44,8 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) return; } - if (request->body_size() > _stub->_abnormal_write_size_threshold) { + if (_stub->_abnormal_write_size_threshold && + request->body_size() > _stub->_abnormal_write_size_threshold) { dwarn_replica("client from {} write request body size exceed threshold = {}, it will be " "reject!", request->header->from_address.to_string(), From 7cab76c5929c7c267661238f6cf66dd9d8721f28 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 09:58:02 +0800 Subject: [PATCH 05/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 6 +++--- src/dist/replication/lib/replica_stub.cpp | 6 +++--- src/dist/replication/lib/replica_stub.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index 5a49020334..83b6818091 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -44,12 +44,12 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) return; } - if (_stub->_abnormal_write_size_threshold && - request->body_size() > _stub->_abnormal_write_size_threshold) { + if (_stub->_max_allowed_write_size && + request->body_size() > _stub->_max_allowed_write_size) { dwarn_replica("client from {} write request body size exceed threshold = {}, it will be " "reject!", request->header->from_address.to_string(), - _stub->_abnormal_write_size_threshold); + _stub->_max_allowed_write_size); _stub->_counter_recent_write_size_exceed_threshold_count->increment(); response_client_write(request, ERR_INVALID_DATA); } diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index bdeb3388cf..3848b17b6e 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -86,9 +86,9 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _primary_address_str[0] = '\0'; install_perf_counters(); - _abnormal_write_size_threshold = dsn_config_get_value_uint64( + _max_allowed_write_size = dsn_config_get_value_uint64( "pegasus.server", - "rocksdb_abnormal_write_size_threshold", + "max_allowed_write_size", 1000000, "write operation exceed this threshold will be logged and reject, 0 means no check"); } @@ -331,7 +331,7 @@ void replica_stub::install_perf_counters() _counter_recent_write_size_exceed_threshold_count.init_app_counter( "eon.replica_stub", - "recent.write.size.exceed.count", + "recent.write.size.exceed.threshold.count", COUNTER_TYPE_VOLATILE_NUMBER, "write size exceed threshold count in the recent period"); } diff --git a/src/dist/replication/lib/replica_stub.h b/src/dist/replication/lib/replica_stub.h index 5c867102a1..9da8a03ba9 100644 --- a/src/dist/replication/lib/replica_stub.h +++ b/src/dist/replication/lib/replica_stub.h @@ -338,7 +338,7 @@ class replica_stub : public serverlet, public ref_counter std::unique_ptr _cli_service; // write body size exceed this threshold will be logged and reject, 0 means no check - uint64_t _abnormal_write_size_threshold; + uint64_t _max_allowed_write_size; // performance counters perf_counter_wrapper _counter_replicas_count; From 2cf85cb7e38a4da2b9e2111a82fdf6a91e3843de Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 10:32:35 +0800 Subject: [PATCH 06/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index 83b6818091..e2b131ef2a 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -44,8 +44,8 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) return; } - if (_stub->_max_allowed_write_size && - request->body_size() > _stub->_max_allowed_write_size) { + if (dsn_unlikely(_stub->_max_allowed_write_size && + request->body_size() > _stub->_max_allowed_write_size)) { dwarn_replica("client from {} write request body size exceed threshold = {}, it will be " "reject!", request->header->from_address.to_string(), From 56d0d360c383ed733c77732d9561ce0c97fa87d1 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 10:36:40 +0800 Subject: [PATCH 07/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index e2b131ef2a..c9876f6a5c 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -52,6 +52,7 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) _stub->_max_allowed_write_size); _stub->_counter_recent_write_size_exceed_threshold_count->increment(); response_client_write(request, ERR_INVALID_DATA); + return; } task_spec *spec = task_spec::get(request->rpc_code()); From e8cd6234c21f5ee90ba8e4fbf70222a85afe85fc Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 10:56:15 +0800 Subject: [PATCH 08/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index c9876f6a5c..9032ecab20 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -46,10 +46,12 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) if (dsn_unlikely(_stub->_max_allowed_write_size && request->body_size() > _stub->_max_allowed_write_size)) { - dwarn_replica("client from {} write request body size exceed threshold = {}, it will be " - "reject!", + dwarn_replica("client from {} write request body size exceed threshold = {}, gpid = " + "({}.{}), it will be reject!", request->header->from_address.to_string(), - _stub->_max_allowed_write_size); + _stub->_max_allowed_write_size, + get_gpid().get_app_id(), + get_gpid().get_partition_index()); _stub->_counter_recent_write_size_exceed_threshold_count->increment(); response_client_write(request, ERR_INVALID_DATA); return; From 8bbc9f100e97acc29884946ee95529291f212c9e Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 14:18:22 +0800 Subject: [PATCH 09/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 10 ++++------ src/dist/replication/lib/replica_stub.cpp | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index 9032ecab20..ea1c09b127 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -46,12 +46,10 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) if (dsn_unlikely(_stub->_max_allowed_write_size && request->body_size() > _stub->_max_allowed_write_size)) { - dwarn_replica("client from {} write request body size exceed threshold = {}, gpid = " - "({}.{}), it will be reject!", - request->header->from_address.to_string(), - _stub->_max_allowed_write_size, - get_gpid().get_app_id(), - get_gpid().get_partition_index()); + dwarn_replica( + "client from {} write request body size exceed threshold = {}, it will be reject!", + request->header->from_address.to_string(), + _stub->_max_allowed_write_size); _stub->_counter_recent_write_size_exceed_threshold_count->increment(); response_client_write(request, ERR_INVALID_DATA); return; diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index 3848b17b6e..85765248a0 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -89,7 +89,7 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _max_allowed_write_size = dsn_config_get_value_uint64( "pegasus.server", "max_allowed_write_size", - 1000000, + 1 << 20, "write operation exceed this threshold will be logged and reject, 0 means no check"); } From 47d95b48a36d6304edf5cdabea1104b7b8317888 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 14:20:26 +0800 Subject: [PATCH 10/16] add test and counter --- src/dist/replication/lib/replica_stub.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index 85765248a0..202a531483 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -87,10 +87,9 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, install_perf_counters(); _max_allowed_write_size = dsn_config_get_value_uint64( - "pegasus.server", - "max_allowed_write_size", - 1 << 20, - "write operation exceed this threshold will be logged and reject, 0 means no check"); + "pegasus.server", "max_allowed_write_size", 1048576, "write operation exceed this " + "threshold will be logged and reject, " + "default is 1MB, 0 means no check"); } replica_stub::~replica_stub(void) { close(); } From 8dec87b44d8c177cc4720ed755a4e8a03218ee4a Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 14:22:31 +0800 Subject: [PATCH 11/16] add test and counter --- src/dist/replication/lib/replica_stub.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index 202a531483..30cf6d7326 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -86,10 +86,12 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _primary_address_str[0] = '\0'; install_perf_counters(); - _max_allowed_write_size = dsn_config_get_value_uint64( - "pegasus.server", "max_allowed_write_size", 1048576, "write operation exceed this " - "threshold will be logged and reject, " - "default is 1MB, 0 means no check"); + _max_allowed_write_size = dsn_config_get_value_uint64("pegasus.server", + "max_allowed_write_size", + 1048576, + "write operation exceed this " + "threshold will be logged and reject, " + "default is 1MB, 0 means no check"); } replica_stub::~replica_stub(void) { close(); } From ce0ff0f8c27a4c2e9b3d5e92297fc74b36b6fcfe Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 14:46:09 +0800 Subject: [PATCH 12/16] add test and counter --- .../test/replica_test/unit_test/replica_test.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp index 2ea6253d74..a220986d97 100644 --- a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp +++ b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp @@ -13,7 +13,6 @@ namespace replication { class replica_test : public replica_test_base { public: - int total_count = 0; dsn::app_info _app_info; dsn::gpid pid = gpid(2, 1); @@ -25,9 +24,9 @@ class replica_test : public replica_test_base stub->generate_replica(_app_info, pid, partition_status::PS_PRIMARY, 1); } - void calc_write_size_exceed_threshold_count() + int get_write_size_exceed_threshold_count() { - total_count += stub->_counter_recent_write_size_exceed_threshold_count->get_value(); + return stub->_counter_recent_write_size_exceed_threshold_count->get_value(); } void mock_app_info() @@ -52,10 +51,9 @@ TEST_F(replica_test, write_size_limited) write_request->header = &header; while (count-- > 0) { stub->on_client_write(pid, write_request); - calc_write_size_exceed_threshold_count(); } - ASSERT_EQ(total_count, 100); + ASSERT_EQ(get_write_size_exceed_threshold_count(), 100); } } // namespace replication From 727dfae5582a9d7b3be2e4d9bbd49f9e40402298 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 17:43:19 +0800 Subject: [PATCH 13/16] add test and counter --- src/dist/replication/lib/replica.h | 1 - src/dist/replication/lib/replica_2pc.cpp | 10 ++++++---- src/dist/replication/lib/replica_stub.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/dist/replication/lib/replica.h b/src/dist/replication/lib/replica.h index 75d27da306..1c38df9b86 100644 --- a/src/dist/replication/lib/replica.h +++ b/src/dist/replication/lib/replica.h @@ -55,7 +55,6 @@ #include "prepare_list.h" #include "replica_context.h" #include "throttling_controller.h" -#include namespace dsn { namespace replication { diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index ea1c09b127..b8bedb17ee 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -29,6 +29,7 @@ #include "mutation_log.h" #include "replica_stub.h" #include +#include namespace dsn { namespace replication { @@ -46,10 +47,11 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) if (dsn_unlikely(_stub->_max_allowed_write_size && request->body_size() > _stub->_max_allowed_write_size)) { - dwarn_replica( - "client from {} write request body size exceed threshold = {}, it will be reject!", - request->header->from_address.to_string(), - _stub->_max_allowed_write_size); + dwarn_replica("client from {} write request body size exceed threshold, request_body_size " + "= {}, max_allowed_write_size = {}, it will be reject!", + request->header->from_address.to_string(), + request->body_size(), + _stub->_max_allowed_write_size); _stub->_counter_recent_write_size_exceed_threshold_count->increment(); response_client_write(request, ERR_INVALID_DATA); return; diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index 30cf6d7326..d7bd1d478e 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -88,7 +88,7 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _max_allowed_write_size = dsn_config_get_value_uint64("pegasus.server", "max_allowed_write_size", - 1048576, + 1 << 20, "write operation exceed this " "threshold will be logged and reject, " "default is 1MB, 0 means no check"); @@ -331,8 +331,8 @@ void replica_stub::install_perf_counters() "write busy count in the recent period"); _counter_recent_write_size_exceed_threshold_count.init_app_counter( - "eon.replica_stub", - "recent.write.size.exceed.threshold.count", + "eon_replica_stub", + "recent_write_size_exceed_threshold_count", COUNTER_TYPE_VOLATILE_NUMBER, "write size exceed threshold count in the recent period"); } From d97fbe9257f3855dbc72cf6ae0be30f5a5f1a90f Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Wed, 11 Mar 2020 18:55:52 +0800 Subject: [PATCH 14/16] add test and counter --- src/dist/replication/lib/replica_2pc.cpp | 2 +- .../test/replica_test/unit_test/replica_test.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dist/replication/lib/replica_2pc.cpp b/src/dist/replication/lib/replica_2pc.cpp index b8bedb17ee..67b8020ffe 100644 --- a/src/dist/replication/lib/replica_2pc.cpp +++ b/src/dist/replication/lib/replica_2pc.cpp @@ -48,7 +48,7 @@ void replica::on_client_write(dsn::message_ex *request, bool ignore_throttling) if (dsn_unlikely(_stub->_max_allowed_write_size && request->body_size() > _stub->_max_allowed_write_size)) { dwarn_replica("client from {} write request body size exceed threshold, request_body_size " - "= {}, max_allowed_write_size = {}, it will be reject!", + "= {}, max_allowed_write_size = {}, it will be rejected!", request->header->from_address.to_string(), request->body_size(), _stub->_max_allowed_write_size); diff --git a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp index a220986d97..86345fe71c 100644 --- a/src/dist/replication/test/replica_test/unit_test/replica_test.cpp +++ b/src/dist/replication/test/replica_test/unit_test/replica_test.cpp @@ -6,6 +6,7 @@ #include #include "replica_test_base.h" +#include namespace dsn { namespace replication { @@ -48,12 +49,14 @@ TEST_F(replica_test, write_size_limited) header.body_length = 10000000; auto write_request = dsn::message_ex::create_request(default_code); + auto cleanup = dsn::defer([=]() { delete write_request; }); write_request->header = &header; - while (count-- > 0) { + + for (int i = 0; i < count; i++) { stub->on_client_write(pid, write_request); } - ASSERT_EQ(get_write_size_exceed_threshold_count(), 100); + ASSERT_EQ(get_write_size_exceed_threshold_count(), count); } } // namespace replication From e9cc8d9d244d0916debb39f2a783d987df8cd9dc Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Thu, 12 Mar 2020 10:56:04 +0800 Subject: [PATCH 15/16] add test and counter --- src/dist/replication/lib/replica_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index d7bd1d478e..02bba80b75 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -86,7 +86,7 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/, _primary_address_str[0] = '\0'; install_perf_counters(); - _max_allowed_write_size = dsn_config_get_value_uint64("pegasus.server", + _max_allowed_write_size = dsn_config_get_value_uint64("replication", "max_allowed_write_size", 1 << 20, "write operation exceed this " From 4d294a4c14d7f19b7b1791d0e08420cdcc4a9834 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Thu, 12 Mar 2020 13:37:19 +0800 Subject: [PATCH 16/16] add test and counter --- src/dist/replication/lib/replica_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dist/replication/lib/replica_stub.cpp b/src/dist/replication/lib/replica_stub.cpp index c067d58cbc..45e4a4c20a 100644 --- a/src/dist/replication/lib/replica_stub.cpp +++ b/src/dist/replication/lib/replica_stub.cpp @@ -331,7 +331,7 @@ void replica_stub::install_perf_counters() "write busy count in the recent period"); _counter_recent_write_size_exceed_threshold_count.init_app_counter( - "eon_replica_stub", + "eon.replica_stub", "recent_write_size_exceed_threshold_count", COUNTER_TYPE_VOLATILE_NUMBER, "write size exceed threshold count in the recent period");