tillrohrmann commented on a change in pull request #10754: 
[FLINK-14091][coordination] Allow updates to connection state when 
ZKCheckpointIDCounter reconnects to ZK
URL: https://github.com/apache/flink/pull/10754#discussion_r366394875
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/ZooKeeperCheckpointIDCounter.java
 ##########
 @@ -77,14 +84,26 @@ public ZooKeeperCheckpointIDCounter(CuratorFramework 
client, String counterPath)
                this.client = checkNotNull(client, "Curator client");
                this.counterPath = checkNotNull(counterPath, "Counter path");
                this.sharedCount = new SharedCount(client, counterPath, 1);
+
+               this.connectionStateListeners = new ArrayList<>();
+               this.connectionStateListeners.add((ignore, newState) -> 
lastState = newState);
+       }
+
+       @VisibleForTesting
+       ZooKeeperCheckpointIDCounter(CuratorFramework client, String 
counterPath, Collection<ConnectionStateListener> listeners) {
+               this(client, counterPath);
+               this.connectionStateListeners.addAll(listeners);
        }
 
        @Override
        public void start() throws Exception {
                synchronized (startStopLock) {
                        if (!isStarted) {
                                sharedCount.start();
-                               
client.getConnectionStateListenable().addListener(connStateListener);
+
+                               for (ConnectionStateListener listener : 
connectionStateListeners) {
+                                       
client.getConnectionStateListenable().addListener(listener);
 
 Review comment:
   Since `getConnectionStateListenable` does not guarantee the order in which 
the listener are called, the added test case is unstable (if the testing 
listener is called before the one which sets `lastState`). I suggest to 
introduce a `LastStateConnectionStateListener` (similar to 
`SharedCountConnectionStateListener`) which we pass into the class.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to