This is an automated email from the ASF dual-hosted git repository. laiyingchun pushed a commit to branch branch-1.17.x in repository https://gitbox.apache.org/repos/asf/kudu.git
commit f7038fcd617c6d26c958cd079c34abb349b0ef93 Author: kedeng <[email protected]> AuthorDate: Tue Feb 7 17:07:49 2023 +0800 [www] add slow scans show control The slow scans show functionality may lead to full scanning and affecting normal Kudu service unexpectedly. Add --show_slow_scans flag to control whether to show slow scans on the /scans page of web and record the slow scans in the log. The default value of the flag --show_slow_scans is false, which means slow scans show is disabled by default. Change-Id: Ia96f80561a4c889cbdd1c6dc992184981be86fb6 Reviewed-on: http://gerrit.cloudera.org:8080/19480 Reviewed-by: Yingchun Lai <[email protected]> Tested-by: Kudu Jenkins (cherry picked from commit 97ec58742182bb8175dbf38a94027f845e806926) Reviewed-on: http://gerrit.cloudera.org:8080/19675 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Yifan Zhang <[email protected]> --- src/kudu/client/scan_token-test.cc | 21 +++++++++++++++++++++ src/kudu/tserver/scanners.cc | 24 +++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/kudu/client/scan_token-test.cc b/src/kudu/client/scan_token-test.cc index d46bfc12b..0e3997f3c 100644 --- a/src/kudu/client/scan_token-test.cc +++ b/src/kudu/client/scan_token-test.cc @@ -75,6 +75,7 @@ DECLARE_bool(tserver_enforce_access_control); DECLARE_int32(scanner_inject_latency_on_each_batch_ms); DECLARE_int32(slow_scanner_threshold_ms); +DECLARE_bool(show_slow_scans); METRIC_DECLARE_histogram(handler_latency_kudu_master_MasterService_GetTableSchema); METRIC_DECLARE_histogram(handler_latency_kudu_master_MasterService_GetTableLocations); @@ -367,6 +368,10 @@ class ScanTokenTest : public KuduTest { }; TEST_F(ScanTokenTest, SlowScansListTest) { + // Slow scans show is disabled by default. + ASSERT_FALSE(FLAGS_show_slow_scans); + FLAGS_show_slow_scans = true; + constexpr const char* const kTableName = "slow_scans_show"; // Create schema KuduSchema schema; @@ -418,6 +423,22 @@ TEST_F(ScanTokenTest, SlowScansListTest) { ASSERT_EQ(2, GetCompletedScansCount()); ASSERT_EQ(1, GetSlowScansCount()); } + + { + // Disable the slow scans show. + FLAGS_show_slow_scans = false; + vector<KuduScanToken*> tokens; + ElementDeleter deleter(&tokens); + ASSERT_OK(KuduScanTokenBuilder(table.get()).Build(&tokens)); + + // Create a slow scan scenarios. + FLAGS_scanner_inject_latency_on_each_batch_ms = 50; + FLAGS_slow_scanner_threshold_ms = 40; + ASSERT_EQ(200, CountRows(tokens)); + ASSERT_EQ(3, GetCompletedScansCount()); + // If disable the slow scans, we can only get 0, which represents the count of slow scans. + ASSERT_EQ(0, GetSlowScansCount()); + } } TEST_F(ScanTokenTest, TestScanTokens) { diff --git a/src/kudu/tserver/scanners.cc b/src/kudu/tserver/scanners.cc index 584880968..c53b331a1 100644 --- a/src/kudu/tserver/scanners.cc +++ b/src/kudu/tserver/scanners.cc @@ -65,8 +65,13 @@ DEFINE_int32(completed_scan_history_count, 10, "latest scans will be shown on the tablet server's scans dashboard."); TAG_FLAG(completed_scan_history_count, experimental); -// TODO(kedeng) : Add flag to control the display of slow scans, and avoid full scanning -// affecting normal Kudu service without perception. +DEFINE_bool(show_slow_scans, false, + "Whether to show slow scans on the /scans page of web or record it in the log. " + "Please note that once set to true, full table scans may occur, which may affect " + "the normal Kudu service unexpectedly."); +TAG_FLAG(show_slow_scans, advanced); +TAG_FLAG(show_slow_scans, runtime); + DEFINE_int32(slow_scanner_threshold_ms, 60 * 1000L, // 1 minute "Number of milliseconds for the threshold of slow scan."); TAG_FLAG(slow_scanner_threshold_ms, advanced); @@ -181,7 +186,12 @@ void ScannerManager::RunCollectAndRemovalThread() { } shutdown_cv_.WaitFor(MonoDelta::FromMicroseconds(FLAGS_scanner_gc_check_interval_us)); } - CollectSlowScanners(); + + if (FLAGS_show_slow_scans) { + // Control the collection of slow scans to avoid full scanning affecting normal Kudu + // service without perception. + CollectSlowScanners(); + } RemoveExpiredScanners(); } } @@ -344,6 +354,12 @@ vector<SharedScanDescriptor> ScannerManager::ListScans() const { } vector<SharedScanDescriptor> ScannerManager::ListSlowScans() const { + vector<SharedScanDescriptor> ret; + if (!FLAGS_show_slow_scans) { + LOG(INFO) << "Slow scans show is disabled. Set --show_slow_scans to enable it."; + return ret; + } + // Get all the scans first. unordered_map<string, SharedScanDescriptor> scans; { @@ -353,7 +369,6 @@ vector<SharedScanDescriptor> ScannerManager::ListSlowScans() const { } } - vector<SharedScanDescriptor> ret; ret.reserve(scans.size()); AppendValuesFromMap(scans, &ret); @@ -386,7 +401,6 @@ void ScannerManager::CollectSlowScanners() { MonoDelta delta_time = now - start_time - MonoDelta::FromMilliseconds(slow_scanner_threshold); - // TODO(kedeng) : Add flag to control whether to print this log. LOG(INFO) << Substitute( "Slow scanner id: $0, of tablet $1, " "exceed the time threshold $2 ms for $3 ms.",
