diff --git a/src/kudu/tablet/tablet-test.cc b/src/kudu/tablet/tablet-test.cc index 27a0724b42..a42d268fd9 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 = 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 04e312cfee..c6489b5225 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 comps; GetComponents(&comps); + if (!comps) { + return Status::RuntimeError("The tablet has been shut down"); + } int64_t ret = 0; int64_t tmp = 0;