jiajunwang commented on a change in pull request #682: Implement sharding key trie node class URL: https://github.com/apache/helix/pull/682#discussion_r371979972
########## File path: helix-rest/src/main/java/org/apache/helix/rest/metadatastore/ShardingKeyTrieNode.java ########## @@ -0,0 +1,118 @@ +package org.apache.helix.rest.metadatastore; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Collections; +import java.util.Map; + +/** + * A trie node that is used to represent Zk path sharding keys. Terminal nodes contain ZkRealm + * addresses. + */ +public class ShardingKeyTrieNode { + /** + * Children trie nodes of this trie node. Each node is identified by their name. + */ + private final Map<String, ShardingKeyTrieNode> _children; + /** + * Boolean value dictating if this trie node is a terminal node. + */ + private final boolean _isLeaf; + /** + * This trie node's name. + */ + private final String _name; + /** + * ZkRealm address corresponding to this trie node. The value is only valid when the node is a + * terminal node. + */ + private final String _zkRealmAddress; + + public ShardingKeyTrieNode(Map<String, ShardingKeyTrieNode> children, boolean isLeaf, String name, + String zkRealmAddress) { + _children = children; + _isLeaf = isLeaf; + _name = name; + _zkRealmAddress = zkRealmAddress; + } + + public Map<String, ShardingKeyTrieNode> getChildren() { + return Collections.unmodifiableMap(_children); + } + + public boolean isLeaf() { + return _isLeaf; + } + + public String getName() { + return _name; + } + + public String getZkRealmAddress() { Review comment: What I proposed are TreeNode and LeafNode. LeafNode is the child of the TreeNode. getZkRealmAddress() is the method of LeafNode, TreeNode only supports the tree-related operations. I think it is easier because the caller does not call isLeaf() to check then call getZkRealmAddress() to fetch the information. For easier access, every TreeNode can have a method called getLeafNodes() which returns all the leaf nodes under its branch. Then, 1. When you adding a new realm address, construct a LeafNode then adding to the right TreeNode. 2. When you search for a node, find the TreeNode first, then call getLeafNodes() which will return all the leaves. ---------------------------------------------------------------- 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]
