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 2022/04/11 21:23:17 UTC

[GitHub] [pinot] richardstartin commented on a diff in pull request #8491: Add connection based FailureDetector

richardstartin commented on code in PR #8491:
URL: https://github.com/apache/pinot/pull/8491#discussion_r847746972


##########
pinot-broker/src/main/java/org/apache/pinot/broker/failuredetector/BaseExponentialBackoffRetryFailureDetector.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * 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.broker.failuredetector;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.concurrent.ThreadSafe;
+import org.apache.pinot.common.metrics.BrokerGauge;
+import org.apache.pinot.common.metrics.BrokerMetrics;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants.Broker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The {@code BaseExponentialBackoffRetryFailureDetector} is a base failure detector implementation that retries the
+ * unhealthy servers with exponential increasing delays.
+ */
+@ThreadSafe
+public abstract class BaseExponentialBackoffRetryFailureDetector implements FailureDetector {
+  protected final Logger _logger = LoggerFactory.getLogger(getClass());
+  protected final String _name = getClass().getSimpleName();
+  protected final List<Listener> _listeners = new ArrayList<>();
+  protected final ConcurrentHashMap<String, RetryInfo> _unhealthyServerRetryInfoMap = new ConcurrentHashMap<>();
+
+  protected BrokerMetrics _brokerMetrics;
+  protected long _retryInitialDelayNs;
+  protected double _retryDelayFactor;
+  protected int _maxRetries;
+  protected Thread _retryThread;
+
+  protected volatile boolean _running;
+
+  @Override
+  public void init(PinotConfiguration config, BrokerMetrics brokerMetrics) {
+    _brokerMetrics = brokerMetrics;
+    long retryInitialDelayMs = config.getProperty(Broker.FailureDetector.CONFIG_OF_RETRY_INITIAL_DELAY_MS,
+        Broker.FailureDetector.DEFAULT_RETRY_INITIAL_DELAY_MS);
+    _retryInitialDelayNs = TimeUnit.MILLISECONDS.toNanos(retryInitialDelayMs);
+    _retryDelayFactor = config.getProperty(Broker.FailureDetector.CONFIG_OF_RETRY_DELAY_FACTOR,
+        Broker.FailureDetector.DEFAULT_RETRY_DELAY_FACTOR);
+    _maxRetries =
+        config.getProperty(Broker.FailureDetector.CONFIG_OF_MAX_RETRIES, Broker.FailureDetector.DEFAULT_MAX_RETIRES);
+    _logger.info("Initialized {} with retry initial delay: {}ms, exponential backoff factor: {}, max " + "retries: {}",
+        _name, retryInitialDelayMs, _retryDelayFactor, _maxRetries);
+  }
+
+  @Override
+  public void register(Listener listener) {
+    _listeners.add(listener);
+  }
+
+  @Override
+  public void start() {
+    _logger.info("Starting {}", _name);
+    _running = true;
+
+    _retryThread = new Thread(() -> {

Review Comment:
   Why don’t you use a single threaded ExecutorService here instead?



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

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

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