You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by la...@apache.org on 2023/02/23 03:23:06 UTC
[kudu] 02/03: [www] add slow scans show control
This is an automated email from the ASF dual-hosted git repository.
laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 97ec58742182bb8175dbf38a94027f845e806926
Author: kedeng <kd...@gmail.com>
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 <la...@apache.org>
Tested-by: Kudu Jenkins
---
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 165190fe7..0caba95ec 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 d68aa161b..d28f1a4aa 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);
@@ -171,7 +176,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();
}
}
@@ -315,6 +325,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;
{
@@ -324,7 +340,6 @@ vector<SharedScanDescriptor> ScannerManager::ListSlowScans() const {
}
}
- vector<SharedScanDescriptor> ret;
ret.reserve(scans.size());
AppendValuesFromMap(scans, &ret);
@@ -357,7 +372,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.",