fx19880617 commented on a change in pull request #5793: URL: https://github.com/apache/incubator-pinot/pull/5793#discussion_r467517563
########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/PinotServerTierStorage.java ########## @@ -0,0 +1,46 @@ +/** + * 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 org.apache.pinot.common.tier.TierFactory.TierStorageType; + + +/** + * Tier storage type which uses Pinot servers as storage + */ +public class PinotServerTierStorage implements TierStorage { + private final String _type = TierStorageType.PINOT_SERVER.toString(); + private final String _tag; Review comment: Shall we support multiple tags for a tier? ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/assignment/segment/SegmentAssignmentUtils.java ########## @@ -326,4 +328,68 @@ static void rebalanceReplicaGroupBasedPartition(Map<String, Map<String, String>> return _offlineSegmentAssignment; } } + + /** + * Takes a segment assignment adn splits them up based on which tiers the segments are eligible for. Only considers ONLINE segments. Review comment: typo ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TierSegmentSelector.java ########## @@ -0,0 +1,39 @@ +/** + * 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; + +/** + * Interface for the segment selection strategy of a tier + */ +public interface TierSegmentSelector { + + /** + * The type of the segment selector (e.g. TIME) + */ + String getType(); Review comment: +1 ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TierFactory.java ########## @@ -0,0 +1,70 @@ +/** + * 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 org.apache.helix.HelixManager; +import org.apache.pinot.spi.config.table.TierConfig; + + +/** + * Factory class to create and sort {@link Tier} + */ +public final class TierFactory { + + /** + * Types of segmentSelectors for tiers + */ + public enum TierSegmentSelectorType { + TIME + } + + /** + * Types of storage for tiers + */ + public enum TierStorageType { + PINOT_SERVER + } + + private TierFactory() { + } + + /** + * Constructs a {@link Tier} from the {@link TierConfig} in the table config + */ + public static Tier getTier(TierConfig tierConfig, HelixManager helixManager) { + TierSegmentSelector segmentSelector; + TierStorage storageSelector; + + String segmentSelectorType = tierConfig.getSegmentSelectorType(); + if (segmentSelectorType.equalsIgnoreCase(TierSegmentSelectorType.TIME.toString())) { + segmentSelector = new TimeBasedTierSegmentSelector(helixManager, tierConfig.getSegmentAge()); + } else { + throw new IllegalStateException("Unsupported segmentSelectorType: " + segmentSelectorType); + } + + String storageSelectorType = tierConfig.getStorageType(); Review comment: using enum here also? ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TimeBasedTierSegmentSelector.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.tier; + +import com.google.common.base.Preconditions; +import java.util.concurrent.TimeUnit; +import org.apache.helix.HelixManager; +import org.apache.pinot.common.metadata.ZKMetadataProvider; +import org.apache.pinot.common.metadata.segment.SegmentZKMetadata; +import org.apache.pinot.common.tier.TierFactory.TierSegmentSelectorType; +import org.apache.pinot.spi.utils.TimeUtils; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; + + +/** + * A {@link TierSegmentSelector} strategy which selects segments for a tier based on the age of the segment + */ +public class TimeBasedTierSegmentSelector implements TierSegmentSelector { + private final String _type = TierSegmentSelectorType.TIME.toString(); + private final long _segmentAgeMillis; + private final HelixManager _helixManager; + + public TimeBasedTierSegmentSelector(HelixManager helixManager, String segmentAge) { + _segmentAgeMillis = TimeUtils.convertPeriodToMillis(segmentAge); + _helixManager = helixManager; + } + + @Override + public String getType() { + return _type; Review comment: just do `return TierSegmentSelectorType.TIME ` and remove `_type`? ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TierFactory.java ########## @@ -0,0 +1,70 @@ +/** + * 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 org.apache.helix.HelixManager; +import org.apache.pinot.spi.config.table.TierConfig; + + +/** + * Factory class to create and sort {@link Tier} + */ +public final class TierFactory { + + /** + * Types of segmentSelectors for tiers + */ + public enum TierSegmentSelectorType { + TIME + } + + /** + * Types of storage for tiers + */ + public enum TierStorageType { + PINOT_SERVER + } + + private TierFactory() { + } + + /** + * Constructs a {@link Tier} from the {@link TierConfig} in the table config + */ + public static Tier getTier(TierConfig tierConfig, HelixManager helixManager) { + TierSegmentSelector segmentSelector; + TierStorage storageSelector; + + String segmentSelectorType = tierConfig.getSegmentSelectorType(); Review comment: using enum? ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/PinotServerTierStorage.java ########## @@ -0,0 +1,46 @@ +/** + * 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 org.apache.pinot.common.tier.TierFactory.TierStorageType; + + +/** + * Tier storage type which uses Pinot servers as storage + */ +public class PinotServerTierStorage implements TierStorage { + private final String _type = TierStorageType.PINOT_SERVER.toString(); Review comment: We can skip this field and directly return enum in the `getType()` method. ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TierStorage.java ########## @@ -0,0 +1,30 @@ +/** + * 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; + +/** + * Interface for the storage type of the tier + */ +public interface TierStorage { + + /** + * Returns the type of the storage (e.g. PINOT_SERVER) + */ + String getType(); Review comment: enum? ########## File path: pinot-common/src/main/java/org/apache/pinot/common/tier/TierSegmentSelector.java ########## @@ -0,0 +1,39 @@ +/** + * 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; + +/** + * Interface for the segment selection strategy of a tier + */ +public interface TierSegmentSelector { Review comment: thinking of adding a method like `int getPriority()`? For time based tiers we can use internal age for comparison if priority is the same. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org