This is an automated email from the ASF dual-hosted git repository.

smityz 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 a095172  fix: hotkey_collector bug and two function tests (#836)
a095172 is described below

commit a095172ad1559cc0e65c7807a2baedc607cde50c
Author: cauchy1988 <[email protected]>
AuthorDate: Fri Dec 10 15:33:01 2021 +0800

    fix: hotkey_collector bug and two function tests (#836)
---
 src/server/hotkey_collector.cpp           | 10 ++++++++++
 src/server/test/hotkey_collector_test.cpp |  2 ++
 src/test/function_test/test_split.cpp     |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/server/hotkey_collector.cpp b/src/server/hotkey_collector.cpp
index d59214d..d7e5d2b 100644
--- a/src/server/hotkey_collector.cpp
+++ b/src/server/hotkey_collector.cpp
@@ -94,6 +94,16 @@ find_outlier_index(const std::vector<uint64_t> 
&captured_keys, int threshold, in
         }
     }
     standard_deviation = sqrt(standard_deviation / (data_size - 2));
+
+    // There are two cases will lead standard_deviation = 0
+    // Case 1: have hotspot [1, 1, 300, 1]
+    // Case 2: not have hotspot [1, 1, 1, 1]
+    // In both case 1 and case 2, we select [1, 1, 1] to calculate 
standard_deviation, so it equals
+    // to 0. In these scenes, we simply compare the hot_value with the average
+    if (standard_deviation == 0) {
+        return hot_value > captured_keys_avg_count;
+    }
+
     double hot_point = (hot_value - captured_keys_avg_count) / 
standard_deviation;
     if (hot_point >= threshold) {
         return true;
diff --git a/src/server/test/hotkey_collector_test.cpp 
b/src/server/test/hotkey_collector_test.cpp
index 781a5a5..2b40e67 100644
--- a/src/server/test/hotkey_collector_test.cpp
+++ b/src/server/test/hotkey_collector_test.cpp
@@ -114,6 +114,7 @@ TEST_F(coarse_collector_test, coarse_collector)
             coarse_collector.capture_data(hash_key, 1);
         });
     }
+    std::this_thread::sleep_for(std::chrono::seconds(1));
     coarse_collector.analyse_data(result);
     ASSERT_NE(result.coarse_bucket_index, -1);
     _tracker.wait_outstanding_tasks();
@@ -168,6 +169,7 @@ TEST_F(fine_collector_test, fine_collector)
             fine_collector.capture_data(hash_key, 1);
         });
     }
+    std::this_thread::sleep_for(std::chrono::seconds(1));
     fine_collector.analyse_data(result);
     _tracker.wait_outstanding_tasks();
 
diff --git a/src/test/function_test/test_split.cpp 
b/src/test/function_test/test_split.cpp
index c0562fa..b6c3014 100644
--- a/src/test/function_test/test_split.cpp
+++ b/src/test/function_test/test_split.cpp
@@ -205,7 +205,7 @@ public:
         pegasus_client::scan_options options;
         auto ret = pg_client->get_unordered_scanners(10000, options, scanners);
         ASSERT_EQ(ret, PERR_OK);
-        int32_t count;
+        int32_t count = 0;
         for (auto i = 0; i < scanners.size(); i++) {
             std::string hash_key;
             std::string sort_key;

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to