You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2019/06/27 06:28:13 UTC

[kudu] branch branch-1.10.x updated: [tablet] reinforce the CountLiveRows API

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

todd pushed a commit to branch branch-1.10.x
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/branch-1.10.x by this push:
     new d75a770  [tablet] reinforce the CountLiveRows API
d75a770 is described below

commit d75a77081326d2f2e7c4d10bc06afb0b39d2c0a2
Author: helifu <hz...@corp.netease.com>
AuthorDate: Wed Jun 26 15:58:37 2019 +0800

    [tablet] reinforce the CountLiveRows API
    
    In the recent patch 13426, I found that the CountLiveRows API is
    not safe after the tablet is been shut down. Though the API has
    not been used by any real users except test cases, I think it's
    necessary to add this patch to the 1.10.x release in progress if
    it's possible.
    
    Change-Id: I56b25a6acb61564ce089be11a1605a19c25eb9e0
    Reviewed-on: http://gerrit.cloudera.org:8080/13734
    Tested-by: Kudu Jenkins
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
    Reviewed-by: Grant Henke <gr...@apache.org>
    (cherry picked from commit 30b88b464f0b13ede2099832d40f50f4ed4a1b1b)
    Reviewed-on: http://gerrit.cloudera.org:8080/13741
---
 src/kudu/tablet/tablet-test.cc | 18 ++++++++++++++++++
 src/kudu/tablet/tablet.cc      |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/kudu/tablet/tablet-test.cc b/src/kudu/tablet/tablet-test.cc
index 27a0724..a42d268 100644
--- a/src/kudu/tablet/tablet-test.cc
+++ b/src/kudu/tablet/tablet-test.cc
@@ -901,6 +901,24 @@ TYPED_TEST(TestTablet, TestCompaction) {
   }
 }
 
+TYPED_TEST(TestTablet, TestCountLiveRowsAfterShutdown) {
+  // Insert 1000 rows into memrowset
+  uint64_t max_rows = this->ClampRowCount(FLAGS_testflush_num_inserts);
+  this->InsertTestRows(0, max_rows, 0);
+  ASSERT_OK(this->tablet()->Flush());
+  NO_FATALS(this->CheckLiveRowsCount(max_rows));
+
+  // Save the tablet's reference.
+  std::shared_ptr<Tablet> tablet = this->tablet();
+
+  // Shutdown the tablet.
+  NO_FATALS(this->tablet()->Shutdown());
+
+  // Call the CountLiveRows().
+  int64_t count = 0;
+  ASSERT_TRUE(tablet->CountLiveRows(&count).IsRuntimeError());
+}
+
 enum MutationType {
   MRS_MUTATION,
   DELTA_MUTATION,
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 04e312c..c6489b5 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -1923,6 +1923,9 @@ Status Tablet::CountLiveRows(int64_t* count) const {
 
   scoped_refptr<TabletComponents> comps;
   GetComponents(&comps);
+  if (!comps) {
+    return Status::RuntimeError("The tablet has been shut down");
+  }
 
   int64_t ret = 0;
   int64_t tmp = 0;