nick-boss-tech commented on code in PR #5301:
URL: https://github.com/apache/solr/pull/5301#discussion_r4636509363
##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ConnectionManager.java:
##########
@@ -102,24 +112,90 @@ public ConnectionManager(
this.isClosedCheck = isClosed;
}
- private synchronized void connected() {
+ /**
+ * Receives the events of a single ZooKeeper instance. An expiration is
ignored once a newer
+ * instance has been created, since it must not undo the recovery from the
session it was for.
+ */
+ final class SessionWatcher implements Watcher {
+ private final long generation = sessionGeneration.incrementAndGet();
+
+ long nextEventSequence() {
+ return ConnectionManager.this.nextEventSequence();
+ }
+
+ void process(WatchedEvent event, long sequence) {
+ ConnectionManager.this.process(event, sequence, generation);
+ }
+
+ @Override
+ public void process(WatchedEvent event) {
+ process(event, nextEventSequence());
+ }
+ }
+
+ SessionWatcher newSessionWatcher() {
+ return new SessionWatcher();
+ }
+
+ /**
+ * Numbers an event in delivery order. Must be called from the thread that
ZooKeeper delivers
+ * events on, before the event is handed off to another thread.
+ */
+ long nextEventSequence() {
+ return eventSequence.incrementAndGet();
+ }
+
+ /** Returns false, without changing state, if a newer state event has
already been applied. */
+ private synchronized boolean connected(long sequence) {
Review Comment:
🤖 *AI text below* 🤖
Could we apply the generation check to `SyncConnected` and `Disconnected` as
well as `Expired`? The terminal-keeper check can start a replacement before the
previous keeper’s queued callbacks drain. A delayed `SyncConnected` can then
satisfy the new keeper’s wait even though that keeper is still connecting. A
late old `Disconnected` can also clear the new keeper’s state if it gets a
higher sequence number.
I’d reset the connection state on each new attempt and have the wait require
`SyncConnected` from that attempt’s watcher.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]