You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/01/23 07:56:00 UTC

[GitHub] [helix] narendly commented on a change in pull request #700: Call session aware createEphemeral to create live instance.

narendly commented on a change in pull request #700: Call session aware createEphemeral to create live instance.
URL: https://github.com/apache/helix/pull/700#discussion_r369971790
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestParticipantManager.java
 ##########
 @@ -0,0 +1,182 @@
+package org.apache.helix.manager.zk;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
+
+import org.apache.helix.PreConnectCallback;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkTestHelper;
+import org.apache.helix.common.ZkTestBase;
+import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.model.LiveInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestParticipantManager extends ZkTestBase {
+  private static Logger LOG = LoggerFactory.getLogger(TestParticipantManager.class);
+
+  /*
+   * Simulates zk session expiry before creating live instance in participant manager. This test
+   * makes sure the session aware create ephemeral API is called.
+   * What this test does is:
+   * 1. Sets up live instance with session S0
+   * 2. Expires S0 and gets new session S1
+   * 3. S1 is blocked before creating live instance in participant manager
+   * 4. Expires S1 and gets new session S2
+   * 5. Proceeds S1 to create live instance, which will fail because session S1 is expired
+   * 6. Proceeds S2 to create live instance, which will succeed
+   */
+  @Test
+  public void testSessionExpiryCreateLiveInstance() throws Exception {
+    final String className = TestHelper.getTestClassName();
+    final String methodName = TestHelper.getTestMethodName();
+    final String clusterName = className + "_" + methodName;
+
+    final ZKHelixDataAccessor accessor =
+        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(ZK_ADDR));
+    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR,
+        12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        10, // partitions per resource
+        5, // number of nodes
+        3, // replicas
+        "MasterSlave",
+        true); // do rebalance
+
+    final String instanceName = "localhost_12918";
+    final MockParticipantManager manager =
+        new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+
+    manager.syncStart();
+
+    final LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceName));
+    final long originalCreationTime = liveInstance.getStat().getCreationTime();
+    final String originalSessionId = manager.getSessionId();
+
+    // Verify current live instance.
+    Assert.assertNotNull(liveInstance);
+    Assert.assertEquals(liveInstance.getEphemeralOwner(), originalSessionId);
+
+    final CountDownLatch startCountdown = new CountDownLatch(1);
+    final CountDownLatch endCountdown = new CountDownLatch(1);
+    final Semaphore semaphore = new Semaphore(0);
+    manager.addPreConnectCallback(
+        new BlockingPreConnectCallback(instanceName, startCountdown, endCountdown, semaphore));
+
+    // Expire S0 and new session S1 will be created.
+    ZkTestHelper.asyncExpireSession(manager.getZkClient());
+
+    // Wait for onPreConnect to start
+    semaphore.acquire();
+
+    // New session S1 should not be equal to S0.
+    Assert.assertFalse(originalSessionId.equals(manager.getSessionId()));
+
+    // Live instance should be gone as original session S0 is expired.
+    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance(instanceName)));
+
+    final String lastSessionId = manager.getSessionId();
+
+    // Expire S1 when S1 is blocked in onPreConnect().
+    // New session S2 will be created.
+    ZkTestHelper.asyncExpireSession(manager.getZkClient());
+
+    TestHelper.verify(
+        () -> !(ZKUtil.toHexSessionId(manager.getZkClient().getSessionId()).equals(lastSessionId)),
+        3000L);
+
+    // New session S2 should not be equal to S1.
+    final String latestSessionId = ZKUtil.toHexSessionId(manager.getZkClient().getSessionId());
+    Assert.assertFalse(lastSessionId.equals(latestSessionId));
+
+    // Proceed S1 to create live instance, which will fail.
+    startCountdown.countDown();
+
+    // Wait until S1's handling new session is completed.
+    semaphore.acquire();
 
 Review comment:
   Does this really wait? At this point isn't `release()` called by S2?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org