kaisun2000 commented on a change in pull request #1119:
URL: https://github.com/apache/helix/pull/1119#discussion_r447904389



##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1165,20 +1177,92 @@ private void reconnect() {
     }
   }
 
+  private class SyncContext {
+    private CountDownLatch _latch;
+    private AtomicInteger _rc;
+
+    public SyncContext(CountDownLatch latch) {
+      _latch = latch;
+    }
+
+    AtomicInteger getRc() {
+      return _rc;
+    }
+
+    void setRc(AtomicInteger rc) {
+      _rc = rc;
+    }
+
+    CountDownLatch getLatch() {
+      return _latch;
+    }
+  }
+
+  private boolean retrySync(String sessionId) throws ZkInterruptedException {
+    if (!_syncOnNewSession) {
+      return true;
+    }
+    while (true) {
+      CountDownLatch latch = new CountDownLatch(1);
+      SyncContext ctx = new SyncContext(latch);
+
+      final ZkConnection zkConnection = (ZkConnection) getConnection();
+      zkConnection.getZookeeper().sync(_syncPath, new 
AsyncCallback.VoidCallback() {
+        @Override
+        public void processResult(int rt, String s, Object ctx) {
+          LOG.info("sycnOnNewSession with sessionID {} async return code: {}", 
sessionId, rt);
+          SyncContext synCtx = ((SyncContext) ctx);
+          synCtx.setRc(new AtomicInteger(rt));
+          synCtx.getLatch().countDown();
+        }
+      }, ctx);
+
+      try {
+        latch.await();
+      } catch (InterruptedException e) {
+        LOG.info("retrySync latch waiting got interrrupted with sessionId {} 
", sessionId);
+        throw new ZkInterruptedException(e);
+      }
+
+      KeeperException.Code code = KeeperException.Code.get(ctx.getRc().get());
+      if (code == OK) {
+        LOG.info("sycnOnNewSession with sessionID {} async return code: {} and 
proceeds", sessionId,
+            code);
+        break;
+      }
+      if (code == CONNECTIONLOSS || code == SESSIONMOVED) {

Review comment:
       We intentionally not to handle others, including session expiration. See 
comment on line 1238




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to