mcvsubbu commented on a change in pull request #3633: Use 
ZkCacheBaseDataAccessor to cache instance configs in PinotHelixResourceManager
URL: https://github.com/apache/incubator-pinot/pull/3633#discussion_r245437779
 
 

 ##########
 File path: 
pinot-controller/src/test/java/com/linkedin/pinot/controller/helix/core/PinotHelixResourceManagerTest.java
 ##########
 @@ -78,6 +88,94 @@ public void testGetInstanceEndpoints() throws 
InvalidConfigException {
     }
   }
 
+  @Test
+  public void testGetInstanceConfigs() throws Exception {
+    Set<String> servers = 
_helixResourceManager.getAllInstancesForServerTenant(SERVER_TENANT_NAME);
+    for (String server : servers) {
+      InstanceConfig cachedInstanceConfig = 
_helixResourceManager.getHelixInstanceConfig(server);
+      InstanceConfig realInstanceConfig = 
_helixAdmin.getInstanceConfig(_helixClusterName, server);
+      Assert.assertEquals(cachedInstanceConfig, realInstanceConfig);
+    }
+
+    ZkClient zkClient = new ZkClient(_helixResourceManager.getHelixZkURL(), 
10_000, 10_000, new ZNRecordSerializer());
+
+    modifyExistingInstanceConfig(zkClient);
+    addAndRemoveNewInstanceConfig(zkClient);
+
+    zkClient.close();
+  }
+
+  private void modifyExistingInstanceConfig(ZkClient zkClient) throws 
InterruptedException {
+    String instanceName = "Server_localhost_" + new 
Random().nextInt(NUM_INSTANCES);
+    String instanceConfigPath = 
PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
+    Assert.assertTrue(zkClient.exists(instanceConfigPath));
+    ZNRecord znRecord = zkClient.readData(instanceConfigPath, null);
+
+    InstanceConfig cachedInstanceConfig = 
_helixResourceManager.getHelixInstanceConfig(instanceName);
+    String originalPort = cachedInstanceConfig.getPort();
+    Assert.assertNotNull(originalPort);
+    String newPort = Long.toString(System.currentTimeMillis());
+    Assert.assertTrue(!newPort.equals(originalPort));
+
+    // Set new port to this instance config.
+    
znRecord.setSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_PORT.toString(),
 newPort);
+    zkClient.writeData(instanceConfigPath, znRecord);
+
+    long start = System.currentTimeMillis();
+    int retry = 0;
+    InstanceConfig latestCachedInstanceConfig 
=_helixResourceManager.getHelixInstanceConfig(instanceName);
+    String latestPort = latestCachedInstanceConfig.getPort();
+    while (!newPort.equals(latestPort) && retry < 10) {
+      Thread.sleep(500L);
+      retry++;
+      latestCachedInstanceConfig 
=_helixResourceManager.getHelixInstanceConfig(instanceName);
+      latestPort = latestCachedInstanceConfig.getPort();
+    }
+    System.out.println("It took " + (System.currentTimeMillis() - start) + "ms 
to update the cached value.");
+
+    // Set original port back to this instance config.
+    
znRecord.setSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_PORT.toString(),
 originalPort);
+    zkClient.writeData(instanceConfigPath, znRecord);
+  }
+
+  private void addAndRemoveNewInstanceConfig(ZkClient zkClient) throws 
Exception {
+    int biggerRandomNumber = NUM_INSTANCES + new 
Random().nextInt(NUM_INSTANCES);
+    String instanceName = "Server_localhost_" + 
String.valueOf(biggerRandomNumber);
+    String instanceConfigPath = 
PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName);
+    Assert.assertFalse(zkClient.exists(instanceConfigPath));
+    List<String> instances = _helixResourceManager.getAllInstances();
+    Assert.assertFalse(instances.contains(instanceName));
+
+    // Add new ZNode.
+    ZNRecord znRecord = new ZNRecord(instanceName);
+    zkClient.createPersistent(instanceConfigPath, znRecord);
+
+    long start = System.currentTimeMillis();
+    List<String> latestAllInstances = _helixResourceManager.getAllInstances();
+    int retry = 0;
+    while (!latestAllInstances.contains(instanceName) && retry < 10) {
+      Thread.sleep(500L);
+      retry++;
+      latestAllInstances = _helixResourceManager.getAllInstances();
+    }
+    Assert.assertTrue(retry < 10, "Retry more than 10 times");
+    System.out.println("It took " + (System.currentTimeMillis() - start) + "ms 
to update the cached value.");
 
 Review comment:
   remove this

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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