narendly commented on a change in pull request #1178:
URL: https://github.com/apache/helix/pull/1178#discussion_r462066464



##########
File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/GenericBaseDataAccessorBuilder.java
##########
@@ -83,7 +82,7 @@ protected RealmAwareZkClient 
createZkClient(RealmAwareZkClient.RealmMode realmMo
       case MULTI_REALM:
         try {
           zkClient = new FederatedZkClient(connectionConfig, clientConfig);
-        } catch (IOException | InvalidRoutingDataException e) {
+        } catch (InvalidRoutingDataException e) {

Review comment:
       It was removed from the signature. We don't throw it anymore. It will be 
thrown in the form of a MultiZkException, and will be a RuntimeException, not a 
typed exception.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/api/client/RealmAwareZkClient.java
##########
@@ -486,6 +500,13 @@ private void validate() {
           throw new IllegalArgumentException(
               "RealmAwareZkConnectionConfig.Builder: ZK sharding key must be 
set on single-realm mode!");
         }
+        if ((_routingDataSourceEndpoint == null && _routingDataSourceType != 
null) || (
+            _routingDataSourceEndpoint != null && _routingDataSourceType == 
null)) {
+          // For routing data source type and endpoint, if one is set and not 
the other, it is invalid

Review comment:
       If nothing is set, it will try to use the default MSDS endpoint, which 
is provided in System Properties.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/constant/RoutingSystemPropertyKeys.java
##########
@@ -0,0 +1,38 @@
+package org.apache.helix.zookeeper.constant;
+
+/*
+ * 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.
+ */
+
+/**
+ * This class contains various routing-related system property keys for 
multi-zk clients.
+ */
+public class RoutingSystemPropertyKeys {
+
+  /**
+   * If enabled, FederatedZkClient (multiZkClient) will invalidate the cached 
routing data and
+   * re-read the routing data from the routing data source upon ZK path 
sharding key cache miss.
+   */
+  public static final String UPDATE_ROUTING_DATA_ON_CACHE_MISS =
+      "update.routing.data.on.cache.miss.enabled";

Review comment:
       I can rename this and put "routing" in front.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/routing/HttpZkFallbackRoutingDataReader.java
##########
@@ -0,0 +1,81 @@
+package org.apache.helix.zookeeper.routing;
+
+/*
+ * 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.List;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.helix.zookeeper.constant.RoutingDataReaderType;
+import org.apache.helix.zookeeper.exception.MultiZkException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * HTTP and ZK-based RoutingDataReader that first tries an HTTP call to MSDS 
and upon failure,
+ * falls back to ZK for routing data.
+ * HttpZkFallbackRoutingDataReader does not maintain a ZK connection - it 
establishes for reading
+ * and closes it right away.
+ */
+public class HttpZkFallbackRoutingDataReader implements RoutingDataReader {

Review comment:
       The implementations of RoutingDataReader are supposed to be stateless 
and to be garbage-collected after use. So we should not maintain states. The 
Javadoc makes that clear.
   
   For example, we don't want to hold onto a ZkFallbackRoutingDataReader since 
that would mean we hold onto an active ZK connection. We only want a 
RoutingDataReader instance at initialization, once.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/routing/HttpZkFallbackRoutingDataReader.java
##########
@@ -0,0 +1,81 @@
+package org.apache.helix.zookeeper.routing;
+
+/*
+ * 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.List;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.helix.zookeeper.constant.RoutingDataReaderType;
+import org.apache.helix.zookeeper.exception.MultiZkException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * HTTP and ZK-based RoutingDataReader that first tries an HTTP call to MSDS 
and upon failure,
+ * falls back to ZK for routing data.
+ * HttpZkFallbackRoutingDataReader does not maintain a ZK connection - it 
establishes for reading
+ * and closes it right away.
+ */
+public class HttpZkFallbackRoutingDataReader implements RoutingDataReader {

Review comment:
       The implementations of RoutingDataReader are supposed to be stateless 
and to be garbage-collected after use. So we should not maintain states. The 
Javadoc makes that clear.
   
   For example, we don't want to hold onto a ZkFallbackRoutingDataReader since 
that would mean we hold onto an active ZK connection. We only want a 
RoutingDataReader instance at initialization, once.
   
   Extending it complicates the design, and you can ask a question of which one 
it should extend, and you can never do so consistently for other 
implementations. For that reason, I prefer composition over inheritance.

##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/routing/ZkRoutingDataReader.java
##########
@@ -0,0 +1,83 @@
+package org.apache.helix.zookeeper.routing;
+
+/*
+ * 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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.msdcommon.constant.MetadataStoreRoutingConstants;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.helix.zookeeper.datamodel.serializer.ZNRecordSerializer;
+import org.apache.helix.zookeeper.exception.MultiZkException;
+import org.apache.helix.zookeeper.impl.client.ZkClient;
+import org.apache.helix.zookeeper.zkclient.exception.ZkNoNodeException;
+
+
+/**
+ * Zk-based RoutingDataReader that establishes a ZK connection to the routing 
ZK to fetch routing
+ * data.
+ * The reading of routing data by nature should only be performed in cases of 
a Helix client
+ * initialization or routing data reset. That means we do not have to maintain 
an active ZK
+ * connection. To minimize the number of client-side ZK connections, 
ZkRoutingDataReader establishes
+ * a ZK session temporarily only to read from ZK afresh and closes sessions 
upon read completion.
+ */
+public class ZkRoutingDataReader implements RoutingDataReader {
+
+  /**
+   * Returns a map form of metadata store routing data.
+   * The map fields stand for metadata store realm address (key), and a 
corresponding list of ZK
+   * path sharding keys (key).
+   * @param endpoint
+   * @return
+   */
+  @Override
+  public Map<String, List<String>> getRawRoutingData(String endpoint) {
+    ZkClient zkClient =
+        new ZkClient.Builder().setZkServer(endpoint).setZkSerializer(new 
ZNRecordSerializer())
+            .build();

Review comment:
       If this throws an exception, we should let it throw the exception and 
not proceed. We should fail early.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to