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 97d775ae883181645dfcbbf1c4c18affc130ea78
Author: Andrew Wong <[email protected]>
AuthorDate: Tue Jun 2 16:34:29 2020 -0700

    tablet_replica-test: refactor to pull out some useful code
    
    In preparation for testing a new system table that is backed by tablet
    replicas, this pulls out some of the tablet replica initialization code
    used in TabletReplicaTest to facilitate its reuse.
    
    There are no major functional changes in this patch.
    
    Change-Id: I912221d73b4d83bb967d91ca7592618b4a89d74c
    Reviewed-on: http://gerrit.cloudera.org:8080/16027
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <[email protected]>
---
 src/kudu/tablet/CMakeLists.txt              |   3 +-
 src/kudu/tablet/tablet.h                    |   2 +
 src/kudu/tablet/tablet_replica-test-base.cc | 192 ++++++++++++++++++++++++++++
 src/kudu/tablet/tablet_replica-test-base.h  |  81 ++++++++++++
 src/kudu/tablet/tablet_replica-test.cc      | 178 ++------------------------
 src/kudu/tablet/tablet_replica.h            |   2 +
 6 files changed, 290 insertions(+), 168 deletions(-)

diff --git a/src/kudu/tablet/CMakeLists.txt b/src/kudu/tablet/CMakeLists.txt
index e4f3229..d9c8772 100644
--- a/src/kudu/tablet/CMakeLists.txt
+++ b/src/kudu/tablet/CMakeLists.txt
@@ -85,7 +85,8 @@ target_link_libraries(tablet
   consensus)
 
 add_library(tablet_test_util
-  tablet-test-util.cc)
+  tablet-test-util.cc
+  tablet_replica-test-base.cc)
 target_link_libraries(tablet_test_util
   kudu_common
   log_proto)
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index 459b62c..48f3b3e 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -83,6 +83,7 @@ class HistoryGcOpts;
 class MemRowSet;
 class RowSetTree;
 class RowSetsInCompaction;
+class TabletReplicaTestBase;
 class WriteOpState;
 struct RowOp;
 struct TabletComponents;
