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



##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1172,13 +1176,32 @@ private void fireNewSessionEvents() {
     }
     final String sessionId = getHexSessionId();
     for (final IZkStateListener stateListener : _stateListener) {
-      _eventThread.send(new ZkEventThread.ZkEvent("New session event sent to " 
+ stateListener, sessionId) {
+      _eventThread
+          .send(new ZkEventThread.ZkEvent("New session event sent to " + 
stateListener, sessionId) {
 
-        @Override
-        public void run() throws Exception {
-          stateListener.handleNewSession(sessionId);
-        }
-      });
+            @Override
+            public void run() throws Exception {
+              if (_syncOnNewSession) {
+                //System.out.println("syncOnNewSession with sessionID:" + 
sessionId);

Review comment:
       Remove commented debugging code?

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1172,13 +1176,32 @@ private void fireNewSessionEvents() {
     }
     final String sessionId = getHexSessionId();
     for (final IZkStateListener stateListener : _stateListener) {
-      _eventThread.send(new ZkEventThread.ZkEvent("New session event sent to " 
+ stateListener, sessionId) {
+      _eventThread
+          .send(new ZkEventThread.ZkEvent("New session event sent to " + 
stateListener, sessionId) {
 
-        @Override
-        public void run() throws Exception {
-          stateListener.handleNewSession(sessionId);
-        }
-      });
+            @Override
+            public void run() throws Exception {
+              if (_syncOnNewSession) {
+                //System.out.println("syncOnNewSession with sessionID:" + 
sessionId);
+                LOG.info("syncOnNewSession with sessionId {}", sessionId);
+                final ZkConnection zkConnection = (ZkConnection) 
getConnection();
+                if (zkConnection == null || zkConnection.getZookeeper() == 
null) {
+                  throw new IllegalStateException(
+                      "ZkConnection is in invalid state! Please close this 
ZkClient and create new client.");
+                }
+                final String syncPath = new String("/");

Review comment:
       Whats the purpose of using such `new String("/")`? This brings in extra 
unnecessary string object creation. I think a constant would be nicer 
`SYNC_ROOT_PATH = "/"`.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1172,13 +1176,32 @@ private void fireNewSessionEvents() {
     }
     final String sessionId = getHexSessionId();
     for (final IZkStateListener stateListener : _stateListener) {
-      _eventThread.send(new ZkEventThread.ZkEvent("New session event sent to " 
+ stateListener, sessionId) {
+      _eventThread
+          .send(new ZkEventThread.ZkEvent("New session event sent to " + 
stateListener, sessionId) {
 
-        @Override
-        public void run() throws Exception {
-          stateListener.handleNewSession(sessionId);
-        }
-      });
+            @Override
+            public void run() throws Exception {
+              if (_syncOnNewSession) {
+                //System.out.println("syncOnNewSession with sessionID:" + 
sessionId);
+                LOG.info("syncOnNewSession with sessionId {}", sessionId);
+                final ZkConnection zkConnection = (ZkConnection) 
getConnection();
+                if (zkConnection == null || zkConnection.getZookeeper() == 
null) {

Review comment:
       I don't think this null check is necessary, as zkConnection/zk won't be 
null once zkClient object is constructed. Only chance zk being null is this 
zkClient.close() is called, then zk is null. I would say this may be overcheck 
for nulls.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1172,13 +1176,32 @@ private void fireNewSessionEvents() {
     }
     final String sessionId = getHexSessionId();
     for (final IZkStateListener stateListener : _stateListener) {
-      _eventThread.send(new ZkEventThread.ZkEvent("New session event sent to " 
+ stateListener, sessionId) {
+      _eventThread
+          .send(new ZkEventThread.ZkEvent("New session event sent to " + 
stateListener, sessionId) {
 
-        @Override
-        public void run() throws Exception {
-          stateListener.handleNewSession(sessionId);
-        }
-      });
+            @Override
+            public void run() throws Exception {
+              if (_syncOnNewSession) {
+                //System.out.println("syncOnNewSession with sessionID:" + 
sessionId);
+                LOG.info("syncOnNewSession with sessionId {}", sessionId);
+                final ZkConnection zkConnection = (ZkConnection) 
getConnection();
+                if (zkConnection == null || zkConnection.getZookeeper() == 
null) {
+                  throw new IllegalStateException(
+                      "ZkConnection is in invalid state! Please close this 
ZkClient and create new client.");
+                }
+                final String syncPath = new String("/");
+                zkConnection.getZookeeper().sync(syncPath, new 
AsyncCallback.VoidCallback() {
+                  @Override
+                  public void processResult(int rt, String s, Object ctx) {
+                    //System.out.println("sycnOnNewSession with sessionID " + 
sessionId + " async return code:" + rt);
+                    LOG.info("sycnOnNewSession with sessionID {} async return 
code: {}", sessionId,

Review comment:
       Do we also need to log time on this sync?




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