Elffuss BraidHub

kikocis/java-driver public

Fix merge errors in single-connection pool implementation.
Changeset9e0cf2e1fe2af461392b8252a2b98c7f00077cdbc1ffc5d6a86078e0ff11ae65
Authorolim7t <omichallat+github@gmail.com> · 2015-05-12 19:25 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-05-19 09:57 +02:00
Parentsaf491f25bb81

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/DynamicConnectionPool.java +0 −1
@@ -475,7 +475,6 @@
475475 addConnectionIfUnderMaximum();
476476 }
477477 });
478- connection.closeAsync();
479478 }
480479
481480 @Override
modified driver-core/src/main/java/com/datastax/driver/core/SingleConnectionPool.java +15 −15
@@ -96,14 +96,14 @@
9696 Futures.addCallback(connectionFuture, new FutureCallback<Void>() {
9797 @Override
9898 public void onSuccess(Void result) {
99- connectionRef.set(connection);
100- open.set(true);
10199 if (isClosed()) {
102100 initFuture.setException(new ConnectionException(host.getSocketAddress(), "Pool was closed during initialization"));
103101 // we're not sure if closeAsync() saw the connection, so ensure it gets closed
104102 connection.closeAsync().force();
105103 } else {
106104 logger.trace("Created connection pool to host {}", host);
105+ connectionRef.set(connection);
106+ open.set(true);
107107 phase = Phase.READY;
108108 initFuture.set(null);
109109 }
@@ -235,6 +235,8 @@
235235
236236 @Override
237237 public void returnConnection(Connection connection) {
238+ int inFlight = connection.inFlight.decrementAndGet();
239+
238240 if (isClosed()) {
239241 close(connection);
240242 return;
@@ -246,8 +248,6 @@
246248 return;
247249 }
248250
249- int inFlight = connection.inFlight.decrementAndGet();
250-
251251 if (trash.contains(connection)) {
252252 if (inFlight == 0 && trash.remove(connection))
253253 close(connection);
@@ -264,14 +264,15 @@
264264 // directly because we want to make sure the connection is always trashed.
265265 private void replaceConnection(Connection connection) {
266266 if (!connection.state.compareAndSet(OPEN, TRASHED))
267- open.set(false);
267+ return;
268+ open.set(false);
268269 maybeSpawnNewConnection();
269270 doTrashConnection(connection);
270271 }
271272
272273 private void doTrashConnection(Connection connection) {
273- trash.add(connection);
274274 connectionRef.compareAndSet(connection, null);
275+ trash.add(connection);
275276
276277 if (connection.inFlight.get() == 0 && trash.remove(connection))
277278 close(connection);
@@ -329,14 +330,13 @@
329330 public void replaceDefunctConnection(final Connection connection) {
330331 if (connection.state.compareAndSet(OPEN, GONE))
331332 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+ });
340340 }
341341
342342 @Override
@@ -379,7 +379,7 @@
379379 if (isClosed())
380380 return;
381381
382- if (open.compareAndSet(false, true) && scheduledForCreation.compareAndSet(false, true)) {
382+ if (!open.get() && scheduledForCreation.compareAndSet(false, true)) {
383383 manager.blockingExecutor().submit(newConnectionTask);
384384 }
385385 }