NealSun96 commented on a change in pull request #682: Implement sharding key 
trie node class
URL: https://github.com/apache/helix/pull/682#discussion_r371431929
 
 

 ##########
 File path: 
helix-rest/src/main/java/org/apache/helix/rest/metadatastore/ShardingKeyTrieNode.java
 ##########
 @@ -0,0 +1,117 @@
+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.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 _children;
+  }
+
+  public boolean isLeaf() {
+    return _isLeaf;
+  }
+
+  public String getName() {
+    return _name;
+  }
+
+  public String getZkRealmAddress() {
+    return _zkRealmAddress;
+  }
+
+  public static class Builder {
+    private Map<String, ShardingKeyTrieNode> _children;
+    private boolean _isLeaf;
+    private String _name;
+    private String _zkRealmAddress;
+
+    public ShardingKeyTrieNode build() {
+      validate();
+      return new ShardingKeyTrieNode(_children, _isLeaf, _name, 
_zkRealmAddress);
+    }
+
+    public Builder setChildren(final Map<String, ShardingKeyTrieNode> 
children) {
 
 Review comment:
   As of the current design, if changes occur on the source of truth, the 
entire trie will be rebuilt based on the source of truth. The reasoning of this 
design is as follows: 
   1. This is a clean way of updating the in-memory trie; no need to worry 
about syncing;
   2. updates to the routing data (such as adding a new path) are very rare (so 
much so our current design of the cached routing data is a static mapping, 
instead of a dynamically updated cache);
   3. the cost of building a trie is not very high - given that updating is 
rare, the cost to rebuild the trie is not a bottleneck to anything;
   4. simplicity. 

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