You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2019/11/03 21:29:50 UTC

[kudu] branch master updated: KUDU-2986 p1: adjust the kudu CLI output from 0 to N/A

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

adar 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 951dea6  KUDU-2986 p1: adjust the kudu CLI output from 0 to N/A
951dea6 is described below

commit 951dea688d73768942d05a1ec71337de83bf4939
Author: helifu <hz...@corp.netease.com>
AuthorDate: Tue Oct 29 21:08:10 2019 +0800

    KUDU-2986 p1: adjust the kudu CLI output from 0 to N/A
    
    The `live_row_count` metric value should be invalid(N/A) in
    kudu CLI output("kudu table statistics") while there is any
    tablet which doesn't support live row count.
    
    Change-Id: I82c47f5ac07cf63d455c0720614c5383bfa88ca3
    Reviewed-on: http://gerrit.cloudera.org:8080/14567
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <as...@cloudera.com>
---
 src/kudu/client/client-test.cc              | 14 ++++++++++++--
 src/kudu/client/client.cc                   |  5 +++--
 src/kudu/client/client.h                    |  1 +
 src/kudu/client/table_statistics-internal.h | 16 +++++++++-------
 src/kudu/master/catalog_manager.cc          |  9 ++++++++-
 src/kudu/tools/kudu-tool-test.cc            |  5 +++--
 6 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index 4e19e00..7a66110 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -119,6 +119,7 @@
 #include "kudu/util/thread_restrictions.h"
 
 DECLARE_bool(allow_unsafe_replication_factor);
+DECLARE_bool(catalog_manager_support_live_row_count);
 DECLARE_bool(fail_dns_resolution);
 DECLARE_bool(location_mapping_by_uuid);
 DECLARE_bool(log_inject_latency);
@@ -795,13 +796,22 @@ TEST_F(ClientTest, TestGetTableStatistics) {
   FLAGS_mock_table_metrics_for_testing = true;
   FLAGS_on_disk_size_for_testing = 1024;
   FLAGS_live_row_count_for_testing = 1000;
-  {
+  const auto GetTableStatistics = [&] () {
     KuduTableStatistics *table_statistics;
     ASSERT_OK(client_->GetTableStatistics(kTableName, &table_statistics));
     statistics.reset(table_statistics);
-  }
+  };
+
+  // Master supports live row count.
+  NO_FATALS(GetTableStatistics());
   ASSERT_EQ(FLAGS_on_disk_size_for_testing, statistics->on_disk_size());
   ASSERT_EQ(FLAGS_live_row_count_for_testing, statistics->live_row_count());
+  // Master doesn't support live row count.
+  FLAGS_catalog_manager_support_live_row_count = false;
+  NO_FATALS(GetTableStatistics());
+  ASSERT_EQ(FLAGS_on_disk_size_for_testing, statistics->on_disk_size());
+  ASSERT_EQ(-1, statistics->live_row_count());
+  ASSERT_NE(-1, FLAGS_live_row_count_for_testing);
 }
 
 TEST_F(ClientTest, TestBadTable) {
diff --git a/src/kudu/client/client.cc b/src/kudu/client/client.cc
index 93930d2..33d78f3 100644
--- a/src/kudu/client/client.cc
+++ b/src/kudu/client/client.cc
@@ -17,6 +17,7 @@
 
 #include "kudu/client/client.h"
 
+#include <cstdint>
 #include <cstdlib>
 #include <map>
 #include <memory>
@@ -602,7 +603,7 @@ Status KuduClient::GetTableStatistics(const string& table_name,
   }
   unique_ptr<KuduTableStatistics> table_statistics(new KuduTableStatistics);
   table_statistics->data_ = new KuduTableStatistics::Data(resp.on_disk_size(),
-      resp.live_row_count());
+      resp.has_live_row_count() ? boost::optional<int64_t>(resp.live_row_count()) : boost::none);
 
   *statistics = table_statistics.release();
   return Status::OK();
