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 2018/03/24 03:04:12 UTC

[2/2] kudu git commit: consensus: Add consensus peers health reporting test

consensus: Add consensus peers health reporting test

This new test provides functional coverage on tablet health states and
common health status transitions.

This patch also adds a version of CauseFollowerToFallBehindLogGC() that
allows for a pre-selected follower to fall behind the log GC threshold.
That enables us to verify a health status transition from FAILED to
FAILED_UNAVAILABLE.

Change-Id: I65d787a3146749e36e33d78e253914a5ffe5762d
Reviewed-on: http://gerrit.cloudera.org:8080/9766
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <as...@cloudera.com>


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

Branch: refs/heads/master
Commit: f2d2a328880a3b7e4b28dbedf675e2fc4eec3045
Parents: 38a5c49
Author: Mike Percy <mp...@apache.org>
Authored: Tue Dec 12 20:28:44 2017 -0800
Committer: Mike Percy <mp...@apache.org>
Committed: Sat Mar 24 03:03:58 2018 +0000

----------------------------------------------------------------------
 src/kudu/integration-tests/CMakeLists.txt       |   1 +
 src/kudu/integration-tests/cluster_itest_util.h |   2 +-
 .../consensus_peer_health_status-itest.cc       | 211 +++++++++++++++++++
 .../raft_consensus-itest-base.cc                |  33 ++-
 .../raft_consensus-itest-base.h                 |  16 +-
 5 files changed, 252 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/f2d2a328/src/kudu/integration-tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/CMakeLists.txt b/src/kudu/integration-tests/CMakeLists.txt
