You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2014/11/19 18:31:27 UTC
[1/5] hbase git commit: Patch up Jetty to disable SSLv3
(CVE-2014-3566)
Repository: hbase
Updated Branches:
refs/heads/0.98 2db279046 -> 1591fa9f1
refs/heads/branch-1 bfe5f2442 -> 865ffebfc
refs/heads/master 640274d5e -> 05ced20a3
Patch up Jetty to disable SSLv3 (CVE-2014-3566)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3f95fe22
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3f95fe22
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3f95fe22
Branch: refs/heads/master
Commit: 3f95fe22e0b8bbcf332766af039d041d3fc8189b
Parents: 640274d
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Wed Nov 19 16:40:18 2014 +0000
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Wed Nov 19 16:40:18 2014 +0000
----------------------------------------------------------------------
.../apache/hadoop/hbase/http/HttpServer.java | 2 +-
.../hbase/http/SslSocketConnectorSecure.java | 58 ++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/3f95fe22/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
index 9de02f0..68524ab 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
@@ -356,7 +356,7 @@ public class HttpServer implements FilterContainer {
if ("http".equals(scheme)) {
listener = HttpServer.createDefaultChannelConnector();
} else if ("https".equals(scheme)) {
- SslSocketConnector c = new SslSocketConnector();
+ SslSocketConnector c = new SslSocketConnectorSecure();
c.setNeedClientAuth(needsClientAuth);
c.setKeyPassword(keyPassword);
http://git-wip-us.apache.org/repos/asf/hbase/blob/3f95fe22/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
new file mode 100644
index 0000000..2d78a3f
--- /dev/null
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.hbase.http;
+
+import org.mortbay.jetty.security.SslSocketConnector;
+
+import javax.net.ssl.SSLServerSocket;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+
+/**
+ * This subclass of the Jetty SslSocketConnector exists solely to control
+ * the TLS protocol versions allowed. This is fallout from the POODLE
+ * vulnerability (CVE-2014-3566), which requires that SSLv3 be disabled.
+ * Only TLS 1.0 and later protocols are allowed.
+ */
+public class SslSocketConnectorSecure extends SslSocketConnector {
+
+ public SslSocketConnectorSecure() {
+ super();
+ }
+
+ /**
+ * Create a new ServerSocket that will not accept SSLv3 connections,
+ * but will accept TLSv1.x connections.
+ */
+ protected ServerSocket newServerSocket(String host, int port,int backlog)
+ throws IOException {
+ SSLServerSocket socket = (SSLServerSocket)
+ super.newServerSocket(host, port, backlog);
+ ArrayList<String> nonSSLProtocols = new ArrayList<String>();
+ for (String p : socket.getEnabledProtocols()) {
+ if (!p.contains("SSLv3")) {
+ nonSSLProtocols.add(p);
+ }
+ }
+ socket.setEnabledProtocols(nonSSLProtocols.toArray(
+ new String[nonSSLProtocols.size()]));
+ return socket;
+ }
+}
[3/5] hbase git commit: Patch up Jetty to disable SSLv3
(CVE-2014-3566)
Posted by mb...@apache.org.
Patch up Jetty to disable SSLv3 (CVE-2014-3566)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/6e376b90
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/6e376b90
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/6e376b90
Branch: refs/heads/branch-1
Commit: 6e376b900e125f71a71fd2a25c3ad08057b97f73
Parents: bfe5f24
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Wed Nov 19 16:40:18 2014 +0000
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Wed Nov 19 16:51:19 2014 +0000
----------------------------------------------------------------------
.../apache/hadoop/hbase/http/HttpServer.java | 2 +-
.../hbase/http/SslSocketConnectorSecure.java | 58 ++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/6e376b90/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
index 9de02f0..68524ab 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
@@ -356,7 +356,7 @@ public class HttpServer implements FilterContainer {
if ("http".equals(scheme)) {
listener = HttpServer.createDefaultChannelConnector();
} else if ("https".equals(scheme)) {
- SslSocketConnector c = new SslSocketConnector();
+ SslSocketConnector c = new SslSocketConnectorSecure();
c.setNeedClientAuth(needsClientAuth);
c.setKeyPassword(keyPassword);
http://git-wip-us.apache.org/repos/asf/hbase/blob/6e376b90/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
new file mode 100644
index 0000000..2d78a3f
--- /dev/null
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/http/SslSocketConnectorSecure.java
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.hbase.http;
+
+import org.mortbay.jetty.security.SslSocketConnector;
+
+import javax.net.ssl.SSLServerSocket;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+
+/**
+ * This subclass of the Jetty SslSocketConnector exists solely to control
+ * the TLS protocol versions allowed. This is fallout from the POODLE
+ * vulnerability (CVE-2014-3566), which requires that SSLv3 be disabled.
+ * Only TLS 1.0 and later protocols are allowed.
+ */
+public class SslSocketConnectorSecure extends SslSocketConnector {
+
+ public SslSocketConnectorSecure() {
+ super();
+ }
+
+ /**
+ * Create a new ServerSocket that will not accept SSLv3 connections,
+ * but will accept TLSv1.x connections.
+ */
+ protected ServerSocket newServerSocket(String host, int port,int backlog)
+ throws IOException {
+ SSLServerSocket socket = (SSLServerSocket)
+ super.newServerSocket(host, port, backlog);
+ ArrayList<String> nonSSLProtocols = new ArrayList<String>();
+ for (String p : socket.getEnabledProtocols()) {
+ if (!p.contains("SSLv3")) {
+ nonSSLProtocols.add(p);
+ }
+ }
+ socket.setEnabledProtocols(nonSSLProtocols.toArray(
+ new String[nonSSLProtocols.size()]));
+ return socket;
+ }
+}
[2/5] hbase git commit: HBASE-12529 Use ThreadLocalRandom for
RandomQueueBalancer
Posted by mb...@apache.org.
HBASE-12529 Use ThreadLocalRandom for RandomQueueBalancer
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/05ced20a
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/05ced20a
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/05ced20a
Branch: refs/heads/master
Commit: 05ced20a347213c31e46c528e53b93c675f85891
Parents: 3f95fe2
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Wed Nov 19 16:50:29 2014 +0000
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Wed Nov 19 16:50:29 2014 +0000
----------------------------------------------------------------------
.../hbase/ipc/BalancedQueueRpcExecutor.java | 48 +-------------------
.../hadoop/hbase/ipc/RWQueueRpcExecutor.java | 14 ++++--
.../apache/hadoop/hbase/ipc/RpcExecutor.java | 44 ++++++++++++++++++
3 files changed, 54 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/05ced20a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
index 40ba9fe..2418cf7 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
@@ -28,8 +28,6 @@ import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.util.ReflectionUtils;
-import com.google.common.base.Preconditions;
-
/**
* An {@link RpcExecutor} that will balance requests evenly across all its queues, but still remains
* efficient with a single queue via an inlinable queue balancing mechanism.
@@ -39,7 +37,7 @@ import com.google.common.base.Preconditions;
public class BalancedQueueRpcExecutor extends RpcExecutor {
protected final List<BlockingQueue<CallRunner>> queues;
- private QueueBalancer balancer;
+ private final QueueBalancer balancer;
public BalancedQueueRpcExecutor(final String name, final int handlerCount, final int numQueues,
final int maxQueueLength) {
@@ -80,48 +78,4 @@ public class BalancedQueueRpcExecutor extends RpcExecutor {
public List<BlockingQueue<CallRunner>> getQueues() {
return queues;
}
-
- private static abstract class QueueBalancer {
- /**
- * @return the index of the next queue to which a request should be inserted
- */
- public abstract int getNextQueue();
- }
-
- public static QueueBalancer getBalancer(int queueSize) {
- Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
- if (queueSize == 1) {
- return ONE_QUEUE;
- } else {
- return new RandomQueueBalancer(queueSize);
- }
- }
-
- /**
- * All requests go to the first queue, at index 0
- */
- private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
-
- @Override
- public int getNextQueue() {
- return 0;
- }
- };
-
- /**
- * Queue balancer that just randomly selects a queue in the range [0, num queues).
- */
- private static class RandomQueueBalancer extends QueueBalancer {
- private int queueSize;
- private Random random;
-
- public RandomQueueBalancer(int queueSize) {
- this.queueSize = queueSize;
- this.random = new Random();
- }
-
- public int getNextQueue() {
- return random.nextInt(queueSize);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/05ced20a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
index 4f0448d..deac2f8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.ipc;
import java.util.ArrayList;
import java.util.List;
-import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -50,7 +49,9 @@ public class RWQueueRpcExecutor extends RpcExecutor {
private static final Log LOG = LogFactory.getLog(RWQueueRpcExecutor.class);
private final List<BlockingQueue<CallRunner>> queues;
- private final Random balancer = new Random();
+ private final QueueBalancer writeBalancer;
+ private final QueueBalancer readBalancer;
+ private final QueueBalancer scanBalancer;
private final int writeHandlersCount;
private final int readHandlersCount;
private final int scanHandlersCount;
@@ -115,6 +116,9 @@ public class RWQueueRpcExecutor extends RpcExecutor {
this.numWriteQueues = numWriteQueues;
this.numReadQueues = numReadQueues;
this.numScanQueues = numScanQueues;
+ this.writeBalancer = getBalancer(numWriteQueues);
+ this.readBalancer = getBalancer(numReadQueues);
+ this.scanBalancer = getBalancer(numScanQueues);
queues = new ArrayList<BlockingQueue<CallRunner>>(writeHandlersCount + readHandlersCount);
LOG.debug(name + " writeQueues=" + numWriteQueues + " writeHandlers=" + writeHandlersCount +
@@ -146,11 +150,11 @@ public class RWQueueRpcExecutor extends RpcExecutor {
RpcServer.Call call = callTask.getCall();
int queueIndex;
if (isWriteRequest(call.getHeader(), call.param)) {
- queueIndex = balancer.nextInt(numWriteQueues);
+ queueIndex = writeBalancer.getNextQueue();
} else if (numScanQueues > 0 && isScanRequest(call.getHeader(), call.param)) {
- queueIndex = numWriteQueues + numReadQueues + balancer.nextInt(numScanQueues);
+ queueIndex = numWriteQueues + numReadQueues + scanBalancer.getNextQueue();
} else {
- queueIndex = numWriteQueues + balancer.nextInt(numReadQueues);
+ queueIndex = numWriteQueues + readBalancer.getNextQueue();
}
queues.get(queueIndex).put(callTask);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/05ced20a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
index 5fe2590..1b0934c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
@@ -22,12 +22,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
@InterfaceAudience.Private
@@ -124,4 +126,46 @@ public abstract class RpcExecutor {
}
}
}
+
+ public static abstract class QueueBalancer {
+ /**
+ * @return the index of the next queue to which a request should be inserted
+ */
+ public abstract int getNextQueue();
+ }
+
+ public static QueueBalancer getBalancer(int queueSize) {
+ Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
+ if (queueSize == 1) {
+ return ONE_QUEUE;
+ } else {
+ return new RandomQueueBalancer(queueSize);
+ }
+ }
+
+ /**
+ * All requests go to the first queue, at index 0
+ */
+ private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
+
+ @Override
+ public int getNextQueue() {
+ return 0;
+ }
+ };
+
+ /**
+ * Queue balancer that just randomly selects a queue in the range [0, num queues).
+ */
+ private static class RandomQueueBalancer extends QueueBalancer {
+ private final int queueSize;
+
+ public RandomQueueBalancer(int queueSize) {
+ this.queueSize = queueSize;
+ }
+
+ public int getNextQueue() {
+ return ThreadLocalRandom.current().nextInt(queueSize);
+ }
+ }
}
[4/5] hbase git commit: HBASE-12529 Use ThreadLocalRandom for
RandomQueueBalancer
Posted by mb...@apache.org.
HBASE-12529 Use ThreadLocalRandom for RandomQueueBalancer
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/865ffebf
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/865ffebf
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/865ffebf
Branch: refs/heads/branch-1
Commit: 865ffebfc6989c79ff84a43ddb39df8067a28d8b
Parents: 6e376b9
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Wed Nov 19 16:50:29 2014 +0000
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Wed Nov 19 16:51:26 2014 +0000
----------------------------------------------------------------------
.../hbase/ipc/BalancedQueueRpcExecutor.java | 48 +-------------------
.../hadoop/hbase/ipc/RWQueueRpcExecutor.java | 14 ++++--
.../apache/hadoop/hbase/ipc/RpcExecutor.java | 44 ++++++++++++++++++
3 files changed, 54 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/865ffebf/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
index 40ba9fe..2418cf7 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
@@ -28,8 +28,6 @@ import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.util.ReflectionUtils;
-import com.google.common.base.Preconditions;
-
/**
* An {@link RpcExecutor} that will balance requests evenly across all its queues, but still remains
* efficient with a single queue via an inlinable queue balancing mechanism.
@@ -39,7 +37,7 @@ import com.google.common.base.Preconditions;
public class BalancedQueueRpcExecutor extends RpcExecutor {
protected final List<BlockingQueue<CallRunner>> queues;
- private QueueBalancer balancer;
+ private final QueueBalancer balancer;
public BalancedQueueRpcExecutor(final String name, final int handlerCount, final int numQueues,
final int maxQueueLength) {
@@ -80,48 +78,4 @@ public class BalancedQueueRpcExecutor extends RpcExecutor {
public List<BlockingQueue<CallRunner>> getQueues() {
return queues;
}
-
- private static abstract class QueueBalancer {
- /**
- * @return the index of the next queue to which a request should be inserted
- */
- public abstract int getNextQueue();
- }
-
- public static QueueBalancer getBalancer(int queueSize) {
- Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
- if (queueSize == 1) {
- return ONE_QUEUE;
- } else {
- return new RandomQueueBalancer(queueSize);
- }
- }
-
- /**
- * All requests go to the first queue, at index 0
- */
- private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
-
- @Override
- public int getNextQueue() {
- return 0;
- }
- };
-
- /**
- * Queue balancer that just randomly selects a queue in the range [0, num queues).
- */
- private static class RandomQueueBalancer extends QueueBalancer {
- private int queueSize;
- private Random random;
-
- public RandomQueueBalancer(int queueSize) {
- this.queueSize = queueSize;
- this.random = new Random();
- }
-
- public int getNextQueue() {
- return random.nextInt(queueSize);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/865ffebf/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
index 4f0448d..deac2f8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.ipc;
import java.util.ArrayList;
import java.util.List;
-import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -50,7 +49,9 @@ public class RWQueueRpcExecutor extends RpcExecutor {
private static final Log LOG = LogFactory.getLog(RWQueueRpcExecutor.class);
private final List<BlockingQueue<CallRunner>> queues;
- private final Random balancer = new Random();
+ private final QueueBalancer writeBalancer;
+ private final QueueBalancer readBalancer;
+ private final QueueBalancer scanBalancer;
private final int writeHandlersCount;
private final int readHandlersCount;
private final int scanHandlersCount;
@@ -115,6 +116,9 @@ public class RWQueueRpcExecutor extends RpcExecutor {
this.numWriteQueues = numWriteQueues;
this.numReadQueues = numReadQueues;
this.numScanQueues = numScanQueues;
+ this.writeBalancer = getBalancer(numWriteQueues);
+ this.readBalancer = getBalancer(numReadQueues);
+ this.scanBalancer = getBalancer(numScanQueues);
queues = new ArrayList<BlockingQueue<CallRunner>>(writeHandlersCount + readHandlersCount);
LOG.debug(name + " writeQueues=" + numWriteQueues + " writeHandlers=" + writeHandlersCount +
@@ -146,11 +150,11 @@ public class RWQueueRpcExecutor extends RpcExecutor {
RpcServer.Call call = callTask.getCall();
int queueIndex;
if (isWriteRequest(call.getHeader(), call.param)) {
- queueIndex = balancer.nextInt(numWriteQueues);
+ queueIndex = writeBalancer.getNextQueue();
} else if (numScanQueues > 0 && isScanRequest(call.getHeader(), call.param)) {
- queueIndex = numWriteQueues + numReadQueues + balancer.nextInt(numScanQueues);
+ queueIndex = numWriteQueues + numReadQueues + scanBalancer.getNextQueue();
} else {
- queueIndex = numWriteQueues + balancer.nextInt(numReadQueues);
+ queueIndex = numWriteQueues + readBalancer.getNextQueue();
}
queues.get(queueIndex).put(callTask);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/865ffebf/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
index 5fe2590..1b0934c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
@@ -22,12 +22,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
@InterfaceAudience.Private
@@ -124,4 +126,46 @@ public abstract class RpcExecutor {
}
}
}
+
+ public static abstract class QueueBalancer {
+ /**
+ * @return the index of the next queue to which a request should be inserted
+ */
+ public abstract int getNextQueue();
+ }
+
+ public static QueueBalancer getBalancer(int queueSize) {
+ Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
+ if (queueSize == 1) {
+ return ONE_QUEUE;
+ } else {
+ return new RandomQueueBalancer(queueSize);
+ }
+ }
+
+ /**
+ * All requests go to the first queue, at index 0
+ */
+ private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
+
+ @Override
+ public int getNextQueue() {
+ return 0;
+ }
+ };
+
+ /**
+ * Queue balancer that just randomly selects a queue in the range [0, num queues).
+ */
+ private static class RandomQueueBalancer extends QueueBalancer {
+ private final int queueSize;
+
+ public RandomQueueBalancer(int queueSize) {
+ this.queueSize = queueSize;
+ }
+
+ public int getNextQueue() {
+ return ThreadLocalRandom.current().nextInt(queueSize);
+ }
+ }
}
[5/5] hbase git commit: HBASE-12529 Use ThreadLocalRandom for
RandomQueueBalancer
Posted by mb...@apache.org.
HBASE-12529 Use ThreadLocalRandom for RandomQueueBalancer
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1591fa9f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1591fa9f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1591fa9f
Branch: refs/heads/0.98
Commit: 1591fa9f14713f54f9912ba171d7bb30e5c7aabe
Parents: 2db2790
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Wed Nov 19 17:29:45 2014 +0000
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Wed Nov 19 17:29:45 2014 +0000
----------------------------------------------------------------------
.../hbase/ipc/BalancedQueueRpcExecutor.java | 48 +-----------------
.../hadoop/hbase/ipc/RWQueueRpcExecutor.java | 10 ++--
.../apache/hadoop/hbase/ipc/RpcExecutor.java | 52 ++++++++++++++++++++
3 files changed, 59 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/1591fa9f/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
index 40ba9fe..2418cf7 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BalancedQueueRpcExecutor.java
@@ -28,8 +28,6 @@ import org.apache.hadoop.hbase.classification.InterfaceStability;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.util.ReflectionUtils;
-import com.google.common.base.Preconditions;
-
/**
* An {@link RpcExecutor} that will balance requests evenly across all its queues, but still remains
* efficient with a single queue via an inlinable queue balancing mechanism.
@@ -39,7 +37,7 @@ import com.google.common.base.Preconditions;
public class BalancedQueueRpcExecutor extends RpcExecutor {
protected final List<BlockingQueue<CallRunner>> queues;
- private QueueBalancer balancer;
+ private final QueueBalancer balancer;
public BalancedQueueRpcExecutor(final String name, final int handlerCount, final int numQueues,
final int maxQueueLength) {
@@ -80,48 +78,4 @@ public class BalancedQueueRpcExecutor extends RpcExecutor {
public List<BlockingQueue<CallRunner>> getQueues() {
return queues;
}
-
- private static abstract class QueueBalancer {
- /**
- * @return the index of the next queue to which a request should be inserted
- */
- public abstract int getNextQueue();
- }
-
- public static QueueBalancer getBalancer(int queueSize) {
- Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
- if (queueSize == 1) {
- return ONE_QUEUE;
- } else {
- return new RandomQueueBalancer(queueSize);
- }
- }
-
- /**
- * All requests go to the first queue, at index 0
- */
- private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
-
- @Override
- public int getNextQueue() {
- return 0;
- }
- };
-
- /**
- * Queue balancer that just randomly selects a queue in the range [0, num queues).
- */
- private static class RandomQueueBalancer extends QueueBalancer {
- private int queueSize;
- private Random random;
-
- public RandomQueueBalancer(int queueSize) {
- this.queueSize = queueSize;
- this.random = new Random();
- }
-
- public int getNextQueue() {
- return random.nextInt(queueSize);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/1591fa9f/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
index 6df2bf2..ddab8fa 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RWQueueRpcExecutor.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.ipc;
import java.util.ArrayList;
import java.util.List;
-import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -48,7 +47,8 @@ public class RWQueueRpcExecutor extends RpcExecutor {
private static final Log LOG = LogFactory.getLog(RWQueueRpcExecutor.class);
private final List<BlockingQueue<CallRunner>> queues;
- private final Random balancer = new Random();
+ private final QueueBalancer writeBalancer;
+ private final QueueBalancer readBalancer;
private final int writeHandlersCount;
private final int readHandlersCount;
private final int numWriteQueues;
@@ -79,6 +79,8 @@ public class RWQueueRpcExecutor extends RpcExecutor {
this.readHandlersCount = Math.max(readHandlers, numReadQueues);
this.numWriteQueues = numWriteQueues;
this.numReadQueues = numReadQueues;
+ this.writeBalancer = getBalancer(numWriteQueues);
+ this.readBalancer = getBalancer(numReadQueues);
queues = new ArrayList<BlockingQueue<CallRunner>>(writeHandlersCount + readHandlersCount);
LOG.debug(name + " writeQueues=" + numWriteQueues + " writeHandlers=" + writeHandlersCount +
@@ -106,9 +108,9 @@ public class RWQueueRpcExecutor extends RpcExecutor {
RpcServer.Call call = callTask.getCall();
int queueIndex;
if (isWriteRequest(call.getHeader(), call.param)) {
- queueIndex = balancer.nextInt(numWriteQueues);
+ queueIndex = writeBalancer.getNextQueue();
} else {
- queueIndex = numWriteQueues + balancer.nextInt(numReadQueues);
+ queueIndex = numWriteQueues + readBalancer.getNextQueue();
}
queues.get(queueIndex).put(callTask);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/1591fa9f/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
index 68dc063..233c26e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcExecutor.java
@@ -22,12 +22,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
@InterfaceAudience.Private
@@ -127,4 +129,54 @@ public abstract class RpcExecutor {
}
}
}
+
+ public static abstract class QueueBalancer {
+ /**
+ * @return the index of the next queue to which a request should be inserted
+ */
+ public abstract int getNextQueue();
+ }
+
+ public static QueueBalancer getBalancer(int queueSize) {
+ Preconditions.checkArgument(queueSize > 0, "Queue size is <= 0, must be at least 1");
+ if (queueSize == 1) {
+ return ONE_QUEUE;
+ } else {
+ return new RandomQueueBalancer(queueSize);
+ }
+ }
+
+ /**
+ * All requests go to the first queue, at index 0
+ */
+ private static QueueBalancer ONE_QUEUE = new QueueBalancer() {
+
+ @Override
+ public int getNextQueue() {
+ return 0;
+ }
+ };
+
+ /**
+ * Queue balancer that just randomly selects a queue in the range [0, num queues).
+ */
+ private static class RandomQueueBalancer extends QueueBalancer {
+ private final int queueSize;
+
+ private final ThreadLocal<Random> threadRandom =
+ new ThreadLocal<Random>() {
+ @Override
+ protected Random initialValue() {
+ return new Random();
+ }
+ };
+
+ public RandomQueueBalancer(int queueSize) {
+ this.queueSize = queueSize;
+ }
+
+ public int getNextQueue() {
+ return threadRandom.get().nextInt(queueSize);
+ }
+ }
}