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/02/17 23:30:24 UTC

[GitHub] [incubator-pinot] snleee commented on a change in pull request #6586: Server `queriesDisabled` metric:

snleee commented on a change in pull request #6586:
URL: https://github.com/apache/incubator-pinot/pull/6586#discussion_r578016471



##########
File path: pinot-server/src/main/java/org/apache/pinot/server/starter/ServerQueriesDisabledTracker.java
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.server.starter;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.helix.HelixManager;
+import org.apache.helix.ZNRecord;
+import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class to track if the server is queries disabled.
+ */
+public class ServerQueriesDisabledTracker {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ServerQueriesDisabledTracker.class);
+  private static final long FETCH_INTERVAL_MINS = 10L;
+  private static ServerQueriesDisabledTracker _singletonInstance;
+
+  private final ScheduledExecutorService _executorService = Executors.newSingleThreadScheduledExecutor();
+  private final HelixManager _helixManager;
+  private final ServerMetrics _serverMetrics;
+  private final String _clusterName;
+  private final String _instanceId;
+  private AtomicBoolean _queriesDisabled = new AtomicBoolean();
+
+  private ServerQueriesDisabledTracker(
+      String helixClusterName, String instanceId, HelixManager helixManager, ServerMetrics serverMetrics) {
+    _helixManager = helixManager;
+    _serverMetrics = serverMetrics;
+    _clusterName = helixClusterName;
+    _instanceId = instanceId;
+  }
+
+  public static synchronized void init(

Review comment:
       Do we need `synchronized` ? I think that only a single thread will make calls on this class.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -418,7 +418,11 @@ public synchronized PinotResourceManagerResponse addInstance(Instance instance)
     if (instances.contains(instanceIdToAdd)) {
       return PinotResourceManagerResponse.failure("Instance " + instanceIdToAdd + " already exists");
     } else {
-      _helixAdmin.addInstance(_helixClusterName, InstanceUtils.toHelixInstanceConfig(instance));
+      InstanceConfig instanceConfig = InstanceUtils.toHelixInstanceConfig(instance);
+      if (instance.isQueriesDisabled()) {

Review comment:
       Can you move this part into `InstanceUtils.toHelixInstanceConfig()` so that all the conversion happens in a single place?

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotInstanceRestletResource.java
##########
@@ -104,6 +105,10 @@ public String getInstance(
     response.set("tags", JsonUtils.objectToJsonNode(instanceConfig.getTags()));
     response.set("pools", JsonUtils.objectToJsonNode(instanceConfig.getRecord().getMapField(InstanceUtils.POOL_KEY)));
     response.put("grpcPort", getGrpcPort(instanceConfig));
+    String queriesDisabled = instanceConfig.getRecord().getSimpleField(CommonConstants.Helix.QUERIES_DISABLED);
+    if ("true".equals(queriesDisabled)) {

Review comment:
       I think that it's better to handle upper/lower cases:
   ```
   e.g.
   
   queriesDisabled = true
   queriesDisabled = True <- By default, Python uses this pattern for boolean and we had an issue with this once. 
   queriesDisabled = TRUE
   ...
   ```

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/config/instance/Instance.java
##########
@@ -52,13 +52,15 @@
   private final List<String> _tags;
   private final Map<String, Integer> _pools;
   private final int _grpcPort;
+  private final boolean _queriesDisabled;
 
   @JsonCreator
   public Instance(@JsonProperty(value = "host", required = true) String host,
       @JsonProperty(value = "port", required = true) int port,
       @JsonProperty(value = "type", required = true) InstanceType type,
       @JsonProperty("tags") @Nullable List<String> tags, @JsonProperty("pools") @Nullable Map<String, Integer> pools,
-      @JsonProperty("grpcPort") int grpcPort) {
+      @JsonProperty("grpcPort") int grpcPort,
+      @JsonProperty("queriesDisabled") boolean queriesDisabled) {

Review comment:
       Let's also add `adminPort`




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