You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/11/04 21:15:41 UTC

[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #4778: Decoupling Server instance name from physical host and port

kishoreg commented on a change in pull request #4778: Decoupling Server instance name from physical host and port
URL: https://github.com/apache/incubator-pinot/pull/4778#discussion_r342273013
 
 

 ##########
 File path: pinot-common/src/main/java/org/apache/pinot/common/helix/HelixInstanceConfigCache.java
 ##########
 @@ -0,0 +1,104 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.common.helix;
+
+import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.helix.HelixConstants;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.pinot.common.helix.ClusterChangeHandler;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Helper class to maintain a cache of all the {@code INSTANCE_CONFIG} managed by
+ * the Pinot Helix cluster. It provides a singleton object to lookup the host
+ * and port information based on the specified instance name.
+ *
+ * This will be helpful in decoupling instance name from the physical host and port
+ * information (https://github.com/apache/incubator-pinot/issues/4525)
+ */
+public class HelixInstanceConfigCache implements ClusterChangeHandler {
+  private static final Logger LOGGER = LoggerFactory.getLogger(HelixInstanceConfigCache.class);
+  private HelixManager _helixManager;
+  private Map<String, InstanceConfig> _instanceNameToConfigMap;
+  private static HelixInstanceConfigCache _instance;
+  private volatile boolean _initialized;
+
+  private HelixInstanceConfigCache() {
+    _initialized = false;
+  }
+
+  public static synchronized HelixInstanceConfigCache getInstance() {
+    if (_instance == null) {
+      _instance = new HelixInstanceConfigCache();
+    }
+    return _instance;
+  }
+
+  public boolean isInitialized() {
+    return _initialized;
+  }
+
+  @Override
+  public void init(HelixManager helixManager) {
+    Preconditions.checkState(_helixManager == null, "HelixInstanceConfigCache is already initialized");
+    _helixManager = helixManager;
+    _instanceNameToConfigMap = new HashMap<>();
+    _initialized = true;
+  }
+
+  @Override
+  public void processClusterChange(HelixConstants.ChangeType changeType) {
 
 Review comment:
   This might not be efficient when the size of the cluster is large. We already do this in an efficient way in routing table handler.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org