kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject [3/3] incubator-kudu git commit: KUDU-966. Construct and cache the master registration PB at startup
Date Thu, 04 Feb 2016 23:42:12 GMT
KUDU-966. Construct and cache the master registration PB at startup

On some clusters, calls to determine the FQDN can run very slowly if the DNS is
not set up properly. This can cause GetMasterRegistration RPCs to take several
seconds, and cause the master to basically fall over.

This moves the call to construct the registration protobuf into the startup
sequence, so that the RPC can be satisfied by a simple copy from the
cached value.

No new tests since this is a performance improvement which is only visible
on machines with broken DNS.

Change-Id: I79bac224d905cad579a6f4fa6552b8ea17af6b4a
Reviewed-on: http://gerrit.cloudera.org:8080/2053
Reviewed-by: Jean-Daniel Cryans
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: 1ad16aa0b742a75b86152cd7034f150674070606
Parents: b0b051b
Author: Todd Lipcon <todd@apache.org>
Authored: Thu Feb 4 15:04:48 2016 -0800
Committer: Jean-Daniel Cryans <jdcryans@gerrit.cloudera.org>
Committed: Thu Feb 4 23:39:30 2016 +0000

----------------------------------------------------------------------
 src/kudu/master/master.cc | 23 +++++++++++++++++++++--
 src/kudu/master/master.h  | 18 +++++++++++++-----
 2 files changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/1ad16aa0/src/kudu/master/master.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.cc b/src/kudu/master/master.cc
index 6efa1ff..c3c46f3 100644
--- a/src/kudu/master/master.cc
+++ b/src/kudu/master/master.cc
@@ -67,6 +67,7 @@ Master::Master(const MasterOptions& opts)
     catalog_manager_(new CatalogManager(this)),
     path_handlers_(new MasterPathHandlers(this)),
     opts_(opts),
+    registration_initialized_(false),
     maintenance_manager_(new MaintenanceManager(MaintenanceManager::DEFAULT_OPTIONS)) {
 }
 
@@ -116,6 +117,9 @@ Status Master::StartAsync() {
   RETURN_NOT_OK(ServerBase::RegisterService(consensus_service.Pass()));
   RETURN_NOT_OK(ServerBase::Start());
 
+  // Now that we've bound, construct our ServerRegistrationPB.
+  RETURN_NOT_OK(InitMasterRegistration());
+
   // Start initializing the catalog manager.
   RETURN_NOT_OK(init_pool_->SubmitClosure(Bind(&Master::InitCatalogManagerTask,
                                                Unretained(this))));
@@ -178,13 +182,28 @@ void Master::Shutdown() {
 }
 
 Status Master::GetMasterRegistration(ServerRegistrationPB* reg) const {
+  if (!registration_initialized_.load(std::memory_order_acquire)) {
+    return Status::ServiceUnavailable("Master startup not complete");
+  }
+  reg->CopyFrom(registration_);
+  return Status::OK();
+}
+
+Status Master::InitMasterRegistration() {
+  CHECK(!registration_initialized_.load());
+
+  ServerRegistrationPB reg;
   vector<Sockaddr> rpc_addrs;
   RETURN_NOT_OK_PREPEND(rpc_server()->GetBoundAddresses(&rpc_addrs),
                         "Couldn't get RPC addresses");
-  RETURN_NOT_OK(AddHostPortPBs(rpc_addrs, reg->mutable_rpc_addresses()));
+  RETURN_NOT_OK(AddHostPortPBs(rpc_addrs, reg.mutable_rpc_addresses()));
   vector<Sockaddr> http_addrs;
   web_server()->GetBoundAddresses(&http_addrs);
-  RETURN_NOT_OK(AddHostPortPBs(http_addrs, reg->mutable_http_addresses()));
+  RETURN_NOT_OK(AddHostPortPBs(http_addrs, reg.mutable_http_addresses()));
+
+  registration_.Swap(&reg);
+  registration_initialized_.store(true);
+
   return Status::OK();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/1ad16aa0/src/kudu/master/master.h
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.h b/src/kudu/master/master.h
index 30627cf..b3296b5 100644
--- a/src/kudu/master/master.h
+++ b/src/kudu/master/master.h
@@ -17,8 +17,9 @@
 #ifndef KUDU_MASTER_MASTER_H
 #define KUDU_MASTER_MASTER_H
 
-#include <string>
+#include <atomic>
 #include <memory>
+#include <string>
 #include <vector>
 
 #include "kudu/gutil/gscoped_ptr.h"
@@ -36,7 +37,6 @@ class MaintenanceManager;
 class RpcServer;
 struct RpcServerOptions;
 class ServerEntryPB;
-class ServerRegistrationPB;
 class ThreadPool;
 
 namespace rpc {
@@ -103,15 +103,19 @@ class Master : public server::ServerBase {
  private:
   friend class MasterTest;
 
+  void InitCatalogManagerTask();
+  Status InitCatalogManager();
+
+  // Initialize registration_.
+  // Requires that the web server and RPC server have been started.
+  Status InitMasterRegistration();
+
   enum MasterState {
     kStopped,
     kInitialized,
     kRunning
   };
 
-  void InitCatalogManagerTask();
-  Status InitCatalogManager();
-
   MasterState state_;
 
   gscoped_ptr<TSManager> ts_manager_;
@@ -127,6 +131,10 @@ class Master : public server::ServerBase {
 
   MasterOptions opts_;
 
+  ServerRegistrationPB registration_;
+  // True once registration_ has been initialized.
+  std::atomic<bool> registration_initialized_;
+
   // The maintenance manager for this master.
   std::shared_ptr<MaintenanceManager> maintenance_manager_;
 


Mime
View raw message