deniskuzZ commented on code in PR #543:
URL: https://github.com/apache/tez/pull/543#discussion_r4512642961
##########
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)) {
+ node.close();
+ throw new IOException("Timed out creating AMRecord at zkpath " + path);
}
- amRecords.add(server);
+ amNodes.put(server, node);
+ LOG.info("Added AMRecord to zkpath {}", path);
}
@Override
public void remove(AMRecord server) throws Exception {
- amRecords.remove(server);
+ PersistentNode node = amNodes.remove(server);
final String path = pathFor(server);
- client.delete().forPath(path);
+ if (node != null) {
+ node.close(); // deletes the node
+ }
LOG.info("Deleted AMRecord from zkpath {}", path);
Review Comment:
changed
--
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]