pkuwm commented on a change in pull request #751: Implement 
getAllMappingUnderPath and getMetadataStoreRealm
URL: https://github.com/apache/helix/pull/751#discussion_r378477655
 
 

 ##########
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/metadatastore/accessor/ZkRoutingDataReader.java
 ##########
 @@ -53,55 +53,45 @@ public ZkRoutingDataReader(String namespace, String 
zkAddress,
       throw new IllegalArgumentException("Zk address cannot be null or 
empty!");
     }
     _zkAddress = zkAddress;
-    _zkClient = DedicatedZkClientFactory.getInstance()
-        .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddress),
-            new HelixZkClient.ZkClientConfig().setZkSerializer(new 
ZNRecordSerializer()));
+    _zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(
+        new HelixZkClient.ZkConnectionConfig(zkAddress),
+        new HelixZkClient.ZkClientConfig().setZkSerializer(new 
ZNRecordSerializer()));
     _routingDataListener = routingDataListener;
     if (_routingDataListener != null) {
       // Subscribe child changes
       
_zkClient.subscribeChildChanges(MetadataStoreRoutingConstants.ROUTING_DATA_PATH,
 this);
       // Subscribe data changes
       for (String child : 
_zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH)) {
-        _zkClient
-            
.subscribeDataChanges(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + 
child,
-                this);
+        _zkClient.subscribeDataChanges(
+            MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + child, 
this);
       }
     }
   }
 
   /**
    * Returns (realm, list of ZK path sharding keys) mappings.
    * @return Map <realm, list of ZK path sharding keys>
-   * @throws InvalidRoutingDataException
+   * @throws InvalidRoutingDataException - when the node on
+   *           MetadataStoreRoutingConstants.ROUTING_DATA_PATH is missing
    */
-  public Map<String, List<String>> getRoutingData()
-      throws InvalidRoutingDataException {
+  public Map<String, List<String>> getRoutingData() throws 
InvalidRoutingDataException {
     Map<String, List<String>> routingData = new HashMap<>();
-    List<String> children;
+    List<String> allRealmAddresses;
     try {
-      children = 
_zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH);
+      allRealmAddresses = 
_zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH);
     } catch (ZkNoNodeException e) {
       throw new InvalidRoutingDataException(
           "Routing data directory ZNode " + 
MetadataStoreRoutingConstants.ROUTING_DATA_PATH
               + " does not exist. Routing ZooKeeper address: " + _zkAddress);
     }
-    if (children == null || children.isEmpty()) {
-      throw new InvalidRoutingDataException(
-          "There are no metadata store realms defined. Routing ZooKeeper 
address: " + _zkAddress);
-    }
-    for (String child : children) {
+    for (String realmAddress : allRealmAddresses) {
       ZNRecord record =
-          _zkClient.readData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + 
"/" + child);
+          _zkClient.readData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + 
"/" + realmAddress);
 
 Review comment:
   It seems quite several places use this concatenation 
`MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + realmAddress`. I 
suggest creating a static util method to build the path, which may look cleaner.

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