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 2019/05/16 20:18:52 UTC

[GitHub] [incubator-pinot] npawar commented on a change in pull request #4211: StreamPartitionAssignmentStrategy interface to plug in various partition assignment strategies (uniform, replica group based)

npawar commented on a change in pull request #4211: StreamPartitionAssignmentStrategy interface to plug in various partition assignment strategies (uniform, replica group based)
URL: https://github.com/apache/incubator-pinot/pull/4211#discussion_r284880484
 
 

 ##########
 File path: pinot-common/src/main/java/org/apache/pinot/common/partition/ReplicaGroupBasedStreamPartitionAssignmentStrategy.java
 ##########
 @@ -0,0 +1,85 @@
+/**
+ * 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.common.partition;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.apache.helix.HelixManager;
+import org.apache.pinot.common.exception.InvalidConfigException;
+
+
+/**
+ * Replica group based partition assignment strategy for realtime partitions
+ */
+public class ReplicaGroupBasedStreamPartitionAssignmentStrategy implements StreamPartitionAssignmentStrategy {
+
+  /**
+   * Fetches the replica group partition assignment znode and assigns partitions across the replica groups.
+   * A vertical slice will be picked form the replica group sets for a partition, based on the formula:
+   * vertical slice = partition % numInstancesPerReplicaGroup
+   */
+  @Override
+  public PartitionAssignment getStreamPartitionAssignment(HelixManager helixManager, @Nonnull String tableNameWithType,
+      @Nonnull List<String> partitions, int numReplicas, List<String> instances) throws InvalidConfigException {
+
+    ReplicaGroupPartitionAssignment replicaGroupPartitionAssignment =
+        getReplicaGroupPartitionAssignment(helixManager, tableNameWithType);
+    if (replicaGroupPartitionAssignment == null) {
+      throw new InvalidConfigException("ReplicaGroupPartitionAssignment is null for table:" + tableNameWithType);
+    }
+    int numReplicaGroups = replicaGroupPartitionAssignment.getNumReplicaGroups();
+    if (numReplicaGroups != numReplicas) {
+      throw new InvalidConfigException(
+          "numReplicas:" + numReplicas + " is not equal to numReplicaGroups:" + numReplicaGroups
+              + " from znode for table:" + tableNameWithType);
+    }
+    int numInstancesPerReplicaGroup = replicaGroupPartitionAssignment.getInstancesFromReplicaGroup(0, 0).size();
 
 Review comment:
   That would be a good extension. Will add a TODO indicating that we might want to do this if we want to remove strict requirement that numInstancesPerReplicaGroup is same across all replica groups

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