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 ba7c64f  [mini-cluster] built-in NTP client configuration mode
ba7c64f is described below

commit ba7c64f255eebbffe540cdb0c7b5779eb8a564ab
Author: Alexey Serbin <[email protected]>
AuthorDate: Fri Feb 14 16:25:46 2020 -0800

    [mini-cluster] built-in NTP client configuration mode
    
    This patch introduces configuration mode for the built-in NTP client
    in the scope of Kudu external mini-cluster.
    
    Prior to this patch, the only way to configure the built-in NTP client
    in a Kudu external mini-cluster was using all available test NTP servers
    as reference servers.  With this patch, it's now possible to point
    different tablet servers and masters to different NTP servers run
    as a part of a test mini-cluster.
    
    A follow-up patch will use the newly introduced mode for a new test.
    
    Change-Id: I88561f757678b664b810b54a27317cac99297403
    Reviewed-on: http://gerrit.cloudera.org:8080/15238
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <[email protected]>
---
 src/kudu/mini-cluster/external_mini_cluster.cc | 37 +++++++++++++++++-------
 src/kudu/mini-cluster/external_mini_cluster.h  | 40 +++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/src/kudu/mini-cluster/external_mini_cluster.cc 
b/src/kudu/mini-cluster/external_mini_cluster.cc
index 54eae8f..2d47c70 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.cc
+++ b/src/kudu/mini-cluster/external_mini_cluster.cc
@@ -123,6 +123,7 @@ ExternalMiniClusterOptions::ExternalMiniClusterOptions()
       rpc_negotiation_timeout(MonoDelta::FromSeconds(3))
 #if !defined(NO_CHRONY)
       , num_ntp_servers(1)
+      , ntp_config_mode(BuiltinNtpConfigMode::ALL_SERVERS)
 #endif // #if !defined(NO_CHRONY) ...
 {
 }
@@ -167,19 +168,31 @@ Status ExternalMiniCluster::HandleOptions() {
   return Status::OK();
 }
 
