pinot-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #5046: Re-design the broker routing
Date Thu, 06 Feb 2020 18:49:56 GMT
Jackie-Jiang commented on a change in pull request #5046: Re-design the broker routing
URL: https://github.com/apache/incubator-pinot/pull/5046#discussion_r376017180
 
 

 ##########
 File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/v2/instanceselector/BaseInstanceSelector.java
 ##########
 @@ -0,0 +1,177 @@
+/**
+ * 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.routing.v2.instanceselector;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.Nullable;
+import org.apache.helix.model.ExternalView;
+import org.apache.pinot.common.metrics.BrokerMeter;
+import org.apache.pinot.common.metrics.BrokerMetrics;
+import org.apache.pinot.common.request.BrokerRequest;
+import org.apache.pinot.common.utils.CommonConstants.Helix.StateModel.RealtimeSegmentOnlineOfflineStateModel;
+import org.apache.pinot.common.utils.HashUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+abstract class BaseInstanceSelector implements InstanceSelector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(BaseInstanceSelector.class);
+
+  // To prevent int overflow, reset the request id once it reaches this value
+  private static final int MAX_REQUEST_ID = 1_000_000_000;
+
+  private final AtomicLong _requestId = new AtomicLong();
+  private final String _tableNameWithType;
+  private final BrokerMetrics _brokerMetrics;
+
+  private volatile Set<String> _enabledInstances;
+  private volatile Map<String, List<String>> _segmentToInstancesMap;
+  private volatile Map<String, List<String>> _instanceToSegmentsMap;
+  private volatile Map<String, List<String>> _segmentToEnabledInstancesMap;
+
+  BaseInstanceSelector(String tableNameWithType, BrokerMetrics brokerMetrics) {
+    _tableNameWithType = tableNameWithType;
+    _brokerMetrics = brokerMetrics;
+  }
+
+  @Override
+  public void init(Set<String> enabledInstances, ExternalView externalView, Set<String>
onlineSegments) {
+    _enabledInstances = enabledInstances;
+    onExternalViewChange(externalView, onlineSegments);
+  }
+
+  @Override
+  public void onInstancesChange(Set<String> enabledInstances, List<String> changedInstances)
{
+    _enabledInstances = enabledInstances;
+
+    // Update all segments served by the changed instances
+    Set<String> segmentsToUpdate = new HashSet<>();
+    Map<String, List<String>> instanceToSegmentsMap = _instanceToSegmentsMap;
+    for (String instance : changedInstances) {
+      List<String> segments = instanceToSegmentsMap.get(instance);
+      if (segments != null) {
+        segmentsToUpdate.addAll(segments);
+      }
+    }
+
+    // Directly return if no segment needs to be updated
+    if (segmentsToUpdate.isEmpty()) {
+      return;
+    }
+
+    // Generate a new map from segment to enabled instances
+    Map<String, List<String>> segmentToInstancesMap = _segmentToInstancesMap;
+    Map<String, List<String>> segmentToEnabledInstancesMap = _segmentToEnabledInstancesMap;
+    Map<String, List<String>> newSegmentToEnabledInstancesMap =
+        new HashMap<>(HashUtil.getHashMapCapacity(segmentToEnabledInstancesMap.size()));
+    for (Map.Entry<String, List<String>> entry : segmentToEnabledInstancesMap.entrySet())
{
+      String segment = entry.getKey();
+      if (segmentsToUpdate.contains(segment)) {
+        newSegmentToEnabledInstancesMap.put(segment,
+            calculateEnabledInstancesForSegment(segment, segmentToInstancesMap.get(segment),
enabledInstances));
+      } else {
+        newSegmentToEnabledInstancesMap.put(segment, entry.getValue());
+      }
+    }
+    _segmentToEnabledInstancesMap = newSegmentToEnabledInstancesMap;
+  }
+
+  @Override
+  public void onExternalViewChange(ExternalView externalView, Set<String> onlineSegments)
{
+    Map<String, Map<String, String>> segmentAssignment = externalView.getRecord().getMapFields();
+    Map<String, List<String>> segmentToInstancesMap =
+        new HashMap<>(HashUtil.getHashMapCapacity(segmentAssignment.size()));
+    Map<String, List<String>> instanceToSegmentsMap = new HashMap<>();
+
+    for (Map.Entry<String, Map<String, String>> entry : segmentAssignment.entrySet())
{
+      // Keep segments in both external view and ideal state
 
 Review comment:
   Yes, as the realtime one needs to handle CONSUMING state

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


Mime
View raw message