kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 9e0cf2e1fe2af461392b8252a2b98c7f00077cdbc1ffc5d6a86078e0ff11ae65 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-05-12 19:25 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-05-19 09:57 +02:00 |
| Parents | af491f25bb81 |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/DynamicConnectionPool.java +0 −1
| @@ -475,7 +475,6 @@ | ||
| 475 | 475 | addConnectionIfUnderMaximum(); |
| 476 | 476 | } |
| 477 | 477 | }); |
| 478 | - connection.closeAsync(); | |
| 479 | 478 | } |
| 480 | 479 | |
| 481 | 480 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/SingleConnectionPool.java +15 −15
| @@ -96,14 +96,14 @@ | ||
| 96 | 96 | Futures.addCallback(connectionFuture, new FutureCallback<Void>() { |
| 97 | 97 | @Override |
| 98 | 98 | public void onSuccess(Void result) { |
| 99 | - connectionRef.set(connection); | |
| 100 | - open.set(true); | |
| 101 | 99 | if (isClosed()) { |
| 102 | 100 | initFuture.setException(new ConnectionException(host.getSocketAddress(), "Pool was closed during initialization")); |
| 103 | 101 | // we're not sure if closeAsync() saw the connection, so ensure it gets closed |
| 104 | 102 | connection.closeAsync().force(); |
| 105 | 103 | } else { |
| 106 | 104 | logger.trace("Created connection pool to host {}", host); |
| 105 | + connectionRef.set(connection); | |
| 106 | + open.set(true); | |
| 107 | 107 | phase = Phase.READY; |
| 108 | 108 | initFuture.set(null); |
| 109 | 109 | } |
| @@ -235,6 +235,8 @@ | ||
| 235 | 235 | |
| 236 | 236 | @Override |
| 237 | 237 | public void returnConnection(Connection connection) { |
| 238 | + int inFlight = connection.inFlight.decrementAndGet(); | |
| 239 | + | |
| 238 | 240 | if (isClosed()) { |
| 239 | 241 | close(connection); |
| 240 | 242 | return; |
| @@ -246,8 +248,6 @@ | ||
| 246 | 248 | return; |
| 247 | 249 | } |
| 248 | 250 | |
| 249 | - int inFlight = connection.inFlight.decrementAndGet(); | |
| 250 | - | |
| 251 | 251 | if (trash.contains(connection)) { |
| 252 | 252 | if (inFlight == 0 && trash.remove(connection)) |
| 253 | 253 | close(connection); |
| @@ -264,14 +264,15 @@ | ||
| 264 | 264 | // directly because we want to make sure the connection is always trashed. |
| 265 | 265 | private void replaceConnection(Connection connection) { |
| 266 | 266 | if (!connection.state.compareAndSet(OPEN, TRASHED)) |
| 267 | - open.set(false); | |
| 267 | + return; | |
| 268 | + open.set(false); | |
| 268 | 269 | maybeSpawnNewConnection(); |
| 269 | 270 | doTrashConnection(connection); |
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | private void doTrashConnection(Connection connection) { |
| 273 | - trash.add(connection); | |
| 274 | 274 | connectionRef.compareAndSet(connection, null); |
| 275 | + trash.add(connection); | |
| 275 | 276 | |
| 276 | 277 | if (connection.inFlight.get() == 0 && trash.remove(connection)) |
| 277 | 278 | close(connection); |
| @@ -329,14 +330,13 @@ | ||
| 329 | 330 | public void replaceDefunctConnection(final Connection connection) { |
| 330 | 331 | if (connection.state.compareAndSet(OPEN, GONE)) |
| 331 | 332 | open.set(false); |
| 332 | - connectionRef.compareAndSet(connection, null); | |
| 333 | - connection.closeAsync(); | |
| 334 | - manager.blockingExecutor().submit(new Runnable() { | |
| 335 | - @Override | |
| 336 | - public void run() { | |
| 337 | - addConnectionIfNeeded(); | |
| 338 | - } | |
| 339 | - }); | |
| 333 | + if (connectionRef.compareAndSet(connection, null)) | |
| 334 | + manager.blockingExecutor().submit(new Runnable() { | |
| 335 | + @Override | |
| 336 | + public void run() { | |
| 337 | + addConnectionIfNeeded(); | |
| 338 | + } | |
| 339 | + }); | |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | @Override |
| @@ -379,7 +379,7 @@ | ||
| 379 | 379 | if (isClosed()) |
| 380 | 380 | return; |
| 381 | 381 | |
| 382 | - if (open.compareAndSet(false, true) && scheduledForCreation.compareAndSet(false, true)) { | |
| 382 | + if (!open.get() && scheduledForCreation.compareAndSet(false, true)) { | |
| 383 | 383 | manager.blockingExecutor().submit(newConnectionTask); |
| 384 | 384 | } |
| 385 | 385 | } |