kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] branch master updated: KUDU-2797 p1: expose the tablet's live row count
Date Thu, 18 Jul 2019 22:20:38 GMT
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 786d45d  KUDU-2797 p1: expose the tablet's live row count
786d45d is described below

commit 786d45d2ba76230ccd25e7fe24dcebb3828b48c2
Author: helifu <hzhelifu@corp.netease.com>
AuthorDate: Wed Jul 17 20:07:11 2019 +0800

    KUDU-2797 p1: expose the tablet's live row count
    
    The tablet's live row count is exposed in below ways:
    1) be exposed as metrics on the tablet server;
    2) be exposed on the tablet server's Web-UI;
    
    Change-Id: I2b15d7d2a5c84a3716215608b2444395ca94e64c
    Reviewed-on: http://gerrit.cloudera.org:8080/13877
    Reviewed-by: Adar Dembo <adar@cloudera.com>
    Tested-by: Adar Dembo <adar@cloudera.com>
---
 src/kudu/tablet/tablet_replica-test.cc    | 26 +++++++++++++++++++++++++-
 src/kudu/tablet/tablet_replica.cc         | 24 +++++++++++++++++++++++-
 src/kudu/tablet/tablet_replica.h          |  4 ++++
 src/kudu/tserver/tserver_path_handlers.cc |  8 ++++++++
 www/tablet.mustache                       |  1 +
 5 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/src/kudu/tablet/tablet_replica-test.cc b/src/kudu/tablet/tablet_replica-test.cc
index 9cf08d7..376fb89 100644
--- a/src/kudu/tablet/tablet_replica-test.cc
+++ b/src/kudu/tablet/tablet_replica-test.cc
@@ -50,6 +50,7 @@
 #include "kudu/fs/fs_manager.h"
 #include "kudu/gutil/bind.h"
 #include "kudu/gutil/bind_helpers.h"
+#include "kudu/gutil/callback.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/ref_counted.h"
@@ -73,14 +74,17 @@
 #include "kudu/util/monotime.h"
 #include "kudu/util/net/dns_resolver.h"
 #include "kudu/util/pb_util.h"
+#include "kudu/util/random.h"
 #include "kudu/util/status.h"
 #include "kudu/util/test_macros.h"
 #include "kudu/util/test_util.h"
 #include "kudu/util/threadpool.h"
 
+DECLARE_int32(flush_threshold_mb);
+
 METRIC_DECLARE_entity(tablet);
 
-DECLARE_int32(flush_threshold_mb);
+METRIC_DECLARE_gauge_int64(live_row_count);
 
 using kudu::consensus::CommitMsg;
 using kudu::consensus::ConsensusBootstrapInfo;
@@ -771,5 +775,25 @@ TEST_F(TabletReplicaTest, Kudu2690Test) {
   NO_FATALS(RestartReplica());
 }
 
+TEST_F(TabletReplicaTest, TestLiveRowCountMetric) {
+  ConsensusBootstrapInfo info;
+  ASSERT_OK(StartReplicaAndWaitUntilLeader(info));
+
+  auto live_row_count = METRIC_live_row_count.InstantiateFunctionGauge(
+      tablet_replica_->tablet()->GetMetricEntity(), Callback<int64_t(void)>());
+  ASSERT_EQ(0, live_row_count->value());
+
+  // Insert some rows.
+  Random rand(SeedRandom());
+  const int kNumInsert = rand.Next() % 100 + 1;
+  ASSERT_OK(ExecuteInsertsAndRollLogs(kNumInsert));
+  ASSERT_EQ(kNumInsert, live_row_count->value());
+
+  // Delete some rows.
+  const int kNumDelete = rand.Next() % kNumInsert;
+  ASSERT_OK(ExecuteDeletesAndRollLogs(kNumDelete));
+  ASSERT_EQ(kNumInsert - kNumDelete, live_row_count->value());
+}
+
 } // namespace tablet
 } // namespace kudu
