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


The following commit(s) were added to refs/heads/master by this push:
     new 158cf0fa0 [ExternalMiniCluster] improve leader_master()
158cf0fa0 is described below

commit 158cf0fa00b86cdaf75f60e520c99920bbe6c8c3
Author: Ádám Bakai <[email protected]>
AuthorDate: Fri Nov 17 14:50:47 2023 +0100

    [ExternalMiniCluster] improve leader_master()
    
    ExternalMiniCluster::leader_master() function was improved to use the
    RPC. However during the dns_alias_itest cases, the host that was stored
    in the masters_[]->bound_rpc_hostport was a domain name, and the RPC
    returns IP address and they are compared as strings. This made
    leader_master() check in ExternalMiniCluster::AddTabletServer() fail.
    The solution is that bound_rpc_hostport values are converted to Sockaddr
    and compared to the leader_master_addr that is retrieved from the
    ConnectToClusterRpc call.
    
    ConnectToFollowerMasterTest::AuthnTokenVerifierHaveKeys was changed so
    it doesn't start any tservers, since leader_master() check can't find
    leader during tablet server initialization.
    
    In master_cert_authority-itest, num of tablet servers was set to zero as
    well because tablet servers are not needed for the test and waiting for
    leader made the test flaky.
    
    Change-Id: I4a40fa8e9513066d08b42eefc57a04ba90bded82
    Reviewed-on: http://gerrit.cloudera.org:8080/20714
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <[email protected]>
---
 .../master_cert_authority-itest.cc                 |  5 ++++
 src/kudu/integration-tests/security-itest.cc       |  3 +++
 src/kudu/mini-cluster/external_mini_cluster.cc     | 30 ++++++++++++++++------
 src/kudu/mini-cluster/external_mini_cluster.h      |  6 +----
 4 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/kudu/integration-tests/master_cert_authority-itest.cc 
b/src/kudu/integration-tests/master_cert_authority-itest.cc
index d4c674b38..f8cc9e033 100644
--- a/src/kudu/integration-tests/master_cert_authority-itest.cc
+++ b/src/kudu/integration-tests/master_cert_authority-itest.cc
@@ -21,6 +21,7 @@
 #include <optional>
 #include <string>
 #include <thread>
+#include <type_traits>
 #include <vector>
 
 #include <gflags/gflags_declare.h>
@@ -362,6 +363,10 @@ class ConnectToClusterBaseTest : public KuduTest {
       : run_time_seconds_(run_time_seconds),
         latency_ms_(latency_ms) {
     cluster_opts_.num_masters = num_masters;
+
+    // Tablet Servers are not needed because the goal of these tests are to 
check that kudu client
+    // succesfully connects to the cluster even if there are big latences or 
election in progress.
+    cluster_opts_.num_tablet_servers = 0;
   }
 
   void SetUp() override {
diff --git a/src/kudu/integration-tests/security-itest.cc 
b/src/kudu/integration-tests/security-itest.cc
index e4c6e5b91..39ae5a793 100644
--- a/src/kudu/integration-tests/security-itest.cc
+++ b/src/kudu/integration-tests/security-itest.cc
@@ -1487,6 +1487,9 @@ TEST_P(ConnectToFollowerMasterTest, 
AuthnTokenVerifierHaveKeys) {
       Substitute("--rpc_encryption=$0", params.rpc_encryption));
   cluster_opts_.extra_tserver_flags.emplace_back(
       Substitute("--rpc_encryption=$0", params.rpc_encryption));
+  // Since leader falure detection is disabled, there is no leader at this 
point, so tablet servers
+  // can not be started.
+  cluster_opts_.num_tablet_servers = 0;
   ASSERT_OK(StartCluster());
 
   const auto& master_host = cluster_->master(0)->bound_rpc_addr().host();
diff --git a/src/kudu/mini-cluster/external_mini_cluster.cc 
b/src/kudu/mini-cluster/external_mini_cluster.cc
index ea621f44e..a935e17c1 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.cc
+++ b/src/kudu/mini-cluster/external_mini_cluster.cc
@@ -76,6 +76,7 @@
 #include "kudu/util/jwt-util.h"
 #include "kudu/util/mini_oidc.h"
 #include "kudu/util/monotime.h"
+#include "kudu/util/net/dns_resolver.h"
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/net/socket.h"
 #include "kudu/util/path_util.h"
@@ -995,6 +996,15 @@ Status ExternalMiniCluster::WaitForTabletsRunning(
   return Status::TimedOut(SecureDebugString(resp));
 }
 
+ExternalMaster* ExternalMiniCluster::leader_master() {
+  int idx = 0;
+  Status s = GetLeaderMasterIndex(&idx);
+  if (!s.ok()) {
+    return nullptr;
+  }
+  return master(idx);
+}
+
 Status ExternalMiniCluster::GetLeaderMasterIndex(int* idx) {
   scoped_refptr<ConnectToClusterRpc> rpc;
   Synchronizer sync;
@@ -1026,18 +1036,22 @@ Status ExternalMiniCluster::GetLeaderMasterIndex(int* 
idx) {
   rpc->SendRpc();
   RETURN_NOT_OK(sync.Wait());
   bool found = false;
-  for (int i = 0; i < masters_.size(); i++) {
-    const auto& bound_hp = masters_[i]->bound_rpc_hostport();
+  DnsResolver dns_resolver;
+  for (int i = 0; i < masters_.size() && !found; i++) {
+    vector<Sockaddr> addresses;
+    
RETURN_NOT_OK(dns_resolver.ResolveAddresses(masters_[i]->bound_rpc_hostport(), 
&addresses));
+    for (const auto& adress : addresses) {
+      if (adress == leader_master_addr) {
+        found = true;
+        *idx = i;
+        break;
+      }
+    }
+
     // If using BindMode::UNIQUE_LOOPBACK mode, in rare cases different masters
     // might bind to different local IP addresses but use same port numbers.
     // So, it's necessary to check both the returned hostnames and IP addresses
     // to point to leader master.
-    if (bound_hp.port() == leader_master_addr.port() &&
-        bound_hp.host() == leader_master_hostname) {
-      found = true;
-      *idx = i;
-      break;
-    }
   }
   if (!found) {
     // There is never a situation where this should happen, so it's
diff --git a/src/kudu/mini-cluster/external_mini_cluster.h 
b/src/kudu/mini-cluster/external_mini_cluster.h
index 47cdfe1cb..b60dcc4d1 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.h
+++ b/src/kudu/mini-cluster/external_mini_cluster.h
@@ -387,11 +387,7 @@ class ExternalMiniCluster : public MiniCluster {
 
   // Return a pointer to the running leader master. This may be NULL
   // if the cluster is not started.
-  //
-  // TODO(unknown): Use the appropriate RPC here to return the leader master,
-  // to allow some of the existing tests (e.g., raft_consensus-itest)
-  // to use multiple masters.
-  ExternalMaster* leader_master() { return master(0); }
+  ExternalMaster* leader_master();
 
   // Perform an RPC to determine the leader of the external mini
   // cluster.  Set 'index' to the leader master's index (for calls to

Reply via email to