@@ -489,6 +490,7 @@ class Tablet {
   friend class kudu::AlterTableTest;
   friend class Iterator;
   friend class TabletReplicaTest;
+  friend class TabletReplicaTestBase;
   FRIEND_TEST(TestTablet, TestGetReplaySizeForIndex);
   FRIEND_TEST(TestTabletStringKey, TestSplitKeyRange);
   FRIEND_TEST(TestTabletStringKey, TestSplitKeyRangeWithZeroRowSets);
diff --git a/src/kudu/tablet/tablet_replica-test-base.cc 
b/src/kudu/tablet/tablet_replica-test-base.cc
new file mode 100644
index 0000000..e6e6dc3
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica-test-base.cc
@@ -0,0 +1,192 @@
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/tablet/tablet_replica-test-base.h"
+
+#include <functional>
+#include <memory>
+#include <ostream>
+#include <string>
+
+#include <glog/logging.h>
+#include <gtest/gtest.h>
+
+#include "kudu/common/common.pb.h"
+#include "kudu/consensus/consensus_meta.h"
+#include "kudu/consensus/consensus_meta_manager.h"
+#include "kudu/consensus/log.h"
+#include "kudu/consensus/log_anchor_registry.h"
+#include "kudu/consensus/log_util.h"
+#include "kudu/consensus/metadata.pb.h"
+#include "kudu/consensus/opid_util.h"
+#include "kudu/consensus/raft_consensus.h"
+#include "kudu/fs/fs_manager.h"
+#include "kudu/gutil/ref_counted.h"
+#include "kudu/gutil/strings/substitute.h"
+#include "kudu/rpc/messenger.h"
+#include "kudu/rpc/result_tracker.h"
+#include "kudu/tablet/tablet-test-util.h"
+#include "kudu/tablet/tablet.h"
+#include "kudu/tablet/tablet_bootstrap.h"
+#include "kudu/tablet/tablet_metadata.h"
+#include "kudu/tablet/tablet_replica.h"
+#include "kudu/util/monotime.h"
+#include "kudu/util/test_macros.h"
+
+using kudu::consensus::ConsensusBootstrapInfo;
+using kudu::consensus::ConsensusMetadata;
+using kudu::consensus::ConsensusMetadataManager;
+using kudu::consensus::RaftConfigPB;
+using kudu::consensus::RaftPeerPB;
+using kudu::log::Log;
+using kudu::log::LogOptions;
+using kudu::rpc::MessengerBuilder;
+using kudu::rpc::ResultTracker;
+using kudu::tablet::KuduTabletTest;
+using kudu::tablet::TabletReplica;
+using std::shared_ptr;
+using std::string;
+
+METRIC_DECLARE_entity(tablet);
+
+namespace kudu {
+namespace tablet {
+
+namespace {
+const MonoDelta kLeadershipTimeout = MonoDelta::FromSeconds(10);
+} // anonymous namespace
+
+void TabletReplicaTestBase::SetUp() {
+  KuduTabletTest::SetUp();
+
+  ASSERT_OK(ThreadPoolBuilder("prepare").Build(&prepare_pool_));
+  ASSERT_OK(ThreadPoolBuilder("apply").Build(&apply_pool_));
+  ASSERT_OK(ThreadPoolBuilder("raft").Build(&raft_pool_));
+  MessengerBuilder builder("TxnStatusManagerTest");
+  ASSERT_OK(builder.Build(&messenger_));
+
+  cmeta_manager_.reset(new ConsensusMetadataManager(fs_manager()));
+  metric_entity_ = METRIC_ENTITY_tablet.Instantiate(&metric_registry_, 
"test-tablet");
+  ASSERT_OK(SetUpReplica());
+}
+
+void TabletReplicaTestBase::TearDown() {
+  tablet_replica_->Shutdown();
+  prepare_pool_->Shutdown();
+  apply_pool_->Shutdown();
+  raft_pool_->Shutdown();
+  KuduTabletTest::TearDown();
+}
+
+Status TabletReplicaTestBase::SetUpReplica(bool new_replica) {
+  DCHECK(tablet_replica_ == nullptr);
+
+  RaftConfigPB config;
+  config.set_opid_index(consensus::kInvalidOpIdIndex);
+  RaftPeerPB* config_peer = config.add_peers();
+  config_peer->set_permanent_uuid(tablet()->metadata()->fs_manager()->uuid());
+  config_peer->mutable_last_known_addr()->set_host("0.0.0.0");
+  config_peer->mutable_last_known_addr()->set_port(0);
+  config_peer->set_member_type(RaftPeerPB::VOTER);
+  if (new_replica) {
+    RETURN_NOT_OK(cmeta_manager_->Create(tablet()->tablet_id(), config, 
consensus::kMinimumTerm));
+  }
+
+  // "Bootstrap" and start the TabletReplica.
+  const auto& tablet_id = tablet()->tablet_id();
+  tablet_replica_.reset(
+    new TabletReplica(tablet()->shared_metadata(),
+                      cmeta_manager_,
+                      *config_peer,
+                      apply_pool_.get(),
+                      [tablet_id] (const string& reason) {
+                        LOG(INFO) << Substitute(
+                            "state change callback run for $0: $1", tablet_id, 
reason);
+                      }));
+  // Make the replica use the same LogAnchorRegistry as the tablet harness.
+  // TODO(mpercy): Refactor TabletHarness to allow taking a LogAnchorRegistry,
+  // while also providing TabletMetadata for consumption by TabletReplica
+  // before Tablet is instantiated.
+  RETURN_NOT_OK(tablet_replica_->Init({ /*quiescing*/nullptr,
+                                        /*num_leaders*/nullptr,
+                                        raft_pool_.get() }));
+  tablet_replica_->log_anchor_registry_ = tablet()->log_anchor_registry_;
+  return Status::OK();
+}
+
+Status TabletReplicaTestBase::StartReplica(const ConsensusBootstrapInfo& info) 
{
+  scoped_refptr<Log> log;
+  RETURN_NOT_OK(Log::Open(LogOptions(),
+                          fs_manager(),
+                          /*file_cache*/nullptr,
+                          tablet()->tablet_id(),
+                          *tablet()->schema(),
+                          tablet()->metadata()->schema_version(),
+                          metric_entity_.get(),
+                          &log));
+  tablet_replica_->SetBootstrapping();
+  return tablet_replica_->Start(info,
+                                tablet(),
+                                clock(),
+                                messenger_,
+                                scoped_refptr<ResultTracker>(),
+                                log,
+                                prepare_pool_.get(),
+                                dns_resolver_.get());
+}
+
+Status TabletReplicaTestBase::StartReplicaAndWaitUntilLeader(const 
ConsensusBootstrapInfo& info) {
+  RETURN_NOT_OK(StartReplica(info));
+  return 
tablet_replica_->consensus()->WaitUntilLeaderForTests(kLeadershipTimeout);
+}
+
+Status TabletReplicaTestBase::RestartReplica() {
+  tablet_replica_->Shutdown();
+  tablet_replica_.reset();
+  RETURN_NOT_OK(SetUpReplica(/*new_replica=*/ false));
+  scoped_refptr<ConsensusMetadata> cmeta;
+  RETURN_NOT_OK(cmeta_manager_->Load(tablet_replica_->tablet_id(), &cmeta));
+  shared_ptr<Tablet> tablet;
+  scoped_refptr<Log> log;
+  ConsensusBootstrapInfo bootstrap_info;
+
+  tablet_replica_->SetBootstrapping();
+  RETURN_NOT_OK(BootstrapTablet(tablet_replica_->tablet_metadata(),
+                            cmeta->CommittedConfig(),
+                            clock(),
+                            /*mem_tracker*/nullptr,
+                            /*result_tracker*/nullptr,
+                            &metric_registry_,
+                            /*file_cache*/nullptr,
+                            tablet_replica_,
+                            tablet_replica_->log_anchor_registry(),
+                            &tablet,
+                            &log,
+                            &bootstrap_info));
+  RETURN_NOT_OK(tablet_replica_->Start(bootstrap_info,
+                                    tablet,
+                                    clock(),
+                                    messenger_,
+                                    scoped_refptr<ResultTracker>(),
+                                    log,
+                                    prepare_pool_.get(),
+                                    dns_resolver_.get()));
+  // Wait for the replica to be usable.
+  return 
tablet_replica_->consensus()->WaitUntilLeaderForTests(kLeadershipTimeout);
+}
+
+} // namespace tablet
+} // namespace kudu
diff --git a/src/kudu/tablet/tablet_replica-test-base.h 
b/src/kudu/tablet/tablet_replica-test-base.h
new file mode 100644
index 0000000..a302dd2
--- /dev/null
+++ b/src/kudu/tablet/tablet_replica-test-base.h
@@ -0,0 +1,81 @@
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#pragma once
+
+#include <memory>
+
+#include "kudu/consensus/consensus_meta_manager.h"
+#include "kudu/gutil/ref_counted.h"
+#include "kudu/tablet/tablet-harness.h"
+#include "kudu/tablet/tablet-test-util.h"
+#include "kudu/tablet/tablet_replica.h"
+#include "kudu/util/metrics.h"
+#include "kudu/util/net/dns_resolver.h"
+#include "kudu/util/status.h"
+#include "kudu/util/threadpool.h"
+
+namespace kudu {
+
+class Schema;
+
+namespace consensus {
+struct ConsensusBootstrapInfo;
+}  // namespace consensus
+
+namespace rpc {
+class Messenger;
+}  // namespace rpc
+
+namespace tablet {
+
+class TabletReplicaTestBase : public KuduTabletTest {
+ public:
+  explicit TabletReplicaTestBase(const Schema& schema)
+      : KuduTabletTest(schema, 
TabletHarness::Options::ClockType::HYBRID_CLOCK),
+        dns_resolver_(new DnsResolver) {}
+  void SetUp() override;
+  void TearDown() override;
+
+  // Initializes the tablet replica.
+  Status SetUpReplica(bool new_replica = true);
+
+  // Bootstraps the tablet replica.
+  Status StartReplica(const consensus::ConsensusBootstrapInfo& info);
+  Status StartReplicaAndWaitUntilLeader(const 
consensus::ConsensusBootstrapInfo& info);
+
+  // Shuts down and restarts the tablet replica, bootstrapping it from its
+  // on-disk stores and WALs.
+  Status RestartReplica();
+
+  const scoped_refptr<TabletReplica>& tablet_replica() const { return 
tablet_replica_; }
+
+ protected:
+  MetricRegistry metric_registry_;
+  scoped_refptr<MetricEntity> metric_entity_;
+  std::shared_ptr<rpc::Messenger> messenger_;
+  std::unique_ptr<ThreadPool> prepare_pool_;
+  std::unique_ptr<ThreadPool> apply_pool_;
+  std::unique_ptr<ThreadPool> raft_pool_;
+  std::unique_ptr<DnsResolver> dns_resolver_;
+
+  scoped_refptr<consensus::ConsensusMetadataManager> cmeta_manager_;
+
+  // NOTE: This must be destroyed before thread pools.
+  scoped_refptr<TabletReplica> tablet_replica_;
+};
+
+} // namespace tablet
+} // namespace kudu
diff --git a/src/kudu/tablet/tablet_replica-test.cc 
b/src/kudu/tablet/tablet_replica-test.cc
index 371eba0..a29e174 100644
--- a/src/kudu/tablet/tablet_replica-test.cc
+++ b/src/kudu/tablet/tablet_replica-test.cc
@@ -36,31 +36,24 @@
 #include "kudu/common/wire_protocol.h"
 #include "kudu/common/wire_protocol.pb.h"
 #include "kudu/consensus/consensus.pb.h"
-#include "kudu/consensus/consensus_meta.h"
-#include "kudu/consensus/consensus_meta_manager.h"
 #include "kudu/consensus/log.h"
 #include "kudu/consensus/log_anchor_registry.h"
 #include "kudu/consensus/log_reader.h"
 #include "kudu/consensus/log_util.h"
-#include "kudu/consensus/metadata.pb.h"
 #include "kudu/consensus/opid.pb.h"
 #include "kudu/consensus/opid_util.h"
 #include "kudu/consensus/raft_consensus.h"
 #include "kudu/fs/fs_manager.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/ref_counted.h"
-#include "kudu/rpc/messenger.h"
-#include "kudu/rpc/result_tracker.h"
 #include "kudu/tablet/ops/alter_schema_op.h"
 #include "kudu/tablet/ops/op.h"
 #include "kudu/tablet/ops/op_driver.h"
 #include "kudu/tablet/ops/op_tracker.h"
 #include "kudu/tablet/ops/write_op.h"
-#include "kudu/tablet/tablet-harness.h"
-#include "kudu/tablet/tablet-test-util.h"
 #include "kudu/tablet/tablet.h"
-#include "kudu/tablet/tablet_bootstrap.h"
 #include "kudu/tablet/tablet_metadata.h"
+#include "kudu/tablet/tablet_replica-test-base.h"
 #include "kudu/tablet/tablet_replica_mm_ops.h"
 #include "kudu/tserver/tserver.pb.h"
 #include "kudu/tserver/tserver_admin.pb.h"
@@ -68,13 +61,11 @@
 #include "kudu/util/maintenance_manager.h"
 #include "kudu/util/metrics.h"
 #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_bool(enable_maintenance_manager);
 DECLARE_int32(flush_threshold_mb);
@@ -86,19 +77,12 @@ METRIC_DECLARE_gauge_uint64(live_row_count);
 
 using kudu::consensus::CommitMsg;
 using kudu::consensus::ConsensusBootstrapInfo;
-using kudu::consensus::ConsensusMetadata;
-using kudu::consensus::ConsensusMetadataManager;
 using kudu::consensus::OpId;
 using kudu::consensus::RECEIVED_OPID;
-using kudu::consensus::RaftConfigPB;
 using kudu::consensus::RaftConsensus;
-using kudu::consensus::RaftPeerPB;
 using kudu::log::Log;
-using kudu::log::LogOptions;
 using kudu::pb_util::SecureDebugString;
 using kudu::pb_util::SecureShortDebugString;
-using kudu::rpc::Messenger;
-using kudu::rpc::ResultTracker;
 using kudu::tserver::AlterSchemaRequestPB;
 using kudu::tserver::AlterSchemaResponsePB;
 using kudu::tserver::WriteRequestPB;
@@ -108,147 +92,19 @@ using std::string;
 using std::unique_ptr;
 
 namespace kudu {
+
 namespace tablet {
 
 static Schema GetTestSchema() {
   return Schema({ ColumnSchema("key", INT32) }, 1);
 }
 
-class TabletReplicaTest : public KuduTabletTest {
+class TabletReplicaTest : public TabletReplicaTestBase {
  public:
   TabletReplicaTest()
-      : KuduTabletTest(GetTestSchema(),
-                       TabletHarness::Options::ClockType::HYBRID_CLOCK),
+      : TabletReplicaTestBase(GetTestSchema()),
         insert_counter_(0),
-        delete_counter_(0),
-        dns_resolver_(new DnsResolver) {
-  }
-
-  void SetUpReplica(bool new_replica = true) {
-    ASSERT_TRUE(tablet_replica_.get() == nullptr);
-
-    RaftConfigPB config;
-    config.set_opid_index(consensus::kInvalidOpIdIndex);
-
-    RaftPeerPB* config_peer = config.add_peers();
-    
config_peer->set_permanent_uuid(tablet()->metadata()->fs_manager()->uuid());
-    config_peer->mutable_last_known_addr()->set_host("0.0.0.0");
-    config_peer->mutable_last_known_addr()->set_port(0);
-    config_peer->set_member_type(RaftPeerPB::VOTER);
-
-
-    if (new_replica) {
-      ASSERT_OK(cmeta_manager_->Create(tablet()->tablet_id(), config, 
consensus::kMinimumTerm));
-    }
-
-    // "Bootstrap" and start the TabletReplica.
-    const auto& tablet_id = tablet()->tablet_id();
-    tablet_replica_.reset(
-      new TabletReplica(tablet()->shared_metadata(),
-                        cmeta_manager_,
-                        *config_peer,
-                        apply_pool_.get(),
-                        [this, tablet_id](const string& reason) {
-                          this->TabletReplicaStateChangedCallback(tablet_id, 
reason);
-                        }));
-    ASSERT_OK(tablet_replica_->Init({ /*quiescing*/nullptr,
-                                      /*num_leaders*/nullptr,
-                                      raft_pool_.get() }));
-    // Make TabletReplica use the same LogAnchorRegistry as the Tablet created 
by the harness.
-    // TODO(mpercy): Refactor TabletHarness to allow taking a
-    // LogAnchorRegistry, while also providing TabletMetadata for consumption
-    // by TabletReplica before Tablet is instantiated.
-    tablet_replica_->log_anchor_registry_ = tablet()->log_anchor_registry_;
-  }
-
-  virtual void SetUp() override {
-    KuduTabletTest::SetUp();
-
-    ASSERT_OK(ThreadPoolBuilder("prepare").Build(&prepare_pool_));
-    ASSERT_OK(ThreadPoolBuilder("apply").Build(&apply_pool_));
-    ASSERT_OK(ThreadPoolBuilder("raft").Build(&raft_pool_));
-
-    rpc::MessengerBuilder builder(CURRENT_TEST_NAME());
-    ASSERT_OK(builder.Build(&messenger_));
-
-    cmeta_manager_.reset(new ConsensusMetadataManager(fs_manager()));
-
-    metric_entity_ = METRIC_ENTITY_tablet.Instantiate(&metric_registry_, 
"test-tablet");
-    NO_FATALS(SetUpReplica());
-  }
-
-  Status StartReplica(const ConsensusBootstrapInfo& info) {
-    scoped_refptr<Log> log;
-    RETURN_NOT_OK(Log::Open(LogOptions(),
-                            fs_manager(),
-                            /*file_cache*/nullptr,
-                            tablet()->tablet_id(),
-                            *tablet()->schema(),
-                            tablet()->metadata()->schema_version(),
-                            metric_entity_.get(),
-                            &log));
-    tablet_replica_->SetBootstrapping();
-    return tablet_replica_->Start(info,
-                                  tablet(),
-                                  clock(),
-                                  messenger_,
-                                  scoped_refptr<ResultTracker>(),
-                                  log,
-                                  prepare_pool_.get(),
-                                  dns_resolver_.get());
-  }
-
-  Status StartReplicaAndWaitUntilLeader(const ConsensusBootstrapInfo& info) {
-    RETURN_NOT_OK(StartReplica(info));
-    const MonoDelta kTimeout = MonoDelta::FromSeconds(10);
-    return tablet_replica_->consensus()->WaitUntilLeaderForTests(kTimeout);
-  }
-
-  void TabletReplicaStateChangedCallback(const string& tablet_id, const 
string& reason) {
-    LOG(INFO) << "Tablet replica state changed for tablet " << tablet_id << ". 
Reason: " << reason;
-  }
-
-  virtual void TearDown() override {
-    tablet_replica_->Shutdown();
-    prepare_pool_->Shutdown();
-    apply_pool_->Shutdown();
-    KuduTabletTest::TearDown();
-  }
-
-  void RestartReplica() {
-    tablet_replica_->Shutdown();
-    tablet_replica_.reset();
-    NO_FATALS(SetUpReplica(/*new_replica=*/ false));
-    scoped_refptr<ConsensusMetadata> cmeta;
-    ASSERT_OK(cmeta_manager_->Load(tablet_replica_->tablet_id(), &cmeta));
-    shared_ptr<Tablet> tablet;
-    scoped_refptr<Log> log;
-    ConsensusBootstrapInfo bootstrap_info;
-
-    tablet_replica_->SetBootstrapping();
-    ASSERT_OK(BootstrapTablet(tablet_replica_->tablet_metadata(),
-                              cmeta->CommittedConfig(),
-                              clock(),
-                              /*mem_tracker*/nullptr,
-                              /*result_tracker*/nullptr,
-                              &metric_registry_,
-                              /*file_cache*/nullptr,
-                              tablet_replica_,
-                              tablet_replica_->log_anchor_registry(),
-                              &tablet,
-                              &log,
-                              &bootstrap_info));
-    ASSERT_OK(tablet_replica_->Start(bootstrap_info,
-                                     tablet,
-                                     clock(),
-                                     messenger_,
-                                     scoped_refptr<ResultTracker>(),
-                                     log,
-                                     prepare_pool_.get(),
-                                     dns_resolver_.get()));
-    // Wait for the replica to be usable.
-    const MonoDelta kTimeout = MonoDelta::FromSeconds(30);
-    ASSERT_OK(tablet_replica_->consensus()->WaitUntilLeaderForTests(kTimeout));
+        delete_counter_(0) {
   }
 
  protected:
@@ -369,7 +225,7 @@ class TabletReplicaTest : public KuduTabletTest {
   // destructed. So, this should always be called with an ASSERT_EVENTUALLY 
wrapper.
   void AssertNoLogAnchors() {
     // Make sure that there are no registered anchors in the registry
-    ASSERT_EQ(0, 
tablet_replica_->log_anchor_registry()->GetAnchorCountForTests());
+    ASSERT_EQ(0, 
tablet_replica()->log_anchor_registry()->GetAnchorCountForTests());
   }
 
   // Assert that the Log GC() anchor is earlier than the latest OpId in the 
Log.
@@ -388,18 +244,6 @@ class TabletReplicaTest : public KuduTabletTest {
 
   int32_t insert_counter_;
   int32_t delete_counter_;
-  MetricRegistry metric_registry_;
-  scoped_refptr<MetricEntity> metric_entity_;
-  shared_ptr<Messenger> messenger_;
-  unique_ptr<ThreadPool> prepare_pool_;
-  unique_ptr<ThreadPool> apply_pool_;
-  unique_ptr<ThreadPool> raft_pool_;
-  unique_ptr<DnsResolver> dns_resolver_;
-
-  scoped_refptr<ConsensusMetadataManager> cmeta_manager_;
-
-  // Must be destroyed before thread pools.
-  scoped_refptr<TabletReplica> tablet_replica_;
 };
 
 // A Op that waits on the apply_continue latch inside of Apply().
@@ -723,7 +567,7 @@ TEST_F(TabletReplicaTest, TestRollLogSegmentSchemaOnAlter) {
   };
   // Upon restarting, our log segment header schema should have "new_col".
   NO_FATALS(write());
-  NO_FATALS(RestartReplica());
+  ASSERT_OK(RestartReplica());
 
   // Get rid of the alter in the WALs.
   NO_FATALS(write());
@@ -736,7 +580,7 @@ TEST_F(TabletReplicaTest, TestRollLogSegmentSchemaOnAlter) {
   // didn't have "new_col", bootstrapping would fail, complaining about a
   // mismatch between the segment header schema and the write request schema.
   NO_FATALS(write());
-  NO_FATALS(RestartReplica());
+  ASSERT_OK(RestartReplica());
 }
 
 // Regression test for KUDU-2690, wherein a alter schema request that failed
@@ -775,7 +619,7 @@ TEST_F(TabletReplicaTest, Kudu2690Test) {
   // Before KUDU-2960 was fixed, bootstrapping would fail, complaining that the
   // write requests contained a column that was not in the log segment header's
   // schema.
-  NO_FATALS(RestartReplica());
+  ASSERT_OK(RestartReplica());
 }
 
 TEST_F(TabletReplicaTest, TestLiveRowCountMetric) {
@@ -833,7 +677,7 @@ TEST_F(TabletReplicaTest, TestRestartAfterGCDeletedRowsets) 
{
   ASSERT_EQ(0, live_row_count->value());
 
   // Restart and ensure we can rebuild our DMS okay.
-  NO_FATALS(RestartReplica());
+  ASSERT_OK(RestartReplica());
   tablet = tablet_replica_->tablet();
   ASSERT_EQ(1, tablet->num_rowsets());
   live_row_count = METRIC_live_row_count.InstantiateFunctionGauge(
@@ -842,7 +686,7 @@ TEST_F(TabletReplicaTest, TestRestartAfterGCDeletedRowsets) 
{
 
   // Now do that again but with deltafiles.
   ASSERT_OK(tablet->FlushBiggestDMS());
-  NO_FATALS(RestartReplica());
+  ASSERT_OK(RestartReplica());
   tablet = tablet_replica_->tablet();
   ASSERT_EQ(1, tablet->num_rowsets());
 
diff --git a/src/kudu/tablet/tablet_replica.h b/src/kudu/tablet/tablet_replica.h
index 67bbd5b..aa52910 100644
--- a/src/kudu/tablet/tablet_replica.h
+++ b/src/kudu/tablet/tablet_replica.h
@@ -72,6 +72,7 @@ class ResultTracker;
 
 namespace tablet {
 class AlterSchemaOpState;
+class TabletReplicaTestBase;
 class TabletStatusPB;
 class OpDriver;
 class WriteOpState;
@@ -313,6 +314,7 @@ class TabletReplica : public 
RefCountedThreadSafe<TabletReplica>,
   friend class kudu::AlterTableTest;
   friend class RefCountedThreadSafe<TabletReplica>;
   friend class TabletReplicaTest;
+  friend class TabletReplicaTestBase;
   FRIEND_TEST(TabletReplicaTest, TestMRSAnchorPreventsLogGC);
   FRIEND_TEST(TabletReplicaTest, TestDMSAnchorPreventsLogGC);
   FRIEND_TEST(TabletReplicaTest, TestActiveOpPreventsLogGC);

Reply via email to