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 2021/05/06 21:20:42 UTC

[GitHub] [incubator-pinot] rkanumul commented on a change in pull request #6842: Core Pinot Environment Provider Implementation Logic to fetch Failureā€¦

rkanumul commented on a change in pull request #6842:
URL: https://github.com/apache/incubator-pinot/pull/6842#discussion_r627758592



##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -119,51 +122,57 @@
   private ServerQueriesDisabledTracker _serverQueriesDisabledTracker;
   private RealtimeLuceneIndexRefreshState _realtimeLuceneIndexRefreshState;
 
-  public HelixServerStarter(String helixClusterName, String zkAddress, PinotConfiguration serverConf)
-      throws Exception {
+  public HelixServerStarter(String helixClusterName, String zkAddress, PinotConfiguration serverConf) throws Exception {
     _helixClusterName = helixClusterName;
     _zkAddress = zkAddress;
     // Make a clone so that changes to the config won't propagate to the caller
     _serverConf = serverConf.clone();
     _listenerConfigs = ListenerConfigUtil.buildServerAdminConfigs(_serverConf);
 
-    _host = _serverConf.getProperty(Helix.KEY_OF_SERVER_NETTY_HOST,
-        _serverConf.getProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils.getHostnameOrAddress()
+    _host = _serverConf.getProperty(KEY_OF_SERVER_NETTY_HOST,
+        _serverConf.getProperty(SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils.getHostnameOrAddress()
             : NetUtils.getHostAddress());
-    _port = _serverConf.getProperty(Helix.KEY_OF_SERVER_NETTY_PORT, Helix.DEFAULT_SERVER_NETTY_PORT);
+    _port = _serverConf.getProperty(KEY_OF_SERVER_NETTY_PORT, DEFAULT_SERVER_NETTY_PORT);
 
-    String instanceId = _serverConf.getProperty(Server.CONFIG_OF_INSTANCE_ID);
+    String instanceId = _serverConf.getProperty(CONFIG_OF_INSTANCE_ID);
     if (instanceId == null) {
-      instanceId = Helix.PREFIX_OF_SERVER_INSTANCE + _host + "_" + _port;
-      _serverConf.addProperty(Server.CONFIG_OF_INSTANCE_ID, instanceId);
+      instanceId = PREFIX_OF_SERVER_INSTANCE + _host + "_" + _port;
+      _serverConf.addProperty(CONFIG_OF_INSTANCE_ID, instanceId);
     }
     _instanceId = instanceId;
 
     _instanceConfigScope =
         new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT, _helixClusterName).forParticipant(_instanceId)
             .build();
 
+    // Invoke pinot environment provider factory's init method to register the environment provider
+    for (String key : _serverConf.toMap().keySet()) {
+      if (key.startsWith(PREFIX_OF_CONFIG_OF_ENVIRONMENT_PROVIDER_FACTORY.toLowerCase())) {

Review comment:
       why not get it from the map instead of iterating ? that is more efficient

##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -261,12 +270,39 @@ private void updateInstanceConfigIfNeeded(String host, int port) {
         "Failed to update instance config");
   }
 
+  // Fetch the overridden server configs for the invoked environment provider
+  private void populateFailureDomain() {
+    String className = _serverConf.getProperty(ENVIRONMENT_PROVIDER_CLASS_NAME);
+    if (className == null) return;

Review comment:
       some comments and spacing b/w blocks to break logic will make it more readable.
   This function has lot of logic, the comments will help.

##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -261,12 +270,39 @@ private void updateInstanceConfigIfNeeded(String host, int port) {
         "Failed to update instance config");
   }
 
+  // Fetch the overridden server configs for the invoked environment provider
+  private void populateFailureDomain() {
+    String className = _serverConf.getProperty(ENVIRONMENT_PROVIDER_CLASS_NAME);
+    if (className == null) return;
+    PinotEnvironmentProvider pinotEnvironmentProvider = PinotEnvironmentProviderFactory.getEnvironmentProvider(className.toLowerCase());
+    _serverConf = pinotEnvironmentProvider.getEnvironment(_serverConf.toMap());
+    Map<String, Object> overriddenPinotConfigurationMap = _serverConf.toMap();

Review comment:
       essentially this part to be in constructor 

##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -103,10 +107,9 @@
  */
 public class HelixServerStarter implements ServiceStartable {
   private static final Logger LOGGER = LoggerFactory.getLogger(HelixServerStarter.class);
-
   private final String _helixClusterName;
   private final String _zkAddress;
-  private final PinotConfiguration _serverConf;
+  private PinotConfiguration _serverConf;

Review comment:
       If we override the configs in the constructor, we can keep this as final.
   can we not do that ?
   populating the instance config can happen on startup.

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/environmentprovider/PinotEnvironmentProviderFactory.java
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.spi.environmentprovider;
+
+import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This factory class initializes the PinotEnvironmentProvider class.
+ * It creates a PinotEnvironment object based on the URI found.
+ */
+public class PinotEnvironmentProviderFactory {
+
+  private PinotEnvironmentProviderFactory() {
+  }
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(PinotEnvironmentProviderFactory.class);
+  private static final String CLASS = "class";
+  private static final Map<String, PinotEnvironmentProvider> PINOT_ENVIRONMENT_PROVIDER_MAP = new HashMap<>();
+
+  public static void register(
+      String environment, String environmentProviderFileName, PinotConfiguration environmentProviderConfiguration) {
+    try {
+      LOGGER.info("Initializing PinotEnvironmentProvider for environment {}, classname {}", environment, environmentProviderFileName);
+      PinotEnvironmentProvider pinotEnvironmentProvider = PluginManager.get().createInstance(environmentProviderFileName);
+      pinotEnvironmentProvider.init(environmentProviderConfiguration);
+      PINOT_ENVIRONMENT_PROVIDER_MAP.put(environment, pinotEnvironmentProvider);
+    } catch (Exception ex) {
+      LOGGER.error(
+          "Could not instantiate environment provider for class {} with environment {}", environmentProviderFileName, environment, ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
+  public static void init(PinotConfiguration environmentProviderFactoryConfig) {
+    // Get environment and their respective classes
+    PinotConfiguration environmentConfiguration = environmentProviderFactoryConfig.subset(CLASS);
+    List<String> environments = environmentConfiguration.getKeys();
+
+    if (environments.isEmpty()) {
+      LOGGER.info("Did not find any environment provider classes in the configuration");
+      return;
+    }
+
+    for (String environment : environments) {

Review comment:
       we dont have multiple environments at once ? based on how the config is, we can only setup one. Isn't that true?
   An example of how the config looks will help

##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
##########
@@ -66,21 +66,25 @@
 import org.apache.pinot.server.starter.ServerInstance;
 import org.apache.pinot.server.starter.ServerQueriesDisabledTracker;
 import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.environmentprovider.PinotEnvironmentProvider;
+import org.apache.pinot.spi.environmentprovider.PinotEnvironmentProviderFactory;
 import org.apache.pinot.spi.filesystem.PinotFSFactory;
 import org.apache.pinot.spi.plugin.PluginManager;
 import org.apache.pinot.spi.services.ServiceRole;
 import org.apache.pinot.spi.services.ServiceStartable;
 import org.apache.pinot.spi.utils.CommonConstants;
-import org.apache.pinot.spi.utils.CommonConstants.Helix;
 import org.apache.pinot.spi.utils.CommonConstants.Helix.Instance;
 import org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel;
-import org.apache.pinot.spi.utils.CommonConstants.Server;
 import org.apache.pinot.spi.utils.CommonConstants.Server.SegmentCompletionProtocol;
 import org.apache.pinot.spi.utils.NetUtils;
 import org.apache.pinot.spi.utils.builder.TableNameBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.pinot.spi.environmentprovider.PinotEnvironmentProvider.*;
+import static org.apache.pinot.spi.utils.CommonConstants.*;
+import static org.apache.pinot.spi.utils.CommonConstants.Helix.*;
+import static org.apache.pinot.spi.utils.CommonConstants.Server.*;

Review comment:
       Let's stick to class imports and refer constants as classname.constant




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



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