ankitsultana commented on code in PR #17296:
URL: https://github.com/apache/pinot/pull/17296#discussion_r2641402556


##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/MultiClusterRoutingManager.java:
##########
@@ -0,0 +1,217 @@
+/**
+ * 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;
+
+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.function.Function;
+import java.util.function.Predicate;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.request.BrokerRequest;
+import org.apache.pinot.core.routing.RoutingManager;
+import org.apache.pinot.core.routing.RoutingTable;
+import org.apache.pinot.core.routing.SegmentsToQuery;
+import org.apache.pinot.core.routing.TablePartitionInfo;
+import org.apache.pinot.core.routing.TablePartitionReplicatedServersInfo;
+import org.apache.pinot.core.routing.timeboundary.TimeBoundaryInfo;
+import org.apache.pinot.core.transport.ServerInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The {@code MultiClusterRoutingManager} implements the {@link 
RoutingManager} to support multi-cluster routing.
+ * It contains a local {@link BrokerRoutingManager} and multiple remote {@link 
RemoteClusterBrokerRoutingManager}
+ * instances. For each routing request, it first queries the local cluster 
routing manager, and then queries the remote
+ * cluster routing managers to combine the results.
+ * For example, when getting the routing table for a table, it first gets the 
routing table from the local cluster
+ * routing manager, and then gets the routing tables from the remote cluster 
routing managers to merge into a combined
+ * routing table.
+ */
+public class MultiClusterRoutingManager implements RoutingManager {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(MultiClusterRoutingManager.class);
+
+  private final BrokerRoutingManager _localClusterRoutingManager;
+  private final List<RemoteClusterBrokerRoutingManager> 
_remoteClusterRoutingManagers;
+
+  public MultiClusterRoutingManager(BrokerRoutingManager 
localClusterRoutingManager,
+      List<RemoteClusterBrokerRoutingManager> remoteClusterRoutingManagers) {
+    _localClusterRoutingManager = localClusterRoutingManager;
+    _remoteClusterRoutingManagers = remoteClusterRoutingManagers;
+  }
+
+  @Nullable
+  private <T> T findFirst(Function<BrokerRoutingManager, T> getter, String 
tableNameForLog) {
+    T result = getter.apply(_localClusterRoutingManager);
+    if (result != null) {
+      return result;
+    }
+    for (BrokerRoutingManager remoteCluster : _remoteClusterRoutingManagers) {
+      try {
+        result = getter.apply(remoteCluster);
+        if (result != null) {
+          return result;
+        }
+      } catch (Exception e) {
+        LOGGER.error("Error querying remote cluster routing manager for table 
{}", tableNameForLog, e);
+      }
+    }
+    return null;
+  }
+
+  private boolean anyMatch(Predicate<BrokerRoutingManager> predicate) {

Review Comment:
   nit: can we remove this method and inline the logic?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to