-Status ExternalMiniCluster::AddTimeSourceFlags(std::vector<std::string>* 
flags) {
+Status ExternalMiniCluster::AddTimeSourceFlags(
+    int idx, std::vector<std::string>* flags) {
+  DCHECK_LE(0, idx);
   DCHECK(flags);
+  CHECK_LE(0, opts_.num_ntp_servers);
 #if defined(NO_CHRONY)
   flags->emplace_back("--time_source=system_unsync");
 #else
-  if (opts_.num_ntp_servers > 0) {
+  if (opts_.num_ntp_servers == 0) {
+    flags->emplace_back("--time_source=system_unsync");
+  } else {
     vector<string> ntp_endpoints;
     CHECK_EQ(opts_.num_ntp_servers, ntp_servers_.size());
-    for (const auto& server : ntp_servers_) {
-      ntp_endpoints.emplace_back(server->address().ToString());
+    // Point the built-in NTP client to the test NTP servers.
+    switch (opts_.ntp_config_mode) {
+      case BuiltinNtpConfigMode::ALL_SERVERS:
+        for (const auto& server : ntp_servers_) {
+          ntp_endpoints.emplace_back(server->address().ToString());
+        }
+        break;
+      case BuiltinNtpConfigMode::ROUND_ROBIN_SINGLE_SERVER:
+        ntp_endpoints.emplace_back(
+            ntp_servers_[idx % opts_.num_ntp_servers]->address().ToString());
+        break;
     }
-    // Point the built-in NTP client to the test NTP server running as a part
-    // of the cluster.
     flags->emplace_back(Substitute("--builtin_ntp_servers=$0",
                                    JoinStrings(ntp_endpoints, ",")));
     // The chronyd server supports very short polling interval: let's use this
@@ -192,8 +205,6 @@ Status 
ExternalMiniCluster::AddTimeSourceFlags(std::vector<std::string>* flags)
     // Switch the clock to use the built-in NTP client which clock is
     // synchronized with the test NTP server.
     flags->emplace_back("--time_source=builtin");
-  } else {
-    flags->emplace_back("--time_source=system_unsync");
   }
 #endif // #if defined(NO_CHRONY) ... else ...
   return Status::OK();
@@ -548,7 +559,6 @@ Status ExternalMiniCluster::StartMasters() {
     flags.emplace_back("--location_mapping_by_uuid");
 #   endif
   }
-  RETURN_NOT_OK(AddTimeSourceFlags(&flags));
 
   // Add custom master flags.
   copy(opts_.extra_master_flags.begin(), opts_.extra_master_flags.end(),
@@ -570,6 +580,13 @@ Status ExternalMiniCluster::StartMasters() {
       opts.perf_record_filename =
           Substitute("$0/perf-$1.data", opts.log_dir, daemon_id);
     }
+
+    vector<string> time_source_flags;
+    RETURN_NOT_OK(AddTimeSourceFlags(i, &time_source_flags));
+    // Custom flags come last because they can contain overrides.
+    flags.insert(flags.begin(),
+                 time_source_flags.begin(), time_source_flags.end());
+
     opts.extra_flags = SubstituteInFlags(flags, i);
     opts.start_process_timeout = opts_.start_process_timeout;
     opts.rpc_bind_address = master_rpc_addrs[i];
@@ -636,7 +653,7 @@ Status ExternalMiniCluster::AddTabletServer() {
         Substitute("$0/perf-$1.data", opts.log_dir, daemon_id);
   }
   vector<string> extra_flags;
-  RETURN_NOT_OK(AddTimeSourceFlags(&extra_flags));
+  RETURN_NOT_OK(AddTimeSourceFlags(idx, &extra_flags));
   auto flags = SubstituteInFlags(opts_.extra_tserver_flags, idx);
   copy(flags.begin(), flags.end(), std::back_inserter(extra_flags));
   opts.extra_flags = extra_flags;
diff --git a/src/kudu/mini-cluster/external_mini_cluster.h 
b/src/kudu/mini-cluster/external_mini_cluster.h
index 5b7b81d..dccc0d1 100644
--- a/src/kudu/mini-cluster/external_mini_cluster.h
+++ b/src/kudu/mini-cluster/external_mini_cluster.h
@@ -94,6 +94,35 @@ class ExternalTabletServer;
 // Location --> number of tablet servers in location.
 typedef std::map<std::string, int> LocationInfo;
 
+#if !defined(NO_CHRONY)
+// The enumeration below describes the way Kudu's built-in NTP client is
+// configured given the set of dedicated NTP servers run by the mini-cluster.
+enum class BuiltinNtpConfigMode {
+  // Each server (master/tserver) uses all available NTP servers for its
+  // built-in NTP client. For example, given 3 tservers and 2 NTP servers:
+  //
+  // tserver index | NTP server indices
+  // ----------------------------------
+  //   0           |  0 1
+  //   1           |  0 1
+  //   2           |  0 1
+  ALL_SERVERS,
+
+  // Each server (master/tserver) uses a single NTP server. The assignment runs
+  // in a round-robin manner. For example, given 5 tservers and 2 NTP servers:
+  //
+  // tserver index | NTP server indices
+  // ----------------------------------
+  //   0           |  0
+  //   1           |  1
+  //   2           |  0
+  //   3           |  1
+  //   4           |  0
+  //
+  ROUND_ROBIN_SINGLE_SERVER,
+};
+#endif
+
 struct ExternalMiniClusterOptions {
   ExternalMiniClusterOptions();
 
@@ -200,6 +229,12 @@ struct ExternalMiniClusterOptions {
   //
   // Default: 0
   int num_ntp_servers;
+
+  // Mapping of NTP servers to built-in NTP client for each Kudu server.
+  // This parameter is effective iff num_ntp_servers > 0.
+  //
+  // Default: BuiltinNtpConfigMode::ALL_SERVERS
+  BuiltinNtpConfigMode ntp_config_mode;
 #endif // #if !defined(NO_CHRONY) ...
 };
 
@@ -434,7 +469,10 @@ class ExternalMiniCluster : public MiniCluster {
 
   Status DeduceBinRoot(std::string* ret);
   Status HandleOptions();
-  Status AddTimeSourceFlags(std::vector<std::string>* flags);
+
+  // Add flags related to time source and clock for the daemon at index 'idx'.
+  // The time source flags are appended to the 'flags' in-out parameter.
+  Status AddTimeSourceFlags(int idx, std::vector<std::string>* flags);
 
   ExternalMiniClusterOptions opts_;
 

Reply via email to