[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 <awong@cloudera.com>
Reviewed-by: Grant Henke <granthenke@apache.org>
(cherry picked from commit 30b88b464f0b13ede2099832d40f50f4ed4a1b1b)
Reviewed-on: http://gerrit.cloudera.org:8080/13741
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, 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 @@
 
   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;