You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/07/08 18:15:27 UTC

[10/12] tinkerpop git commit: Prevented driver from decrementing open connection count when replacing a connection

Prevented driver from decrementing open connection count when replacing a connection

Depending on the configuration and if connection replacement was high, this number could sometimes go negative.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f198ce1e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f198ce1e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f198ce1e

Branch: refs/heads/tp31
Commit: f198ce1e714c9f2daa140e9832c6f97f29d866a8
Parents: e0b6dc4
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 1 07:40:37 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 1 07:40:37 2016 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/ConnectionPool.java | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f198ce1e/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
index 96cb81b..9955e82 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ConnectionPool.java
@@ -232,10 +232,6 @@ final class ConnectionPool {
         return closeFuture.compareAndSet(null, future) ? future : closeFuture.get();
     }
 
-    public int opened() {
-        return open.get();
-    }
-
     private CompletableFuture[] killAvailableConnections() {
         final List<CompletableFuture<Void>> futures = new ArrayList<>(connections.size());
         for (Connection connection : connections) {
@@ -321,15 +317,18 @@ final class ConnectionPool {
     }
 
     private void definitelyDestroyConnection(final Connection connection) {
-        bin.add(connection);
-        connections.remove(connection);
-        open.decrementAndGet();
+        // only add to the bin for future removal if its not already there.
+        if (!bin.contains(connection)) {
+            bin.add(connection);
+            connections.remove(connection);
+            open.decrementAndGet();
+        }
 
-        if (connection.borrowed.get() == 0 && bin.remove(connection))
+        // only close the connection for good once it is done being borrowed
+        if (connection.borrowed.get() == 0 && bin.remove(connection)) {
             connection.closeAsync();
-
-        if (logger.isDebugEnabled())
             logger.debug("{} destroyed", connection.getConnectionInfo());
+        }
     }
 
     private Connection waitForConnection(final long timeout, final TimeUnit unit) throws TimeoutException, ConnectionException {