You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/03/26 15:01:19 UTC

(kudu) branch master updated (950072596 -> 00619af30)

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

alexey pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


    from 950072596 [postgres] fix result status handling
     new e8a8325b0 KUDU-3481 more diagnostics on non-monotonic event IDs
     new 7241bfb25 [fs] fix result status handling
     new 110352d01 KUDU-3653 fix flaky test in ts_tablet_manager-test
     new 00619af30 [tserver] fix result status handling

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/kudu/fs/block_manager-test.cc                  |  4 +-
 src/kudu/fs/default_key_provider.h                 |  2 +-
 src/kudu/fs/file_block_manager.cc                  |  2 +-
 src/kudu/fs/fs_manager-test.cc                     | 11 ++-
 src/kudu/fs/log_block_manager-test.cc              | 16 ++---
 src/kudu/master/hms_notification_log_listener.cc   | 30 ++++++++
 src/kudu/tserver/heartbeater.cc                    |  4 +-
 src/kudu/tserver/tablet_copy_client-test.cc        | 12 ++--
 .../tserver/tablet_copy_source_session-test.cc     |  4 +-
 src/kudu/tserver/tablet_server-test-base.cc        | 21 +++++-
 src/kudu/tserver/tablet_server-test-base.h         |  1 +
 src/kudu/tserver/tablet_server-test.cc             | 82 ++++++++++++----------
 .../tserver/tablet_server_authorization-test.cc    |  6 +-
 src/kudu/tserver/ts_tablet_manager-test.cc         | 33 +++++----
 src/kudu/tserver/ts_tablet_manager.cc              |  3 +-
 15 files changed, 148 insertions(+), 83 deletions(-)


(kudu) 02/04: [fs] fix result status handling

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 7241bfb2532d80e66d61930e3da3306b5172cbe6
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Feb 27 18:36:02 2025 -0800

    [fs] fix result status handling
    
    This patch addresses sloppy result handling of functions/methods
    that return Status under the src/kudu/fs directory.
    
    Change-Id: Ib2033dee550c144b57a2e97d74427b86bb45ebfe
    Reviewed-on: http://gerrit.cloudera.org:8080/22663
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Yifan Zhang <ch...@163.com>
---
 src/kudu/fs/block_manager-test.cc     |  4 ++--
 src/kudu/fs/default_key_provider.h    |  2 +-
 src/kudu/fs/file_block_manager.cc     |  2 +-
 src/kudu/fs/fs_manager-test.cc        | 11 ++++++++---
 src/kudu/fs/log_block_manager-test.cc | 16 ++++++++--------
 5 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/kudu/fs/block_manager-test.cc b/src/kudu/fs/block_manager-test.cc
index c4968ff64..b01fe4a6e 100644
--- a/src/kudu/fs/block_manager-test.cc
+++ b/src/kudu/fs/block_manager-test.cc
@@ -657,8 +657,8 @@ TYPED_TEST(BlockManagerTest, CloseManyBlocksTest) {
       for (int i = 0; i < sizeof(data); i += sizeof(uint32_t)) {
         data[i] = rand.Next();
       }
-      written_block->Append(Slice(data, sizeof(data)));
-      written_block->Finalize();
+      ASSERT_OK(written_block->Append(Slice(data, sizeof(data))));
+      ASSERT_OK(written_block->Finalize());
       creation_transaction->AddCreatedBlock(std::move(written_block));
     }
   }
diff --git a/src/kudu/fs/default_key_provider.h b/src/kudu/fs/default_key_provider.h
index 807ede669..043403ce1 100644
--- a/src/kudu/fs/default_key_provider.h
+++ b/src/kudu/fs/default_key_provider.h
@@ -63,7 +63,7 @@ public:
     OPENSSL_RET_NOT_OK(RAND_bytes(iv_bytes, num_bytes),
                        "Failed to generate random key");
     strings::b2a_hex(iv_bytes, iv, num_bytes);
-    DecryptEncryptionKey(dek, *iv, *key_version, encryption_key);
+    RETURN_NOT_OK(DecryptEncryptionKey(dek, *iv, *key_version, encryption_key));
     *key_version = "encryptionkey@0";
     return Status::OK();
   }
