kaisun2000 commented on a change in pull request #924: Fix ZkHelixPropertyStore 
loses Zookeeper notification issue
URL: https://github.com/apache/helix/pull/924#discussion_r408439012
 
 

 ##########
 File path: 
helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
 ##########
 @@ -37,6 +38,93 @@
 import org.testng.annotations.Test;
 
 public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
+  @Test
+  public void testSessionExpirationWithSharedZkClient() throws Exception {
+    int curstateCnt = 10;
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+
+    // init external base data accessor
+    HelixZkClient sharedZkclient = SharedZkClientFactory.getInstance()
+        .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));
+    sharedZkclient.setZkSerializer(new ZNRecordSerializer());
+    ZkBaseDataAccessor<ZNRecord> sharedBaseAccessor = new 
ZkBaseDataAccessor<>(sharedZkclient);
+
+    // init zkCacheBaseDataAccessor
+    String curStatePath = 
PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901");
+    String extViewPath = PropertyPathBuilder.externalView(clusterName);
+
+    ZkBaseDataAccessor<ZNRecord> extBaseAccessor = new 
ZkBaseDataAccessor<>(_gZkClient);
+    extBaseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
+
+    List<String> zkCacheInitPaths = Arrays.asList(curStatePath, extViewPath);
+    ZkCacheBaseDataAccessor<ZNRecord> accessor =
+        new ZkCacheBaseDataAccessor<>(sharedBaseAccessor, null, null, 
zkCacheInitPaths);
+
+    boolean ret =
+        TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, 
_gZkClient, true);
+    Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
+
+    // create 10 current states using external base accessor
+    List<String> paths = new ArrayList<>();
+    List<ZNRecord> records = new ArrayList<>();
+    for (int i = 0; i < curstateCnt; i++) {
+      String path = PropertyPathBuilder
+          .instanceCurrentState(clusterName, "localhost_8901", "session_0", 
"TestDB" + i);
+      ZNRecord record = new ZNRecord("TestDB" + i);
+
+      paths.add(path);
+      records.add(record);
+    }
+
+    boolean[] success = extBaseAccessor.createChildren(paths, records, 
AccessOption.PERSISTENT);
+    for (int i = 0; i < curstateCnt; i++) {
+      Assert.assertTrue(success[i], "Should succeed in create: " + 
paths.get(i));
+    }
+
+    TestHelper.verifyWithTimeout("verifyZkCache", 5000, zkCacheInitPaths, 
accessor._zkCache._cache,
+        _gZkClient, true);
+
+    // dup shared ZkClient
+    HelixZkClient dupZkclient = SharedZkClientFactory.getInstance()
+        .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));
+
+    // kill the session to make sure shared zkClient re-installs watcher
+    final long sessionId = dupZkclient.getSessionId();
+    ZkTestHelper.asyncExpireSession(dupZkclient);
+    ret = TestHelper.verify(() -> {
+      long curSessionId = dupZkclient.getSessionId();
+      return curSessionId != sessionId && curSessionId != 0;
+    }, 10000);
+    Assert.assertTrue(ret, "kill session timed out!");
+
+    // kill the session one more time to cover code path ZkClient resetting 
flag that
+    // indicates first time synconnect happened.
+    final long sessionId1 = dupZkclient.getSessionId();
+    ZkTestHelper.asyncExpireSession(dupZkclient);
+    ret = TestHelper.verify(() -> {
+      long curSessionId = dupZkclient.getSessionId();
+      return curSessionId != sessionId1 && curSessionId != 0;
+    }, 10000);
+    Assert.assertTrue(ret, "kill session second time timed out!");
+
+    // remove the currentstates
+    paths.clear();
+    for (int i = 0; i < curstateCnt; i++) {
+      String path = PropertyPathBuilder
+          .instanceCurrentState(clusterName, "localhost_8901", "session_0", 
"TestDB" + i);
+      paths.add(path);
+    }
 
 Review comment:
   This is necessary.  This removal of currentstate should trigger 
propertystore to reflect this removal in its cache as well. 
   
   Without this fix, this is not going to be true because the watcher to 
zookeeper is lost. 

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


With regards,
Apache Git Services

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

Reply via email to