kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 3d0416253712a15d371454a313a919fc81d12a9600437c695b9c4a435f8bb70e |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-31 12:53 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-03 11:32 +01:00 |
| Parents | 468145015408 |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +33 −4
| @@ -64,7 +64,39 @@ | ||
| 64 | 64 | // If we haven't initialized the cluster, do it now |
| 65 | 65 | cluster.init(); |
| 66 | 66 | |
| 67 | - // Create pool to initial nodes (and wait for them to be created) | |
| 67 | + // Create pools to initial nodes (and wait for them to be created) | |
| 68 | + Collection<Host> hosts = cluster.getMetadata().allHosts(); | |
| 69 | + if (cluster.manager.sessions.size() == 1) { | |
| 70 | + // We only do it in parallel if this is the first session (meaning that the cluster just initialized). | |
| 71 | + createPoolsInParallel(hosts); | |
| 72 | + } else { | |
| 73 | + // Otherwise, we don't want to fill executor() because this is also where up/down notifications are processed, | |
| 74 | + // it's important that existing sessions get them in a timely manner. So we create the pools one by one: | |
| 75 | + createPoolsSequentially(hosts); | |
| 76 | + } | |
| 77 | + | |
| 78 | + isInit = true; | |
| 79 | + updateCreatedPools(executor()); | |
| 80 | + return this; | |
| 81 | + } | |
| 82 | + | |
| 83 | + private void createPoolsInParallel(Collection<Host> hosts) { | |
| 84 | + List<ListenableFuture<Boolean>> futures = new ArrayList<ListenableFuture<Boolean>>(hosts.size()); | |
| 85 | + for (Host host : hosts) | |
| 86 | + if (host.state != Host.State.DOWN) | |
| 87 | + futures.add(maybeAddPool(host, executor())); | |
| 88 | + ListenableFuture<List<Boolean>> f = Futures.allAsList(futures); | |
| 89 | + try { | |
| 90 | + f.get(); | |
| 91 | + } catch (ExecutionException e) { | |
| 92 | + // This is not supposed to happen | |
| 93 | + throw new DriverInternalError(e); | |
| 94 | + } catch (InterruptedException e) { | |
| 95 | + Thread.currentThread().interrupt(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + private void createPoolsSequentially(Collection<Host> hosts) { | |
| 68 | 100 | for (Host host : cluster.getMetadata().allHosts()) { |
| 69 | 101 | try { |
| 70 | 102 | if (host.state != Host.State.DOWN) |
| @@ -76,9 +108,6 @@ | ||
| 76 | 108 | Thread.currentThread().interrupt(); |
| 77 | 109 | } |
| 78 | 110 | } |
| 79 | - isInit = true; | |
| 80 | - updateCreatedPools(executor()); | |
| 81 | - return this; | |
| 82 | 111 | } |
| 83 | 112 | |
| 84 | 113 | public String getLoggedKeyspace() { |