Skip to content

Commit 367ff74

Browse files
committed
refactor: move column cache reset from setNewConnection to tryConnect
The reset belongs in tryConnect() because that is the earliest point where we have a new connection but have not yet issued any system table queries. By the time setNewConnection() is called, tryConnect() has already reset the caches and populated them via refreshNodeListAndTokenMap() — so resetting in setNewConnection() was discarding freshly-discovered, correct, warm caches and forcing an unnecessary extra SELECT * on the next query. Both connect() and backgroundReconnect() go through tryConnect() before setNewConnection(), so a single reset in tryConnect() covers both flows.
1 parent db67e8a commit 367ff74

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ private void signalError() {
340340
private void setNewConnection(Connection newConnection) {
341341
Host.statesLogger.debug("[Control connection] established to {}", newConnection.endPoint);
342342
newConnection.setOwner(this);
343-
// Reset column caches so the new connection triggers a fresh SELECT * to discover which
344-
// columns the server exposes before switching to projected queries.
345-
localColumns = null;
346-
peersColumns = null;
347-
peersV2Columns = null;
348343
Connection old = connectionRef.getAndSet(newConnection);
349344
if (old != null && !old.isClosed()) old.closeAsync().force();
350345
}
@@ -438,9 +433,9 @@ private Connection tryConnect(Host host, boolean isInitialConnection)
438433
connection.write(new Requests.Register(evs));
439434

440435
// Reset column caches so refreshNodeListAndTokenMap() uses SELECT * to rediscover
441-
// which columns this server exposes, rather than a projected query built for the
442-
// previous connection's server. setNewConnection() also resets these, but it is
443-
// called after tryConnect() returns — too late to protect the queries below.
436+
// which columns this server exposes, rather than a projected query built for a
437+
// previous connection's server. The caches are populated during the queries below
438+
// and remain warm for the lifetime of this connection.
444439
localColumns = null;
445440
peersColumns = null;
446441
peersV2Columns = null;

0 commit comments

Comments
 (0)