diff --git a/src/kudu/tablet/tablet_replica.cc b/src/kudu/tablet/tablet_replica.cc
index f9c4000..9a58352 100644
--- a/src/kudu/tablet/tablet_replica.cc
+++ b/src/kudu/tablet/tablet_replica.cc
@@ -89,6 +89,11 @@ METRIC_DEFINE_gauge_size(tablet, on_disk_size, "Tablet Size On Disk",
 METRIC_DEFINE_gauge_string(tablet, state, "Tablet State",
                            kudu::MetricUnit::kState,
                            "State of this tablet.");
+METRIC_DEFINE_gauge_int64(tablet, live_row_count, "Tablet Live Row Count",
+                          kudu::MetricUnit::kRows,
+                          "Number of live rows in this tablet, excludes deleted rows."
+                          "When the tablet doesn't support live row counting, -1 will "
+                          "be returned.");
 
 namespace kudu {
 namespace tablet {
@@ -199,11 +204,14 @@ Status TabletReplica::Start(const ConsensusBootstrapInfo& bootstrap_info,
         txn_tracker_.StartInstrumentation(tablet_->GetMetricEntity());
 
         METRIC_on_disk_size.InstantiateFunctionGauge(
-                tablet_->GetMetricEntity(), Bind(&TabletReplica::OnDiskSize, Unretained(this)))
+            tablet_->GetMetricEntity(), Bind(&TabletReplica::OnDiskSize, Unretained(this)))
             ->AutoDetach(&metric_detacher_);
         METRIC_state.InstantiateFunctionGauge(
             tablet_->GetMetricEntity(), Bind(&TabletReplica::StateName, Unretained(this)))
             ->AutoDetach(&metric_detacher_);
+        METRIC_live_row_count.InstantiateFunctionGauge(
+            tablet_->GetMetricEntity(), Bind(&TabletReplica::CountLiveRows, Unretained(this)))
+            ->AutoDetach(&metric_detacher_);
       }
       txn_tracker_.StartMemoryTracking(tablet_->mem_tracker());
 
@@ -797,6 +805,20 @@ size_t TabletReplica::OnDiskSize() const {
   return ret;
 }
 
+int64_t TabletReplica::CountLiveRows() const {
+  int64_t ret = -1;
+  shared_ptr<Tablet> tablet;
+  {
+    std::lock_guard<simple_spinlock> l(lock_);
+    tablet = tablet_;
+  }
+
+  if (tablet) {
+    ignore_result(tablet->CountLiveRows(&ret));
+  }
+  return ret;
+}
+
 void TabletReplica::MakeUnavailable(const Status& error) {
   std::shared_ptr<Tablet> tablet;
   {
diff --git a/src/kudu/tablet/tablet_replica.h b/src/kudu/tablet/tablet_replica.h
index 044f6a8..f27faed 100644
--- a/src/kudu/tablet/tablet_replica.h
+++ b/src/kudu/tablet/tablet_replica.h
@@ -300,6 +300,10 @@ class TabletReplica : public RefCountedThreadSafe<TabletReplica>,
   // Return the total on-disk size of this tablet replica, in bytes.
   size_t OnDiskSize() const;
 
+  // Return the number of live rows of this tablet replica.
+  // -1 will be returned if the tablet doesn't support live row counting.
+  int64_t CountLiveRows() const;
+
  private:
   friend class kudu::AlterTableTest;
   friend class RefCountedThreadSafe<TabletReplica>;
diff --git a/src/kudu/tserver/tserver_path_handlers.cc b/src/kudu/tserver/tserver_path_handlers.cc
index eb858e3..d0e7951 100644
--- a/src/kudu/tserver/tserver_path_handlers.cc
+++ b/src/kudu/tserver/tserver_path_handlers.cc
@@ -17,6 +17,8 @@
 
 #include "kudu/tserver/tserver_path_handlers.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 #include <iosfwd>
 #include <map>
@@ -415,6 +417,12 @@ void TabletServerPathHandlers::HandleTabletPage(const Webserver::WebRequest&
req
   output->Set("partition",
               tmeta->partition_schema().PartitionDebugString(tmeta->partition(), schema));
   output->Set("on_disk_size", HumanReadableNumBytes::ToString(replica->OnDiskSize()));
+  int64_t live_row_count = replica->CountLiveRows();
+  if (live_row_count >= 0) {
+    output->Set("tablet_live_row_count", live_row_count);
+  } else {
+    output->Set("tablet_live_row_count", "N/A");
+  }
 
   SchemaToJson(schema, output);
 }
diff --git a/www/tablet.mustache b/www/tablet.mustache
index 739dc0b..2483d0f 100644
--- a/www/tablet.mustache
+++ b/www/tablet.mustache
@@ -25,6 +25,7 @@ under the License.
 
   <table class='table'>
     <tr><td>Partition</td><td>{{partition}}</td></tr>
+    <tr><td>Live Row Count</td><td>{{tablet_live_row_count}}</td></tr>
     <tr><td>On-disk Size</td><td>{{on_disk_size}}</td></tr>
   </table>
 


Mime
View raw message