deniskuzZ commented on code in PR #543:
URL: https://github.com/apache/tez/pull/543#discussion_r4512641539


##########
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:
   Good catch! It's now closed on any failure of the wait



-- 
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]

Reply via email to