You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by da...@apache.org on 2017/08/31 04:02:17 UTC
[3/3] kudu git commit: tablet copy: Allow voting from failed initial
tablet copies
tablet copy: Allow voting from failed initial tablet copies
This patch changes the behavior of tablets being copied for the first
time, i.e. to a new tablet server that has never hosted that replica. In
that case, if the tablet copy fails, with this patch that replica will
still be allowed to vote while tombstoned. This improves availability.
Without this patch, if a tablet copy to a new replica fails, that
replica will not be able to vote while tombstoned because its
last-logged OpId field in its superblock will be unset.
This is achieved within tablet copy by setting the initial
tombstoned_last_logged_opid to (1,0).
This patch is a bit of a hack, since it takes advantage of the fact that
it is impossible to have a "real" OpId of 1.0 in the current
implementation (1.1 is the operational minimum) so having a last-logged
OpId of 1.0 represents having never logged any actual ops.
Change-Id: Ibaad2f56797db731a0f701bbd37e3e450bc17b51
Reviewed-on: http://gerrit.cloudera.org:8080/7904
Reviewed-by: Alexey Serbin <as...@cloudera.com>
Tested-by: Kudu Jenkins
Reviewed-on: http://gerrit.cloudera.org:8080/7913
Reviewed-by: Dan Burkert <da...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/2de07e59
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/2de07e59
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/2de07e59
Branch: refs/heads/branch-1.5.x
Commit: 2de07e5940377e39947e11daa2442c94b4f8dbbe
Parents: 9d71f99
Author: Mike Percy <mp...@apache.org>
Authored: Tue Aug 29 19:23:34 2017 -0700
Committer: Dan Burkert <da...@apache.org>
Committed: Thu Aug 31 04:01:50 2017 +0000
----------------------------------------------------------------------
src/kudu/integration-tests/tablet_copy-itest.cc | 78 ++++++++++++++++++++
src/kudu/tserver/tablet_copy_client.cc | 7 ++
2 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/2de07e59/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 52df993..de492ae 100644
--- a/src/kudu/integration-tests/tablet_copy-itest.cc
+++ b/src/kudu/integration-tests/tablet_copy-itest.cc
@@ -40,6 +40,7 @@
#include "kudu/common/wire_protocol-test-util.h"
#include "kudu/common/wire_protocol.h"
#include "kudu/common/wire_protocol.pb.h"
+#include "kudu/consensus/consensus.pb.h"
#include "kudu/consensus/consensus_meta_manager.h"
#include "kudu/consensus/metadata.pb.h"
#include "kudu/consensus/opid.pb.h"
@@ -55,6 +56,7 @@
#include "kudu/integration-tests/external_mini_cluster.h"
#include "kudu/integration-tests/external_mini_cluster_fs_inspector.h"
#include "kudu/integration-tests/test_workload.h"
+#include "kudu/master/master.pb.h"
#include "kudu/tablet/metadata.pb.h"
#include "kudu/tablet/tablet.pb.h"
#include "kudu/tablet/tablet_metadata.h"
@@ -87,9 +89,13 @@ DEFINE_int32(test_delete_leader_num_writer_threads, 1,
using kudu::client::KuduSchema;
using kudu::client::KuduSchemaFromSchema;
using kudu::client::KuduTableCreator;
+using kudu::consensus::COMMITTED_OPID;
using kudu::consensus::ConsensusMetadataManager;
+using kudu::consensus::ConsensusMetadataPB;
+using kudu::consensus::RaftPeerPB;
using kudu::itest::TServerDetails;
using kudu::itest::WaitForNumTabletServers;
+using kudu::tablet::TABLET_DATA_COPYING;
using kudu::tablet::TABLET_DATA_DELETED;
using kudu::tablet::TABLET_DATA_TOMBSTONED;
using kudu::tserver::ListTabletsResponsePB;
@@ -1084,6 +1090,78 @@ TEST_F(TabletCopyITest, TestTabletCopyThrottling) {
LOG(INFO) << "Number of in progress responses: " << num_inprogress;
}
+// Test that a failed tablet copy of a brand-new replica results in still being
+// able to vote while tombstoned.
+TEST_F(TabletCopyITest, TestTabletCopyNewReplicaFailureCanVote) {
+ const MonoDelta kTimeout = MonoDelta::FromSeconds(30);
+ // We want all tablet copy attempts to fail after initial setup.
+ NO_FATALS(StartCluster({"--tablet_copy_early_session_timeout_prob=1.0"}, {},
+ /*num_tablet_servers=*/ 4));
+ TestWorkload workload(cluster_.get());
+ workload.Setup();
+
+ ASSERT_OK(inspect_->WaitForReplicaCount(3));
+ master::GetTableLocationsResponsePB table_locations;
+ ASSERT_OK(itest::GetTableLocations(cluster_->master_proxy(), TestWorkload::kDefaultTableName,
+ kTimeout, &table_locations));
+ ASSERT_EQ(1, table_locations.tablet_locations_size());
+ string tablet_id = table_locations.tablet_locations(0).tablet_id();
+ set<string> replica_uuids;
+ for (const auto& replica : table_locations.tablet_locations(0).replicas()) {
+ replica_uuids.insert(replica.ts_info().permanent_uuid());
+ }
+
+ TServerDetails* leader_ts;
+ ASSERT_OK(itest::FindTabletLeader(ts_map_, tablet_id, kTimeout, &leader_ts));
+ ASSERT_OK(itest::WaitForOpFromCurrentTerm(leader_ts, tablet_id, COMMITTED_OPID, kTimeout));
+
+ string new_replica_uuid;
+ for (int i = 0; i < cluster_->num_tablet_servers(); i++) {
+ if (!ContainsKey(replica_uuids, cluster_->tablet_server(i)->uuid())) {
+ new_replica_uuid = cluster_->tablet_server(i)->uuid();
+ break;
+ }
+ }
+ ASSERT_FALSE(new_replica_uuid.empty());
+ auto* new_replica_ts = ts_map_[new_replica_uuid];
+
+ // Adding a server will trigger a tablet copy.
+ ASSERT_OK(itest::AddServer(leader_ts, tablet_id, new_replica_ts, RaftPeerPB::VOTER,
+ boost::none, kTimeout));
+
+ // Wait until the new replica has done its initial download, and has either
+ // failed or is about to fail (the check is nondeterministic) plus has
+ // persisted its cmeta.
+ int new_replica_idx = cluster_->tablet_server_index_by_uuid(new_replica_uuid);
+ ASSERT_EVENTUALLY([&] {
+ ASSERT_OK(inspect_->CheckTabletDataStateOnTS(new_replica_idx, tablet_id,
+ { TABLET_DATA_COPYING, TABLET_DATA_TOMBSTONED }));
+ ConsensusMetadataPB cmeta_pb;
+ ASSERT_OK(inspect_->ReadConsensusMetadataOnTS(new_replica_idx, tablet_id, &cmeta_pb));
+ });
+
+ // Restart the cluster with 3 voters instead of 4, including the new replica
+ // that should be tombstoned. It should be able to vote and get the leader up
+ // and running.
+ cluster_->Shutdown();
+ for (int i = 0; i < cluster_->num_tablet_servers(); i++) {
+ // Remove the "early timeout" flag.
+ cluster_->tablet_server(i)->mutable_flags()->pop_back();
+ }
+ ASSERT_OK(cluster_->master()->Restart());
+ ASSERT_OK(cluster_->tablet_server_by_uuid(new_replica_uuid)->Restart());
+ auto iter = replica_uuids.cbegin();
+ ASSERT_OK(cluster_->tablet_server_by_uuid(*iter)->Restart());
+ ASSERT_OK(cluster_->tablet_server_by_uuid(*++iter)->Restart());
+
+ // Now wait until we can write.
+ workload.Start();
+ ASSERT_EVENTUALLY([&] {
+ ASSERT_GE(workload.rows_inserted(), 100);
+ });
+ workload.StopAndJoin();
+}
+
// This test uses CountBlocksUnderManagement() which only works with the
// LogBlockManager.
#ifndef __APPLE__
http://git-wip-us.apache.org/repos/asf/kudu/blob/2de07e59/src/kudu/tserver/tablet_copy_client.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_copy_client.cc b/src/kudu/tserver/tablet_copy_client.cc
index 6d1731e..b10336d 100644
--- a/src/kudu/tserver/tablet_copy_client.cc
+++ b/src/kudu/tserver/tablet_copy_client.cc
@@ -34,6 +34,7 @@
#include "kudu/consensus/consensus_meta_manager.h"
#include "kudu/consensus/metadata.pb.h"
#include "kudu/consensus/opid.pb.h"
+#include "kudu/consensus/opid_util.h"
#include "kudu/fs/block_id.h"
#include "kudu/fs/block_manager.h"
#include "kudu/fs/data_dirs.h"
@@ -96,6 +97,7 @@ namespace tserver {
using consensus::ConsensusMetadata;
using consensus::ConsensusMetadataManager;
+using consensus::MakeOpId;
using consensus::OpId;
using env_util::CopyFile;
using fs::BlockTransaction;
@@ -284,6 +286,11 @@ Status TabletCopyClient::Start(const HostPort& copy_source_addr,
"Could not replace superblock with COPYING data state");
CHECK_OK(fs_manager_->dd_manager()->CreateDataDirGroup(tablet_id_));
} else {
+ // HACK: Set the initial tombstoned last-logged OpId to 1.0 when copying a
+ // replica for the first time, so that if the tablet copy fails, the
+ // tombstoned replica will still be able to vote.
+ // TODO(mpercy): Give this particular OpId a name.
+ *superblock_->mutable_tombstone_last_logged_opid() = MakeOpId(1, 0);
Partition partition;
Partition::FromPB(superblock_->partition(), &partition);
PartitionSchema partition_schema;