pkuwm 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_r353329675
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
##########
@@ -531,12 +558,29 @@ public String create(final String path, Object datat,
final List<ACL> acl, final
try {
final byte[] data = datat == null ? null : serialize(datat, path);
checkDataSizeLimit(data);
- String actualPath = retryUntilConnected(new Callable<String>() {
- @Override
- public String call() throws Exception {
- return getConnection().create(path, data, acl, mode);
- }
- });
+
+ /*
+ * We pass different implementation of callable.
+ * 1. If the session id is null, it means the operation is NOT session
aware.
+ * In this case, we will create a regular callable to create an
ephemeral node.
+ * 2. Otherwise, the operation is session aware. We will use a
SessionAwareCallable to
+ * create an ephemeral node, which is guaranteed to be created in the
expected session.
+ */
+ String actualPath;
+ if (sessionId == null) {
Review comment:
I understand your concern. My initial idea was to keep minimal changes.
There are other createEphemeral() APIs that don't pass a sessionId. My thought
was to keep the those APIs for now and keep the logic for them.
If we need to consider session aware for all createEphemeral() APIs, we have
to add new APIs with sessionId createEphemeral(path, acl, sessionId) and change
the code logic, which would make this PR bigger.
To make this logic more accurate, maybe we can do:
```
if (sessionId != null && mode == CreateMode.EPHEMERAL) {
SessionAware;
} esle {
NonSessionAware;
}
```
----------------------------------------------------------------
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]