Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@

import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDriver;
import org.apache.phoenix.util.DelayedRegionServer;
import org.apache.phoenix.util.PhoenixRuntime;
Expand All@@ -31,22 +32,17 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import static org.apache.phoenix.exception.SQLExceptionCode.NEW_CONNECTION_THROTTLED;
import static org.apache.phoenix.exception.SQLExceptionCode.NEW_INTERNAL_CONNECTION_THROTTLED;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_OPEN_INTERNAL_PHOENIX_CONNECTIONS;
import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_OPEN_PHOENIX_CONNECTIONS;
import static org.apache.phoenix.query.QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS;
import static org.apache.phoenix.query.QueryServices.INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS;
import static org.apache.phoenix.query.QueryServices.RENEW_LEASE_ENABLED;
import static org.apache.phoenix.query.QueryServices.TASK_HANDLING_INITIAL_DELAY_MS_ATTRIB;
import static org.apache.phoenix.query.QueryServices.TASK_HANDLING_INTERVAL_MS_ATTRIB;
import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
Expand DownExpand Up@@ -129,4 +125,39 @@ public void testDeleteRuntimeFailureClosesConnections() throws Exception {
}

}

@Test public void testClosedChildConnectionsRemovedFromParentQueue() throws SQLException {
String tableName = generateUniqueName();
String connectionUrl = getUniqueUrl();
int NUMBER_OF_ROWS = 10;
String ddl = "CREATE TABLE " + tableName + " (V BIGINT PRIMARY KEY, K BIGINT)";
Properties props = new Properties();
props.setProperty(CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS, String.valueOf(10));
props.setProperty(INTERNAL_CONNECTION_MAX_ALLOWED_CONNECTIONS, String.valueOf(10));
try (Connection conn = DriverManager.getConnection(connectionUrl, props);
Statement statement = conn.createStatement()) {
statement.execute(ddl);
}
PhoenixConnection
connection =
(PhoenixConnection) DriverManager.getConnection(connectionUrl, props);
for (int i = 0; i < NUMBER_OF_ROWS; i++) {
connection.createStatement()
.execute("UPSERT INTO " + tableName + " VALUES (" + i + ", " + i + ")");
connection.commit();
}
connection.setAutoCommit(false);
try {
for (int i = 0; i < NUMBER_OF_ROWS; i++) {
connection.createStatement()
.execute("DELETE FROM " + tableName + " WHERE K = " + i);
}
} catch (SQLException e) {
fail();
} finally {
connection.close();
}
// All 10 child connections should be removed successfully from the queue
assertEquals(0, connection.getChildConnectionsCount());
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,6 +112,8 @@ public void close() throws SQLException {
MutatingParallelIteratorFactory.this.connection.getMutationState()
.join(finalState);
} finally {
//Removing to be closed connection from the parent connection queue.
connection.removeChildConnection(clonedConnection);
clonedConnection.close();
}
}
Expand All@@ -124,6 +126,8 @@ public Tuple peek() {
} catch (Throwable ex) {
// Catch just to make sure we close the cloned connection and then rethrow
try {
//Removing to be closed connection from the parent connection queue.
connection.removeChildConnection(clonedConnection);
// closeQuietly only handles IOException
clonedConnection.close();
} catch (SQLException sqlEx) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,6 +475,30 @@ public void addChildConnection(PhoenixConnection connection) {
childConnections.add(connection);
}

/**
* Method to remove child connection from childConnections Queue
*
* @param connection
*/
public void removeChildConnection(PhoenixConnection connection) {
if (childConnections != null) {
childConnections.remove(connection);
}
}

/**
* Method to fetch child connections count from childConnections Queue
*
* @return int count
*/
@VisibleForTesting
public int getChildConnectionsCount() {
if (childConnections != null) {
return childConnections.size();
}
return 0;
}

public Sampler<?> getSampler() {
return this.sampler;
}
Expand Down