diff --git a/src/kudu/fs/file_block_manager.cc b/src/kudu/fs/file_block_manager.cc
index 041667c12..ba12dc290 100644
--- a/src/kudu/fs/file_block_manager.cc
+++ b/src/kudu/fs/file_block_manager.cc
@@ -372,7 +372,7 @@ Status FileWritableBlock::Finalize() {
   VLOG(3) << "Finalizing block " << id();
   if (state_ == DIRTY &&
       FLAGS_block_manager_preflush_control == "finalize") {
-    FlushDataAsync();
+    RETURN_NOT_OK(FlushDataAsync());
   }
   state_ = FINALIZED;
   return Status::OK();
diff --git a/src/kudu/fs/fs_manager-test.cc b/src/kudu/fs/fs_manager-test.cc
index 23c38226e..f9ea04075 100644
--- a/src/kudu/fs/fs_manager-test.cc
+++ b/src/kudu/fs/fs_manager-test.cc
@@ -19,6 +19,7 @@
 
 #include <sys/stat.h>
 #include <unistd.h>
+// IWYU pragma: no_include <bits/struct_stat.h>
 
 #include <cstdint>
 #include <functional>
@@ -281,8 +282,12 @@ TEST_P(FsManagerTestBase, TestTenantAccountOperation) {
     ASSERT_FALSE(fs_manager()->is_tenants_exist());
 
     // Add tenant is not allowed.
-    ASSERT_DEATH(fs_manager()->AddTenant(non_exist_tenant_name, non_exist_tenant,
-                                         nullopt, nullopt, nullopt), "");
+    ASSERT_DEATH({ ASSERT_OK(fs_manager()->AddTenant(
+                       non_exist_tenant_name,
+                       non_exist_tenant,
+                       nullopt,
+                       nullopt,
+                       nullopt)); }, "");
     ASSERT_FALSE(fs_manager()->VertifyTenant(non_exist_tenant));
     ASSERT_TRUE(fs_manager()->VertifyTenant(default_tenant_id));
     ASSERT_EQ(0, fs_manager()->GetDataRootDirs(non_exist_tenant).size());
@@ -621,7 +626,7 @@ TEST_P(FsManagerTestBase, TestCreateWithFailedDirs) {
   // Create some top-level paths to place roots in.
   vector<string> data_paths = { GetTestPath("data1"), GetTestPath("data2"), GetTestPath("data3") };
   for (const string& path : data_paths) {
-    GetEnv()->CreateDir(path);
+    ASSERT_OK(GetEnv()->CreateDir(path));
   }
   // Initialize the FS layout with roots in subdirectories of data_paths. When
   // we canonicalize paths, we canonicalize the dirname of each path (e.g.
diff --git a/src/kudu/fs/log_block_manager-test.cc b/src/kudu/fs/log_block_manager-test.cc
index a4ee00928..4b2e72b7f 100644
--- a/src/kudu/fs/log_block_manager-test.cc
+++ b/src/kudu/fs/log_block_manager-test.cc
@@ -475,7 +475,7 @@ TEST_P(LogBlockManagerTest, MetricsTest) {
       for (int j = 0; j < sizeof(data); j += sizeof(uint32_t)) {
         data[j] = rand.Next();
       }
-      b->Append(Slice(data, sizeof(data)));
+      ASSERT_OK(b->Append(Slice(data, sizeof(data))));
       ASSERT_OK(b->Finalize());
       transaction->AddCreatedBlock(std::move(b));
     }
@@ -550,7 +550,7 @@ TEST_P(LogBlockManagerTest, MetricsTest) {
       unique_ptr<WritableBlock> b;
       ASSERT_OK(bm_->CreateBlock(test_block_opts_, &b));
       blocks.emplace_back(b->id());
-      b->Append("test data");
+      ASSERT_OK(b->Append("test data"));
       ASSERT_OK(b->Finalize());
       transaction->AddCreatedBlock(std::move(b));
     }
@@ -2062,7 +2062,7 @@ TEST_P(LogBlockManagerTest, TestLIFOContainerSelection) {
   for (int i = 0; i < 4; i++) {
     unique_ptr<WritableBlock> writer;
     ASSERT_OK(bm_->CreateBlock(test_block_opts_, &writer));
-    writer->Append("test data");
+    ASSERT_OK(writer->Append("test data"));
     blocks.emplace_back(std::move(writer));
   }
   for (const auto& block : blocks) {
@@ -2078,7 +2078,7 @@ TEST_P(LogBlockManagerTest, TestLIFOContainerSelection) {
   for (int i = 0; i < 4; i++) {
     unique_ptr<WritableBlock> writer;
     ASSERT_OK(bm_->CreateBlock(test_block_opts_, &writer));
-    writer->Append("test data");
+    ASSERT_OK(writer->Append("test data"));
     ASSERT_OK(writer->Finalize());
     // After finalizing the written block, the used container will be
     // available again and can be reused for the following created block.
@@ -2207,7 +2207,7 @@ TEST_P(LogBlockManagerTest, TestDeleteDeadContainersByDeletionTransaction) {
           {0, &METRIC_log_block_manager_dead_containers_deleted} }));
 
     // After the reader is closed, the container is actually deleted.
-    reader->Close();
+    ASSERT_OK(reader->Close());
     NO_FATALS(CheckLogMetrics(entity,
         { {0, &METRIC_log_block_manager_bytes_under_management},
           {0, &METRIC_log_block_manager_blocks_under_management},
@@ -2322,7 +2322,7 @@ TEST_P(LogBlockManagerNativeMetaTest, TestHalfPresentContainer) {
     opts.is_sensitive = true;
     ASSERT_OK(env_->NewWritableFile(opts, metadata_file_name, &metadata_file_writer));
     ASSERT_OK(metadata_file_writer->Append(Slice("a")));
-    metadata_file_writer->Close();
+    ASSERT_OK(metadata_file_writer->Close());
   };
 
   const auto CreateDataFile = [&] () {
@@ -2334,7 +2334,7 @@ TEST_P(LogBlockManagerNativeMetaTest, TestHalfPresentContainer) {
     WritableFileOptions opts;
     opts.is_sensitive = true;
     ASSERT_OK(env_->NewWritableFile(opts, data_file_name, &data_file_writer));
-    data_file_writer->Close();
+    ASSERT_OK(data_file_writer->Close());
   };
 
   const auto DeleteBlock = [&] () {
@@ -2597,7 +2597,7 @@ TEST_P(LogBlockManagerRdbMetaTest, TestHalfPresentContainer) {
     WritableFileOptions opts;
     opts.is_sensitive = true;
     ASSERT_OK(env_->NewWritableFile(opts, data_file_name, &data_file_writer));
-    data_file_writer->Close();
+    ASSERT_OK(data_file_writer->Close());
   };
 
   const auto DeleteBlock = [&] () {


(kudu) 04/04: [tserver] fix result status handling

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 00619af3070a41b8eaba50290807e378a0285152
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Feb 27 18:45:37 2025 -0800

    [tserver] fix result status handling
    
    This patch addresses sloppy result handling of functions/methods
    that return Status under the src/kudu/tserver directory.
    
    Change-Id: If40eb0a273b13dc3b91817fc74a95a0dd99569a1
    Reviewed-on: http://gerrit.cloudera.org:8080/22660
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Marton Greber <gr...@gmail.com>
---
 src/kudu/tserver/heartbeater.cc                    |  4 +-
 src/kudu/tserver/tablet_copy_client-test.cc        | 12 ++--
 .../tserver/tablet_copy_source_session-test.cc     |  4 +-
 src/kudu/tserver/tablet_server-test-base.cc        | 21 +++++-
 src/kudu/tserver/tablet_server-test-base.h         |  1 +
 src/kudu/tserver/tablet_server-test.cc             | 82 ++++++++++++----------
 .../tserver/tablet_server_authorization-test.cc    |  6 +-
 src/kudu/tserver/ts_tablet_manager.cc              |  3 +-
 8 files changed, 80 insertions(+), 53 deletions(-)

diff --git a/src/kudu/tserver/heartbeater.cc b/src/kudu/tserver/heartbeater.cc
index 5a671daf6..d9bd2e9e6 100644
--- a/src/kudu/tserver/heartbeater.cc
+++ b/src/kudu/tserver/heartbeater.cc
@@ -34,8 +34,6 @@
 
 #include <gflags/gflags.h>
 #include <glog/logging.h>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/port.h>
 
 #include "kudu/common/common.pb.h"
 #include "kudu/common/wire_protocol.h"
@@ -255,7 +253,7 @@ Status Heartbeater::Start() {
       for (int j = 0; j < i; j++) {
         // Ignore failures; we should try to stop every thread, and
         // 'first_failure' is the most interesting status anyway.
-        threads_[j]->Stop();
+        WARN_NOT_OK(threads_[j]->Stop(), "Unable to stop heartbeater thread");
       }
       return first_failure;
     }
diff --git a/src/kudu/tserver/tablet_copy_client-test.cc b/src/kudu/tserver/tablet_copy_client-test.cc
index fadaca536..cdb371078 100644
--- a/src/kudu/tserver/tablet_copy_client-test.cc
+++ b/src/kudu/tserver/tablet_copy_client-test.cc
@@ -256,8 +256,8 @@ Status TabletCopyClientTest::ResetRemoteTabletCopyClient(
   scoped_refptr<ConsensusMetadataManager> cmeta_manager(
       new ConsensusMetadataManager(fs_manager_.get()));
 
-  tablet_replica_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10.0));
-  rpc::MessengerBuilder(CURRENT_TEST_NAME()).Build(&messenger_);
+  RETURN_NOT_OK(tablet_replica_->WaitUntilConsensusRunning(MonoDelta::FromSeconds(10.0)));
+  RETURN_NOT_OK(rpc::MessengerBuilder(CURRENT_TEST_NAME()).Build(&messenger_));
   client_.reset(new RemoteTabletCopyClient(GetTabletId(),
                                            fs_manager_.get(),
                                            cmeta_manager,
@@ -281,7 +281,7 @@ Status TabletCopyClientTest::ResetLocalTabletCopyClient() {
     tablet_id_ = tablet_replica_->tablet_id();
 
     // Prepare parameters to create source FsManager.
-    rpc::MessengerBuilder(CURRENT_TEST_NAME()).Build(&messenger_);
+    RETURN_NOT_OK(rpc::MessengerBuilder(CURRENT_TEST_NAME()).Build(&messenger_));
 
     FsManagerOpts opts;
     string wal = mini_server_->server()->fs_manager()->GetWalsRootDir();
@@ -617,7 +617,7 @@ TEST_P(TabletCopyClientBasicTest, TestFailedDiskStopsClient) {
   // metadata directory).
   while (true) {
     if (rand() % 10 == 0) {
-      dd_manager->MarkDirFailed(1, "injected failure in non-client thread");
+      ASSERT_OK(dd_manager->MarkDirFailed(1, "injected failure in non-client thread"));
       LOG(INFO) << "INJECTING FAILURE";
       break;
     }
@@ -686,7 +686,7 @@ void TabletCopyClientAbortTest::CreateTestBlocks(int num_blocks) {
   for (int i = 0; i < num_blocks; i++) {
     unique_ptr<fs::WritableBlock> block;
     ASSERT_OK(fs_manager_->CreateNewBlock({}, &block));
-    block->Append("Test");
+    ASSERT_OK(block->Append("Test"));
     ASSERT_OK(block->Close());
   }
 }
@@ -765,7 +765,7 @@ TEST_P(TabletCopyClientAbortTest, TestAbort) {
     ASSERT_EQ(tablet::TABLET_DATA_TOMBSTONED, meta->tablet_data_state());
     ASSERT_FALSE(fs_manager_->Exists(wal_path));
     vector<BlockId> latest_blocks;
-    fs_manager_->block_manager()->GetAllBlockIds(&latest_blocks);
+    ASSERT_OK(fs_manager_->block_manager()->GetAllBlockIds(&latest_blocks));
     ASSERT_EQ(local_block_ids.size(), latest_blocks.size());
   }
   for (const auto& block_id : local_block_ids) {
diff --git a/src/kudu/tserver/tablet_copy_source_session-test.cc b/src/kudu/tserver/tablet_copy_source_session-test.cc
index 03811dce0..614741c07 100644
--- a/src/kudu/tserver/tablet_copy_source_session-test.cc
+++ b/src/kudu/tserver/tablet_copy_source_session-test.cc
@@ -23,6 +23,7 @@
 #include <memory>
 #include <ostream>
 #include <string>
+#include <type_traits>
 #include <utility>
 #include <vector>
 
@@ -54,7 +55,6 @@
 #include "kudu/tablet/ops/op.h"
 #include "kudu/tablet/ops/write_op.h"
 #include "kudu/tablet/tablet-test-util.h"
-#include "kudu/tablet/tablet.h"
 #include "kudu/tablet/tablet_metadata.h"
 #include "kudu/tablet/tablet_replica.h"
 #include "kudu/tserver/tablet_copy.pb.h"
@@ -176,7 +176,7 @@ class TabletCopyTest : public KuduTabletTest,
 
     shared_ptr<Messenger> messenger;
     MessengerBuilder mbuilder(CURRENT_TEST_NAME());
-    mbuilder.Build(&messenger);
+    ASSERT_OK(mbuilder.Build(&messenger));
 
     log_anchor_registry_.reset(new LogAnchorRegistry());
     tablet_replica_->SetBootstrapping();
diff --git a/src/kudu/tserver/tablet_server-test-base.cc b/src/kudu/tserver/tablet_server-test-base.cc
index 6f9aef844..7ca496c48 100644
--- a/src/kudu/tserver/tablet_server-test-base.cc
+++ b/src/kudu/tserver/tablet_server-test-base.cc
@@ -23,6 +23,7 @@
 #include <iostream>
 #include <memory>
 #include <string>
+#include <type_traits>
 #include <vector>
 
 #include <gflags/gflags.h>
@@ -384,6 +385,24 @@ void TabletServerTestBase::ShutdownTablet() {
   }
 }
 
+Status TabletServerTestBase::ShutdownAndRebuildDataDirs(int num_data_dirs) {
+  ShutdownTablet();
+
+  // Start server.
+  mini_server_.reset(new MiniTabletServer(GetTestPath("TabletServerTest-fsroot"),
+                                          HostPort("127.0.0.1", 0), num_data_dirs));
+  mini_server_->options()->master_addresses.clear();
+  mini_server_->options()->master_addresses.emplace_back("255.255.255.255", 1);
+  // this should open the tablet created on StartTabletServer()
+  RETURN_NOT_OK(mini_server_->Start());
+
+  RETURN_NOT_OK(mini_server_->WaitStarted());
+
+  // Connect to the server.
+  ResetClientProxies();
+  return Status::OK();
+}
+
 Status TabletServerTestBase::ShutdownAndRebuildTablet(int num_data_dirs) {
   ShutdownTablet();
 
@@ -405,7 +424,7 @@ Status TabletServerTestBase::ShutdownAndRebuildTablet(int num_data_dirs) {
     return Status::NotFound("Tablet was not found");
   }
 
-  // Connect to it.
+  // Connect to the server.
   ResetClientProxies();
 
   // Opening a tablet is async, we wait here instead of having to handle errors later.
diff --git a/src/kudu/tserver/tablet_server-test-base.h b/src/kudu/tserver/tablet_server-test-base.h
index 43478e873..8afd0b37a 100644
--- a/src/kudu/tserver/tablet_server-test-base.h
+++ b/src/kudu/tserver/tablet_server-test-base.h
@@ -108,6 +108,7 @@ class TabletServerTestBase : public KuduTest {
 
   void ShutdownTablet();
 
+  Status ShutdownAndRebuildDataDirs(int num_data_dirs);
   Status ShutdownAndRebuildTablet(int num_data_dirs = 1);
 
   // Verifies that a set of expected rows (key, value) is present in the tablet.
diff --git a/src/kudu/tserver/tablet_server-test.cc b/src/kudu/tserver/tablet_server-test.cc
index c0d5f2a97..b58be42c1 100644
--- a/src/kudu/tserver/tablet_server-test.cc
+++ b/src/kudu/tserver/tablet_server-test.cc
@@ -785,7 +785,7 @@ TEST_P(TabletServerDiskSpaceTest, TestFullGroupAddsDir) {
   // Otherwise the 'mini_server_' will fail starting later because of the failure to acquire
   // the RocksDB LOCK file.  Reset it in any case, there is no side effect.
   dd_manager.reset();
-  NO_FATALS(ShutdownAndRebuildTablet(kNumDirs));
+  ASSERT_OK(ShutdownAndRebuildTablet(kNumDirs));
   dd_manager = mini_server_->server()->fs_manager()->dd_manager();
   ASSERT_OK(dd_manager->FindDataDirsByTabletId(kTabletId, &dir_group));
   ASSERT_EQ(kNumDirs, dir_group.size());
@@ -872,7 +872,7 @@ TEST_F(TabletServerStartupWebPageTest, TestStartupWebPage) {
   const string url = Substitute("http://$0/startup", mini_server_->bound_http_addr().ToString());
 
   // Verify if the startup status is complete.
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->WaitStarted());
 
   EasyCurl c;
   faststring buf;
@@ -905,8 +905,11 @@ TEST_F(TabletServerStartupWebPageTest, TestStartupWebPage) {
     status_reader.join();
   });
 
-  mini_server_->Start();
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->Start());
+  const auto s = mini_server_->WaitStarted();
+  ASSERT_TRUE(s.IsIOError()) << s.ToString();
+  ASSERT_STR_CONTAINS(s.ToString(), "some tablet data is in a failed directory");
+
   run_status_reader = false;
 
   // After the server has startup up, ensure every startup step has 100 percent status.
@@ -920,7 +923,7 @@ TEST_F(TabletServerStartupWebPageTest, TestAggregateStartupMetrics) {
   string addr = mini_server_->bound_http_addr().ToString();
 
   // Verify the startup steps remaining are zero once the server is started up.
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->WaitStarted());
   ASSERT_OK(c.FetchURL(Substitute("http://$0/metrics?metrics=startup_progress_steps_remaining",
                                   addr),
                        &buf));
@@ -936,7 +939,7 @@ TEST_F(TabletServerStartupWebPageTest, TestTabletsMetrics) {
   EasyCurl c;
   faststring buf;
   // Verify if the startup status is complete.
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->WaitStarted());
   const string url = Substitute("http://$0/metrics", mini_server_->bound_http_addr().ToString());
   // Validate populated metrics in case of zero tablets during startup.
   ASSERT_OK(c.FetchURL(url, &buf));
@@ -966,7 +969,7 @@ TEST_F(TabletServerStartupWebPageTest, TestLogBlockContainerMetrics) {
 
   EasyCurl c;
   faststring buf;
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->WaitStarted());
   string addr = mini_server_->bound_http_addr().ToString();
   // Validate populated metrics in case of zero containers during startup.
   ASSERT_OK(c.FetchURL(Substitute("http://$0/metrics", addr), &buf));
@@ -1021,7 +1024,7 @@ class TabletServerMaintenanceManagerWebPageTest: public TabletServerStartupWebPa
 };
 
 TEST_F(TabletServerMaintenanceManagerWebPageTest, OpDataRetainedStats) {
-  mini_server_->WaitStarted();
+  ASSERT_OK(mini_server_->WaitStarted());
 
   faststring buf;
   ASSERT_OK(EasyCurl().FetchURL(Substitute("http://$0/maintenance-manager",
@@ -1196,7 +1199,7 @@ TEST_F(TabletServerTest, TestAddRemoveDirectory) {
   }
   // Start with multiple data dirs so the dirs are suffixed with numbers, and
   // so when we remove a data dirs, we'll be using the same set of dirs.
-  NO_FATALS(ShutdownAndRebuildTablet(/*num_data_dirs*/2));
+  ASSERT_OK(ShutdownAndRebuildDataDirs(/*num_data_dirs*/2));
   const char* kFooTablet1 = "fffffffffffffffffffffffffffffff1";
   ASSERT_OK(mini_server_->AddTestTablet("footable", kFooTablet1, schema_));
   ASSERT_OK(WaitForTabletRunning(kFooTablet1));
@@ -1204,7 +1207,7 @@ TEST_F(TabletServerTest, TestAddRemoveDirectory) {
   // Shut down and restart with a new directory. This is allowed, and the
   // tablet server will be able to use the new directory if we create a new
   // tablet.
-  NO_FATALS(ShutdownAndRebuildTablet(/*num_data_dirs*/3));
+  ASSERT_OK(ShutdownAndRebuildDataDirs(/*num_data_dirs*/3));
   const char* kFooTablet2 = "fffffffffffffffffffffffffffffff2";
   ASSERT_OK(mini_server_->AddTestTablet("footable", kFooTablet2, schema_));
   ASSERT_OK(WaitForTabletRunning(kFooTablet2));
@@ -1212,7 +1215,12 @@ TEST_F(TabletServerTest, TestAddRemoveDirectory) {
   // Now open up again with a our original two directories. The second tablet
   // should fail because it should have been striped across the third
   // directory. The first tablet should be unaffected.
-  NO_FATALS(ShutdownAndRebuildTablet(/*num_data_dirs*/2));
+  const auto s = ShutdownAndRebuildDataDirs(/*num_data_dirs*/2);
+  ASSERT_TRUE(s.IsNotFound()) << s.ToString();
+  ASSERT_STR_CONTAINS(s.ToString(),
+      "error retrieving tablet data dir group (one or more data dirs "
+      "may have been removed): could not find data dir group for tablet "
+      "fffffffffffffffffffffffffffffff2");
   ASSERT_EVENTUALLY([&] {
     scoped_refptr<TabletReplica> replica1;
     ASSERT_TRUE(mini_server_->server()->tablet_manager()->LookupTablet(kFooTablet1, &replica1));
@@ -1429,7 +1437,7 @@ TEST_F(TabletServerTest, TestInsert) {
   Timestamp now_before = mini_server_->server()->clock()->Now();
 
   rows_inserted = nullptr;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(1, 1), KeyValue(2, 1), KeyValue(1234, 5678) });
 
   // get the clock's timestamp after replay
@@ -1718,7 +1726,7 @@ TEST_F(TabletServerTest, TestInsertAndMutate) {
 
   rows_inserted = nullptr;
   rows_updated = nullptr;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(2, 3), KeyValue(3, 4), KeyValue(4, 4), KeyValue(6, 6) });
 
   // get the clock's timestamp after replay
@@ -1919,7 +1927,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushing) {
   // Shutdown the tserver and try and rebuild the tablet from the log
   // produced on recovery (recovery flushed no state, but produced a new
   // log).
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(1, 10),
                         KeyValue(2, 20),
                         KeyValue(3, 30),
@@ -1932,7 +1940,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushing) {
 
   // Shutdown and rebuild again to test that the log generated during
   // the previous recovery allows to perform recovery again.
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(1, 10),
                         KeyValue(2, 20),
                         KeyValue(3, 30),
@@ -1957,7 +1965,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
   // flush the first time
   ASSERT_OK(tablet_replica_->tablet()->Flush());
 
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(1, 10),
                         KeyValue(2, 20),
                         KeyValue(3, 30),
@@ -1997,7 +2005,7 @@ TEST_F(TabletServerTest, TestRecoveryWithMutationsWhileFlushingAndCompacting) {
   // Shutdown the tserver and try and rebuild the tablet from the log
   // produced on recovery (recovery flushed no state, but produced a new
   // log).
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(schema_, { KeyValue(1, 11),
                         KeyValue(2, 22),
                         KeyValue(3, 32),
@@ -2129,7 +2137,7 @@ TEST_F(TabletServerTest, TestExactlyOnceForErrorsAcrossRestart) {
   req.clear_row_operations();
   for (int i = 1; i <= 5; i++) {
     SCOPED_TRACE(Substitute("restart attempt #$0", i));
-    NO_FATALS(ShutdownAndRebuildTablet());
+    ASSERT_OK(ShutdownAndRebuildTablet());
     rpc.Reset();
     req_id.set_attempt_no(req_id.attempt_no() + 1);
     rpc.SetRequestIdPB(unique_ptr<rpc::RequestIdPB>(new rpc::RequestIdPB(req_id)));
@@ -2374,7 +2382,7 @@ TEST_F(ScannerScansTest, TestScanMetricsAffectedOnOrderedScan) {
 
   SchemaBuilder sb;
   for (int i = schema_.num_key_columns(); i < schema_.num_columns(); i++) {
-    sb.AddColumn(schema_.column(i), false);
+    ASSERT_OK(sb.AddColumn(schema_.column(i), false));
   }
   const Schema& projection = sb.BuildWithoutIds();
   DoOrderedScanTest(projection, R"((int32 int_val=$1, string string_val="hello $0"))");
@@ -2535,7 +2543,7 @@ TEST_P(ScanCorruptedDeltasParamTest, Test) {
 
   // Fudge with some delta blocks.
   TabletSuperBlockPB superblock_pb;
-  tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb);
+  ASSERT_OK(tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb));
   FsManager* fs_manager = mini_server_->server()->fs_manager();
   for (int rowset_no = 0; rowset_no < superblock_pb.rowsets_size(); rowset_no++) {
     RowSetDataPB* rowset_pb = superblock_pb.mutable_rowsets(rowset_no);
@@ -2813,7 +2821,7 @@ TEST_F(ScannerScansTest, TestSnapshotScan_LastRow) {
   // to the client.
   SchemaBuilder sb(schema_);
   for (int i = 0; i < schema_.num_key_columns(); i++) {
-    sb.RemoveColumn(schema_.column(i).name());
+    ASSERT_OK(sb.RemoveColumn(schema_.column(i).name()));
   }
   const Schema& projection = sb.BuildWithoutIds();
 
@@ -3425,7 +3433,7 @@ TEST_F(ScannerScansTest, TestScanWithSimplifiablePredicates) {
   // Set up a projection without the key columns or the column after the last key column
   SchemaBuilder sb(schema_);
   for (int i = 0; i <= schema_.num_key_columns(); i++) {
-    sb.RemoveColumn(schema_.column(i).name());
+    ASSERT_OK(sb.RemoveColumn(schema_.column(i).name()));
   }
   const Schema& projection = sb.BuildWithoutIds();
   ASSERT_OK(SchemaToColumnPBs(projection, scan->mutable_projected_columns()));
@@ -3975,7 +3983,7 @@ TEST_F(ScannerScansTest, TestOrderedScan_ProjectionWithKeyColumnsInOrder) {
   // Build a projection with all the columns, but don't mark the key columns as such.
   SchemaBuilder sb;
   for (int i = 0; i < schema_.num_columns(); i++) {
-    sb.AddColumn(schema_.column(i), false);
+    ASSERT_OK(sb.AddColumn(schema_.column(i), false));
   }
   const Schema& projection = sb.BuildWithoutIds();
   DoOrderedScanTest(projection,
@@ -3987,7 +3995,7 @@ TEST_F(ScannerScansTest, TestOrderedScan_ProjectionWithoutKeyColumns) {
   // Build a projection without the key columns.
   SchemaBuilder sb;
   for (int i = schema_.num_key_columns(); i < schema_.num_columns(); i++) {
-    sb.AddColumn(schema_.column(i), false);
+    ASSERT_OK(sb.AddColumn(schema_.column(i), false));
   }
   const Schema& projection = sb.BuildWithoutIds();
   DoOrderedScanTest(projection, R"((int32 int_val=$1, string string_val="hello $0"))");
@@ -3998,7 +4006,7 @@ TEST_F(ScannerScansTest, TestOrderedScan_ProjectionWithKeyColumnsOutOfOrder) {
   // Build a projection with the order of the columns reversed.
   SchemaBuilder sb;
   for (int i = schema_.num_columns() - 1; i >= 0; i--) {
-    sb.AddColumn(schema_.column(i), false);
+    ASSERT_OK(sb.AddColumn(schema_.column(i), false));
   }
   const Schema& projection = sb.BuildWithoutIds();
   DoOrderedScanTest(projection,
@@ -4068,14 +4076,14 @@ TEST_F(TabletServerTest, TestAlterSchema) {
   const Schema projection({ ColumnSchema("key", INT32), (ColumnSchema("c2", INT32)) }, 1);
 
   // Try recovering from the original log
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(projection, { KeyValue(0, 7),
                            KeyValue(1, 7),
                            KeyValue(2, 5),
                            KeyValue(3, 5) });
 
   // Try recovering from the log generated on recovery
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(projection, { KeyValue(0, 7),
                            KeyValue(1, 7),
                            KeyValue(2, 5),
@@ -4119,11 +4127,11 @@ TEST_F(TabletServerTest, TestAlterSchema_AddColWithoutWriteDefault) {
   VerifyRows(projection, { KeyValue(0, 7), KeyValue(1, 7) });
 
   // Try recovering from the original log
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(projection, { KeyValue(0, 7), KeyValue(1, 7) });
 
   // Try recovering from the log generated on recovery
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   VerifyRows(projection, { KeyValue(0, 7), KeyValue(1, 7) });
 }
 
@@ -4684,7 +4692,7 @@ TEST_F(TabletServerTest, TestFailedDnsResolution) {
 TEST_F(TabletServerTest, TestDataDirGroupsCreated) {
   // Get the original superblock.
   TabletSuperBlockPB superblock;
-  tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock);
+  ASSERT_OK(tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock));
   DataDirGroupPB orig_group = superblock.data_dir_group();
 
   // Remove the DataDirGroupPB on-disk.
@@ -4703,7 +4711,7 @@ TEST_F(TabletServerTest, TestDataDirGroupsCreated) {
   // group will be created with all data directories and should be identical to
   // the original one.
   ASSERT_OK(ShutdownAndRebuildTablet());
-  tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock);
+  ASSERT_OK(tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock));
   DataDirGroupPB new_group = superblock.data_dir_group();
   MessageDifferencer md;
   ASSERT_TRUE(md.Compare(orig_group, new_group));
@@ -4827,7 +4835,7 @@ TEST_F(TabletServerTest, SetEncodedKeysWhenStartingUp) {
   // maintenance operations when we restart.
   FLAGS_enable_maintenance_manager = false;
   TabletSuperBlockPB superblock_pb;
-  tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb);
+  ASSERT_OK(tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb));
   // Make sure the min/max key do not exist in the rowset metadata.
   for (int rowset_no = 0; rowset_no < superblock_pb.rowsets_size(); rowset_no++) {
     RowSetDataPB* rowset_pb = superblock_pb.mutable_rowsets(rowset_no);
@@ -4881,7 +4889,7 @@ TEST_F(TabletServerTest, SetEncodedKeysWhenStartingUp) {
     }
 
     TabletSuperBlockPB superblock_pb;
-    tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb);
+    ASSERT_OK(tablet_replica_->tablet()->metadata()->ToSuperBlock(&superblock_pb));
     for (int rowset_no = 0; rowset_no < superblock_pb.rowsets_size(); rowset_no++) {
       RowSetDataPB* rowset_pb = superblock_pb.mutable_rowsets(rowset_no);
       if (set_keys_during_restart) {
@@ -4990,7 +4998,7 @@ TEST_F(TabletServerTest, TestScannerCheckMatchingUser) {
 TEST_F(TabletServerTest, TestTimeBasedFlushDMS) {
   SKIP_IF_SLOW_NOT_ALLOWED();
   FLAGS_enable_maintenance_manager = false;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   // We're going to generate a bunch of DMSs, and for that, we need multiple
   // rowsets, so disable merge compactions.
   FLAGS_enable_rowset_compaction = false;
@@ -5011,7 +5019,7 @@ TEST_F(TabletServerTest, TestTimeBasedFlushDMS) {
   FLAGS_enable_maintenance_manager = true;
   FLAGS_maintenance_manager_polling_interval_ms = 1;
   FLAGS_flush_threshold_secs = 1;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
   // We should be able to wait for the flush threshold and very quickly see all
   // DMSs get flushed. We'll wait 5x the flush threshold, which should be ample
   // time given how little we're writing.
@@ -5025,7 +5033,7 @@ TEST_F(TabletServerTest, TestTimeBasedFlushDMS) {
 TEST_F(TabletServerTest, StartupWithConcurrentOpsBenchmark) {
   SKIP_IF_SLOW_NOT_ALLOWED();
   FLAGS_enable_maintenance_manager = false;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
 
   // Create a bunch of tablets with a bunch of rowsets.
   ObjectIdGenerator oid;
@@ -5060,7 +5068,7 @@ TEST_F(TabletServerTest, StartupWithConcurrentOpsBenchmark) {
 TEST_F(TabletServerTest, TestStarvePerfImprovementOpsInColdTablet) {
   SKIP_IF_SLOW_NOT_ALLOWED();
   FLAGS_enable_maintenance_manager = true;
-  NO_FATALS(ShutdownAndRebuildTablet());
+  ASSERT_OK(ShutdownAndRebuildTablet());
 
   // Disable flushing and compactions to create overlapping rowsets.
   FLAGS_enable_flush_memrowset = false;
diff --git a/src/kudu/tserver/tablet_server_authorization-test.cc b/src/kudu/tserver/tablet_server_authorization-test.cc
index 6ec8c43bd..1255505b7 100644
--- a/src/kudu/tserver/tablet_server_authorization-test.cc
+++ b/src/kudu/tserver/tablet_server_authorization-test.cc
@@ -504,13 +504,13 @@ class ScanPrivilegeAuthzTest : public AuthzTabletServerTestBase,
     SchemaBuilder schema_builder;
     for (int i = 0; i < kNumKeys; i++) {
       const string key = Substitute("key$0", i);
-      schema_builder.AddKeyColumn(key, DataType::INT32);
+      ASSERT_OK(schema_builder.AddKeyColumn(key, DataType::INT32));
       col_names_.emplace_back(key);
     }
     for (int i = 0; i < kNumVals; i++) {
       const string val = Substitute("val$0", kNumKeys + i);
-      schema_builder.AddColumn(ColumnSchema(val, DataType::INT32),
-                               /*is_key=*/false);
+      ASSERT_OK(schema_builder.AddColumn(ColumnSchema(val, DataType::INT32),
+                                         /*is_key=*/false));
       col_names_.emplace_back(val);
     }
     schema_ = schema_builder.Build();
diff --git a/src/kudu/tserver/ts_tablet_manager.cc b/src/kudu/tserver/ts_tablet_manager.cc
index b56524dde..f7f3269c1 100644
--- a/src/kudu/tserver/ts_tablet_manager.cc
+++ b/src/kudu/tserver/ts_tablet_manager.cc
@@ -1969,7 +1969,8 @@ void TSTabletManager::FailTabletsInDataDir(const string& uuid,
     return;
   }
   // Fail the directory to prevent other tablets from being placed in it.
-  dd_manager->MarkDirFailed(uuid_idx);
+  WARN_NOT_OK(dd_manager->MarkDirFailed(uuid_idx),
+              "error marking data directory as failed");
   set<string> tablets = dd_manager->FindTabletsByDirUuidIdx(uuid_idx);
   LOG(INFO) << Substitute("Data dir $0 has $1 tablets", uuid, tablets.size());
   for (const string& tablet_id : dd_manager->FindTabletsByDirUuidIdx(uuid_idx)) {


(kudu) 01/04: KUDU-3481 more diagnostics on non-monotonic event IDs

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit e8a8325b0fd1afaa60394a91b55a31fa63a25516
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Fri Mar 21 17:01:25 2025 -0700

    KUDU-3481 more diagnostics on non-monotonic event IDs
    
    This is to help understand where the issue reported by KUDU-3481
    originates from: whether it's due to non-monotonic or duplicate
    event IDs in the response received from HMS, or that's something else.
    
    Change-Id: Idac2f8969e10f066442aad0570c41767b98a0b75
    Reviewed-on: http://gerrit.cloudera.org:8080/22657
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Yifan Zhang <ch...@163.com>
---
 src/kudu/master/hms_notification_log_listener.cc | 30 ++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/kudu/master/hms_notification_log_listener.cc b/src/kudu/master/hms_notification_log_listener.cc
index 67e369478..2e6ba2cce 100644
--- a/src/kudu/master/hms_notification_log_listener.cc
+++ b/src/kudu/master/hms_notification_log_listener.cc
@@ -17,8 +17,10 @@
 
 #include "kudu/master/hms_notification_log_listener.h"
 
+#include <cstddef>
 #include <cstdint>
 #include <functional>
+#include <limits>
 #include <map>
 #include <optional>
 #include <ostream>
@@ -76,6 +78,7 @@ TAG_FLAG(hive_metastore_notification_log_listener_catch_up_deadline_ms, runtime)
 using rapidjson::Document;
 using rapidjson::Value;
 using std::optional;
+using std::ostringstream;
 using std::string;
 using std::vector;
 using strings::Substitute;
@@ -259,6 +262,33 @@ Status HmsNotificationLogListenerTask::Poll() {
       }
     }
 
+#if DCHECK_IS_ON()
+    {
+      int64_t last_seen_event_id = std::numeric_limits<int64_t>::min();
+      for (size_t idx = 0; idx < events.size(); ++idx) {
+        const auto event_id = events[idx].eventId;
+        DCHECK_GT(event_id, std::numeric_limits<int64_t>::min());
+        if (event_id > last_seen_event_id) {
+          last_seen_event_id = event_id;
+          continue;
+        }
+        // Print out diagnostic information into the logs.
+        DCHECK_GT(idx, 0);
+        string msg = Substitute(
+            "non-monotonous event IDs from HMS: current $0, previous $1; "
+            "dumping first $2 out of $3 received events:",
+            event_id, events[idx - 1].eventId, idx + 1, events.size());
+        ostringstream events_str;
+        for (size_t j = 0; j <= idx; ++j) {
+          events_str << " ";
+          events[j].printTo(events_str);
+          events_str << ";";
+        }
+        LOG(DFATAL) << msg << events_str.str();
+      }
+    }
+#endif // #if DCHECK_IS_ON() ...
+
     for (const auto& event : events) {
       VLOG(1) << "Processing notification log event: " << EventDebugString(event);
 


(kudu) 03/04: KUDU-3653 fix flaky test in ts_tablet_manager-test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 110352d0163fa390ac25f4d69232886f84fb85dd
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Mon Mar 24 13:45:19 2025 -0700

    KUDU-3653 fix flaky test in ts_tablet_manager-test
    
    Before this patch, the TestCreateAndDifferentModeDeleteMetrics scenario
    of TestCreateAndDeleteMetrics in ts_tablet_manager-test would usually
    fail once in every 30 runs.  With this patch, not a single failure
    has been detected in more than 500 runs of the test scenario.
    
    Change-Id: Iec7832d24e94247b0788c6eca7c85deedce54e4e
    Reviewed-on: http://gerrit.cloudera.org:8080/22659
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Yifan Zhang <ch...@163.com>
---
 src/kudu/tserver/ts_tablet_manager-test.cc | 33 ++++++++++++++++--------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/kudu/tserver/ts_tablet_manager-test.cc b/src/kudu/tserver/ts_tablet_manager-test.cc
index a3bf78889..930729f2f 100644
--- a/src/kudu/tserver/ts_tablet_manager-test.cc
+++ b/src/kudu/tserver/ts_tablet_manager-test.cc
@@ -198,28 +198,31 @@ INSTANTIATE_TEST_SUITE_P(Params, TestCreateAndDeleteMetrics,
                                            TabletDataState::TABLET_DATA_TOMBSTONED));
 
 TEST_P(TestCreateAndDeleteMetrics, TestCreateAndDifferentModeDeleteMetrics) {
-  TabletDataState data_state = GetParam();
-  scoped_refptr<Histogram> create_tablet_run_time =
-    METRIC_create_tablet_run_time.Instantiate(mini_server_->server()->metric_entity());
-  ASSERT_EQ(0, create_tablet_run_time->TotalCount());
-
-  scoped_refptr<Histogram> delete_tablet_run_time =
-    METRIC_delete_tablet_run_time.Instantiate(mini_server_->server()->metric_entity());
-  ASSERT_EQ(0, delete_tablet_run_time->TotalCount());
-
-  string test_tablet = "ffffffffffffffffffffffffffffffff";
+  static const string kTestTablet = "ffffffffffffffffffffffffffffffff";
+  const TabletDataState data_state = GetParam();
   scoped_refptr<TabletReplica> test_replica;
 
+  scoped_refptr<Histogram> create_tablet_run_time =
+      METRIC_create_tablet_run_time.Instantiate(mini_server_->server()->metric_entity());
+  ASSERT_EQ(0, create_tablet_run_time->TotalCount());
   // Create a new tablet.
-  ASSERT_OK(CreateNewTablet(test_tablet, schema_, true, nullopt, nullopt, &test_replica));
-  ASSERT_EQ(test_tablet, test_replica->tablet()->tablet_id());
+  ASSERT_OK(CreateNewTablet(kTestTablet, schema_, true, nullopt, nullopt, &test_replica));
+  ASSERT_EQ(kTestTablet, test_replica->tablet()->tablet_id());
   // Metrics should be incremented.
   ASSERT_EQ(1, create_tablet_run_time->TotalCount());
 
+  // Wait for the tablet state transition to complete, otherwise there will be
+  // an error reported by TSTabletManager::StartTabletStateTransitionUnlocked().
+  ASSERT_EVENTUALLY([&] () {
+    ASSERT_OK(tablet_manager_->WaitForNoTransitionsForTests(
+        MonoDelta::FromSeconds(1)));
+  });
+
+  scoped_refptr<Histogram> delete_tablet_run_time =
+      METRIC_delete_tablet_run_time.Instantiate(mini_server_->server()->metric_entity());
   ASSERT_EQ(0, delete_tablet_run_time->TotalCount());
-  ASSERT_OK(tablet_manager_->DeleteTablet(test_tablet,
-                                          data_state,
-                                          nullopt));
+  // Delete the newly created tablet.
+  ASSERT_OK(tablet_manager_->DeleteTablet(kTestTablet, data_state, nullopt));
   // Metrics should be incremented.
   ASSERT_EQ(1, delete_tablet_run_time->TotalCount());
 }