Fixed BLUR-339
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/561b49b3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/561b49b3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/561b49b3 Branch: refs/heads/apache-blur-0.2 Commit: 561b49b3c3c1ca325d7f0f803cbcbe086b0944d6 Parents: 928b340 Author: Aaron McCurry <[email protected]> Authored: Tue Jun 17 10:36:31 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Jun 17 10:36:31 2014 -0400 ---------------------------------------------------------------------- .../org/apache/blur/thrift/BlurClientManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/561b49b3/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClientManager.java ---------------------------------------------------------------------- diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClientManager.java b/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClientManager.java index 9aea16f..967bd60 100644 --- a/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClientManager.java +++ b/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClientManager.java @@ -139,23 +139,28 @@ public class BlurClientManager { AtomicInteger retries = new AtomicInteger(); AtomicReference<Blur.Client> client = new AtomicReference<Client>(); List<Connection> shuffledConnections = new ArrayList<Connection>(); - Random random = new Random(); } + private static ThreadLocal<Random> _random = new ThreadLocal<Random>() { + @Override + protected Random initialValue() { + return new Random(); + } + }; + @SuppressWarnings("unchecked") public static <CLIENT, T> T execute(List<Connection> connections, AbstractCommand<CLIENT, T> command, int maxRetries, long backOffTime, long maxBackOffTime) throws BlurException, TException, IOException { Tracer traceSetup = Trace.trace("execute - setup"); LocalResources localResources = new LocalResources(); AtomicReference<Client> client = localResources.client; - Random random = localResources.random; AtomicInteger retries = localResources.retries; List<Connection> shuffledConnections = localResources.shuffledConnections; retries.set(0); shuffledConnections.addAll(connections); - Collections.shuffle(shuffledConnections, random); + Collections.shuffle(shuffledConnections, _random.get()); boolean allBad = true; int connectionErrorCount = 0; traceSetup.done(); @@ -230,9 +235,10 @@ public class BlurClientManager { } if (allBad) { connectionErrorCount++; - LOG.error("All connections are bad [" + connectionErrorCount + "]."); + LOG.error("All connections are bad [{0}] for [{1}].", connectionErrorCount, connections); if (connectionErrorCount >= maxRetries) { - throw new BadConnectionException("Could not connect to controller/shard server. All connections are bad."); + throw new BadConnectionException("Could not connect to controller/shard server [" + connections + + "]. All connections are bad."); } try { Thread.sleep(1000);
