narendly commented on a change in pull request #759: Add validation logic to MSD write operations URL: https://github.com/apache/helix/pull/759#discussion_r379098852
########## 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); } /** - * If findLeafAlongPath is false, then starting from the root node, find the trie node that the - * given path is pointing to and return it; raise NoSuchElementException if the path does - * not point to any node. If findLeafAlongPath is true, then starting from the root node, find the - * leaf node along the provided path; raise NoSuchElementException if the path does not - * point to any node or if there is no leaf node along the path. + * Given a path, find a trie node that represents the longest prefix of the path. For example, Review comment: "longest prefix"? Could we just call it the closest existing sharding key node? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org