This is an automated email from the ASF dual-hosted git repository. xiangfu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push: new 71e156c Make Pinot Broker/Server/Minion can start by just passing a config file (#5446) 71e156c is described below commit 71e156c83030ea48cc8f6eefd0f6986591189bc8 Author: Xiang Fu <xiangfu.1...@gmail.com> AuthorDate: Mon May 24 00:40:54 2021 -0700 Make Pinot Broker/Server/Minion can start by just passing a config file (#5446) * Make Pinot Broker/Server/Minion can start by just passing a config file * Put lock for swagger and reflection method --- .github/workflows/scripts/.pinot_quickstart.sh | 100 +++++++++++++++++---- .../broker/broker/BrokerAdminApiApplication.java | 6 +- .../broker/broker/helix/HelixBrokerStarter.java | 34 +++++-- .../broker/broker/HelixBrokerStarterTest.java | 7 +- .../apache/pinot/controller/ControllerConf.java | 24 ++++- .../api/ControllerAdminApiApplication.java | 6 +- .../pinot/integration/tests/ClusterTest.java | 16 ++-- .../tests/ServerStarterIntegrationTest.java | 5 +- .../pinot/minion/MinionAdminApiApplication.java | 6 +- .../org/apache/pinot/minion/MinionStarter.java | 19 +++- .../server/starter/helix/AdminApiApplication.java | 5 +- .../server/starter/helix/HelixServerStarter.java | 21 ++++- .../apache/pinot/spi/env/PinotConfiguration.java | 14 ++- .../apache/pinot/spi/utils/CommonConstants.java | 4 +- .../pinot/spi/utils/PinotReflectionUtils.java | 20 ++++- .../admin/command/AbstractBaseAdminCommand.java | 3 - .../pinot/tools/admin/command/AddTableCommand.java | 2 +- .../command/LaunchDataIngestionJobCommand.java | 2 +- .../tools/admin/command/StartBrokerCommand.java | 14 ++- .../admin/command/StartControllerCommand.java | 15 +++- .../tools/admin/command/StartMinionCommand.java | 2 +- .../tools/admin/command/StartServerCommand.java | 19 +++- .../admin/command/StartServiceManagerCommand.java | 16 ++-- .../tools/admin/command/StartZookeeperCommand.java | 2 + .../pinot/tools/perf/PerfBenchmarkDriver.java | 9 +- .../pinot/tools/service/PinotServiceManager.java | 28 +++++- .../PinotServiceManagerAdminApiApplication.java | 5 +- .../apache/pinot/tools/utils/PinotConfigUtils.java | 19 ++-- .../src/main/resources/conf/pinot-broker.conf | 36 ++++++++ .../src/main/resources/conf/pinot-controller.conf | 42 +++++++++ .../src/main/resources/conf/pinot-minion.conf | 39 ++++++++ .../src/main/resources/conf/pinot-server.conf | 42 +++++++++ 32 files changed, 486 insertions(+), 96 deletions(-) diff --git a/.github/workflows/scripts/.pinot_quickstart.sh b/.github/workflows/scripts/.pinot_quickstart.sh index 6124e9a..8fbe3ee 100755 --- a/.github/workflows/scripts/.pinot_quickstart.sh +++ b/.github/workflows/scripts/.pinot_quickstart.sh @@ -18,6 +18,19 @@ # under the License. # + +cleanup () { + # Terminate the process and wait for the clean up to be done + kill "$1" + while true; + do + kill -0 "$1" && sleep 1 || break + done + + # Delete ZK directory + rm -rf '/tmp/PinotAdmin/zkData' +} + # Print environment variables printenv @@ -30,7 +43,7 @@ java -version # Build PASS=0 -for i in $(seq 1 5) +for i in $(seq 1 2) do mvn clean install -B -DskipTests=true -Pbin-dist -Dmaven.javadoc.skip=true if [ $? -eq 0 ]; then @@ -43,11 +56,74 @@ if [ "${PASS}" != 1 ]; then fi # Quickstart -DIST_BIN_DIR=`ls -d pinot-distribution/target/apache-pinot-*/apache-pinot-*`/bin +DIST_BIN_DIR=`ls -d pinot-distribution/target/apache-pinot-*/apache-pinot-*` cd "${DIST_BIN_DIR}" +# Test standalone pinot +bin/pinot-admin.sh StartZookeeper & +ZK_PID=$! +sleep 10 +# Print the JVM settings +jps -lvm + +bin/pinot-admin.sh StartServiceManager -bootstrapConfigPaths conf/pinot-controller.conf conf/pinot-broker.conf conf/pinot-server.conf conf/pinot-minion.conf& +PINOT_PID=$! +# Print the JVM settings +jps -lvm + +# Wait for at most 6 minutes for all services up. +sleep 60 +for i in $(seq 1 150) +do + if [[ `curl localhost:9000/health` = "OK" ]]; then + if [[ `curl localhost:8099/health` = "OK" ]]; then + if [[ `curl localhost:8097/health` = "OK" ]]; then + break + fi + fi + fi + sleep 2 +done + +# Add Table +bin/pinot-admin.sh AddTable -tableConfigFile examples/batch/baseballStats/baseballStats_offline_table_config.json -schemaFile examples/batch/baseballStats/baseballStats_schema.json -exec +if [ $? -ne 0 ]; then + echo 'Failed to create table baseballStats.' + exit 1 +fi + +# Ingest Data +bin/pinot-admin.sh LaunchDataIngestionJob -jobSpecFile examples/batch/baseballStats/ingestionJobSpec.yaml +if [ $? -ne 0 ]; then + echo 'Failed to ingest data for table baseballStats.' + exit 1 +fi +PASS=0 + +# Wait for 10 Seconds for table to be set up, then query the total count. +sleep 10 +for i in $(seq 1 150) +do + QUERY_RES=`curl -X POST --header 'Accept: application/json' -d '{"sql":"select count(*) from baseballStats limit 1","trace":false}' http://localhost:8099/query/sql` + if [ $? -eq 0 ]; then + COUNT_STAR_RES=`echo "${QUERY_RES}" | jq '.resultTable.rows[0][0]'` + if [[ "${COUNT_STAR_RES}" =~ ^[0-9]+$ ]] && [ "${COUNT_STAR_RES}" -eq 97889 ]; then + PASS=1 + break + fi + fi + sleep 2 +done + +cleanup "${PINOT_PID}" +cleanup "${ZK_PID}" +if [ "${PASS}" -eq 0 ]; then + echo 'Standalone test failed: Cannot get correct result for count star query.' + exit 1 +fi + # Test quick-start-batch -./quick-start-batch.sh & +bin/quick-start-batch.sh & PID=$! # Print the JVM settings @@ -70,18 +146,6 @@ do sleep 2 done -cleanup () { - # Terminate the process and wait for the clean up to be done - kill "$1" - while true; - do - kill -0 "$1" && sleep 1 || break - done - - # Delete ZK directory - rm -rf '/tmp/PinotAdmin/zkData' -} - cleanup "${PID}" if [ "${PASS}" -eq 0 ]; then echo 'Batch Quickstart failed: Cannot get correct result for count star query.' @@ -89,7 +153,7 @@ if [ "${PASS}" -eq 0 ]; then fi # Test quick-start-batch-with-minion -./quick-start-batch-with-minion.sh & +bin/quick-start-batch-with-minion.sh & PID=$! # Print the JVM settings @@ -119,7 +183,7 @@ if [ "${PASS}" -eq 0 ]; then fi # Test quick-start-streaming -./quick-start-streaming.sh & +bin/quick-start-streaming.sh & PID=$! PASS=0 @@ -156,7 +220,7 @@ if [ "${PASS}" -eq 0 ]; then fi # Test quick-start-hybrid -./quick-start-hybrid.sh & +bin/quick-start-hybrid.sh & PID=$! # Print the JVM settings diff --git a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/BrokerAdminApiApplication.java b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/BrokerAdminApiApplication.java index e6b6714..54192d8 100644 --- a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/BrokerAdminApiApplication.java +++ b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/BrokerAdminApiApplication.java @@ -30,6 +30,7 @@ import org.apache.pinot.core.transport.ListenerConfig; import org.apache.pinot.core.util.ListenerConfigUtil; import org.apache.pinot.spi.env.PinotConfiguration; import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.PinotReflectionUtils; import org.glassfish.grizzly.http.server.CLStaticHttpHandler; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; @@ -70,8 +71,9 @@ public class BrokerAdminApiApplication extends ResourceConfig { } catch (IOException e) { throw new RuntimeException("Failed to start http server", e); } - - setupSwagger(); + synchronized (PinotReflectionUtils.getReflectionLock()) { + setupSwagger(); + } } private void setupSwagger() { diff --git a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java index d077dc3..03d39b6 100644 --- a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java +++ b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java @@ -63,7 +63,6 @@ import org.apache.pinot.spi.env.PinotConfiguration; import org.apache.pinot.spi.metrics.PinotMetricsRegistry; 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.Broker; import org.apache.pinot.spi.utils.CommonConstants.Helix; import org.apache.pinot.spi.utils.NetUtils; @@ -102,25 +101,43 @@ public class HelixBrokerStarter implements ServiceStartable { // Participant Helix manager handles Helix functionality such as state transitions and messages private HelixManager _participantHelixManager; + @Deprecated public HelixBrokerStarter(PinotConfiguration brokerConf, String clusterName, String zkServer) throws Exception { this(brokerConf, clusterName, zkServer, null); } + @Deprecated public HelixBrokerStarter(PinotConfiguration brokerConf, String clusterName, String zkServer, @Nullable String brokerHost) throws Exception { + this(applyBrokerConfigs(brokerConf, clusterName, zkServer, brokerHost)); + } + + @Deprecated + private static PinotConfiguration applyBrokerConfigs(PinotConfiguration brokerConf, String clusterName, String zkServers, @Nullable String brokerHost) { + brokerConf.setProperty(Helix.CONFIG_OF_CLUSTER_NAME, clusterName); + brokerConf.setProperty(Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkServers); + if (brokerHost == null) { + brokerConf.clearProperty(Broker.CONFIG_OF_BROKER_HOSTNAME); + } else { + brokerConf.setProperty(Broker.CONFIG_OF_BROKER_HOSTNAME, brokerHost); + } + return brokerConf; + } + + public HelixBrokerStarter(PinotConfiguration brokerConf) throws Exception { _brokerConf = brokerConf; _listenerConfigs = ListenerConfigUtil.buildBrokerConfigs(brokerConf); setupHelixSystemProperties(); - _clusterName = clusterName; + _clusterName = brokerConf.getProperty(Helix.CONFIG_OF_CLUSTER_NAME); // Remove all white-spaces from the list of zkServers (if any). - _zkServers = zkServer.replaceAll("\\s+", ""); - + _zkServers = brokerConf.getProperty(Helix.CONFIG_OF_ZOOKEEPR_SERVER).replaceAll("\\s+", ""); + String brokerHost = brokerConf.getProperty(Broker.CONFIG_OF_BROKER_HOSTNAME); if (brokerHost == null) { - brokerHost = _brokerConf.getProperty(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils + brokerHost = _brokerConf.getProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils .getHostnameOrAddress() : NetUtils.getHostAddress(); } @@ -211,7 +228,7 @@ public class HelixBrokerStarter implements ServiceStartable { _brokerConf.setProperty(Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, Integer.parseInt(log2mStr)); } catch (NumberFormatException e) { LOGGER.warn("Invalid config of '{}': '{}', using: {} as the default log2m for HyperLogLog", - Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, log2mStr, CommonConstants.Helix.DEFAULT_HYPERLOGLOG_LOG2M); + Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, log2mStr, Helix.DEFAULT_HYPERLOGLOG_LOG2M); } } @@ -420,8 +437,9 @@ public class HelixBrokerStarter implements ServiceStartable { properties.put(Helix.KEY_OF_BROKER_QUERY_PORT, 5001); properties.put(Broker.CONFIG_OF_BROKER_TIMEOUT_MS, 60 * 1000L); - - return new HelixBrokerStarter(new PinotConfiguration(properties), "quickstart", "localhost:2122"); + properties.put(Helix.CONFIG_OF_CLUSTER_NAME, "quickstart"); + properties.put(Helix.CONFIG_OF_ZOOKEEPR_SERVER, "localhost:2122"); + return new HelixBrokerStarter(new PinotConfiguration(properties)); } public static void main(String[] args) diff --git a/pinot-broker/src/test/java/org/apache/pinot/broker/broker/HelixBrokerStarterTest.java b/pinot-broker/src/test/java/org/apache/pinot/broker/broker/HelixBrokerStarterTest.java index 4c37819..6e21311 100644 --- a/pinot-broker/src/test/java/org/apache/pinot/broker/broker/HelixBrokerStarterTest.java +++ b/pinot-broker/src/test/java/org/apache/pinot/broker/broker/HelixBrokerStarterTest.java @@ -76,9 +76,10 @@ public class HelixBrokerStarterTest extends ControllerTest { Map<String, Object> properties = new HashMap<>(); properties.put(Helix.KEY_OF_BROKER_QUERY_PORT, 18099); - - _brokerStarter = - new HelixBrokerStarter(new PinotConfiguration(properties), getHelixClusterName(), getZkUrl()); + properties.put(Helix.CONFIG_OF_CLUSTER_NAME, getHelixClusterName()); + properties.put(Helix.CONFIG_OF_ZOOKEEPR_SERVER, getZkUrl()); + + _brokerStarter = new HelixBrokerStarter(new PinotConfiguration(properties)); _brokerStarter.start(); addFakeBrokerInstancesToAutoJoinHelixCluster(NUM_BROKERS - 1, true); diff --git a/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerConf.java b/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerConf.java index ce91c01..43f5754 100644 --- a/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerConf.java +++ b/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerConf.java @@ -28,6 +28,7 @@ import java.util.Random; import org.apache.commons.configuration.Configuration; import org.apache.helix.controller.rebalancer.strategy.AutoRebalanceStrategy; import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.StringUtil; import org.apache.pinot.spi.env.PinotConfiguration; import org.apache.pinot.spi.filesystem.LocalPinotFS; import org.apache.pinot.spi.utils.CommonConstants; @@ -235,7 +236,7 @@ public class ControllerConf extends PinotConfiguration { } public void setHelixClusterName(String clusterName) { - setProperty(HELIX_CLUSTER_NAME, clusterName); + setProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, clusterName); } public void setControllerHost(String host) { @@ -275,7 +276,7 @@ public class ControllerConf extends PinotConfiguration { } public void setZkStr(String zkStr) { - setProperty(ZK_STR, zkStr); + setProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkStr); } public void setDimTableMaxSize(String size) { @@ -293,7 +294,8 @@ public class ControllerConf extends PinotConfiguration { } public String getHelixClusterName() { - return getProperty(HELIX_CLUSTER_NAME); + return containsKey(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME) ? getProperty( + CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME) : getProperty(HELIX_CLUSTER_NAME); } public String getControllerHost() { @@ -339,7 +341,21 @@ public class ControllerConf extends PinotConfiguration { } public String getZkStr() { - return getProperty(ZK_STR); + Object zkAddressObj = containsKey(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER) ? getProperty( + CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER) : getProperty(ZK_STR); + + // The set method converted comma separated string into ArrayList, so need to convert back to String here. + if (zkAddressObj instanceof List) { + List<String> zkAddressList = (List<String>) zkAddressObj; + String[] zkAddress = zkAddressList.toArray(new String[0]); + return StringUtil.join(",", zkAddress); + } else if (zkAddressObj instanceof String) { + return (String) zkAddressObj; + } else { + throw new RuntimeException( + "Unexpected data type for zkAddress PropertiesConfiguration, expecting String but got " + zkAddressObj + .getClass().getName()); + } } @Override diff --git a/pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java b/pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java index 32b5916..f4df0e5 100644 --- a/pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java +++ b/pinot-controller/src/main/java/org/apache/pinot/controller/api/ControllerAdminApiApplication.java @@ -31,6 +31,7 @@ import org.apache.pinot.controller.api.access.AuthenticationFilter; import org.apache.pinot.core.transport.ListenerConfig; import org.apache.pinot.core.util.ListenerConfigUtil; import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.PinotReflectionUtils; import org.glassfish.grizzly.http.server.CLStaticHttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.hk2.utilities.binding.AbstractBinder; @@ -77,8 +78,9 @@ public class ControllerAdminApiApplication extends ResourceConfig { } catch (IOException e) { throw new RuntimeException("Failed to start http server", e); } - - setupSwagger(_httpServer); + synchronized (PinotReflectionUtils.getReflectionLock()) { + setupSwagger(_httpServer); + } ClassLoader classLoader = ControllerAdminApiApplication.class.getClassLoader(); diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java index 726422e..fdb1d5c 100644 --- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java +++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java @@ -117,6 +117,8 @@ public abstract class ClusterTest extends ControllerTest { _brokerPorts = new ArrayList<>(); for (int i = 0; i < numBrokers; i++) { Map<String, Object> properties = getDefaultBrokerConfiguration().toMap(); + properties.put(Helix.CONFIG_OF_CLUSTER_NAME, getHelixClusterName()); + properties.put(Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkStr); properties.put(Broker.CONFIG_OF_BROKER_TIMEOUT_MS, 60 * 1000L); int port = NetUtils.findOpenPort(basePort + i); _brokerPorts.add(port); @@ -125,8 +127,7 @@ public abstract class ClusterTest extends ControllerTest { PinotConfiguration configuration = new PinotConfiguration(properties); overrideBrokerConf(configuration); - HelixBrokerStarter brokerStarter = - new HelixBrokerStarter(configuration, getHelixClusterName(), zkStr, LOCAL_HOST); + HelixBrokerStarter brokerStarter = new HelixBrokerStarter(configuration); brokerStarter.start(); _brokerStarters.add(brokerStarter); } @@ -180,6 +181,8 @@ public abstract class ClusterTest extends ControllerTest { overrideServerConf(configuration); try { for (int i = 0; i < numServers; i++) { + configuration.setProperty(Helix.CONFIG_OF_CLUSTER_NAME, getHelixClusterName()); + configuration.setProperty(Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkStr); configuration.setProperty(Server.CONFIG_OF_INSTANCE_DATA_DIR, Server.DEFAULT_INSTANCE_DATA_DIR + "-" + i); configuration .setProperty(Server.CONFIG_OF_INSTANCE_SEGMENT_TAR_DIR, Server.DEFAULT_INSTANCE_SEGMENT_TAR_DIR + "-" + i); @@ -188,9 +191,9 @@ public abstract class ClusterTest extends ControllerTest { // Thread time measurement is disabled by default, enable it in integration tests. // TODO: this can be removed when we eventually enable thread time measurement by default. configuration.setProperty(Server.CONFIG_OF_ENABLE_THREAD_CPU_TIME_MEASUREMENT, true); - HelixServerStarter helixServerStarter = new HelixServerStarter(getHelixClusterName(), zkStr, configuration); - _serverStarters.add(helixServerStarter); + HelixServerStarter helixServerStarter = new HelixServerStarter(configuration); helixServerStarter.start(); + _serverStarters.add(helixServerStarter); } } catch (Exception e) { throw new RuntimeException(e); @@ -207,7 +210,10 @@ public abstract class ClusterTest extends ControllerTest { @Nullable List<MinionEventObserverFactory> eventObserverFactories) { FileUtils.deleteQuietly(new File(Minion.DEFAULT_INSTANCE_BASE_DIR)); try { - _minionStarter = new MinionStarter(getHelixClusterName(), getZkUrl(), getDefaultMinionConfiguration()); + PinotConfiguration minionConf = getDefaultMinionConfiguration(); + minionConf.setProperty(Helix.CONFIG_OF_CLUSTER_NAME, getHelixClusterName()); + minionConf.setProperty(Helix.CONFIG_OF_ZOOKEEPR_SERVER, getZkUrl()); + _minionStarter = new MinionStarter(minionConf); // Register task executor factories if (taskExecutorFactories != null) { for (PinotTaskExecutorFactory taskExecutorFactory : taskExecutorFactories) { diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ServerStarterIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ServerStarterIntegrationTest.java index 15741cd..9974dec 100644 --- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ServerStarterIntegrationTest.java +++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/ServerStarterIntegrationTest.java @@ -54,8 +54,9 @@ public class ServerStarterIntegrationTest extends ControllerTest { private void verifyInstanceConfig(PinotConfiguration serverConf, String expectedInstanceId, String expectedHost, int expectedPort) throws Exception { - HelixServerStarter helixServerStarter = - new HelixServerStarter(getHelixClusterName(), getZkUrl(), serverConf); + serverConf.setProperty(CONFIG_OF_CLUSTER_NAME, getHelixClusterName()); + serverConf.setProperty(CONFIG_OF_ZOOKEEPR_SERVER, getZkUrl()); + HelixServerStarter helixServerStarter = new HelixServerStarter(serverConf); helixServerStarter.start(); helixServerStarter.stop(); diff --git a/pinot-minion/src/main/java/org/apache/pinot/minion/MinionAdminApiApplication.java b/pinot-minion/src/main/java/org/apache/pinot/minion/MinionAdminApiApplication.java index 12b5058..e94b069 100644 --- a/pinot-minion/src/main/java/org/apache/pinot/minion/MinionAdminApiApplication.java +++ b/pinot-minion/src/main/java/org/apache/pinot/minion/MinionAdminApiApplication.java @@ -27,6 +27,7 @@ import org.apache.pinot.core.transport.ListenerConfig; import org.apache.pinot.core.util.ListenerConfigUtil; import org.apache.pinot.spi.env.PinotConfiguration; import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.PinotReflectionUtils; import org.glassfish.grizzly.http.server.CLStaticHttpHandler; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; @@ -70,8 +71,9 @@ public class MinionAdminApiApplication extends ResourceConfig { } catch (IOException e) { throw new RuntimeException("Failed to start http server", e); } - - setupSwagger(); + synchronized (PinotReflectionUtils.getReflectionLock()) { + setupSwagger(); + } } private void setupSwagger() { diff --git a/pinot-minion/src/main/java/org/apache/pinot/minion/MinionStarter.java b/pinot-minion/src/main/java/org/apache/pinot/minion/MinionStarter.java index 6cd3346..2430baa 100644 --- a/pinot-minion/src/main/java/org/apache/pinot/minion/MinionStarter.java +++ b/pinot-minion/src/main/java/org/apache/pinot/minion/MinionStarter.java @@ -77,10 +77,25 @@ public class MinionStarter implements ServiceStartable { private MinionAdminApiApplication _minionAdminApplication; private final List<ListenerConfig> _listenerConfigs; - public MinionStarter(String helixClusterName, String zkAddress, PinotConfiguration config) + @Deprecated + public MinionStarter(String clusterName, String zkServers, PinotConfiguration minionConfig) + throws Exception { + this(applyMinionConfigs(minionConfig, clusterName, zkServers)); + } + + @Deprecated + private static PinotConfiguration applyMinionConfigs(PinotConfiguration minionConfig, String clusterName, String zkServers) { + minionConfig.setProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, clusterName); + minionConfig.setProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkServers); + return minionConfig; + } + + public MinionStarter(PinotConfiguration config) throws Exception { _config = config; - String host = _config.getProperty(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST, + String helixClusterName = _config.getProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME); + String zkAddress = _config.getProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER); + String host = _config.getProperty(CommonConstants.Helix.KEY_OF_MINION_HOST, _config.getProperty(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils .getHostnameOrAddress() : NetUtils.getHostAddress()); int port = _config.getProperty(CommonConstants.Helix.KEY_OF_MINION_PORT, CommonConstants.Minion.DEFAULT_HELIX_PORT); diff --git a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java index 37a6e60..34b83a4 100644 --- a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java +++ b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/AdminApiApplication.java @@ -34,6 +34,7 @@ import org.apache.pinot.server.api.access.AccessControlFactory; import org.apache.pinot.server.starter.ServerInstance; import org.apache.pinot.spi.env.PinotConfiguration; import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.PinotReflectionUtils; import org.glassfish.grizzly.http.server.CLStaticHttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.hk2.utilities.binding.AbstractBinder; @@ -91,7 +92,9 @@ public class AdminApiApplication extends ResourceConfig { throw new RuntimeException("Failed to start http server", e); } - setupSwagger(httpServer); + synchronized (PinotReflectionUtils.getReflectionLock()) { + setupSwagger(httpServer); + } started = true; return true; } diff --git a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java index ecb01fd..0b2dfda 100644 --- a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java +++ b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java @@ -126,13 +126,25 @@ public class HelixServerStarter implements ServiceStartable { private RealtimeLuceneIndexRefreshState _realtimeLuceneIndexRefreshState; private PinotEnvironmentProvider _pinotEnvironmentProvider; + @Deprecated public HelixServerStarter(String helixClusterName, String zkAddress, PinotConfiguration serverConf) throws Exception { - _helixClusterName = helixClusterName; - _zkAddress = zkAddress; + this(applyServerConfig(serverConf, helixClusterName, zkAddress)); + } + + @Deprecated + private static PinotConfiguration applyServerConfig(PinotConfiguration serverConf, String helixClusterName, String zkAddress) { + serverConf.setProperty(Helix.CONFIG_OF_CLUSTER_NAME, helixClusterName); + serverConf.setProperty(Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkAddress); + return serverConf; + } + + public HelixServerStarter(PinotConfiguration serverConf) throws Exception { // Make a clone so that changes to the config won't propagate to the caller _serverConf = serverConf.clone(); _listenerConfigs = ListenerConfigUtil.buildServerAdminConfigs(_serverConf); + _helixClusterName = _serverConf.getProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME); + _zkAddress = _serverConf.getProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER); _host = _serverConf.getProperty(Helix.KEY_OF_SERVER_NETTY_HOST, _serverConf.getProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false) ? NetUtils.getHostnameOrAddress() @@ -713,12 +725,13 @@ public class HelixServerStarter implements ServiceStartable { throws Exception { Map<String, Object> properties = new HashMap<>(); int port = 8003; + properties.put(Helix.CONFIG_OF_CLUSTER_NAME, "quickstart"); + properties.put(Helix.CONFIG_OF_ZOOKEEPR_SERVER, "localhost:2191"); properties.put(Helix.KEY_OF_SERVER_NETTY_PORT, port); properties.put(Server.CONFIG_OF_INSTANCE_DATA_DIR, "/tmp/PinotServer/test" + port + "/index"); properties.put(Server.CONFIG_OF_INSTANCE_SEGMENT_TAR_DIR, "/tmp/PinotServer/test" + port + "/segmentTar"); - HelixServerStarter serverStarter = - new HelixServerStarter("quickstart", "localhost:2191", new PinotConfiguration(properties)); + HelixServerStarter serverStarter = new HelixServerStarter(new PinotConfiguration(properties)); serverStarter.start(); return serverStarter; } diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/env/PinotConfiguration.java b/pinot-spi/src/main/java/org/apache/pinot/spi/env/PinotConfiguration.java index 20179e2..b20f5d0 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/env/PinotConfiguration.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/env/PinotConfiguration.java @@ -380,16 +380,26 @@ public class PinotConfiguration { /** * Overwrites a property value in memory. - * + * * @param name of the property to overwrite in memory. Applies relaxed binding on the property name. * @param value to overwrite in memory - * + * * @deprecated Configurations should be immutable. Prefer creating a new {@link #PinotConfiguration} with base properties to overwrite properties. */ public void setProperty(String name, Object value) { configuration.setProperty(relaxPropertyName(name), value); } + + /** + * Delete a property value in memory. + * + * @param name of the property to remove in memory. Applies relaxed binding on the property name. + */ + public void clearProperty(String name) { + configuration.clearProperty(relaxPropertyName(name)); + } + /** * <p> * Creates a copy of the configuration only containing properties matching a property prefix. diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java index 71d11ec..f676c89 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java @@ -150,8 +150,9 @@ public class CommonConstants { "pinot.helix.instance.state.maxStateTransitions"; public static final String DEFAULT_HELIX_INSTANCE_MAX_STATE_TRANSITIONS = "100000"; public static final String DEFAULT_FLAPPING_TIME_WINDOW_MS = "1"; - public static final String PINOT_SERVICE_ROLE = "pinot.service.role"; + public static final String CONFIG_OF_CLUSTER_NAME = "pinot.cluster.name"; + public static final String CONFIG_OF_ZOOKEEPR_SERVER = "pinot.zk.server"; } public static class Broker { @@ -178,6 +179,7 @@ public class CommonConstants { public static final String CONFIG_OF_BROKER_TIMEOUT_MS = "pinot.broker.timeoutMs"; public static final long DEFAULT_BROKER_TIMEOUT_MS = 10_000L; public static final String CONFIG_OF_BROKER_ID = "pinot.broker.id"; + public static final String CONFIG_OF_BROKER_HOSTNAME = "pinot.broker.hostname"; // Configuration to consider the broker ServiceStatus as being STARTED if the percent of resources (tables) that // are ONLINE for this this broker has crossed the threshold percentage of the total number of tables // that it is expected to serve. diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/PinotReflectionUtils.java b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/PinotReflectionUtils.java index b626ce3..cfda74c 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/PinotReflectionUtils.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/PinotReflectionUtils.java @@ -29,12 +29,24 @@ import org.reflections.util.FilterBuilder; public class PinotReflectionUtils { private static final String PINOT_PACKAGE_PREFIX = "org.apache.pinot"; + private static final Object REFLECTION_LOCK = new Object(); public static Set<Class<?>> getClassesThroughReflection(final String regexPattern, final Class<? extends Annotation> annotation) { - Reflections reflections = new Reflections( - new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(PINOT_PACKAGE_PREFIX)) - .filterInputsBy(new FilterBuilder.Include(regexPattern)).setScanners(new TypeAnnotationsScanner())); - return reflections.getTypesAnnotatedWith(annotation, true); + synchronized (getReflectionLock()) { + Reflections reflections = new Reflections( + new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(PINOT_PACKAGE_PREFIX)).filterInputsBy(new FilterBuilder.Include(regexPattern)).setScanners(new TypeAnnotationsScanner())); + return reflections.getTypesAnnotatedWith(annotation, true); + } + } + + /** + * Due to the multi-threading issue in org.reflections.vfs.ZipDir, we need to put a lock before calling the + * reflection related methods. + * + * @return + */ + public static Object getReflectionLock() { + return REFLECTION_LOCK; } } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractBaseAdminCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractBaseAdminCommand.java index 8078b7c..741d5b6 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractBaseAdminCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AbstractBaseAdminCommand.java @@ -20,7 +20,6 @@ package org.apache.pinot.tools.admin.command; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -49,8 +48,6 @@ public class AbstractBaseAdminCommand extends AbstractBaseCommand { static final String DEFAULT_CONTROLLER_PORT = "9000"; static final String URI_TABLES_PATH = "/tables/"; - static final String TMP_DIR = System.getProperty("java.io.tmpdir") + File.separator; - public AbstractBaseAdminCommand(boolean addShutdownHook) { super(addShutdownHook); } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java index 7817da4..ed5803b 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/AddTableCommand.java @@ -44,7 +44,7 @@ public class AddTableCommand extends AbstractBaseAdminCommand implements Command @Option(name = "-tableConfigFile", required = true, metaVar = "<string>", aliases = {"-tableConf", "-tableConfig", "-filePath"}, usage = "Path to table config file.") private String _tableConfigFile; - @Option(name = "-schemaFile", required = false, metaVar = "<string>", aliases = {"-schema"}, usage = "Path to table schema file.") + @Option(name = "-schemaFile", required = false, metaVar = "<string>", aliases = {"-schemaFileName","-schema"}, usage = "Path to table schema file.") private String _schemaFile = null; @Option(name = "-controllerHost", required = false, metaVar = "<String>", usage = "host name for controller.") diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchDataIngestionJobCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchDataIngestionJobCommand.java index 573cf5a..62347e6 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchDataIngestionJobCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/LaunchDataIngestionJobCommand.java @@ -43,7 +43,7 @@ public class LaunchDataIngestionJobCommand extends AbstractBaseAdminCommand impl private static final Logger LOGGER = LoggerFactory.getLogger(LaunchDataIngestionJobCommand.class); @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.") private boolean _help = false; - @Option(name = "-jobSpecFile", required = true, metaVar = "<string>", usage = "Ingestion job spec file") + @Option(name = "-jobSpecFile", required = true, metaVar = "<string>", aliases = {"-jobSpec"}, usage = "Ingestion job spec file") private String _jobSpecFile; @Option(name = "-values", required = false, metaVar = "<template context>", handler = StringArrayOptionHandler.class, usage = "Context values set to the job spec template") private List<String> _values; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartBrokerCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartBrokerCommand.java index b0738bf..89af4f7 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartBrokerCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartBrokerCommand.java @@ -19,6 +19,8 @@ package org.apache.pinot.tools.admin.command; import java.io.File; +import java.net.SocketException; +import java.net.UnknownHostException; import java.util.HashMap; import java.util.Map; import org.apache.commons.configuration.ConfigurationException; @@ -40,16 +42,22 @@ public class StartBrokerCommand extends AbstractBaseAdminCommand implements Comm private static final Logger LOGGER = LoggerFactory.getLogger(StartBrokerCommand.class); @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.") private boolean _help = false; + @Option(name = "-brokerHost", required = false, metaVar = "<String>", usage = "host name for broker.") private String _brokerHost; + @Option(name = "-brokerPort", required = false, metaVar = "<int>", usage = "Broker port number to use for query.") private int _brokerPort = CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT; + @Option(name = "-zkAddress", required = false, metaVar = "<http>", usage = "HTTP address of Zookeeper.") private String _zkAddress = DEFAULT_ZK_ADDRESS; + @Option(name = "-clusterName", required = false, metaVar = "<String>", usage = "Pinot cluster name.") private String _clusterName = "PinotCluster"; - @Option(name = "-configFileName", required = false, metaVar = "<Config File Name>", usage = "Broker Starter Config file.", forbids = {"-brokerHost", "-brokerPort"}) + + @Option(name = "-configFileName", required = false, aliases = {"-config", "-configFile", "-brokerConfig", "-brokerConf"}, metaVar = "<Config File Name>", usage = "Broker Starter Config file.", forbids = {"-brokerHost", "-brokerPort"}) private String _configFileName; + private HelixBrokerStarter _brokerStarter; private Map<String, Object> _configOverrides = new HashMap<>(); @@ -129,12 +137,12 @@ public class StartBrokerCommand extends AbstractBaseAdminCommand implements Comm } private Map<String, Object> getBrokerConf() - throws ConfigurationException { + throws ConfigurationException, SocketException, UnknownHostException { Map<String, Object> properties = new HashMap<>(); if (_configFileName != null) { properties.putAll(PinotConfigUtils.readConfigFromFile(_configFileName)); } else { - properties.putAll(PinotConfigUtils.generateBrokerConf(_brokerPort)); + properties.putAll(PinotConfigUtils.generateBrokerConf(_clusterName, _zkAddress, _brokerHost, _brokerPort)); } if (_configOverrides != null) { properties.putAll(_configOverrides); diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartControllerCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartControllerCommand.java index 9d17ad5..6d2cc37 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartControllerCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartControllerCommand.java @@ -33,6 +33,8 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.pinot.tools.utils.PinotConfigUtils.TMP_DIR; + /** * Class to implement StartController command. @@ -40,22 +42,31 @@ import org.slf4j.LoggerFactory; */ public class StartControllerCommand extends AbstractBaseAdminCommand implements Command { private static final Logger LOGGER = LoggerFactory.getLogger(StartControllerCommand.class); + @Option(name = "-controllerMode", required = false, metaVar = "<String>", usage = "Pinot controller mode.") private ControllerConf.ControllerMode _controllerMode = ControllerConf.ControllerMode.DUAL; + @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.") private boolean _help = false; + @Option(name = "-controllerHost", required = false, metaVar = "<String>", usage = "host name for controller.") private String _controllerHost; + @Option(name = "-controllerPort", required = false, metaVar = "<int>", usage = "Port number to start the controller at.") private String _controllerPort = DEFAULT_CONTROLLER_PORT; + @Option(name = "-dataDir", required = false, metaVar = "<string>", usage = "Path to directory containging data.") - private String _dataDir = TMP_DIR + "PinotController"; + private String _dataDir = TMP_DIR + "data/PinotController"; + @Option(name = "-zkAddress", required = false, metaVar = "<http>", usage = "Http address of Zookeeper.") private String _zkAddress = DEFAULT_ZK_ADDRESS; + @Option(name = "-clusterName", required = false, metaVar = "<String>", usage = "Pinot cluster name.") private String _clusterName = DEFAULT_CLUSTER_NAME; - @Option(name = "-configFileName", required = false, metaVar = "<FilePathName>", usage = "Controller Starter config file", forbids = {"-controllerHost", "-controllerPort", "-dataDir", "-zkAddress", "-clusterName", "-controllerMode"}) + + @Option(name = "-configFileName", required = false, aliases = {"-config", "-configFile", "-controllerConfig", "-controllerConf"}, metaVar = "<FilePathName>", usage = "Controller Starter config file", forbids = {"-controllerHost", "-controllerPort", "-dataDir", "-zkAddress", "-clusterName", "-controllerMode"}) private String _configFileName; + // This can be set via the set method, or via config file input. private boolean _tenantIsolation = true; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartMinionCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartMinionCommand.java index 79eb023..2be3267 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartMinionCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartMinionCommand.java @@ -111,7 +111,7 @@ public class StartMinionCommand extends AbstractBaseAdminCommand implements Comm if (_configFileName != null) { properties.putAll(PinotConfigUtils.readConfigFromFile(_configFileName)); } else { - properties.putAll(PinotConfigUtils.generateMinionConf(_minionHost, _minionPort)); + properties.putAll(PinotConfigUtils.generateMinionConf(_clusterName, _zkAddress, _minionHost, _minionPort)); } if (_configOverrides != null) { properties.putAll(_configOverrides); diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServerCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServerCommand.java index 418bff7..aa618b2 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServerCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServerCommand.java @@ -32,6 +32,8 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.pinot.tools.utils.PinotConfigUtils.TMP_DIR; + /** * Class to implement StartServer command. @@ -41,21 +43,29 @@ public class StartServerCommand extends AbstractBaseAdminCommand implements Comm private static final Logger LOGGER = LoggerFactory.getLogger(StartServerCommand.class); @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.") private boolean _help = false; + @Option(name = "-serverHost", required = false, metaVar = "<String>", usage = "Host name for server.") private String _serverHost; + @Option(name = "-serverPort", required = false, metaVar = "<int>", usage = "Port number to start the server at.") private int _serverPort = CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT; + @Option(name = "-serverAdminPort", required = false, metaVar = "<int>", usage = "Port number to serve the server admin API at.") private int _serverAdminPort = CommonConstants.Server.DEFAULT_ADMIN_API_PORT; + @Option(name = "-dataDir", required = false, metaVar = "<string>", usage = "Path to directory containing data.") - private String _dataDir = TMP_DIR + "pinotServerData"; + private String _dataDir = TMP_DIR + "data/pinotServerData"; + @Option(name = "-segmentDir", required = false, metaVar = "<string>", usage = "Path to directory containing segments.") - private String _segmentDir = TMP_DIR + "pinotSegments"; + private String _segmentDir = TMP_DIR + "data/pinotSegments"; + @Option(name = "-zkAddress", required = false, metaVar = "<http>", usage = "Http address of Zookeeper.") private String _zkAddress = DEFAULT_ZK_ADDRESS; + @Option(name = "-clusterName", required = false, metaVar = "<String>", usage = "Pinot cluster name.") private String _clusterName = "PinotCluster"; - @Option(name = "-configFileName", required = false, metaVar = "<Config File Name>", usage = "Server Starter Config file.", forbids = {"-serverHost", "-serverPort", "-dataDir", "-segmentDir",}) + + @Option(name = "-configFileName", required = false, aliases = {"-config", "-configFile", "-serverConfig", "-serverConf"}, metaVar = "<Config File Name>", usage = "Server Starter Config file.", forbids = {"-serverHost", "-serverPort", "-dataDir", "-segmentDir",}) private String _configFileName; private Map<String, Object> _configOverrides = new HashMap<>(); @@ -158,7 +168,8 @@ public class StartServerCommand extends AbstractBaseAdminCommand implements Comm if (_configFileName != null) { properties.putAll(PinotConfigUtils.readConfigFromFile(_configFileName)); } else { - properties.putAll(PinotConfigUtils.generateServerConf(_serverHost, _serverPort, _serverAdminPort, _dataDir, _segmentDir)); + properties.putAll(PinotConfigUtils.generateServerConf(_clusterName, _zkAddress, _serverHost, _serverPort, + _serverAdminPort, _dataDir, _segmentDir)); } if (_configOverrides != null) { properties.putAll(_configOverrides); diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java index 6a988bb..5417cb6 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartServiceManagerCommand.java @@ -62,15 +62,15 @@ public class StartServiceManagerCommand extends AbstractBaseAdminCommand impleme @Option(name = "-help", required = false, help = true, aliases = {"-h", "--h", "--help"}, usage = "Print this message.") private boolean _help; - @Option(name = "-zkAddress", required = true, metaVar = "<http>", usage = "Http address of Zookeeper.") + @Option(name = "-zkAddress", required = false, metaVar = "<http>", usage = "Http address of Zookeeper.", forbids = {"-bootstrapConfigPaths", "-bootstrapServices"}) private String _zkAddress = DEFAULT_ZK_ADDRESS; - @Option(name = "-clusterName", required = true, metaVar = "<String>", usage = "Pinot cluster name.") + @Option(name = "-clusterName", required = false, metaVar = "<String>", usage = "Pinot cluster name.", forbids = {"-bootstrapConfigPaths", "-bootstrapServices"}) private String _clusterName = DEFAULT_CLUSTER_NAME; - @Option(name = "-port", required = true, metaVar = "<int>", usage = "Pinot service manager admin port, -1 means disable, 0 means a random available port.") - private int _port; - @Option(name = "-bootstrapConfigPaths", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service config file paths. Each config file requires an extra config: 'pinot.service.role' to indicate which service to start.", forbids = {"-bootstrapServices"}) + @Option(name = "-port", required = false, metaVar = "<int>", usage = "Pinot service manager admin port, -1 means disable, 0 means a random available port.", forbids = {"-bootstrapConfigPaths", "-bootstrapServices"}) + private int _port = -1; + @Option(name = "-bootstrapConfigPaths", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service config file paths. Each config file requires an extra config: 'pinot.service.role' to indicate which service to start.", forbids = {"-zkAddress", "-clusterName", "-port", "-bootstrapServices"}) private String[] _bootstrapConfigPaths; - @Option(name = "-bootstrapServices", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service roles to start with default config. E.g. CONTROLLER/BROKER/SERVER", forbids = {"-bootstrapConfigPaths"}) + @Option(name = "-bootstrapServices", handler = StringArrayOptionHandler.class, required = false, usage = "A list of Pinot service roles to start with default config. E.g. CONTROLLER/BROKER/SERVER", forbids = {"-zkAddress", "-clusterName", "-port", "-bootstrapConfigPaths"}) private String[] _bootstrapServices = BOOTSTRAP_SERVICES; private PinotServiceManager _pinotServiceManager; @@ -206,9 +206,9 @@ public class StartServiceManagerCommand extends AbstractBaseAdminCommand impleme return PinotConfigUtils.generateControllerConf(_zkAddress, _clusterName, null, DEFAULT_CONTROLLER_PORT, null, ControllerConf.ControllerMode.DUAL, true); case BROKER: - return PinotConfigUtils.generateBrokerConf(CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT); + return PinotConfigUtils.generateBrokerConf(_clusterName, _zkAddress, null, CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT); case SERVER: - return PinotConfigUtils.generateServerConf(null, CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT, + return PinotConfigUtils.generateServerConf(_clusterName, _zkAddress, null, CommonConstants.Helix.DEFAULT_SERVER_NETTY_PORT, CommonConstants.Server.DEFAULT_ADMIN_API_PORT, null, null); default: throw new RuntimeException("No default config found for service role: " + serviceRole); diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartZookeeperCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartZookeeperCommand.java index c44b608..5ddd1d9 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartZookeeperCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/StartZookeeperCommand.java @@ -27,6 +27,8 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.pinot.tools.utils.PinotConfigUtils.TMP_DIR; + /** * Class for command to start ZooKeeper. diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkDriver.java b/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkDriver.java index 5afec65..2e92806 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkDriver.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkDriver.java @@ -223,10 +223,12 @@ public class PerfBenchmarkDriver { Map<String, Object> properties = new HashMap<>(); properties.put(CommonConstants.Helix.Instance.INSTANCE_ID_KEY, brokerInstanceName); properties.put(CommonConstants.Broker.CONFIG_OF_BROKER_TIMEOUT_MS, BROKER_TIMEOUT_MS); + properties.put(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, _clusterName); + properties.put(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, _zkAddress); LOGGER.info("Starting broker instance: {}", brokerInstanceName); - new HelixBrokerStarter(new PinotConfiguration(properties), _clusterName, _zkAddress).start(); + new HelixBrokerStarter(new PinotConfiguration(properties)).start(); } private void startServer() @@ -241,14 +243,15 @@ public class PerfBenchmarkDriver { properties.put(CommonConstants.Server.CONFIG_OF_INSTANCE_SEGMENT_TAR_DIR, _serverInstanceSegmentTarDir); properties.put(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST, "localhost"); properties.put(CommonConstants.Server.CONFIG_OF_INSTANCE_ID, _serverInstanceName); + properties.put(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, _clusterName); + properties.put(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, _zkAddress); if (_segmentFormatVersion != null) { properties.put(CommonConstants.Server.CONFIG_OF_SEGMENT_FORMAT_VERSION, _segmentFormatVersion); } LOGGER.info("Starting server instance: {}", _serverInstanceName); - HelixServerStarter helixServerStarter = - new HelixServerStarter(_clusterName, _zkAddress, new PinotConfiguration(properties)); + HelixServerStarter helixServerStarter = new HelixServerStarter(new PinotConfiguration(properties)); helixServerStarter.start(); } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java index 2a4e4b1..bd5bb28 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManager.java @@ -31,6 +31,7 @@ import org.apache.pinot.server.starter.helix.HelixServerStarter; import org.apache.pinot.spi.env.PinotConfiguration; 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.NetUtils; import org.apache.pinot.tools.service.api.resources.PinotInstanceStatus; import org.slf4j.Logger; @@ -121,10 +122,15 @@ public class PinotServiceManager { public String startBroker(PinotConfiguration brokerConf) throws Exception { LOGGER.info("Trying to start Pinot Broker..."); - String brokerHost = brokerConf.getProperty("broker.host"); + if (!brokerConf.containsKey(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME)) { + brokerConf.setProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, _clusterName); + } + if (!brokerConf.containsKey(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER)) { + brokerConf.setProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, _zkAddress); + } HelixBrokerStarter brokerStarter; try { - brokerStarter = new HelixBrokerStarter(brokerConf, _clusterName, _zkAddress, brokerHost); + brokerStarter = new HelixBrokerStarter(brokerConf); } catch (Exception e) { LOGGER.error("Failed to initialize Pinot Broker Starter", e); throw e; @@ -144,7 +150,15 @@ public class PinotServiceManager { public String startServer(PinotConfiguration serverConf) throws Exception { LOGGER.info("Trying to start Pinot Server..."); - HelixServerStarter serverStarter = new HelixServerStarter(_clusterName, _zkAddress, serverConf); + + if (!serverConf.containsKey(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME)) { + serverConf.setProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, _clusterName); + } + + if (!serverConf.containsKey(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER)) { + serverConf.setProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, _zkAddress); + } + HelixServerStarter serverStarter = new HelixServerStarter(serverConf); serverStarter.start(); String instanceId = serverStarter.getInstanceId(); @@ -156,7 +170,13 @@ public class PinotServiceManager { public String startMinion(PinotConfiguration minionConf) throws Exception { LOGGER.info("Trying to start Pinot Minion..."); - MinionStarter minionStarter = new MinionStarter(_clusterName, _zkAddress, minionConf); + if (!minionConf.containsKey(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME)) { + minionConf.setProperty(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, _clusterName); + } + if (!minionConf.containsKey(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER)) { + minionConf.setProperty(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, _zkAddress); + } + MinionStarter minionStarter = new MinionStarter(minionConf); minionStarter.start(); String instanceId = minionStarter.getInstanceId(); diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManagerAdminApiApplication.java b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManagerAdminApiApplication.java index 415bc6d..c43ac03 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManagerAdminApiApplication.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/service/PinotServiceManagerAdminApiApplication.java @@ -25,6 +25,7 @@ import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.PinotReflectionUtils; import org.glassfish.grizzly.http.server.CLStaticHttpHandler; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; @@ -57,7 +58,9 @@ public class PinotServiceManagerAdminApiApplication extends ResourceConfig { Preconditions.checkArgument(httpPort > 0); _baseUri = URI.create("http://0.0.0.0:" + httpPort + "/"); _httpServer = GrizzlyHttpServerFactory.createHttpServer(_baseUri, this); - setupSwagger(); + synchronized (PinotReflectionUtils.getReflectionLock()) { + setupSwagger(); + } } private void setupSwagger() { diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/utils/PinotConfigUtils.java b/pinot-tools/src/main/java/org/apache/pinot/tools/utils/PinotConfigUtils.java index e3049f8..a08a587 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/utils/PinotConfigUtils.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/utils/PinotConfigUtils.java @@ -139,15 +139,20 @@ public class PinotConfigUtils { return null; } - public static Map<String, Object> generateBrokerConf(int brokerPort) { + public static Map<String, Object> generateBrokerConf(String clusterName, String zkAddress, String brokerHost, + int brokerPort) + throws SocketException, UnknownHostException { Map<String, Object> properties = new HashMap<>(); + properties.put(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, clusterName); + properties.put(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkAddress); + properties.put(CommonConstants.Broker.CONFIG_OF_BROKER_HOSTNAME, !StringUtils.isEmpty(brokerHost) ? brokerHost : NetUtils.getHostAddress()); properties.put(CommonConstants.Helix.KEY_OF_BROKER_QUERY_PORT, brokerPort != 0 ? brokerPort : getAvailablePort()); - return properties; } - public static Map<String, Object> generateServerConf(String serverHost, int serverPort, int serverAdminPort, - String serverDataDir, String serverSegmentDir) throws SocketException, UnknownHostException { + public static Map<String, Object> generateServerConf(String clusterName, String zkAddress, String serverHost, + int serverPort, int serverAdminPort, String serverDataDir, String serverSegmentDir) + throws SocketException, UnknownHostException { if (serverHost == null) { serverHost = NetUtils.getHostAddress(); } @@ -164,6 +169,8 @@ public class PinotConfigUtils { serverSegmentDir = TMP_DIR + String.format("Server_%s_%d/server/segment", serverHost, serverPort); } Map<String, Object> properties = new HashMap<>(); + properties.put(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, clusterName); + properties.put(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkAddress); properties.put(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST, serverHost); properties.put(CommonConstants.Helix.KEY_OF_SERVER_NETTY_PORT, serverPort); properties.put(CommonConstants.Server.CONFIG_OF_ADMIN_API_PORT, serverAdminPort); @@ -173,12 +180,14 @@ public class PinotConfigUtils { return properties; } - public static Map<String, Object> generateMinionConf(String minionHost, int minionPort) + public static Map<String, Object> generateMinionConf(String clusterName, String zkAddress, String minionHost, int minionPort) throws SocketException, UnknownHostException { if (minionHost == null) { minionHost = NetUtils.getHostAddress(); } Map<String, Object> properties = new HashMap<>(); + properties.put(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME, clusterName); + properties.put(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER, zkAddress); properties.put(CommonConstants.Helix.KEY_OF_MINION_HOST, minionHost); properties.put(CommonConstants.Helix.KEY_OF_MINION_PORT, minionPort != 0 ? minionPort : getAvailablePort()); diff --git a/pinot-tools/src/main/resources/conf/pinot-broker.conf b/pinot-tools/src/main/resources/conf/pinot-broker.conf new file mode 100644 index 0000000..9971ce1 --- /dev/null +++ b/pinot-tools/src/main/resources/conf/pinot-broker.conf @@ -0,0 +1,36 @@ +// +// 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. +// + +# Pinot Role +pinot.service.role=BROKER + +# Pinot Cluster name +pinot.cluster.name=pinot-quickstart + +# Pinot Zookeeper Server +pinot.zk.server=localhost:2181 + +# Use hostname as Pinot Instance ID other than IP +pinot.set.instance.id.to.hostname=true + +# Pinot Broker Query Port +pinot.broker.client.queryPort=8099 + +# Pinot Routing table builder class +pinot.broker.routing.table.builder.class=random diff --git a/pinot-tools/src/main/resources/conf/pinot-controller.conf b/pinot-tools/src/main/resources/conf/pinot-controller.conf new file mode 100644 index 0000000..1c4b65c --- /dev/null +++ b/pinot-tools/src/main/resources/conf/pinot-controller.conf @@ -0,0 +1,42 @@ +// +// 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. +// + +# Pinot Role +pinot.service.role=CONTROLLER + +# Pinot Cluster name +pinot.cluster.name=pinot-quickstart + +# Pinot Zookeeper Server +pinot.zk.server=localhost:2181 + +# Use hostname as Pinot Instance ID other than IP +pinot.set.instance.id.to.hostname=true + +# Pinot Controller Port +controller.port=9000 + +# Pinot Controller VIP Host +controller.vip.host=localhost + +# Pinot Controller VIP Port +controller.vip.port=9000 + +# Location to store Pinot Segments pushed from clients +controller.data.dir=/tmp/pinot/data/controller diff --git a/pinot-tools/src/main/resources/conf/pinot-minion.conf b/pinot-tools/src/main/resources/conf/pinot-minion.conf new file mode 100644 index 0000000..d8e5818 --- /dev/null +++ b/pinot-tools/src/main/resources/conf/pinot-minion.conf @@ -0,0 +1,39 @@ +// +// 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. +// + +# Pinot Role +pinot.service.role=MINION + +# Pinot Cluster name +pinot.cluster.name=pinot-quickstart + +# Pinot Zookeeper Server +pinot.zk.server=localhost:2181 + +# Use hostname as Pinot Instance ID other than IP +pinot.set.instance.id.to.hostname=true + +# Pinot Minion Host +# pinot.minion.host=localhost + +# Pinot Minion Port +pinot.minion.port=8098 + +# Pinot Minion Admin API Port +pinot.minion.adminapi.port=6500 diff --git a/pinot-tools/src/main/resources/conf/pinot-server.conf b/pinot-tools/src/main/resources/conf/pinot-server.conf new file mode 100644 index 0000000..066f466 --- /dev/null +++ b/pinot-tools/src/main/resources/conf/pinot-server.conf @@ -0,0 +1,42 @@ +// +// 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. +// + +# Pinot Role +pinot.service.role=SERVER + +# Pinot Cluster name +pinot.cluster.name=pinot-quickstart + +# Pinot Zookeeper Server +pinot.zk.server=localhost:2181 + +# Use hostname as Pinot Instance ID other than IP +pinot.set.instance.id.to.hostname=true + +# Pinot Server Netty Port for queris +pinot.server.netty.port=8098 + +# Pinot Server Admin API port +pinot.server.adminapi.port=8097 + +# Pinot Server Data Directory +pinot.server.instance.dataDir=/tmp/pinot/data/server/index + +# Pinot Server Temporary Segment Tar Directory +pinot.server.instance.segmentTarDir=/tmp/pinot/data/server/segmentTar --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org