This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 69f57e921 [Tool] Fix unit test ToolTest.TableCopyLimitSpeed
69f57e921 is described below
commit 69f57e921c3e08f0a832cda8edb13d458f7c3cbf
Author: xinghuayu007 <[email protected]>
AuthorDate: Wed Jul 24 18:15:40 2024 +0800
[Tool] Fix unit test ToolTest.TableCopyLimitSpeed
This patch refactor some code and fix an test based on the
patch: https://gerrit.cloudera.org/c/21527/
Change-Id: I8906a8c069f6133fab30b3f2da7723e98c82d869
Reviewed-on: http://gerrit.cloudera.org:8080/21609
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
---
src/kudu/tools/kudu-tool-test.cc | 8 ++++----
src/kudu/tools/table_scanner.cc | 9 ++++++---
src/kudu/tools/table_scanner.h | 6 ++++--
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 8d97f4047..4ef500923 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -6026,16 +6026,16 @@ TEST_F(ToolTest, TableCopyLimitSpeed) {
.add_master_server_addr(master_addr)
.Build(&client));
shared_ptr<KuduTable> table;
- client->OpenTable(kNewTableName, &table);
+ ASSERT_OK(client->OpenTable(kNewTableName, &table));
KuduScanner scanner(table.get());
- scanner.Open();
+ ASSERT_OK(scanner.Open());
KuduScanBatch batch;
int64_t data_size = 0;
while (scanner.HasMoreRows()) {
ASSERT_OK(scanner.NextBatch(&batch));
- data_size = batch.direct_data().size() + batch.indirect_data().size();
+ data_size += batch.direct_data().size() + batch.indirect_data().size();
}
- // Table copy speed must less than table_copy_throttler_bytes_per_sec.
+ // Table copy speed must be less than table_copy_throttler_bytes_per_sec.
ASSERT_LE(data_size / (end_time - start_time).ToSeconds(),
table_copy_throttler_bytes_per_sec);
}
diff --git a/src/kudu/tools/table_scanner.cc b/src/kudu/tools/table_scanner.cc
index fac0ce949..415c64ed3 100644
--- a/src/kudu/tools/table_scanner.cc
+++ b/src/kudu/tools/table_scanner.cc
@@ -61,6 +61,7 @@
#include "kudu/util/slice.h"
#include "kudu/util/stopwatch.h"
#include "kudu/util/string_case.h"
+#include "kudu/util/threadpool.h"
#include "kudu/util/throttler.h"
using kudu::client::KuduClient;
@@ -582,12 +583,14 @@ TableScanner::TableScanner(
out_(nullptr) {
CHECK_OK(SetReplicaSelection(FLAGS_replica_selection));
if (FLAGS_table_copy_throttler_bytes_per_sec > 0) {
- throttler_ = std::make_shared<Throttler>(Throttler::kNoLimit,
+ throttler_ = std::make_unique<Throttler>(Throttler::kNoLimit,
FLAGS_table_copy_throttler_bytes_per_sec,
FLAGS_table_copy_throttler_burst_factor);
}
}
+TableScanner::~TableScanner() {}
+
Status TableScanner::ScanData(const vector<KuduScanToken*>& tokens,
const function<Status(const KuduScanBatch&
batch)>& cb) {
for (const auto* token : tokens) {
@@ -608,9 +611,9 @@ Status TableScanner::ScanData(const vector<KuduScanToken*>&
tokens,
count += batch.NumRows();
total_count_ += batch.NumRows();
++next_batch_calls;
- // Limit table copy speed.
+ // Limit table copying speed.
if (throttler_) {
- SCOPED_LOG_SLOW_EXECUTION(WARNING, 1000, "Table copy throttler");
+ SCOPED_LOG_SLOW_EXECUTION(INFO, 1000, "Table copy throttler");
while (!throttler_->Take(0,
batch.direct_data().size() +
batch.indirect_data().size())) {
SleepFor(MonoDelta::FromMicroseconds(Throttler::kRefillPeriodMicros
/ 2));
diff --git a/src/kudu/tools/table_scanner.h b/src/kudu/tools/table_scanner.h
index 1eba9f295..1c55d603b 100644
--- a/src/kudu/tools/table_scanner.h
+++ b/src/kudu/tools/table_scanner.h
@@ -32,9 +32,9 @@
#include "kudu/client/write_op.h"
#include "kudu/util/mutex.h"
#include "kudu/util/status.h"
-#include "kudu/util/threadpool.h"
namespace kudu {
+class ThreadPool;
class Throttler;
namespace tools {
@@ -48,6 +48,8 @@ class TableScanner {
std::nullopt,
std::optional<std::string> dst_table_name = std::nullopt);
+ ~TableScanner();
+
// Set output stream of this tool, or disable output if not set.
// 'out' must remain valid for the lifetime of this class.
void SetOutput(std::ostream* out);
@@ -104,7 +106,7 @@ class TableScanner {
std::optional<std::string> dst_table_name_;
int32_t scan_batch_size_;
std::unique_ptr<ThreadPool> thread_pool_;
- std::shared_ptr<Throttler> throttler_;
+ std::unique_ptr<Throttler> throttler_;
// Protects output to 'out_' so that rows don't get interleaved.
Mutex output_lock_;