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 2018/01/09 21:18:49 UTC
[3/3] kudu git commit: [tests] update tests for replication scheme
consistency
[tests] update tests for replication scheme consistency
Fixed and updated some scenarios once the re-replication scheme
consistency is enforced:
* MasterTest.TestRegisterAndHeartbeat scenario
* MasterReplicationTest.TestHeartbeatAcceptedByAnyMaster
* MasterCertAuthorityTest.RefuseToSignInvalidCSR
* MasterCertAuthorityTest.MasterLeaderSignsCSR
This is a follow-up for 1769eed53ee2c21a88a766cb72bf8c9ae622099d.
Change-Id: I8f5bbb581abeb3a781b522dff90711b2ffc988df
Reviewed-on: http://gerrit.cloudera.org:8080/8979
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-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/746d0a5c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/746d0a5c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/746d0a5c
Branch: refs/heads/master
Commit: 746d0a5cd53c8252af0c0b6ad294cdb6b39a0319
Parents: ad3b6a6
Author: Alexey Serbin <as...@cloudera.com>
Authored: Tue Jan 9 11:11:43 2018 -0800
Committer: Alexey Serbin <as...@cloudera.com>
Committed: Tue Jan 9 21:17:26 2018 +0000
----------------------------------------------------------------------
.../master_cert_authority-itest.cc | 32 +++++++----
.../master_replication-itest.cc | 33 +++++++----
src/kudu/master/master-test.cc | 59 +++++++++++++++++++-
3 files changed, 101 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/746d0a5c/src/kudu/integration-tests/master_cert_authority-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/master_cert_authority-itest.cc b/src/kudu/integration-tests/master_cert_authority-itest.cc
index 109f3f0..806b870 100644
--- a/src/kudu/integration-tests/master_cert_authority-itest.cc
+++ b/src/kudu/integration-tests/master_cert_authority-itest.cc
@@ -20,12 +20,13 @@
#include <vector>
#include <boost/optional/optional.hpp>
+#include <gflags/gflags_declare.h>
#include <gtest/gtest.h>
#include "kudu/common/common.pb.h"
#include "kudu/common/wire_protocol.pb.h"
+#include "kudu/consensus/replica_management.pb.h"
#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/port.h"
#include "kudu/master/master.h"
#include "kudu/master/master.pb.h"
#include "kudu/master/master.proxy.h"
@@ -45,19 +46,21 @@
#include "kudu/util/test_util.h"
#include "kudu/util/user.h"
+DECLARE_bool(raft_prepare_replacement_before_eviction);
+
+using kudu::cluster::InternalMiniCluster;
+using kudu::cluster::InternalMiniClusterOptions;
+using kudu::consensus::ReplicaManagementInfoPB;
+using kudu::security::ca::CertRequestGenerator;
+using kudu::security::Cert;
+using kudu::security::CertSignRequest;
+using kudu::security::DataFormat;
+using kudu::security::PrivateKey;
using std::string;
using std::shared_ptr;
-namespace kudu {
-
-using cluster::InternalMiniCluster;
-using cluster::InternalMiniClusterOptions;
-using security::ca::CertRequestGenerator;
-using security::Cert;
-using security::CertSignRequest;
-using security::DataFormat;
-using security::PrivateKey;
+namespace kudu {
namespace master {
class MasterCertAuthorityTest : public KuduTest {
@@ -71,7 +74,7 @@ class MasterCertAuthorityTest : public KuduTest {
opts_.num_masters = num_masters_ = opts_.master_rpc_ports.size();
}
- virtual void SetUp() OVERRIDE {
+ void SetUp() override {
KuduTest::SetUp();
cluster_.reset(new InternalMiniCluster(env_, opts_));
ASSERT_OK(cluster_->Start());
@@ -117,6 +120,12 @@ class MasterCertAuthorityTest : public KuduTest {
pb->set_host("localhost");
pb->set_port(2000);
+ // Information on the replica management scheme.
+ ReplicaManagementInfoPB rmi;
+ rmi.set_replacement_scheme(FLAGS_raft_prepare_replacement_before_eviction
+ ? ReplicaManagementInfoPB::PREPARE_REPLACEMENT_BEFORE_EVICTION
+ : ReplicaManagementInfoPB::EVICT_FIRST);
+
for (int i = 0; i < cluster_->num_masters(); ++i) {
TSHeartbeatRequestPB req;
TSHeartbeatResponsePB resp;
@@ -124,6 +133,7 @@ class MasterCertAuthorityTest : public KuduTest {
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
MiniMaster* m = cluster_->mini_master(i);
if (!m->is_started()) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/746d0a5c/src/kudu/integration-tests/master_replication-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/master_replication-itest.cc b/src/kudu/integration-tests/master_replication-itest.cc
index f75bca5..a521ee0 100644
--- a/src/kudu/integration-tests/master_replication-itest.cc
+++ b/src/kudu/integration-tests/master_replication-itest.cc
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
+#include <gflags/gflags_declare.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
@@ -29,6 +30,7 @@
#include "kudu/client/shared_ptr.h"
#include "kudu/common/common.pb.h"
#include "kudu/common/wire_protocol.pb.h"
+#include "kudu/consensus/replica_management.pb.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/port.h"
#include "kudu/gutil/ref_counted.h"
@@ -50,9 +52,20 @@
#include "kudu/util/test_util.h"
#include "kudu/util/thread.h"
+DECLARE_bool(raft_prepare_replacement_before_eviction);
+
+using kudu::client::KuduClient;
+using kudu::client::KuduClientBuilder;
+using kudu::client::KuduColumnSchema;
+using kudu::client::KuduSchema;
+using kudu::client::KuduSchemaBuilder;
+using kudu::client::KuduTableCreator;
+using kudu::client::sp::shared_ptr;
+using kudu::consensus::ReplicaManagementInfoPB;
+using kudu::cluster::InternalMiniCluster;
+using kudu::cluster::InternalMiniClusterOptions;
using std::string;
using std::vector;
-
using strings::Substitute;
namespace kudu {
@@ -60,16 +73,6 @@ namespace master {
class TSDescriptor;
-using client::KuduClient;
-using client::KuduClientBuilder;
-using client::KuduColumnSchema;
-using client::KuduSchema;
-using client::KuduSchemaBuilder;
-using client::KuduTableCreator;
-using client::sp::shared_ptr;
-using cluster::InternalMiniCluster;
-using cluster::InternalMiniClusterOptions;
-
const char * const kTableId1 = "testMasterReplication-1";
const char * const kTableId2 = "testMasterReplication-2";
@@ -253,6 +256,13 @@ TEST_F(MasterReplicationTest, TestHeartbeatAcceptedByAnyMaster) {
std::shared_ptr<rpc::Messenger> messenger;
rpc::MessengerBuilder bld("Client");
ASSERT_OK(bld.Build(&messenger));
+
+ // Information on replica management scheme.
+ ReplicaManagementInfoPB rmi;
+ rmi.set_replacement_scheme(FLAGS_raft_prepare_replacement_before_eviction
+ ? ReplicaManagementInfoPB::PREPARE_REPLACEMENT_BEFORE_EVICTION
+ : ReplicaManagementInfoPB::EVICT_FIRST);
+
for (int i = 0; i < cluster_->num_masters(); i++) {
TSHeartbeatRequestPB req;
TSHeartbeatResponsePB resp;
@@ -260,6 +270,7 @@ TEST_F(MasterReplicationTest, TestHeartbeatAcceptedByAnyMaster) {
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
const auto& addr = cluster_->mini_master(i)->bound_rpc_addr();
MasterServiceProxy proxy(messenger, addr, addr.host());
http://git-wip-us.apache.org/repos/asf/kudu/blob/746d0a5c/src/kudu/master/master-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/master-test.cc b/src/kudu/master/master-test.cc
index de0af5c..726b29f 100644
--- a/src/kudu/master/master-test.cc
+++ b/src/kudu/master/master-test.cc
@@ -40,6 +40,7 @@
#include "kudu/common/wire_protocol.h"
#include "kudu/common/wire_protocol.pb.h"
#include "kudu/consensus/consensus.pb.h"
+#include "kudu/consensus/replica_management.pb.h"
#include "kudu/generated/version_defines.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/map-util.h"
@@ -72,6 +73,7 @@
#include "kudu/util/test_util.h"
#include "kudu/util/version_info.h"
+using kudu::consensus::ReplicaManagementInfoPB;
using kudu::pb_util::SecureDebugString;
using kudu::pb_util::SecureShortDebugString;
using kudu::rpc::Messenger;
@@ -89,6 +91,7 @@ using std::vector;
using strings::Substitute;
DECLARE_bool(catalog_manager_check_ts_count_for_create_table);
+DECLARE_bool(raft_prepare_replacement_before_eviction);
DECLARE_double(sys_catalog_fail_during_write);
namespace kudu {
@@ -158,7 +161,7 @@ TEST_F(MasterTest, TestShutdownWithoutStart) {
}
TEST_F(MasterTest, TestRegisterAndHeartbeat) {
- const char *kTsUUID = "my-ts-uuid";
+ const char* const kTsUUID = "my-ts-uuid";
TSToMasterCommonPB common;
common.mutable_ts_instance()->set_permanent_uuid(kTsUUID);
@@ -173,6 +176,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
req.mutable_common()->CopyFrom(common);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_TRUE(resp.leader_master());
ASSERT_TRUE(resp.needs_reregister());
ASSERT_TRUE(resp.needs_full_tablet_report());
@@ -192,14 +196,22 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
MakeHostPortPB("localhost", 2000, fake_reg.add_http_addresses());
fake_reg.set_software_version(VersionInfo::GetVersionInfo());
+ // Information on replica management scheme.
+ ReplicaManagementInfoPB rmi;
+ rmi.set_replacement_scheme(FLAGS_raft_prepare_replacement_before_eviction
+ ? ReplicaManagementInfoPB::PREPARE_REPLACEMENT_BEFORE_EVICTION
+ : ReplicaManagementInfoPB::EVICT_FIRST);
+
{
TSHeartbeatRequestPB req;
TSHeartbeatResponsePB resp;
RpcController rpc;
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_TRUE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -225,8 +237,10 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
RpcController rpc;
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_TRUE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -242,8 +256,10 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
RpcController rpc;
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_FALSE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -263,6 +279,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
tr->set_sequence_number(0);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_FALSE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -281,6 +298,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
tr->set_sequence_number(0);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_TRUE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -298,6 +316,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
tr->set_sequence_number(0);
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
ASSERT_TRUE(resp.leader_master());
ASSERT_FALSE(resp.needs_reregister());
ASSERT_FALSE(resp.needs_full_tablet_report());
@@ -316,7 +335,9 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
ListTabletServersResponsePB resp;
RpcController rpc;
ASSERT_OK(proxy_->ListTabletServers(req, &resp, &rpc));
+
LOG(INFO) << SecureDebugString(resp);
+ ASSERT_FALSE(resp.has_error());
ASSERT_EQ(1, resp.servers_size());
ASSERT_EQ("my-ts-uuid", resp.servers(0).instance_id().permanent_uuid());
ASSERT_EQ(1, resp.servers(0).instance_id().instance_seqno());
@@ -351,11 +372,13 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
RpcController rpc;
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
// This string should never match the actual VersionInfo string, although
// the numeric portion will match.
req.mutable_registration()->set_software_version(Substitute("kudu $0 (rev SOME_NON_GIT_HASH)",
KUDU_VERSION_STRING));
ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_FALSE(resp.has_error());
}
// Ensure that trying to re-register with a different port fails.
@@ -365,6 +388,7 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
RpcController rpc;
req.mutable_common()->CopyFrom(common);
req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
req.mutable_registration()->mutable_rpc_addresses(0)->set_port(1001);
Status s = proxy_->TSHeartbeat(req, &resp, &rpc);
ASSERT_TRUE(s.IsRemoteError());
@@ -372,6 +396,39 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
"Tablet server my-ts-uuid is attempting to re-register "
"with a different host/port.");
}
+
+ // Ensure an attempt to register fails if the tablet server uses the replica
+ // management scheme which is different from the scheme that
+ // the catalog manager uses.
+ {
+ ServerRegistrationPB fake_reg;
+ MakeHostPortPB("localhost", 3000, fake_reg.add_rpc_addresses());
+ MakeHostPortPB("localhost", 4000, fake_reg.add_http_addresses());
+
+ // Set replica management scheme to something different that master uses
+ // (here, it's just inverted).
+ ReplicaManagementInfoPB rmi;
+ rmi.set_replacement_scheme(FLAGS_raft_prepare_replacement_before_eviction
+ ? ReplicaManagementInfoPB::EVICT_FIRST
+ : ReplicaManagementInfoPB::PREPARE_REPLACEMENT_BEFORE_EVICTION);
+
+ TSHeartbeatRequestPB req;
+ req.mutable_common()->CopyFrom(common);
+ req.mutable_registration()->CopyFrom(fake_reg);
+ req.mutable_replica_management_info()->CopyFrom(rmi);
+
+ TSHeartbeatResponsePB resp;
+ RpcController rpc;
+ ASSERT_OK(proxy_->TSHeartbeat(req, &resp, &rpc));
+ ASSERT_TRUE(resp.has_error());
+ const Status s = StatusFromPB(resp.error().status());
+ ASSERT_TRUE(s.IsConfigurationError()) << s.ToString();
+ const string msg = Substitute(
+ "replica replacement scheme (.*) of the tablet server $0 "
+ "at .*:[0-9]+ differs from the catalog manager's (.*); "
+ "they must be run with the same scheme", kTsUUID);
+ ASSERT_STR_MATCHES(s.ToString(), msg);
+ }
}
Status MasterTest::CreateTable(const string& table_name,