kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/3] kudu git commit: [location_awareness] Add 'location' column in tserver list
Date Wed, 05 Sep 2018 16:00:38 GMT
[location_awareness] Add 'location' column in tserver list

Command:
kudu tserver list -columns=uuid,location <master_addresses>

Example result:
                uuid              |   location
----------------------------------+--------------
 1259764cdc5f489984900d49b545802f | loc0
 14446895a8bf47cd92e73836de623ffb | <none>
 9d7a11e19b324f62b2e6d074f6003ca4 | loc1

This command will list the location of each tserver. If the
location of the tserver has not been set, '<none>' will be
displayed.

Change-Id: If6c9dc8bd08b8d907111fac850fc6fd2c2b96fb8
Reviewed-on: http://gerrit.cloudera.org:8080/11313
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
Reviewed-by: Will Berkeley <wdberkeley@gmail.com>


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

Branch: refs/heads/master
Commit: 6b70c275f6636e5e07a56d4ffa371cd8604a6c50
Parents: 17c5d73
Author: fwang29 <fwang@cloudera.com>
Authored: Thu Aug 23 19:09:13 2018 -0700
Committer: Will Berkeley <wdberkeley@gmail.com>
Committed: Wed Sep 5 14:39:31 2018 +0000

----------------------------------------------------------------------
 src/kudu/master/master.proto              |  1 +
 src/kudu/master/master_service.cc         |  2 ++
 src/kudu/tools/CMakeLists.txt             |  3 ++-
 src/kudu/tools/kudu-tool-test.cc          | 31 ++++++++++++++++++++++++++
 src/kudu/tools/testdata/first_argument.sh | 20 +++++++++++++++++
 src/kudu/tools/tool_action_tserver.cc     |  5 +++++
 6 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/master/master.proto
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.proto b/src/kudu/master/master.proto
index 9754af5..a2eff06 100644
--- a/src/kudu/master/master.proto
+++ b/src/kudu/master/master.proto
@@ -702,6 +702,7 @@ message ListTabletServersResponsePB {
     required NodeInstancePB instance_id = 1;
     optional ServerRegistrationPB registration = 2;
     optional int32 millis_since_heartbeat = 3;
+    optional string location = 4;
   }
   repeated Entry servers = 2;
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/master/master_service.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/master_service.cc b/src/kudu/master/master_service.cc
index 3e19929..ef1edb5 100644
--- a/src/kudu/master/master_service.cc
+++ b/src/kudu/master/master_service.cc
@@ -23,6 +23,7 @@
 #include <utility>
 #include <vector>
 
+#include <boost/optional/optional.hpp>
 #include <gflags/gflags.h>
 #include <gflags/gflags_declare.h>
 #include <glog/logging.h>
@@ -418,6 +419,7 @@ void MasterServiceImpl::ListTabletServers(const ListTabletServersRequestPB*
req,
     desc->GetNodeInstancePB(entry->mutable_instance_id());
     desc->GetRegistration(entry->mutable_registration());
     entry->set_millis_since_heartbeat(desc->TimeSinceHeartbeat().ToMilliseconds());
+    if (desc->location()) entry->set_location(desc->location().get());
   }
   rpc->RespondSuccess();
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/tools/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tools/CMakeLists.txt b/src/kudu/tools/CMakeLists.txt
index 8b36461..97310f9 100644
--- a/src/kudu/tools/CMakeLists.txt
+++ b/src/kudu/tools/CMakeLists.txt
@@ -171,7 +171,8 @@ ADD_KUDU_TEST_DEPENDENCIES(kudu-admin-test
   kudu)
 ADD_KUDU_TEST(kudu-tool-test
   NUM_SHARDS 4 PROCESSORS 3
-  DATA_FILES testdata/sample-diagnostics-log.txt testdata/bad-diagnostics-log.txt)
+  DATA_FILES testdata/sample-diagnostics-log.txt testdata/bad-diagnostics-log.txt
+  DATA_FILES testdata/first_argument.sh)
 ADD_KUDU_TEST_DEPENDENCIES(kudu-tool-test
   kudu)
 ADD_KUDU_TEST(kudu-ts-cli-test)

http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 4a0be3a..28180c4 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -2069,6 +2069,37 @@ TEST_F(ToolTest, TestTserverList) {
   }
 }
 
+TEST_F(ToolTest, TestTserverListLocationAssigned) {
+  const string kLocationCmdPath = JoinPathSegments(GetTestExecutableDirectory(),
+                                                   "testdata/first_argument.sh");
+  const string location = "/foo-bar0/BAAZ._9-quux";
+  ExternalMiniClusterOptions opts;
+  opts.extra_master_flags.emplace_back(
+        Substitute("--location_mapping_cmd=$0 $1", kLocationCmdPath, location));
+
+  NO_FATALS(StartExternalMiniCluster(opts));
+
+  string master_addr = cluster_->master()->bound_rpc_addr().ToString();
+
+  string out;
+  NO_FATALS(RunActionStdoutString(
+        Substitute("tserver list $0 --columns=uuid,location --format=csv", master_addr),
&out));
+
+  ASSERT_STR_CONTAINS(out, cluster_->tablet_server(0)->uuid() + "," + location);
+}
+
+TEST_F(ToolTest, TestTserverListLocationNotAssigned) {
+  NO_FATALS(StartExternalMiniCluster());
+
+  string master_addr = cluster_->master()->bound_rpc_addr().ToString();
+
+  string out;
+  NO_FATALS(RunActionStdoutString(
+        Substitute("tserver list $0 --columns=uuid,location --format=csv", master_addr),
&out));
+
+  ASSERT_STR_CONTAINS(out, cluster_->tablet_server(0)->uuid() + ",<none>");
+}
+
 TEST_F(ToolTest, TestMasterList) {
   ExternalMiniClusterOptions opts;
   opts.num_tablet_servers = 0;

http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/tools/testdata/first_argument.sh
----------------------------------------------------------------------
diff --git a/src/kudu/tools/testdata/first_argument.sh b/src/kudu/tools/testdata/first_argument.sh
new file mode 100644
index 0000000..832908c
--- /dev/null
+++ b/src/kudu/tools/testdata/first_argument.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# A script that prints the first argument and ignores all the others.
+echo "$1"

http://git-wip-us.apache.org/repos/asf/kudu/blob/6b70c275/src/kudu/tools/tool_action_tserver.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_tserver.cc b/src/kudu/tools/tool_action_tserver.cc
index 03e007f..7e2f261 100644
--- a/src/kudu/tools/tool_action_tserver.cc
+++ b/src/kudu/tools/tool_action_tserver.cc
@@ -138,6 +138,11 @@ Status ListTServers(const RunnerContext& context) {
       for (const auto& server : servers) {
         values.emplace_back(strings::Substitute("$0ms", server.millis_since_heartbeat()));
       }
+    } else if (boost::iequals(column, "location")) {
+      for (const auto& server : servers) {
+        string loc = server.location();
+        values.emplace_back(loc.empty() ? "<none>" : std::move(loc));
+      }
     } else {
       return Status::InvalidArgument("unknown column (--columns)", column);
     }


Mime
View raw message