pkuwm commented on a change in pull request #924: WIP: fix ZkHelixPropertyStore
loses Zookeeper notification issue
URL: https://github.com/apache/helix/pull/924#discussion_r401176227
##########
File path:
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1073,10 +1073,24 @@ protected void processStateChanged(WatchedEvent event)
{
fireStateChangedEvent(event.getState());
+ // This following is the case for sharedZkClient
if (!isManagingZkConnection()) {
+ /*
+ For SharedZkClient, we will not invoke fireNewSessionEvents and we will
invoke fireAllEvents
+ This keeps the same behavior as original SharedZkClient.
+ Invoking fireAllEvents is important to make sure HelixPropertyStore
working correctly.
+ */
+ if ((event.getState() == KeeperState.SyncConnected) &&
(!_isNewSessionEventFired) && (!"0"
+ .equals(getHexSessionId()))) {
+ fireAllEvents();
+ _isNewSessionEventFired = true;
+ } else if (event.getState() == KeeperState.Expired) {
+ _isNewSessionEventFired = false;
+ }
Review comment:
If we remove ` _isNewSessionEventFired = false;` in `reconnect()` and do
below code, it seems more concise and easier to maintain.
`_isNewSessionEventFired` is only changed in this code block. What do you think?
```java
if (event.getState() == KeeperState.SyncConnected &&
!_isNewSessionEventFired && !"0".equals(getHexSessionId())) {
if (isManagingZkConnection()) {
/*
* Before the new zookeeper instance is connected to the zookeeper
service and its session
* is established, its session id is 0.
* New session event is not fired until the new zookeeper session
receives the first
* SyncConnected state(the zookeeper session is established).
* Now the session id is available and non-zero, and we can fire new
session events.
*/
fireNewSessionEvents();
}
/*
* Set it true to avoid firing events again for the same session next
time
* when SyncConnected events are received.
*/
_isNewSessionEventFired = true;
/*
* With this first SyncConnected state, we just get connected to
zookeeper service after
* reconnecting when the session expired. Because previous session
expired, we also have to
* notify all listeners that something might have changed.
*/
fireAllEvents();
} else if (event.getState() == KeeperState.Expired) {
if (isManagingZkConnection()) {
reconnectOnExpiring();
}
_isNewSessionEventFired = false;
}
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]