kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/3] kudu git commit: [mini-cluster] allow 18-bit PID in LOOPBACK bind mode
Date Wed, 01 Nov 2017 05:00:18 GMT
Repository: kudu
Updated Branches:
  refs/heads/master edae025c4 -> f2c21b4fa


[mini-cluster] allow 18-bit PID in LOOPBACK bind mode

This changelist allows to use 18-bit PIDs for binding in LOOPBACK mode.
Prior to this patch, the minicluster could not use PIDs wider
than 16 bits.

While expanding the range of acceptable PIDs, this changelist also
decreases the maximum allowed number of 'indexed servers' from 254
to 62.  As of now, that's enough for our minicluster-based tests.

The incentive to put up this patch was change of the max PID
up to 147456 in /proc/sys/kernel/pid_max after recent restart of
one of our build servers.

Change-Id: I958729d71ed363e98bea99f3d932cc6b0546e130
Reviewed-on: http://gerrit.cloudera.org:8080/8422
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


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

Branch: refs/heads/master
Commit: 0bd8800b77a5de53b5db896df20abb83ff2e1779
Parents: edae025
Author: Alexey Serbin <aserbin@cloudera.com>
Authored: Mon Oct 30 15:39:30 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Wed Nov 1 04:43:07 2017 +0000

----------------------------------------------------------------------
 src/kudu/mini-cluster/mini_cluster.cc | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/0bd8800b/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
index 1da43e5..b477e79 100644
--- a/src/kudu/mini-cluster/mini_cluster.cc
+++ b/src/kudu/mini-cluster/mini_cluster.cc
@@ -34,15 +34,28 @@ namespace kudu {
 namespace cluster {
 
 string MiniCluster::GetBindIpForDaemon(DaemonType type, int index, BindMode bind_mode) {
+  static const int kPidBits = 18;
+  static const int kServerIdxBits = 24 - kPidBits;
+  static const int kServersMaxNum = (1 << kServerIdxBits) - 2;
+  CHECK(0 <= index && index < kServersMaxNum) << Substitute(
+      "server index $0 is not in range [$1, $2)", index, 0, kServersMaxNum);
+
   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);
+      uint32_t pid = getpid();
+      CHECK_LT(pid, 1 << kPidBits) << Substitute(
+          "PID $0 is more than $1 bits wide", pid, kPidBits);
+      int idx = (type == TSERVER) ? index + 1 : kServersMaxNum - index;
+      uint32_t ip = (pid << kServerIdxBits) | static_cast<uint32_t>(idx);
+      uint8_t octets[] = {
+          static_cast<uint8_t>((ip >> 16) & 0xff),
+          static_cast<uint8_t>((ip >>  8) & 0xff),
+          static_cast<uint8_t>((ip >>  0) & 0xff),
+      };
+      // Range for the last octet of a valid unicast IP address is (0, 255).
+      CHECK(0 < octets[2] && octets[2] < UINT8_MAX) << Substitute(
+          "last IP octet $0 is not in range ($1, $2)", octets[2], 0, UINT8_MAX);
+      return Substitute("127.$0.$1.$2", octets[0], octets[1], octets[2]);
     }
     case WILDCARD:
       return kWildcardIpAddr;


Mime
View raw message