kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/6] kudu git commit: mini-cluster: new module for the mini cluster implementations
Date Mon, 02 Oct 2017 19:25:19 GMT
http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/mini-cluster/mini_cluster.cc
----------------------------------------------------------------------
diff --git a/src/kudu/mini-cluster/mini_cluster.cc b/src/kudu/mini-cluster/mini_cluster.cc
new file mode 100644
index 0000000..1da43e5
--- /dev/null
+++ b/src/kudu/mini-cluster/mini_cluster.cc
@@ -0,0 +1,57 @@
+// 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.
+
+#include "kudu/mini-cluster/mini_cluster.h"
+
+#include <unistd.h>
+
+#include <cstdint>
+#include <ostream>
+#include <string>
+
+#include <glog/logging.h>
+
+#include "kudu/gutil/strings/substitute.h"
+
+using std::string;
+using strings::Substitute;
+
+namespace kudu {
+namespace cluster {
+
+string MiniCluster::GetBindIpForDaemon(DaemonType type, int index, BindMode bind_mode) {
+  switch (bind_mode) {
+    case UNIQUE_LOOPBACK: {
+      // IP address last octet range: [1 - 254].
+      uint8_t last_octet = (type == TSERVER) ? index + 1 : UINT8_MAX - 1 - index;
+      CHECK_GE(last_octet, 1);
+      CHECK_LE(last_octet, 254);
+      pid_t p = getpid();
+      CHECK_LE(p, UINT16_MAX) << "Cannot run on systems with >16-bit pid";
+      return Substitute("127.$0.$1.$2", p >> 8, p & 0xff, last_octet);
+    }
+    case WILDCARD:
+      return kWildcardIpAddr;
+    case LOOPBACK:
+      return kLoopbackIpAddr;
+    default:
+      LOG(FATAL) << bind_mode;
+  }
+}
+
+} // namespace cluster
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/mini-cluster/mini_cluster.h
----------------------------------------------------------------------
diff --git a/src/kudu/mini-cluster/mini_cluster.h b/src/kudu/mini-cluster/mini_cluster.h
new file mode 100644
index 0000000..8a1440c
--- /dev/null
+++ b/src/kudu/mini-cluster/mini_cluster.h
@@ -0,0 +1,161 @@
+// 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.
+#pragma once
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "kudu/client/shared_ptr.h"
+#include "kudu/util/status.h"
+
+namespace kudu {
+
+class HostPort;
+
+namespace client {
+class KuduClient;
+class KuduClientBuilder;
+} // namespace client
+
+namespace master {
+class MasterServiceProxy;
+} // namespace master
+
+namespace rpc {
+class Messenger;
+} // namespace rpc
+
+namespace cluster {
+
+// Mode to which node types a certain action (like Shutdown()) should apply.
+enum class ClusterNodes {
+  ALL,
+  MASTERS_ONLY,
+  TS_ONLY
+};
+
+// Base class for MiniCluster implementations. Provides some commonly-used
+// virtual methods that allow for abstracting the details of whether the
+// mini-cluster implementation is in-process or out-of-process.
+class MiniCluster {
+ public:
+  // BindMode lets you specify the socket binding mode for RPC and/or HTTP server.
+  // A) LOOPBACK binds each server to loopback ip address "127.0.0.1".
+  //
+  // B) WILDCARD specifies "0.0.0.0" as the ip to bind to, which means sockets
+  // can be bound to any interface on the local host.
+  // For example, if a host has two interfaces with addresses
+  // 192.168.0.10 and 192.168.0.11, the server process can accept connection
+  // requests addressed to 192.168.0.10 or 192.168.0.11.
+  //
+  // C) UNIQUE_LOOPBACK binds each tablet server to a different loopback address.
+  // This affects the server's RPC server, and also forces the server to
+  // only use this IP address for outgoing socket connections as well.
+  // This allows the use of iptables on the localhost to simulate network
+  // partitions.
+  //
+  // The addresses used are 127.<A>.<B>.<C> where:
+  // - <A,B> are the high and low bytes of the pid of the process running the
+  //   minicluster (not the daemon itself).
+  // - <C> is the index of the server within this minicluster.
+  //
+  // This requires that the system is set up such that processes may bind
+  // to any IP address in the localhost netblock (127.0.0.0/8). This seems
+  // to be the case on common Linux distributions. You can verify by running
+  // 'ip addr | grep 127.0.0.1' and checking that the address is listed as
+  // '127.0.0.1/8'.
+  //
+  // Note: UNIQUE_LOOPBACK is not supported on macOS.
+  //
+  // Default: UNIQUE_LOOPBACK on Linux, LOOPBACK on macOS.
+  enum BindMode {
+    UNIQUE_LOOPBACK,
+    WILDCARD,
+    LOOPBACK
+  };
+
+#if defined(__APPLE__)
+  static constexpr const BindMode kDefaultBindMode = BindMode::LOOPBACK;
+#else
+  static constexpr const BindMode kDefaultBindMode = BindMode::UNIQUE_LOOPBACK;
+#endif
+
+  enum DaemonType {
+    MASTER,
+    TSERVER
+  };
+
+  static constexpr const char* const kWildcardIpAddr = "0.0.0.0";
+  static constexpr const char* const kLoopbackIpAddr = "127.0.0.1";
+
+  MiniCluster() {}
+  virtual ~MiniCluster() {}
+
+  // Start the cluster.
+  virtual Status Start() = 0;
+
+  // Convenience method for shutting down the whole cluster.
+  virtual void Shutdown() final {
+    ShutdownNodes(ClusterNodes::ALL);
+  }
+
+  // Shuts down the whole cluster or part of it, depending on the selected
+  // 'nodes'.
+  virtual void ShutdownNodes(ClusterNodes nodes) = 0;
+
+  virtual int num_masters() const = 0;
+
+  virtual int num_tablet_servers() const = 0;
+
+  virtual BindMode bind_mode() const = 0;
+
+  virtual std::vector<uint16_t> master_rpc_ports() const = 0;
+
+  virtual std::vector<HostPort> master_rpc_addrs() const = 0;
+
+  // Create a client configured to talk to this cluster. 'builder' may contain
+  // override options for the client. The master address will be overridden to
+  // talk to the running master(s). If 'builder' is a nullptr, default options
+  // will be used.
+  //
+  // REQUIRES: the cluster must have already been Start()ed.
+  virtual Status CreateClient(client::KuduClientBuilder* builder,
+                              client::sp::shared_ptr<client::KuduClient>* client) const
= 0;
+
+  // Return a messenger for use by clients.
+  virtual std::shared_ptr<rpc::Messenger> messenger() const = 0;
+
+  // If the cluster is configured for a single non-distributed master,
+  // return a proxy to that master. Requires that the single master is
+  // running.
+  virtual std::shared_ptr<master::MasterServiceProxy> master_proxy() const = 0;
+
+  // Returns an RPC proxy to the master at 'idx'. Requires that the
+  // master at 'idx' is running.
+  virtual std::shared_ptr<master::MasterServiceProxy> master_proxy(int idx) const =
0;
+
+ protected:
+  // Return the IP address that the daemon with the given index will bind to.
+  // If bind_mode is LOOPBACK, this will be 127.0.0.1 and if it is WILDCARD it
+  // will be 0.0.0.0. Otherwise, it is another IP in the local netblock.
+  static std::string GetBindIpForDaemon(DaemonType type, int index, BindMode bind_mode);
+};
+
+} // namespace cluster
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/tools/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/tools/CMakeLists.txt b/src/kudu/tools/CMakeLists.txt
index c1fb353..9d289dd 100644
--- a/src/kudu/tools/CMakeLists.txt
+++ b/src/kudu/tools/CMakeLists.txt
@@ -100,6 +100,7 @@ set(KUDU_TEST_LINK_LIBS
   kudu_tools_util
   kudu_tools_test_util
   integration-tests
+  mini-cluster
   ${KUDU_MIN_TEST_LIBS})
 ADD_KUDU_TEST(ksck-test)
 ADD_KUDU_TEST(ksck_remote-test RESOURCE_LOCK "master-rpc-ports")

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/tools/ksck_remote-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/ksck_remote-test.cc b/src/kudu/tools/ksck_remote-test.cc
index f413554..2f64c38 100644
--- a/src/kudu/tools/ksck_remote-test.cc
+++ b/src/kudu/tools/ksck_remote-test.cc
@@ -34,8 +34,8 @@
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/ref_counted.h"
-#include "kudu/integration-tests/internal_mini_cluster.h"
 #include "kudu/master/mini_master.h"
+#include "kudu/mini-cluster/internal_mini_cluster.h"
 #include "kudu/tools/data_gen_util.h"
 #include "kudu/tools/ksck.h"
 #include "kudu/tools/ksck_remote.h"
@@ -61,6 +61,8 @@ using client::KuduSession;
 using client::KuduTable;
 using client::KuduTableCreator;
 using client::sp::shared_ptr;
+using cluster::InternalMiniCluster;
+using cluster::InternalMiniClusterOptions;
 using std::string;
 using std::unique_ptr;
 using std::vector;

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/tools/kudu-admin-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-admin-test.cc b/src/kudu/tools/kudu-admin-test.cc
index c36734b..70cf4e7 100644
--- a/src/kudu/tools/kudu-admin-test.cc
+++ b/src/kudu/tools/kudu-admin-test.cc
@@ -49,9 +49,9 @@
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/integration-tests/cluster_itest_util.h"
 #include "kudu/integration-tests/cluster_verifier.h"
-#include "kudu/integration-tests/external_mini_cluster.h"
 #include "kudu/integration-tests/test_workload.h"
 #include "kudu/integration-tests/ts_itest-base.h"
+#include "kudu/mini-cluster/external_mini_cluster.h"
 #include "kudu/tools/tool_test_util.h"
 #include "kudu/tserver/tablet_server-test-base.h"
 #include "kudu/util/monotime.h"
@@ -69,6 +69,7 @@ using client::KuduClientBuilder;
 using client::KuduSchema;
 using client::KuduTableCreator;
 using client::sp::shared_ptr;
+using cluster::ExternalTabletServer;
 using consensus::COMMITTED_OPID;
 using consensus::ConsensusStatePB;
 using consensus::OpId;

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/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 62e7b6e..1779cef 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -72,11 +72,11 @@
 #include "kudu/gutil/strings/strip.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/integration-tests/cluster_itest_util.h"
-#include "kudu/integration-tests/external_mini_cluster.h"
 #include "kudu/integration-tests/external_mini_cluster_fs_inspector.h"
-#include "kudu/integration-tests/internal_mini_cluster.h"
-#include "kudu/integration-tests/mini_cluster.h"
 #include "kudu/integration-tests/test_workload.h"
+#include "kudu/mini-cluster/external_mini_cluster.h"
+#include "kudu/mini-cluster/internal_mini_cluster.h"
+#include "kudu/mini-cluster/mini_cluster.h"
 #include "kudu/rpc/rpc_controller.h"
 #include "kudu/tablet/local_tablet_writer.h"
 #include "kudu/tablet/metadata.pb.h"
@@ -123,6 +123,10 @@ using cfile::CFileWriter;
 using cfile::StringDataGenerator;
 using cfile::WriterOptions;
 using client::sp::shared_ptr;
+using cluster::ExternalMiniCluster;
+using cluster::ExternalMiniClusterOptions;
+using cluster::InternalMiniCluster;
+using cluster::InternalMiniClusterOptions;
 using consensus::OpId;
 using consensus::RECEIVED_OPID;
 using consensus::ReplicateRefPtr;
@@ -1359,7 +1363,7 @@ TEST_F(ToolTest, TestRemoteReplicaCopy) {
   // on the tablet servers in the cluster giving us the test coverage
   // for KUDU-1776. With this, 'kudu remote_replica copy' can be used to
   // connect to tablet servers bound to wildcard ip addresses.
-  cluster_opts_.bind_mode = MiniCluster::WILDCARD;
+  cluster_opts_.bind_mode = cluster::MiniCluster::WILDCARD;
   NO_FATALS(StartExternalMiniCluster(
       {"--catalog_manager_wait_for_new_tablets_to_elect_leader=false"},
       {"--enable_leader_failure_detection=false"}, kNumTservers));

http://git-wip-us.apache.org/repos/asf/kudu/blob/350c8a79/src/kudu/tools/kudu-ts-cli-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-ts-cli-test.cc b/src/kudu/tools/kudu-ts-cli-test.cc
index 91163aa..1143185 100644
--- a/src/kudu/tools/kudu-ts-cli-test.cc
+++ b/src/kudu/tools/kudu-ts-cli-test.cc
@@ -26,9 +26,9 @@
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/integration-tests/cluster_itest_util.h"
 #include "kudu/integration-tests/external_mini_cluster-itest-base.h"
-#include "kudu/integration-tests/external_mini_cluster.h"
 #include "kudu/integration-tests/external_mini_cluster_fs_inspector.h"
 #include "kudu/integration-tests/test_workload.h"
+#include "kudu/mini-cluster/external_mini_cluster.h"
 #include "kudu/tablet/metadata.pb.h"
 #include "kudu/tablet/tablet.pb.h"
 #include "kudu/tools/tool_test_util.h"


Mime
View raw message