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/04/15 18:52:52 UTC

[GitHub] [helix] pkuwm commented on a change in pull request #955: Fix MSD routing data refreshing for update methods

pkuwm commented on a change in pull request #955: Fix MSD routing data refreshing for update methods
URL: https://github.com/apache/helix/pull/955#discussion_r409025076
 
 

 ##########
 File path: helix-rest/src/main/java/org/apache/helix/rest/metadatastore/ZkMetadataStoreDirectory.java
 ##########
 @@ -304,42 +314,35 @@ public boolean deleteShardingKey(String namespace, String realm, String sharding
    */
   @Override
   public void refreshRoutingData(String namespace) {
-    // Safe to ignore the callback if any of the maps are null.
-    // If routingDataMap is null, then it will be populated by the constructor anyway
-    // If routingDataMap is not null, then it's safe for the callback function to update it
-    if (_routingZkAddressMap == null || _realmToShardingKeysMap == null
-        || _routingDataReaderMap == null || _routingDataWriterMap == null) {
-      LOG.warn(
-          "refreshRoutingData callback called before ZKMetadataStoreDirectory was fully initialized. Skipping refresh!");
-      return;
-    }
-
     // Check if namespace exists; otherwise, return as a NOP and log it
     if (!_routingZkAddressMap.containsKey(namespace)) {
       LOG.error(
           "Failed to refresh internally-cached routing data! Namespace not found: " + namespace);
       return;
     }
 
-    // Remove the raw data first in case of failure on creation
-    _realmToShardingKeysMap.remove(namespace);
-    // Remove routing data first in case of failure on creation
-    _routingDataMap.remove(namespace);
-
     Map<String, List<String>> rawRoutingData;
     try {
       rawRoutingData = _routingDataReaderMap.get(namespace).getRoutingData();
-      _realmToShardingKeysMap.put(namespace, rawRoutingData);
     } catch (InvalidRoutingDataException e) {
       LOG.error("Failed to refresh cached routing data for namespace {}", namespace, e);
+      _realmToShardingKeysMap.remove(namespace);
+      _routingDataMap.remove(namespace);
       return;
     }
 
+    TrieRoutingData trieRoutingData;
     try {
-      _routingDataMap.put(namespace, new TrieRoutingData(rawRoutingData));
+      trieRoutingData = new TrieRoutingData(rawRoutingData);
     } catch (InvalidRoutingDataException e) {
       LOG.warn("TrieRoutingData is not created for namespace {}", namespace, e);
+      _realmToShardingKeysMap.remove(namespace);
+      _routingDataMap.remove(namespace);
+      return;
     }
+
+    _realmToShardingKeysMap.put(namespace, rawRoutingData);
+    _routingDataMap.put(namespace, trieRoutingData);
 
 Review comment:
   My logic here is like a validation first and update. We will discuss the behavior first and make the change.

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