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/06/04 05:00:45 UTC

[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #4269: Add interface and implementations for the new segment assignment

Jackie-Jiang commented on a change in pull request #4269: Add interface and implementations for the new segment assignment
URL: https://github.com/apache/incubator-pinot/pull/4269#discussion_r290125924
 
 

 ##########
 File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/assignment/InstancePartitionsUtils.java
 ##########
 @@ -0,0 +1,84 @@
+/**
+ * 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;
+
+import java.util.Collections;
+import java.util.List;
+import org.apache.helix.AccessOption;
+import org.apache.helix.HelixManager;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.store.HelixPropertyStore;
+import org.apache.pinot.common.config.OfflineTagConfig;
+import org.apache.pinot.common.config.RealtimeTagConfig;
+import org.apache.pinot.common.config.TableConfig;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.common.utils.helix.HelixHelper;
+
+
+/**
+ * Utility class for instance partitions.
+ */
+public class InstancePartitionsUtils {
+  private InstancePartitionsUtils() {
+  }
+
+  /**
+   * Fetches the instance partitions from Helix property store if exists, or computes it for backward compatibility.
+   */
+  public static InstancePartitions fetchOrComputeInstancePartitions(HelixManager helixManager,
+      TableConfig tableConfig) {
+    String tableNameWithType = tableConfig.getTableName();
+
+    // Fetch the instance partitions from property store if exists
+    String path = ZKMetadataProvider.constructPropertyStorePathForInstancePartitions(tableNameWithType);
+    ZNRecord znRecord = helixManager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
+    if (znRecord != null) {
+      return InstancePartitions.fromZNRecord(znRecord);
+    }
+
+    // Compute the instance partitions (for backward compatible)
+    // Sort all enabled instances with the server tag, rotate the list based on the table name to prevent creating
+    // hotspot servers
+    InstancePartitions instancePartitions = new InstancePartitions(tableNameWithType);
+    List<InstanceConfig> instanceConfigs = HelixHelper.getInstanceConfigs(helixManager);
+    String serverTag =
+        tableConfig.getTableType() == CommonConstants.Helix.TableType.OFFLINE ? new OfflineTagConfig(tableConfig)
+            .getOfflineServerTag() : new RealtimeTagConfig(tableConfig).getConsumingServerTag();
+    List<String> instances = HelixHelper.getEnabledInstancesWithTag(instanceConfigs, serverTag);
+    instances.sort(null);
+    int numInstances = instances.size();
+    Collections.rotate(instances, -(Math.abs(tableNameWithType.hashCode()) % numInstances));
 
 Review comment:
   Yes, backward compatible with the current realtime behavior (UniformStreamPartitionAssignmentStrategy.class).

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