somandal commented on code in PR #15930:
URL: https://github.com/apache/pinot/pull/15930#discussion_r2126887799


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/assignment/instance/ImplicitRealtimeTablePartitionSelector.java:
##########
@@ -0,0 +1,79 @@
+/**
+ * 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.controller.helix.core.assignment.instance;
+
+import com.google.common.annotations.VisibleForTesting;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.assignment.InstancePartitions;
+import org.apache.pinot.spi.config.table.TableConfig;
+import 
org.apache.pinot.spi.config.table.assignment.InstanceReplicaGroupPartitionConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.utils.IngestionConfigUtils;
+
+
+/**
+ * Variation of {@link InstanceReplicaGroupPartitionSelector} that uses the 
number of partitions from the stream
+ * to determine the number of partitions in each replica group.
+ */
+public class ImplicitRealtimeTablePartitionSelector extends 
InstanceReplicaGroupPartitionSelector {
+  private final TableConfig _tableConfig;
+  private final int _numPartitions;
+
+  public ImplicitRealtimeTablePartitionSelector(TableConfig tableConfig,
+      InstanceReplicaGroupPartitionConfig replicaGroupPartitionConfig, String 
tableNameWithType,
+      @Nullable InstancePartitions existingInstancePartitions, boolean 
minimizeDataMovement) {
+    this(tableConfig, replicaGroupPartitionConfig, tableNameWithType, 
existingInstancePartitions, minimizeDataMovement,
+        
StreamConsumerFactoryProvider.create(IngestionConfigUtils.getFirstStreamConfig(tableConfig))
+            .createStreamMetadataProvider(
+                ImplicitRealtimeTablePartitionSelector.class.getSimpleName() + 
"-" + tableNameWithType));
+  }
+
+  @VisibleForTesting
+  ImplicitRealtimeTablePartitionSelector(TableConfig tableConfig,
+      InstanceReplicaGroupPartitionConfig replicaGroupPartitionConfig, String 
tableNameWithType,
+      @Nullable InstancePartitions existingInstancePartitions, boolean 
minimizeDataMovement,
+      StreamMetadataProvider streamMetadataProvider) {
+    super(replicaGroupPartitionConfig, tableNameWithType, 
existingInstancePartitions, minimizeDataMovement);
+    _tableConfig = tableConfig;
+    _numPartitions = getStreamNumPartitions(streamMetadataProvider);
+  }
+
+  private int getStreamNumPartitions(StreamMetadataProvider 
streamMetadataProvider) {
+    try (streamMetadataProvider) {
+      return streamMetadataProvider.fetchPartitionCount(10_000L);
+    } catch (Exception e) {
+      throw new RuntimeException("Failed to retrieve partition info for table: 
" + _tableNameWithType, e);
+    }
+  }
+
+  @Override
+  protected int getNumPartitions() {
+    return _numPartitions;
+  }
+
+  @Override
+  protected int getNumInstancesPerPartition(int numInstancesPerReplicaGroup) {
+    if (_tableConfig.isUpsertEnabled()) {
+      return 1; // For upsert enabled tables, we enforce one instance per 
partition

Review Comment:
   > This would have the same effect of minimizing partition and data movement 
across instances during repartitioning and scale ups / scale downs when using 
the minimize data movement algorithm.
   
   I think if COMPLETED is configured to have an `INSTANCE_PARTITIONS` ZNode, 
this is not a concern, right (since it can just round-robin the assignment - we 
never enforce that the number of partitions need to match the partitions of the 
stream)? Can you try out a setting where it is setup with numPartitions = 0 
(apologies, I am not sure if you already tried this out) and see what the 
behavior is like?
   
   I'll let @Jackie-Jiang comment on why this is not needed for `COMPLETED` 
though, as I'm also not entirely sure I understand the reasoning here either (I 
thought I did but when I thought some more I realized I don't) 😅 



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