NealSun96 commented on a change in pull request #759: Add validation logic to 
MSD write operations
URL: https://github.com/apache/helix/pull/759#discussion_r379603177
 
 

 ##########
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/metadatastore/TrieRoutingData.java
 ##########
 @@ -89,49 +87,55 @@ public String getMetadataStoreRealm(String path)
           + DELIMITER + "\" character: " + path);
     }
 
-    TrieNode leafNode = findTrieNode(path, true);
-    return leafNode.getRealmAddress();
+    TrieNode node = getLongestPrefixNodeAlongPath(path);
+    if (!node.isShardingKey()) {
+      throw new NoSuchElementException(
+          "No sharding key found within the provided path. Path: " + path);
+    }
+    return node.getRealmAddress();
+  }
+
+  public boolean isShardingKeyInsertionValid(String shardingKey) {
+    if (shardingKey.isEmpty() || !shardingKey.substring(0, 
1).equals(DELIMITER)) {
+      throw new IllegalArgumentException(
+          "Provided shardingKey is empty or does not have a leading \"" + 
DELIMITER
+              + "\" character: " + shardingKey);
+    }
+
+    TrieNode node = getLongestPrefixNodeAlongPath(shardingKey);
+    return !node.isShardingKey() && !node.getPath().equals(shardingKey);
   }
 
   /**
 
 Review comment:
   Interesting point. I have converted the javadoc to block comments. 

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