You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2017/08/22 00:27:22 UTC

[2/2] kudu git commit: consensus: Tablet copy should clear last-logged opid from superblock

consensus: Tablet copy should clear last-logged opid from superblock

Keeping around irrelevant information is bad hygiene.

Change-Id: Iaa84d59c63222e9ddb05dca492f9ecd47b5c63ea
Reviewed-on: http://gerrit.cloudera.org:8080/7718
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Mike Percy <mp...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a7d58963
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a7d58963
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a7d58963

Branch: refs/heads/master
Commit: a7d589635bd889fe31205a600739ae938b803d97
Parents: dc65abb
Author: Mike Percy <mp...@apache.org>
Authored: Thu Aug 17 00:26:00 2017 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Tue Aug 22 00:26:58 2017 +0000

----------------------------------------------------------------------
 src/kudu/integration-tests/tablet_copy-itest.cc | 62 ++++++++++++++++++++
 src/kudu/tablet/tablet_metadata.cc              |  3 +
 src/kudu/tablet/tablet_metadata.h               |  1 +
 3 files changed, 66 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a7d58963/src/kudu/integration-tests/tablet_copy-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/tablet_copy-itest.cc b/src/kudu/integration-tests/tablet_copy-itest.cc
index e8f44b1..0e0977d 100644
--- a/src/kudu/integration-tests/tablet_copy-itest.cc
+++ b/src/kudu/integration-tests/tablet_copy-itest.cc
@@ -904,6 +904,68 @@ TEST_F(TabletCopyITest, TestTabletCopyingDeletedTabletFails) {
   ASSERT_OK(WaitForServersToAgree(kTimeout, ts_map_, tablet_id, 1));
 }
 
+// Test that tablet copy clears the last-logged opid stored in the TabletMetadata.
+TEST_F(TabletCopyITest, TestTabletCopyClearsLastLoggedOpId) {
+  MonoDelta kTimeout = MonoDelta::FromSeconds(30);
+  NO_FATALS(StartCluster({"--enable_leader_failure_detection=false"},
+                         {"--catalog_manager_wait_for_new_tablets_to_elect_leader=false"}));
+
+  TestWorkload workload(cluster_.get());
+  workload.set_num_replicas(3);
+  workload.Setup();
+
+  int leader_index = 0;
+  TServerDetails* leader = ts_map_[cluster_->tablet_server(leader_index)->uuid()];
+
+  // Figure out the tablet id of the created tablet.
+  vector<ListTabletsResponsePB::StatusAndSchemaPB> tablets;
+  ASSERT_OK(WaitForNumTabletsOnTS(leader, 1, kTimeout, &tablets));
+  string tablet_id = tablets[0].tablet_status().tablet_id();
+
+  // Wait until all replicas are up and running.
+  for (int i = 0; i < cluster_->num_tablet_servers(); i++) {
+    ASSERT_OK(itest::WaitUntilTabletRunning(ts_map_[cluster_->tablet_server(i)->uuid()],
+                                            tablet_id, kTimeout));
+  }
+
+  // Elect a leader for term 1, then generate some data to copy.
+  ASSERT_OK(itest::StartElection(leader, tablet_id, kTimeout));
+  workload.Start();
+  const int kMinBatches = 10;
+  while (workload.batches_completed() < kMinBatches) {
+    SleepFor(MonoDelta::FromMilliseconds(10));
+  }
+  workload.StopAndJoin();
+  ASSERT_OK(WaitForServersToAgree(kTimeout, ts_map_, tablet_id, 1));
+
+  // No last-logged opid should initially be stored in the superblock.
+  tablet::TabletSuperBlockPB superblock_pb;
+  inspect_->ReadTabletSuperBlockOnTS(leader_index, tablet_id, &superblock_pb);
+  ASSERT_FALSE(superblock_pb.has_tombstone_last_logged_opid());
+
+  // Now tombstone the leader.
+  ASSERT_OK(itest::DeleteTablet(leader, tablet_id, TABLET_DATA_TOMBSTONED, boost::none, kTimeout));
+
+  // We should end up with a last-logged opid in the superblock.
+  inspect_->ReadTabletSuperBlockOnTS(leader_index, tablet_id, &superblock_pb);
+  ASSERT_TRUE(superblock_pb.has_tombstone_last_logged_opid());
+  consensus::OpId last_logged_opid = superblock_pb.tombstone_last_logged_opid();
+  ASSERT_EQ(1, last_logged_opid.term());
+  ASSERT_GT(last_logged_opid.index(), kMinBatches);
+
+  int follower_index = 1;
+  ASSERT_OK(itest::StartTabletCopy(leader, tablet_id,
+                                   cluster_->tablet_server(follower_index)->uuid(),
+                                   cluster_->tablet_server(follower_index)->bound_rpc_hostport(),
+                                   1, // We are in term 1.
+                                   kTimeout));
+  ASSERT_OK(itest::WaitUntilTabletRunning(leader, tablet_id, kTimeout));
+
+  // Ensure that the last-logged opid has been cleared from the superblock.
+  inspect_->ReadTabletSuperBlockOnTS(leader_index, tablet_id, &superblock_pb);
+  ASSERT_FALSE(superblock_pb.has_tombstone_last_logged_opid());
+}
+
 // Test that the tablet copy thread pool being full results in throttling and
 // backpressure on the callers.
 TEST_F(TabletCopyITest, TestTabletCopyThrottling) {

http://git-wip-us.apache.org/repos/asf/kudu/blob/a7d58963/src/kudu/tablet/tablet_metadata.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_metadata.cc b/src/kudu/tablet/tablet_metadata.cc
index 4d9a197..4ed5352 100644
--- a/src/kudu/tablet/tablet_metadata.cc
+++ b/src/kudu/tablet/tablet_metadata.cc
@@ -717,6 +717,9 @@ uint32_t TabletMetadata::schema_version() const {
 
 void TabletMetadata::set_tablet_data_state(TabletDataState state) {
   std::lock_guard<LockType> l(data_lock_);
+  if (state == TABLET_DATA_READY) {
+    tombstone_last_logged_opid_ = boost::none;
+  }
   tablet_data_state_ = state;
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/a7d58963/src/kudu/tablet/tablet_metadata.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_metadata.h b/src/kudu/tablet/tablet_metadata.h
index ca524b7..3bbd849 100644
--- a/src/kudu/tablet/tablet_metadata.h
+++ b/src/kudu/tablet/tablet_metadata.h
@@ -147,6 +147,7 @@ class TabletMetadata : public RefCountedThreadSafe<TabletMetadata> {
   }
 
   // Set / get the tablet copy / tablet data state.
+  // If set to TABLET_DATA_READY, also clears 'tombstone_last_logged_opid_'.
   void set_tablet_data_state(TabletDataState state);
   TabletDataState tablet_data_state() const;