-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Controller cleanups: SegmentDeletionManager fallback, LLC filter, retention strategy extraction, mock util #18582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
963674c
Ensure segments are deleted from property store if they have a child …
krishan1390 c205686
Add llc filter to getLastLLCCompletedSegments
krishan1390 60c21c9
Abstract RetentionStrategy from retention manager
krishan1390 53f7ca3
Add partition info to SegmentMetadataMockUtils
krishan1390 28efa97
Add getLastLLCCompletedSegments overload accepting pre-fetched Segmen…
krishan1390 ffd1e73
Stub list overload of getLastLLCCompletedSegments in paused-table tes…
krishan1390 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...main/java/org/apache/pinot/controller/helix/core/retention/TableConfigRetentionUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * 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.retention; | ||
|
|
||
| import java.util.Locale; | ||
| import java.util.concurrent.TimeUnit; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.pinot.controller.helix.core.retention.strategy.RetentionStrategy; | ||
| import org.apache.pinot.controller.helix.core.retention.strategy.TimeRetentionStrategy; | ||
| import org.apache.pinot.spi.config.table.SegmentsValidationAndRetentionConfig; | ||
| import org.apache.pinot.spi.config.table.TableConfig; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
||
| /// Utility methods for deriving retention-related objects from a {@link TableConfig}. | ||
| public class TableConfigRetentionUtils { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(TableConfigRetentionUtils.class); | ||
|
|
||
| private TableConfigRetentionUtils() { | ||
| } | ||
|
|
||
| /// Builds a {@link RetentionStrategy} from {@code tableConfig}, or returns {@code null} when the | ||
| /// retention config is absent, empty, or malformed. A null return means no retention is configured | ||
| /// and no segment should be treated as purgeable. | ||
| /// | ||
| /// @param useCreationTimeFallback when true, the strategy falls back to segment creation time | ||
| /// when segment end time is unavailable | ||
| @Nullable | ||
| public static RetentionStrategy buildRetentionStrategy(TableConfig tableConfig, | ||
| boolean useCreationTimeFallback) { | ||
| SegmentsValidationAndRetentionConfig validationConfig = tableConfig.getValidationConfig(); | ||
| String unit = validationConfig.getRetentionTimeUnit(); | ||
| String value = validationConfig.getRetentionTimeValue(); | ||
| if (unit == null || unit.isEmpty() || value == null || value.isEmpty()) { | ||
| LOGGER.warn("Invalid retention time: {} {} for table: {}, skip", unit, value, tableConfig.getTableName()); | ||
| return null; | ||
| } | ||
| try { | ||
| return new TimeRetentionStrategy(TimeUnit.valueOf(unit.toUpperCase(Locale.ROOT)), Long.parseLong(value), | ||
| useCreationTimeFallback); | ||
| } catch (Exception e) { | ||
| LOGGER.warn("Invalid retention time: {} {} for table: {}, skip", unit, value, tableConfig.getTableName()); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
77 changes: 77 additions & 0 deletions
77
.../org/apache/pinot/controller/helix/core/PinotHelixResourceManagerLastLLCSegmentsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * 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; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.apache.pinot.common.metadata.segment.SegmentZKMetadata; | ||
| import org.apache.pinot.common.utils.LLCSegmentName; | ||
| import org.apache.pinot.spi.utils.CommonConstants; | ||
| import org.apache.pinot.spi.utils.builder.TableNameBuilder; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.anyList; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.testng.Assert.assertEquals; | ||
|
|
||
|
|
||
| public class PinotHelixResourceManagerLastLLCSegmentsTest { | ||
|
|
||
| private static final String TABLE_NAME = "testTable"; | ||
| private static final String REALTIME_TABLE_NAME = TableNameBuilder.REALTIME.tableNameWithType(TABLE_NAME); | ||
|
|
||
| /** | ||
| * A realtime table can contain non-LLC-named segments (e.g. uploaded via batch ingestion) sitting in DONE state | ||
| * alongside the LLC-named consuming/committed segments. {@code getLastLLCCompletedSegments} must skip those | ||
| * uploaded segments rather than NPE when {@code LLCSegmentName.of(name)} returns {@code null}. | ||
| */ | ||
| @Test | ||
| public void testGetLastLLCCompletedSegmentsSkipsNonLLCNamedSegments() { | ||
| long now = System.currentTimeMillis(); | ||
| int partitionId = 3; | ||
|
|
||
| List<SegmentZKMetadata> segments = new ArrayList<>(); | ||
| // Two LLC-named DONE segments — sequence 0 and 1 for the same partition; sequence 1 is the latest. | ||
| LLCSegmentName seq0 = new LLCSegmentName(TABLE_NAME, partitionId, 0, now); | ||
| LLCSegmentName seq1 = new LLCSegmentName(TABLE_NAME, partitionId, 1, now); | ||
| segments.add(doneSegment(seq0.getSegmentName())); | ||
| segments.add(doneSegment(seq1.getSegmentName())); | ||
| // An uploaded (non-LLC-named) segment in DONE state — must be ignored, not crash the method. | ||
| segments.add(doneSegment("uploaded_segment_0")); | ||
|
|
||
| PinotHelixResourceManager rm = mock(PinotHelixResourceManager.class); | ||
| when(rm.getSegmentsZKMetadata(REALTIME_TABLE_NAME)).thenReturn(segments); | ||
| when(rm.getLastLLCCompletedSegments(REALTIME_TABLE_NAME)).thenCallRealMethod(); | ||
| when(rm.getLastLLCCompletedSegments(anyList())).thenCallRealMethod(); | ||
|
|
||
| Collection<String> lastCompleted = rm.getLastLLCCompletedSegments(REALTIME_TABLE_NAME); | ||
| Set<String> actual = new HashSet<>(lastCompleted); | ||
| assertEquals(actual, Set.of(seq1.getSegmentName())); | ||
| } | ||
|
|
||
| private static SegmentZKMetadata doneSegment(String name) { | ||
| SegmentZKMetadata md = new SegmentZKMetadata(name); | ||
| md.setStatus(CommonConstants.Segment.Realtime.Status.DONE); | ||
| return md; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Let's follow existing convention for javadoc comments here with /** */.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jackie-Jiang asked to add new comments in markdown style