abstractdog commented on code in PR #543:
URL: https://github.com/apache/tez/pull/543#discussion_r4511906681
##########
tez-dag/src/main/java/org/apache/tez/dag/api/client/registry/zookeeper/ZkAMRegistry.java:
##########
@@ -95,23 +97,27 @@ public void close() {
//zkNode at the path: <TEZ_AM_REGISTRY_NAMESPACE>/<appId>
@Override
public void add(AMRecord server) throws Exception {
- String json = AMRegistryUtils.recordToJsonString(server);
- try {
- final String path = pathFor(server);
- client.setData().forPath(path, json.getBytes(StandardCharsets.UTF_8));
- LOG.info("Added AMRecord to zkpath {}", path);
- } catch (KeeperException.NoNodeException nne) {
-
client.create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL)
- .forPath(pathFor(server), json.getBytes(StandardCharsets.UTF_8));
+ // PersistentNode re-creates the ephemeral node after a session loss or a
delete; a plain create would leave
+ // the AM running but unregistered.
+ final String path = pathFor(server);
+ byte[] json =
AMRegistryUtils.recordToJsonString(server).getBytes(StandardCharsets.UTF_8);
+ PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL,
false, path, json);
+ node.start();
+ if (!node.waitForInitialCreate(zkConfig.getConnectionTimeoutMs(),
TimeUnit.MILLISECONDS)) {
Review Comment:
if `waitForInitialCreate` throws `InterruptedException`, the node is
already started but never closed or put into `amNodes`, it stays active, so its
reconnect listener and NodeDeleted watch keep re-creating the path until
`close()` shuts the Curator client down
what about extra care by:
```java
boolean created;
try {
created = node.waitForInitialCreate(zkConfig.getConnectionTimeoutMs(),
TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
node.close();
throw e;
}
if (!created) {
node.close();
throw new IOException("Timed out creating AMRecord at zkpath " + path);
}
```
--
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]