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 2022/03/23 05:15:23 UTC

[GitHub] [pinot] klsince commented on a change in pull request #8389: FixedSegmentSelector for tier configs

klsince commented on a change in pull request #8389:
URL: https://github.com/apache/pinot/pull/8389#discussion_r832851986



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/tier/FixedTierSegmentSelector.java
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.tier;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.helix.HelixManager;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.CommonConstants.Segment.Realtime;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+
+
+/**
+ * A {@link TierSegmentSelector} strategy which selects segments for a tier based on a fixed list
+ */
+public class FixedTierSegmentSelector implements TierSegmentSelector {
+  private final List<String> _segmentList;

Review comment:
       use Set?

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/tier/FixedTierSegmentSelector.java
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.tier;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.helix.HelixManager;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.CommonConstants.Segment.Realtime;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+
+
+/**
+ * A {@link TierSegmentSelector} strategy which selects segments for a tier based on a fixed list
+ */
+public class FixedTierSegmentSelector implements TierSegmentSelector {
+  private final List<String> _segmentList;
+  private final HelixManager _helixManager;
+
+  public FixedTierSegmentSelector(HelixManager helixManager, @Nullable List<String> segmentList) {
+    _segmentList = segmentList;
+    _helixManager = helixManager;
+  }
+
+  @Override
+  public String getType() {
+    return TierFactory.FIXED_SEGMENT_SELECTOR_TYPE;
+  }
+
+  /**
+   * Checks if a segment is eligible for the tier based on fixed list
+   * @param tableNameWithType Name of the table
+   * @param segmentName Name of the segment
+   * @return true if eligible
+   */
+  @Override
+  public boolean selectSegment(String tableNameWithType, String segmentName) {
+    if (CollectionUtils.isNotEmpty(_segmentList) && _segmentList.contains(segmentName)) {
+      if (TableType.OFFLINE == TableNameBuilder.getTableTypeFromTableName(tableNameWithType)) {
+        return true;
+      }
+
+      SegmentZKMetadata segmentZKMetadata =
+          ZKMetadataProvider.getSegmentZKMetadata(_helixManager.getHelixPropertyStore(), tableNameWithType,
+              segmentName);
+      Preconditions.checkNotNull(segmentZKMetadata, "Could not find zk metadata for segment: {} of table: {}",
+          segmentName, tableNameWithType);
+      return segmentZKMetadata.getStatus().equals(Realtime.Status.DONE);

Review comment:
       there is a `UPLOADED` state, should it be considered ok here? 

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/config/TierConfigUtils.java
##########
@@ -76,16 +76,24 @@ public static boolean shouldRelocateToTiers(TableConfig tableConfig) {
   }
 
   /**
-   * Comparator for sorting the {@link Tier}.
-   * As of now, we have only 1 type of {@link TierSegmentSelector} and 1 type of {@link TierStorage}.
-   * Tier with an older age bucket in {@link TimeBasedTierSegmentSelector} should appear before a younger age bucket,
-   * in sort order
-   * TODO: As we add more types, this logic needs to be upgraded
+   * Comparator for sorting the {@link Tier}. In the sort order,
+   * 1) {@link FixedTierSegmentSelector} are always before others
+   * 2) For {@link TimeBasedTierSegmentSelector}, tiers with an older age bucket appear before a younger age bucket,
    */
   public static Comparator<Tier> getTierComparator() {
     return (o1, o2) -> {
       TierSegmentSelector s1 = o1.getSegmentSelector();
       TierSegmentSelector s2 = o2.getSegmentSelector();
+
+      if (TierFactory.FIXED_SEGMENT_SELECTOR_TYPE.equalsIgnoreCase(s1.getType())

Review comment:
       can save `else` as it `returns` from those branches

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java
##########
@@ -504,7 +504,7 @@ private static void validateTierConfigList(@Nullable List<TierConfig> tierConfig
                 segmentSelectorType, tierName);
         Preconditions.checkState(TimeUtils.isPeriodValid(segmentAge),
             "segmentAge: %s must be a valid period string (eg. 30d, 24h) in tier: %s", segmentAge, tierName);
-      } else {
+      } else if (!segmentSelectorType.equalsIgnoreCase(TierFactory.FIXED_SEGMENT_SELECTOR_TYPE)) {

Review comment:
       anything to check for fixed_selector? maybe require a non-empty segment list?

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/utils/config/TierConfigUtils.java
##########
@@ -76,16 +76,24 @@ public static boolean shouldRelocateToTiers(TableConfig tableConfig) {
   }
 
   /**
-   * Comparator for sorting the {@link Tier}.
-   * As of now, we have only 1 type of {@link TierSegmentSelector} and 1 type of {@link TierStorage}.
-   * Tier with an older age bucket in {@link TimeBasedTierSegmentSelector} should appear before a younger age bucket,
-   * in sort order
-   * TODO: As we add more types, this logic needs to be upgraded
+   * Comparator for sorting the {@link Tier}. In the sort order,
+   * 1) {@link FixedTierSegmentSelector} are always before others
+   * 2) For {@link TimeBasedTierSegmentSelector}, tiers with an older age bucket appear before a younger age bucket,
    */
   public static Comparator<Tier> getTierComparator() {
     return (o1, o2) -> {
       TierSegmentSelector s1 = o1.getSegmentSelector();
       TierSegmentSelector s2 = o2.getSegmentSelector();
+
+      if (TierFactory.FIXED_SEGMENT_SELECTOR_TYPE.equalsIgnoreCase(s1.getType())
+          && TierFactory.FIXED_SEGMENT_SELECTOR_TYPE.equalsIgnoreCase(s2.getType())) {
+        return 0;
+      } else if (TierFactory.FIXED_SEGMENT_SELECTOR_TYPE.equalsIgnoreCase(s1.getType())) {
+        return -1;
+      } else if (TierFactory.FIXED_SEGMENT_SELECTOR_TYPE.equalsIgnoreCase(s2.getType())) {
+        return 1;
+      }
+

Review comment:
       Move the Precondition checks earlier and check both fixed/time based selector?




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org