Repository navigation
Fix SessionConnection.reconnect() self-closing transport when enableRedirection is false - #19543
JackieTien97 wants to merge 2 commits into
Conversation
…edirection is false
JackieTien97
left a comment
There was a problem hiding this comment.
The two default-connection retry tests reproduce the original failure on the base revision and pass on this commit. I reproduced the three cases below with two local Thrift servers.
| Entry<TEndPoint, SessionConnection> entry = it.next(); | ||
| if (entry.getValue().equals(sessionConnection)) { | ||
| removedEndPoints.add(entry.getKey()); | ||
| it.remove(); |
There was a problem hiding this comment.
[P2] Keep a reconnecting query connection visible to forceClose().
With only query redirection enabled, a query on non-default connection B can reopen its transport and remove B here before reconnect() makes B the default. A concurrent forceClose() then sees only A. I paused the reconnect in this window. B received the retried query after forceClose() returned and still had one open socket. On the base revision the retry stopped and both nodes had zero open sockets.
Please coordinate registration of the reopened connection with the session's close state so that a close in this window releases the new transport and stops the retry.
| it.hasNext(); ) { | ||
| Entry<String, TEndPoint> entry = it.next(); | ||
| if (removedEndPoints.contains(entry.getValue())) { | ||
| it.remove(); |
There was a problem hiding this comment.
[P2] Guard device-route cleanup with enableRedirection.
Session.open(..., deviceIdToEndpoint, nodesSupplier) accepts a caller-supplied map. With write redirection disabled and query redirection enabled, I passed a read-only view containing a route to A and made a query fail over to B. B accepted the connection, then it.remove() threw UnsupportedOperationException before B received the query. The same query also deletes a route from a mutable map shared with writers.
Please keep the endpoint-to-connection cleanup independent of the write flag and only invalidate the tree and table device-route caches when write redirection is enabled.
| logger.warn(SessionMessages.CLOSE_CONNECTION_FAILED, e.getMessage()); | ||
| if (session.endPointToSessionConnection != null | ||
| || session.enableRedirection | ||
| || session.enableQueryRedirection) { |
There was a problem hiding this comment.
[P3] Initialize the endpoint cache when enabling query redirection on an open session.
If the session fails over from A to B while both redirection flags are off, the cache stays null. A later setEnableQueryRedirection(true) only changes the flag, so getQuerySessionConnection() keeps returning B even when the node supplier selects A. With A healthy again and the SDK's round-robin policy, the next four queries all went to B. On the base revision each node received two.
Please initialize the cache and register the current default connection when query redirection is enabled on an already-open session.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19543 +/- ##
=========================================
Coverage 50.99% 50.99%
Complexity 145 145
=========================================
Files 5797 5797
Lines 430347 430348 +1
Branches 57344 57345 +1
=========================================
+ Hits 219459 219465 +6
+ Misses 210888 210883 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…vice route cleanup, init cache on setEnableQueryRedirection
|



Closes #19542
Root Cause
SessionConnection.reconnect(), afterinit()opens a fresh transport,session.removeBrokenSessionConnection(this)is called, followed by unconditionally initializing/updatingsession.endPointToSessionConnection.compute(session.defaultEndPoint, ...)which closes any openvwithout checkingv != this(introduced in Fix Session reconnection increase connection number #15677).Session.removeBrokenSessionConnection(SessionConnection), cleanup ofendPointToSessionConnectionwas gated behindif (enableRedirection). However,Session.open()populatesendPointToSessionConnectionwheneverenableRedirection || enableQueryRedirection(andnodeUrls != nullsetsenableQueryRedirection = true), andreconnect()unconditionally createdendPointToSessionConnectioneven when both flags werefalse.enableRedirection == false,removeBrokenSessionConnection(this)leftdefaultEndPoint -> thisinendPointToSessionConnection.compute()then receivedv == this, observedv.transport.isOpen() == true(the newly reopened transport), and immediately invokedv.close()(this.close()), setting Thrift'soutputStream_tonullwhile returningtrue. Every subsequent retry then failed immediately withTTransportException: Cannot write to null outputStream.Fix
SessionConnection.reconnect():v != thisinsession.endPointToSessionConnection.compute(...)soreconnect()never closes itself while still closing any distinct stale connection mapped to the same endpoint (Fix Session reconnection increase connection number #15677).session.endPointToSessionConnectionwhensession.endPointToSessionConnection != null || session.enableRedirection || session.enableQueryRedirection.Session.removeBrokenSessionConnection(SessionConnection):sessionConnectionfromendPointToSessionConnectionwhenever the map is non-null (not gated behindenableRedirection), and remove all corresponding endpoints fromdeviceIdToEndpointandtableModelDeviceIdToEndpoint.Tests
Added unit tests in
SessionConnectionTestandSessionTest:testReconnectWithoutRedirectionDoesNotSelfClose: real localTThreadPoolServerwithenableRedirection = falseandenableQueryRedirection = false, failing 2 consecutiveinsertTabletcalls and succeeding on the 3rd.testReconnectWithQueryRedirectionAndWriteRedirectionDisabledDoesNotSelfClose: real localTThreadPoolServerwithnodeUrls(enableQueryRedirection = true) andenableRedirection = false, failing the 1stinsertTabletcall and succeeding on the 2nd.testReconnectStillClosesDifferentStaleConnectionForSameEndPoint: verifies Fix Session reconnection increase connection number #15677 behavior is preserved when a different open connection is mapped todefaultEndPoint.testRemoveBrokenSessionConnectionWhenRedirectionDisabled: verifiesremoveBrokenSessionConnection()removes all matching entries fromendPointToSessionConnection,deviceIdToEndpoint, andtableModelDeviceIdToEndpointeven whenenableRedirection == false.Verified with:
mvn -pl iotdb-client/session spotless:apply && mvn -pl iotdb-client/session spotless:checkmvn -pl iotdb-client/session -am test -Dsurefire.failIfNoSpecifiedTests=false -Dtest=SessionConnectionTest,SessionTest,SessionCacheLeaderTest,BrokenSessionConnectionTest,SessionSeedNodeFallbackTest,ThriftConnectionLifecycleTest,SessionPoolTest,SessionPoolCloseTest(324 tests run, 0 failures, 0 errors, 0 skipped)