stoty commented on code in PR #1729:
URL: https://github.com/apache/phoenix/pull/1729#discussion_r1393696844
##########
phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java:
##########
@@ -720,17 +717,17 @@ public void clearWarnings() throws SQLException {
}
private void closeStatements() throws SQLException {
- List<? extends PhoenixStatement> statements = this.statements;
- // create new list to prevent close of statements
- // from modifying this list.
- this.statements = Lists.newArrayList();
try {
mutationState.rollback();
} catch (SQLException e) {
// ignore any exceptions while rolling back
} finally {
try {
- SQLCloseables.closeAll(statements);
+ // create new list to prevent close of statements from
modifying this collection.
+ // TODO This could be optimized out by decoupling closing the
stmt and removing it
+ // from the connection.
+ List<? extends PhoenixStatement> statementsCopy = new
ArrayList<>(this.statements);
Review Comment:
Connections may have several open statements.
Removing closed connections from an ArrayList is O(n), while remving them
from a Hash is O(1).
(Though for a few open statements this doesn't matter much)
But you are right, since closeAll() eventually removes the elements from the
copy, it's better to use a HashSet for the copy as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]