kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] 02/02: [tserver] include ip:port in the tserver name
Date Wed, 18 Sep 2019 16:12:30 GMT
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit c55b6b5f79eb15943ac9e49ae935acd5fe28f161
Author: helifu <hzhelifu@corp.netease.com>
AuthorDate: Mon Sep 16 14:54:52 2019 +0800

    [tserver] include ip:port in the tserver name
    
    Consolidate implementation of ToString() for Master and TabletServer
    into RpcServer. And include IP:Port info in the TabletServer name at
    the same time.
    
    Change-Id: Ic6b0d8e29b6cac5a900923b881f0d7a74facbd6e
    Reviewed-on: http://gerrit.cloudera.org:8080/14232
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 src/kudu/master/master.cc         | 13 +++----------
 src/kudu/master/master.h          |  3 ---
 src/kudu/server/rpc_server.cc     | 10 ++++++++--
 src/kudu/tserver/tablet_server.cc | 24 +++++++++++-------------
 src/kudu/tserver/tablet_server.h  |  8 +++++++-
 5 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/kudu/master/master.cc b/src/kudu/master/master.cc
index 4fb8b8f..053b00a 100644
--- a/src/kudu/master/master.cc
+++ b/src/kudu/master/master.cc
@@ -127,13 +127,6 @@ Master::~Master() {
   CHECK_NE(kRunning, state_);
 }
 
