narendly commented on a change in pull request #642: Fix zk session race
condition before creating a live instance
URL: https://github.com/apache/helix/pull/642#discussion_r353571260
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
##########
@@ -1147,6 +1236,35 @@ private void acquireEventLock() {
throw new IllegalStateException(
"ZkConnection is in invalid state! Please close this ZkClient
and create new client.");
}
+
+ /*
+ * If the callable is a SessionAwareCallable, we need to validate
the session.
+ * If the session of current ZK connection does not match the
expected session in
+ * SessionAwareCallable, HelixException is thrown and call()
operation will not be run.
+ * Acquiring event lock is needed to make sure no new session is
established,
+ * while the session is being checked.
+ */
+ if (callable instanceof SessionAwareCallable) {
+ SessionAwareCallable<T> sessionAwareCallable =
(SessionAwareCallable<T>) callable;
+ acquireEventLock();
+ try {
+ final ZooKeeper zooKeeper = zkConnection.getZookeeper();
+ final String currentSessionId =
Long.toHexString(zooKeeper.getSessionId());
+ if
(!currentSessionId.equals(sessionAwareCallable.getSessionId())) {
+ throw new HelixException(
Review comment:
Should we try to not use HelixException here? We want to decouple ZkClient
from Helix as much as possible.
----------------------------------------------------------------
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]