Skip to content

Commit cd8eaed

Browse files
author
aholmberg
committed
avoid multiple prepares per host with multiple sessions
1 parent 016d600 commit cd8eaed

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,14 +1106,10 @@ public void ensurePoolsSizing() {
11061106
}
11071107
}
11081108

1109-
// Prepare a query on all nodes
1110-
// Note that this *assumes* the query is valid.
1111-
public void prepare(PreparedStatement stmt, InetAddress toExclude) throws InterruptedException {
1109+
public void addPrepared(PreparedStatement stmt) {
11121110
if (preparedQueries.putIfAbsent(stmt.id, stmt) != null)
11131111
logger.warn("Re-preparing already prepared query {}. Please note that preparing the same query more than once is "
11141112
+ "generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.", stmt.getQueryString());
1115-
for (SessionManager s : sessions)
1116-
s.prepare(stmt.getQueryString(), toExclude);
11171113
}
11181114

11191115
private void prepareAllQueries(Host host) throws InterruptedException {

driver-core/src/main/java/com/datastax/driver/core/SessionManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ private PreparedStatement toPreparedStatement(String query, Connection.Future fu
144144
case PREPARED:
145145
ResultMessage.Prepared pmsg = (ResultMessage.Prepared)rm;
146146
PreparedStatement stmt = PreparedStatement.fromMessage(pmsg, cluster.getMetadata(), query, poolsState.keyspace);
147+
cluster.manager.addPrepared(stmt);
147148
try {
148-
cluster.manager.prepare(stmt, future.getAddress());
149+
prepare(stmt.getQueryString(), future.getAddress());
149150
} catch (InterruptedException e) {
150151
Thread.currentThread().interrupt();
151152
// This method doesn't propagate interruption, at least not for now. However, if we've

0 commit comments

Comments
 (0)