index 49bcad3..0c77216 100644
--- a/src/kudu/integration-tests/CMakeLists.txt
+++ b/src/kudu/integration-tests/CMakeLists.txt
@@ -67,6 +67,7 @@ ADD_KUDU_TEST(client-negotiation-failover-itest
 ADD_KUDU_TEST(client-stress-test
   RESOURCE_LOCK "master-rpc-ports"
   RUN_SERIAL true)
+ADD_KUDU_TEST(consensus_peer_health_status-itest)
 ADD_KUDU_TEST(consistency-itest PROCESSORS 5)
 ADD_KUDU_TEST(create-table-itest PROCESSORS 3)
 ADD_KUDU_TEST(create-table-stress-test RUN_SERIAL true)

http://git-wip-us.apache.org/repos/asf/kudu/blob/f2d2a328/src/kudu/integration-tests/cluster_itest_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/cluster_itest_util.h b/src/kudu/integration-tests/cluster_itest_util.h
index d984859..7baadd5 100644
--- a/src/kudu/integration-tests/cluster_itest_util.h
+++ b/src/kudu/integration-tests/cluster_itest_util.h
@@ -360,7 +360,7 @@ Status WaitForNumTabletsOnTS(
     TServerDetails* ts,
     int count,
     const MonoDelta& timeout,
-    std::vector<tserver::ListTabletsResponsePB::StatusAndSchemaPB>* tablets,
+    std::vector<tserver::ListTabletsResponsePB::StatusAndSchemaPB>* tablets = nullptr,
     boost::optional<tablet::TabletStatePB> state = boost::none);
 
 // Check if the tablet is in the specified state.

http://git-wip-us.apache.org/repos/asf/kudu/blob/f2d2a328/src/kudu/integration-tests/consensus_peer_health_status-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/consensus_peer_health_status-itest.cc b/src/kudu/integration-tests/consensus_peer_health_status-itest.cc
new file mode 100644
index 0000000..dceffd4
--- /dev/null
+++ b/src/kudu/integration-tests/consensus_peer_health_status-itest.cc
@@ -0,0 +1,211 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// 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 <memory>
+#include <ostream>
+#include <string>
+#include <vector>
+
+#include <gflags/gflags_declare.h>
+#include <glog/logging.h>
+#include <gtest/gtest.h>
+
+#include "kudu/consensus/consensus.pb.h"
+#include "kudu/consensus/metadata.pb.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/map-util.h"
+#include "kudu/integration-tests/cluster_itest_util.h"
+#include "kudu/integration-tests/raft_consensus-itest-base.h"
+#include "kudu/mini-cluster/external_mini_cluster.h"
+#include "kudu/tablet/metadata.pb.h"
+#include "kudu/tablet/tablet.pb.h"
+#include "kudu/tserver/tserver.pb.h"
+#include "kudu/util/monotime.h"
+#include "kudu/util/status.h"
+#include "kudu/util/test_macros.h"
+#include "kudu/util/test_util.h"
+
+DECLARE_int32(num_replicas);
+DECLARE_int32(num_tablet_servers);
+
+using kudu::consensus::ConsensusStatePB;
+using kudu::consensus::HealthReportPB;
+using kudu::consensus::INCLUDE_HEALTH_REPORT;
+using kudu::consensus::RaftPeerPB;
+using kudu::itest::TServerDetails;
+using kudu::tablet::TABLET_DATA_TOMBSTONED;
+using kudu::tserver::RaftConsensusITestBase;
+using std::string;
+using std::vector;
+
+namespace kudu {
+
+class ConsensusPeerHealthStatusITest : public RaftConsensusITestBase {
+};
+
+// This is a functional test that verifies that when a replica goes into a bad
+// state, its health status is detected by the leader replica.
+TEST_F(ConsensusPeerHealthStatusITest, TestPeerHealthStatusTransitions) {
+  if (!AllowSlowTests()) {
+    LOG(WARNING) << "Test disabled in fast test mode. Set KUDU_ALLOW_SLOW_TESTS=1 to enable.";
+    return;
+  }
+
+  const MonoDelta kTimeout = MonoDelta::FromSeconds(30);
+  const vector<string> kMasterFlags = {
+    // Disable re-replication and eviction for this test because we are
+    // verifying that putting a follower into a particular state is detected by
+    // the leader.
+    "--master_add_server_when_underreplicated=false",
+    "--catalog_manager_evict_excess_replicas=false",
+    // Leader elections are handled manually in this test.
+    "--catalog_manager_wait_for_new_tablets_to_elect_leader=false",
+  };
+  vector<string> ts_flags {
+    // Disable failure detection to ensure a stable test environment for health
+    // status testing.
+    "--enable_leader_failure_detection=false",
+    // We want to keep RPC timeouts short, to quickly detect downed servers,
+    // which will put the health status into an UKNOWN state until the point
+    // where they are considered FAILED, which we also control here.
+    "--consensus_rpc_timeout_ms=2000",
+    "--follower_unavailable_considered_failed_sec=6",
+  };
+  AddFlagsForLogRolls(&ts_flags); // For CauseFollowerToFallBehindLogGC().
+  ASSERT_EQ(3, FLAGS_num_tablet_servers);
+  ASSERT_EQ(3, FLAGS_num_replicas);
+  NO_FATALS(BuildAndStart(ts_flags, kMasterFlags));
+
+  vector<TServerDetails*> tservers;
+  AppendValuesFromMap(tablet_servers_, &tservers);
+  ASSERT_EQ(3, tservers.size());
+
+  // We'll use TS 0 as the leader and TS 1 as the follower to "abuse" in this test.
+  TServerDetails* leader_ts = tservers[0];
+  TServerDetails* follower_ts = tservers[1];
+  const string& follower_uuid = follower_ts->uuid();
+
+  // Elect a leader and wait for log index 1 to propagate to all servers.
+  ASSERT_OK(StartElection(leader_ts, tablet_id_, kTimeout));
+  ASSERT_OK(WaitForServersToAgree(kTimeout, tablet_servers_, tablet_id_, /*minimum_index=*/ 1));
+
+  // Wait for the specified follower to get into the specified health state.
+  auto wait_for_health_state = [&](TServerDetails* leader_ts, const string& peer_uuid,
+                                   HealthReportPB::HealthStatus expected_health_status) {
+    ASSERT_EVENTUALLY([&]{
+      ConsensusStatePB cstate;
+      ASSERT_OK(GetConsensusState(leader_ts, tablet_id_, kTimeout, INCLUDE_HEALTH_REPORT, &cstate));
+      bool found_replica = false;
+      for (const auto& peer : cstate.committed_config().peers()) {
+        if (peer.permanent_uuid() != peer_uuid) continue;
+        found_replica = true;
+        ASSERT_TRUE(peer.has_health_report());
+        auto health_status = peer.health_report().overall_health();
+        ASSERT_EQ(expected_health_status, health_status)
+            << "expected: " << HealthReportPB::HealthStatus_Name(expected_health_status) << ", "
+            << "actual: " << HealthReportPB::HealthStatus_Name(health_status);
+        break;
+      }
+      ASSERT_TRUE(found_replica) << "No replica found with UUID " << peer_uuid;
+    });
+  };
+
+  // Convenience constants.
+  constexpr auto UNKNOWN = HealthReportPB::UNKNOWN;
+  constexpr auto HEALTHY = HealthReportPB::HEALTHY;
+  constexpr auto FAILED = HealthReportPB::FAILED;
+  constexpr auto FAILED_UNRECOVERABLE = HealthReportPB::FAILED_UNRECOVERABLE;
+
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, HEALTHY));
+
+  LOG(INFO) << "Test: HEALTHY -> UNKNOWN -> HEALTHY";
+
+  // Make the follower unavailable for long enough to be considered to have
+  // UNKNOWN health status.
+  cluster_->tablet_server_by_uuid(follower_uuid)->Shutdown();
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, UNKNOWN));
+
+  // Recover back to HEALTHY.
+  ASSERT_OK(cluster_->tablet_server_by_uuid(follower_uuid)->Restart());
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, HEALTHY));
+
+  LOG(INFO) << "Test: HEALTHY -> UNKNOWN -> FAILED -> HEALTHY";
+
+  enum ErrorType {
+    PAUSE,
+    SHUTDOWN
+  };
+
+  // Ensure that both SIGSTOP and process shutdown result first in UNKNOWN and
+  // then in FAILED states.
+  for (auto error_type : { PAUSE, SHUTDOWN }) {
+    // Fail the follower. Track the transitions: first through UNKNOWN state,
+    // then into FAILED.
+    if (error_type == SHUTDOWN) {
+      cluster_->tablet_server_by_uuid(follower_uuid)->Shutdown();
+    } else {
+      ASSERT_OK(cluster_->tablet_server_by_uuid(follower_uuid)->Pause());
+    }
+    NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, UNKNOWN));
+    NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, FAILED));
+
+    // Recover back to HEALTHY.
+    if (error_type == SHUTDOWN) {
+      ASSERT_OK(cluster_->tablet_server_by_uuid(follower_uuid)->Restart());
+    } else {
+      ASSERT_OK(cluster_->tablet_server_by_uuid(follower_uuid)->Resume());
+    }
+    NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, HEALTHY));
+  }
+
+  LOG(INFO) << "Test: HEALTHY -> FAILED_UNRECOVERABLE";
+
+  NO_FATALS(CauseSpecificFollowerToFallBehindLogGC(tablet_servers_, follower_uuid));
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, FAILED_UNRECOVERABLE));
+
+  LOG(INFO) << "Recovering test replica...";
+
+  // The master isn't managing re-replication in this test (see gflags set at
+  // the start of the test) so we manually simulate re-replication here to
+  // recover from an "unrecoverable" replica state.
+  //
+  // Manually evict the failed follower from the config, wait for the master to
+  // delete the replica, then manually add the same tablet server back to the
+  // config in order to bring the replica on 'follower_ts' back to a HEALTHY
+  // state.
+  ASSERT_OK(RemoveServer(leader_ts, tablet_id_, follower_ts, kTimeout));
+  ASSERT_EVENTUALLY([&] {
+    vector<tserver::ListTabletsResponsePB::StatusAndSchemaPB> tablets;
+    ASSERT_OK(WaitForNumTabletsOnTS(follower_ts, /*count=*/ 1, kTimeout, &tablets));
+    ASSERT_EQ(1, tablets.size());
+    ASSERT_EQ(TABLET_DATA_TOMBSTONED, tablets[0].tablet_status().tablet_data_state());
+  });
+  ASSERT_OK(AddServer(leader_ts, tablet_id_, follower_ts, RaftPeerPB::VOTER, kTimeout));
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, HEALTHY));
+
+  LOG(INFO) << "Test: HEALTHY -> UNKNOWN -> FAILED -> FAILED_UNRECOVERABLE";
+
+  cluster_->tablet_server_by_uuid(follower_uuid)->Shutdown();
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, UNKNOWN));
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, FAILED));
+  NO_FATALS(CauseSpecificFollowerToFallBehindLogGC(tablet_servers_, follower_uuid,
+                                                   /*leader_uuid=*/ nullptr, /*orig_term=*/ nullptr,
+                                                   DO_NOT_TAMPER));
+  NO_FATALS(wait_for_health_state(leader_ts, follower_uuid, FAILED_UNRECOVERABLE));
+}
+
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/f2d2a328/src/kudu/integration-tests/raft_consensus-itest-base.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/raft_consensus-itest-base.cc b/src/kudu/integration-tests/raft_consensus-itest-base.cc
index 1fee8a8..b357dcc 100644
--- a/src/kudu/integration-tests/raft_consensus-itest-base.cc
+++ b/src/kudu/integration-tests/raft_consensus-itest-base.cc
@@ -40,6 +40,7 @@
 #include "kudu/consensus/opid.pb.h"
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
+#include "kudu/gutil/map-util.h"
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/integration-tests/cluster_itest_util.h"
 #include "kudu/integration-tests/mini_cluster_fs_inspector.h"