@@ -880,7 +881,7 @@ int64_t KuduTableStatistics::on_disk_size() const {
 }
 
 int64_t KuduTableStatistics::live_row_count() const {
-  return data_->live_row_count_;
+  return data_->live_row_count_ ? *data_->live_row_count_ : -1;
 }
 
 std::string KuduTableStatistics::ToString() const {
diff --git a/src/kudu/client/client.h b/src/kudu/client/client.h
index 4b30fb4..0c3dfbe 100644
--- a/src/kudu/client/client.h
+++ b/src/kudu/client/client.h
@@ -969,6 +969,7 @@ class KUDU_EXPORT KuduTableStatistics {
   int64_t on_disk_size() const;
 
   /// @return The table's live row count.
+  ///  -1 is returned if the table doesn't support live_row_count.
   ///
   /// @note This statistic is pre-replication.
   int64_t live_row_count() const;
diff --git a/src/kudu/client/table_statistics-internal.h b/src/kudu/client/table_statistics-internal.h
index eda125d..c720836 100644
--- a/src/kudu/client/table_statistics-internal.h
+++ b/src/kudu/client/table_statistics-internal.h
@@ -19,6 +19,8 @@
 #include <cstdint>
 #include <string>
 
+#include <boost/optional/optional.hpp>
+
 #include "kudu/client/client.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/strings/substitute.h"
@@ -31,23 +33,23 @@ using strings::Substitute;
 
 class KuduTableStatistics::Data {
  public:
-  Data(int64_t on_disk_size, int64_t live_row_count)
+  Data(int64_t on_disk_size, boost::optional<int64_t> live_row_count)
       : on_disk_size_(on_disk_size),
-        live_row_count_(live_row_count) {
+        live_row_count_(std::move(live_row_count)) {
   }
 
   ~Data() {
   }
 
   string ToString() const {
-    string display_string = "";
-    display_string += Substitute("on disk size: $0\n", on_disk_size_);
-    display_string += Substitute("live row count: $0\n", live_row_count_);
-    return display_string;
+    return Substitute("on disk size: $0\n"
+                      "live row count: $1\n",
+                      on_disk_size_,
+                      live_row_count_ ? std::to_string(*live_row_count_) : "N/A");
   }
 
   const int64_t on_disk_size_;
-  const int64_t live_row_count_;
+  const boost::optional<int64_t> live_row_count_;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(Data);
diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc
index a93afc3..6a96d33 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -275,6 +275,11 @@ DEFINE_bool(mock_table_metrics_for_testing, false,
 TAG_FLAG(mock_table_metrics_for_testing, hidden);
 TAG_FLAG(mock_table_metrics_for_testing, runtime);
 
+DEFINE_bool(catalog_manager_support_live_row_count, true,
+            "Whether to enable mock live row count statistic for tables. For testing only");
+TAG_FLAG(catalog_manager_support_live_row_count, hidden);
+TAG_FLAG(catalog_manager_support_live_row_count, runtime);
+
 DEFINE_int64(on_disk_size_for_testing, 0,
              "Mock the on disk size of metrics for testing.");
 TAG_FLAG(on_disk_size_for_testing, hidden);
@@ -2936,7 +2941,9 @@ Status CatalogManager::GetTableStatistics(const GetTableStatisticsRequestPB* req
 
   if (PREDICT_FALSE(FLAGS_mock_table_metrics_for_testing)) {
     resp->set_on_disk_size(FLAGS_on_disk_size_for_testing);
-    resp->set_live_row_count(FLAGS_live_row_count_for_testing);
+    if (FLAGS_catalog_manager_support_live_row_count) {
+      resp->set_live_row_count(FLAGS_live_row_count_for_testing);
+    }
   } else {
     resp->set_on_disk_size(table->GetMetrics()->on_disk_size->value());
     if (table->GetMetrics()->TableSupportsLiveRowCount()) {
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 126fba0..d1f96e2 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -5574,7 +5574,8 @@ TEST_F(ToolTest, TestFailedTableCopy) {
 TEST_F(ToolTest, TestGetTableStatisticsLiveRowCountNotSupported) {
   ExternalMiniClusterOptions opts;
   opts.extra_master_flags = { "--mock_table_metrics_for_testing=true",
-                              "--live_row_count_for_testing=-1" };
+                              "--live_row_count_for_testing=99",
+                              "--catalog_manager_support_live_row_count=false" };
   NO_FATALS(StartExternalMiniCluster(std::move(opts)));
 
   // Create an empty table.
@@ -5588,7 +5589,7 @@ TEST_F(ToolTest, TestGetTableStatisticsLiveRowCountNotSupported) {
                  cluster_->master()->bound_rpc_addr().ToString(),
                  TestWorkload::kDefaultTableName),
       &stdout));
-  ASSERT_STR_CONTAINS(stdout, "live row count: -1");
+  ASSERT_STR_CONTAINS(stdout, "live row count: N/A");
 }
 
 } // namespace tools