-string Master::ToString() const {
-  if (state_ != kRunning) {
-    return "Master (stopped)";
-  }
-  return strings::Substitute("Master@$0", first_rpc_address().ToString());
-}
-
 Status Master::Init() {
   CHECK_EQ(kStopped, state_);
 
@@ -243,8 +236,8 @@ Status Master::WaitUntilCatalogManagerIsLeaderAndReadyForTests(const MonoDelta&
 
 void Master::Shutdown() {
   if (state_ == kRunning) {
-    string name = ToString();
-    LOG(INFO) << name << " shutting down...";
+    const string name = rpc_server_->ToString();
+    LOG(INFO) << "Master@" << name << " shutting down...";
 
     // 1. Stop accepting new RPCs.
     UnregisterAllServices();
@@ -255,7 +248,7 @@ void Master::Shutdown() {
 
     // 3. Shut down generic subsystems.
     KuduServer::Shutdown();
-    LOG(INFO) << name << " shutdown complete.";
+    LOG(INFO) << "Master@" << name << " shutdown complete.";
   }
   state_ = kStopped;
 }
diff --git a/src/kudu/master/master.h b/src/kudu/master/master.h
index 077aabd..0b3c66b 100644
--- a/src/kudu/master/master.h
+++ b/src/kudu/master/master.h
@@ -20,7 +20,6 @@
 #include <atomic>
 #include <cstdint>
 #include <memory>
-#include <string>
 #include <vector>
 
 #include "kudu/common/wire_protocol.pb.h"
@@ -74,8 +73,6 @@ class Master : public kserver::KuduServer {
   Status WaitUntilCatalogManagerIsLeaderAndReadyForTests(const MonoDelta& timeout)
       WARN_UNUSED_RESULT;
 
-  std::string ToString() const;
-
   MasterCertAuthority* cert_authority() { return cert_authority_.get(); }
 
   security::TokenSigner* token_signer() { return token_signer_.get(); }
diff --git a/src/kudu/server/rpc_server.cc b/src/kudu/server/rpc_server.cc
index 1c6eeab..ec5a135 100644
--- a/src/kudu/server/rpc_server.cc
+++ b/src/kudu/server/rpc_server.cc
@@ -30,6 +30,7 @@
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/ref_counted.h"
+#include "kudu/gutil/strings/join.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/rpc/acceptor_pool.h"
 #include "kudu/rpc/messenger.h"
@@ -104,8 +105,13 @@ RpcServer::~RpcServer() {
 }
 
 string RpcServer::ToString() const {
-  // TODO: include port numbers, etc.
-  return "RpcServer";
+  if (PREDICT_FALSE(UNINITIALIZED == server_state_)) {
+    return options_.rpc_bind_addresses;
+  }
+
+  return JoinMapped(rpc_bind_addresses_,
+                    [] (const Sockaddr& sock_addr) { return sock_addr.ToString(); },
+                    ",");
 }
 
 Status RpcServer::Init(const shared_ptr<Messenger>& messenger) {
diff --git a/src/kudu/tserver/tablet_server.cc b/src/kudu/tserver/tablet_server.cc
index b7a5356..c6513e7 100644
--- a/src/kudu/tserver/tablet_server.cc
+++ b/src/kudu/tserver/tablet_server.cc
@@ -31,6 +31,7 @@
 #include "kudu/gutil/bind_helpers.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/rpc/service_if.h"
+#include "kudu/server/rpc_server.h"
 #include "kudu/tserver/heartbeater.h"
 #include "kudu/tserver/scanners.h"
 #include "kudu/tserver/tablet_copy_service.h"
@@ -52,7 +53,7 @@ namespace tserver {
 
 TabletServer::TabletServer(const TabletServerOptions& opts)
   : KuduServer("TabletServer", opts, "kudu.tabletserver"),
-    initted_(false),
+    state_(kStopped),
     fail_heartbeats_for_tests_(false),
     opts_(opts),
     tablet_manager_(new TSTabletManager(this)),
@@ -64,13 +65,8 @@ TabletServer::~TabletServer() {
   Shutdown();
 }
 
-string TabletServer::ToString() const {
-  // TODO: include port numbers, etc.
-  return "TabletServer";
-}
-
 Status TabletServer::Init() {
-  CHECK(!initted_);
+  CHECK_EQ(kStopped, state_);
 
   cfile::BlockCache::GetSingleton()->StartInstrumentation(metric_entity());
 
@@ -113,7 +109,7 @@ Status TabletServer::Init() {
   RETURN_NOT_OK_PREPEND(scanner_manager_->StartRemovalThread(),
                         "Could not start expired Scanner removal thread");
 
-  initted_ = true;
+  state_ = kInitialized;
   return Status::OK();
 }
 
@@ -122,7 +118,7 @@ Status TabletServer::WaitInited() {
 }
 
 Status TabletServer::Start() {
-  CHECK(initted_);
+  CHECK_EQ(kInitialized, state_);
 
   fs_manager_->SetErrorNotificationCb(ErrorHandlerType::DISK_ERROR,
       Bind(&TSTabletManager::FailTabletsInDataDir, Unretained(tablet_manager_.get())));
@@ -146,13 +142,14 @@ Status TabletServer::Start() {
 
   google::FlushLogFiles(google::INFO); // Flush the startup messages.
 
+  state_ = kRunning;
   return Status::OK();
 }
 
 void TabletServer::Shutdown() {
-  if (initted_) {
-    string name = ToString();
-    LOG(INFO) << name << " shutting down...";
+  if (kInitialized == state_ || kRunning == state_) {
+    const string name = rpc_server_->ToString();
+    LOG(INFO) << "TabletServer@" << name << " shutting down...";
 
     // 1. Stop accepting new RPCs.
     UnregisterAllServices();
@@ -166,8 +163,9 @@ void TabletServer::Shutdown() {
 
     // 3. Shut down generic subsystems.
     KuduServer::Shutdown();
-    LOG(INFO) << name << " shutdown complete.";
+    LOG(INFO) << "TabletServer@" << name << " shutdown complete.";
   }
+  state_ = kStopped;
 }
 
 } // namespace tserver
diff --git a/src/kudu/tserver/tablet_server.h b/src/kudu/tserver/tablet_server.h
index 9af1b2f..343a1de 100644
--- a/src/kudu/tserver/tablet_server.h
+++ b/src/kudu/tserver/tablet_server.h
@@ -85,7 +85,13 @@ class TabletServer : public kserver::KuduServer {
  private:
   friend class TabletServerTestBase;
 
-  bool initted_;
+  enum TabletServerState {
+    kStopped,
+    kInitialized,
+    kRunning
+  };
+
+  TabletServerState state_;
 
   // If true, all heartbeats will be seen as failed.
   Atomic32 fail_heartbeats_for_tests_;


Mime
View raw message