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 c0cd1045f7905826c59a33cb3dd196eb2e582d48 Author: Alexey Serbin <[email protected]> AuthorDate: Mon Oct 12 23:27:39 2020 -0700 [client] robust handling of absent master address(es) This patch updates Kudu C++ client with robust handling of the absence of master addresses prior to connection attempt to a Kudu cluster. Before to this patch, KuduClientBuilder::Build() would hang in ConnectToCluster(). After this patch, KuduClientBuilder::Build() instantly returns Status::InvalidArgument() if no master addresses are provided. This patch also contains a test for the new behavior. Change-Id: I4c7400d09298c01cd0b349cc2b9f481d1214f148 Reviewed-on: http://gerrit.cloudera.org:8080/16589 Reviewed-by: Grant Henke <[email protected]> Tested-by: Grant Henke <[email protected]> --- src/kudu/client/client-internal.cc | 4 ++++ src/kudu/client/client-test.cc | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/kudu/client/client-internal.cc b/src/kudu/client/client-internal.cc index afd961a..1f23ccd 100644 --- a/src/kudu/client/client-internal.cc +++ b/src/kudu/client/client-internal.cc @@ -686,6 +686,10 @@ void KuduClient::Data::ConnectToClusterAsync(KuduClient* client, CredentialsPolicy creds_policy) { DCHECK(deadline.Initialized()); + if (master_server_addrs_.empty()) { + cb(Status::InvalidArgument("no master address specified")); + } + vector<pair<Sockaddr, string>> master_addrs_with_names; for (const string& master_server_addr : master_server_addrs_) { vector<Sockaddr> addrs; diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc index 4c76efe..ca89a7a 100644 --- a/src/kudu/client/client-test.cc +++ b/src/kudu/client/client-test.cc @@ -857,6 +857,17 @@ TEST_F(ClientTest, TestBadTable) { ASSERT_STR_CONTAINS(s.ToString(), "Not found: the table does not exist"); } +// If no master address is specified, KuduClientBuilder::Build() should +// immediately return corresponding status code instead of stalling with +// ConnectToCluster() for a long time. +TEST_F(ClientTest, ConnectToClusterNoMasterAddressSpecified) { + shared_ptr<KuduClient> c; + KuduClientBuilder b; + auto s = b.Build(&c); + ASSERT_TRUE(s.IsInvalidArgument()) << s.ToString(); + ASSERT_STR_CONTAINS(s.ToString(), "no master address specified"); +} + // Test that, if the master is down, we experience a network error talking // to it (no "find the new leader master" since there's only one master). TEST_F(ClientTest, TestMasterDown) {