@@ -206,7 +207,23 @@ void RaftConsensusITestBase::CauseFollowerToFallBehindLogGC(
 
   // Pause or shutdown one server. This might be the leader, and making it
   // unresponsive will cause a leader election to happen.
-  TServerDetails* replica = (*tablet_replicas_.begin()).second;
+  TServerDetails* replica = tablet_replicas_.begin()->second;
+  CauseSpecificFollowerToFallBehindLogGC(tablet_servers, replica->uuid(),
+                                         leader_uuid, orig_term,
+                                         tserver_behavior, pre_workload_delay);
+  if (fell_behind_uuid) *fell_behind_uuid = replica->uuid();
+}
+
+void RaftConsensusITestBase::CauseSpecificFollowerToFallBehindLogGC(
+    const itest::TabletServerMap& tablet_servers,
+    const string& follower_uuid_to_fail,
+    string* leader_uuid,
+    int64_t* orig_term,
+    BehindWalGcBehavior tserver_behavior,
+    const MonoDelta& pre_workload_delay) {
+  MonoDelta kTimeout = MonoDelta::FromSeconds(10);
+
+  TServerDetails* replica = FindOrDie(tablet_servers_, follower_uuid_to_fail);
   ExternalTabletServer* replica_ets = cluster_->tablet_server_by_uuid(replica->uuid());
   switch (tserver_behavior) {
     case BehindWalGcBehavior::STOP_CONTINUE:
@@ -216,6 +233,9 @@ void RaftConsensusITestBase::CauseFollowerToFallBehindLogGC(
     case BehindWalGcBehavior::SHUTDOWN:
       replica_ets->Shutdown();
       break;
+    case BehindWalGcBehavior::DO_NOT_TAMPER:
+      // Do nothing.
+      break;
     default:
       CHECK(false) << tserver_behavior
                    << ": unknown behavior for tserver behind WAL GC threshold";
@@ -232,8 +252,8 @@ void RaftConsensusITestBase::CauseFollowerToFallBehindLogGC(
     }
     SleepFor(MonoDelta::FromMilliseconds(10));
   }
-  *leader_uuid = leader->uuid();
-  int leader_index = cluster_->tablet_server_index_by_uuid(*leader_uuid);
+  if (leader_uuid) *leader_uuid = leader->uuid();
+  int leader_index = cluster_->tablet_server_index_by_uuid(leader->uuid());
 
   if (pre_workload_delay.Initialized()) {
     SleepFor(pre_workload_delay);
@@ -274,8 +294,8 @@ void RaftConsensusITestBase::CauseFollowerToFallBehindLogGC(
     OpId op_id;
     ASSERT_OK(GetLastOpIdForReplica(tablet_id_, leader, consensus::RECEIVED_OPID, kTimeout,
                                     &op_id));
-    *orig_term = op_id.term();
-    LOG(INFO) << "Servers converged with original term " << *orig_term;
+    if (orig_term) *orig_term = op_id.term();
+    LOG(INFO) << "Servers converged with original term " << op_id.term();
   }
 
   if (tserver_behavior == BehindWalGcBehavior::STOP_CONTINUE) {
@@ -294,12 +314,11 @@ void RaftConsensusITestBase::CauseFollowerToFallBehindLogGC(
         uuid == replica->uuid()) {
       ASSERT_TRUE(cluster_->tablet_server_by_uuid(uuid)->IsShutdown())
           << "Tablet server " << uuid << " is not shutdown";
-    } else {
+    } else if (tserver_behavior != BehindWalGcBehavior::DO_NOT_TAMPER) {
       ASSERT_TRUE(cluster_->tablet_server_by_uuid(uuid)->IsProcessAlive())
           << "Tablet server " << uuid << " crashed";
     }
   }
-  *fell_behind_uuid = replica->uuid();
 }
 
 Status RaftConsensusITestBase::GetTermMetricValue(ExternalTabletServer* ts,

http://git-wip-us.apache.org/repos/asf/kudu/blob/f2d2a328/src/kudu/integration-tests/raft_consensus-itest-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/raft_consensus-itest-base.h b/src/kudu/integration-tests/raft_consensus-itest-base.h
index c00426d..b3c843d 100644
--- a/src/kudu/integration-tests/raft_consensus-itest-base.h
+++ b/src/kudu/integration-tests/raft_consensus-itest-base.h
@@ -47,6 +47,7 @@ class RaftConsensusITestBase : public TabletServerIntegrationTestBase {
     STOP_CONTINUE,    // Send SIGSTOP and then SIGCONT to the affected tserver.
     SHUTDOWN_RESTART, // Shutdown and then restart the affected tserver.
     SHUTDOWN,         // Shutdown the affected tserver, don't start it back up.
+    DO_NOT_TAMPER,    // Leave the affected tserver alone, running or not.
   };
 
   RaftConsensusITestBase();
@@ -83,9 +84,18 @@ class RaftConsensusITestBase : public TabletServerIntegrationTestBase {
   // AddFlagsForLogRolls() before starting the cluster.
   void CauseFollowerToFallBehindLogGC(
       const itest::TabletServerMap& tablet_servers,
-      std::string* leader_uuid,
-      int64_t* orig_term,
-      std::string* fell_behind_uuid,
+      std::string* leader_uuid = nullptr,
+      int64_t* orig_term = nullptr,
+      std::string* fell_behind_uuid = nullptr,
+      BehindWalGcBehavior tserver_behavior = BehindWalGcBehavior::STOP_CONTINUE,
+      const MonoDelta& pre_workload_delay = {});
+
+  // Same as above, but the follower to fail is chosen in advance.
+  void CauseSpecificFollowerToFallBehindLogGC(
+      const itest::TabletServerMap& tablet_servers,
+      const std::string& follower_uuid_to_fail,
+      std::string* leader_uuid = nullptr,
+      int64_t* orig_term = nullptr,
       BehindWalGcBehavior tserver_behavior = BehindWalGcBehavior::STOP_CONTINUE,
       const MonoDelta& pre_workload_delay = {});