-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-349]: Added new cleaning policy based on number of hours #3646
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
15 commits
Select commit
Hold shift + click to select a range
97113ff
[HUDI-349]: dev in progress
pratyakshsharma 92d085d
added cleaner hours retained function
pratyakshsharma 9c1364c
checkstyle fixes
pratyakshsharma f93ee61
[HUDI-349]: added new cleaning policy
pratyakshsharma 0cd1fe6
Merge branch 'hudi-349' of https://github.com/pratyakshsharma/incubat…
pratyakshsharma 68b0a68
[HUDI-349]: rebased with master
pratyakshsharma f58beda
[HUDI-349]: small changes
pratyakshsharma 3c79136
code review comments addressed
pratyakshsharma 676d999
[HUDI-349]: in sync with master
pratyakshsharma 29e8200
[HUDI-349]: addressed code review comments
pratyakshsharma 9527702
Merge branch 'master' of https://github.com/apache/hudi into hudi-349
pratyakshsharma efa6056
updated documentation for CLEANER_HOURS_RETAINED prop
pratyakshsharma 7eea9ec
build fix
pratyakshsharma 8e7e497
Merge branch 'master' of https://github.com/apache/hudi into hudi-349
pratyakshsharma cc0a44a
[HUDI-349]: moved tests to new test class
pratyakshsharma 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
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
131 changes: 131 additions & 0 deletions
131
...di-spark-client/src/test/java/org/apache/hudi/table/functional/TestCleanPlanExecutor.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,131 @@ | ||
| /* | ||
| * 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.hudi.table.functional; | ||
|
|
||
| import org.apache.hudi.common.HoodieCleanStat; | ||
| import org.apache.hudi.common.config.HoodieMetadataConfig; | ||
| import org.apache.hudi.common.model.BootstrapFileMapping; | ||
| import org.apache.hudi.common.model.HoodieCleaningPolicy; | ||
| import org.apache.hudi.common.model.HoodieCommitMetadata; | ||
| import org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy; | ||
| import org.apache.hudi.common.table.HoodieTableMetaClient; | ||
| import org.apache.hudi.common.table.timeline.HoodieActiveTimeline; | ||
| import org.apache.hudi.common.table.timeline.HoodieInstant; | ||
| import org.apache.hudi.common.table.timeline.HoodieTimeline; | ||
| import org.apache.hudi.common.testutils.HoodieTestTable; | ||
| import org.apache.hudi.common.util.CollectionUtils; | ||
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.config.HoodieCompactionConfig; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.table.TestCleaner; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Instant; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
| import java.util.Collections; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class TestCleanPlanExecutor extends TestCleaner { | ||
|
|
||
| /** | ||
| * Tests cleaning service based on number of hours retained. | ||
| */ | ||
| @ParameterizedTest | ||
| @MethodSource("argumentsForTestKeepLatestCommits") | ||
| public void testKeepXHoursWithCleaning(boolean simulateFailureRetry, boolean enableIncrementalClean, boolean enableBootstrapSourceClean) throws Exception { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have moved only one test in this PR since the rest are already moved in #4385. Once that is merged, changes will automatically reflect here as well. @nsivabalan |
||
| HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withPath(basePath) | ||
| .withMetadataConfig(HoodieMetadataConfig.newBuilder().withAssumeDatePartitioning(true).build()) | ||
| .withCompactionConfig(HoodieCompactionConfig.newBuilder() | ||
| .withIncrementalCleaningMode(enableIncrementalClean) | ||
| .withFailedWritesCleaningPolicy(HoodieFailedWritesCleaningPolicy.EAGER) | ||
| .withCleanBootstrapBaseFileEnabled(enableBootstrapSourceClean) | ||
| .withCleanerPolicy(HoodieCleaningPolicy.KEEP_LATEST_BY_HOURS).cleanerNumHoursRetained(2).build()) | ||
| .build(); | ||
|
|
||
| HoodieTestTable testTable = HoodieTestTable.of(metaClient); | ||
| String p0 = "2020/01/01"; | ||
| String p1 = "2020/01/02"; | ||
| Map<String, List<BootstrapFileMapping>> bootstrapMapping = enableBootstrapSourceClean ? generateBootstrapIndexAndSourceData(p0, p1) : null; | ||
|
|
||
| String file1P0C0 = enableBootstrapSourceClean ? bootstrapMapping.get(p0).get(0).getFileId() | ||
| : UUID.randomUUID().toString(); | ||
| String file1P1C0 = enableBootstrapSourceClean ? bootstrapMapping.get(p1).get(0).getFileId() | ||
| : UUID.randomUUID().toString(); | ||
| Instant instant = Instant.now(); | ||
| ZonedDateTime commitDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); | ||
| int minutesForFirstCommit = 150; | ||
| String firstCommitTs = HoodieActiveTimeline.formatDate(Date.from(commitDateTime.minusMinutes(minutesForFirstCommit).toInstant())); | ||
| testTable.addInflightCommit(firstCommitTs).withBaseFilesInPartition(p0, file1P0C0).withBaseFilesInPartition(p1, file1P1C0); | ||
|
|
||
| HoodieCommitMetadata commitMetadata = generateCommitMetadata(firstCommitTs, | ||
| Collections.unmodifiableMap(new HashMap<String, List<String>>() { | ||
| { | ||
| put(p0, CollectionUtils.createImmutableList(file1P0C0)); | ||
| put(p1, CollectionUtils.createImmutableList(file1P1C0)); | ||
| } | ||
| }) | ||
| ); | ||
| metaClient.getActiveTimeline().saveAsComplete( | ||
| new HoodieInstant(HoodieInstant.State.INFLIGHT, HoodieTimeline.COMMIT_ACTION, firstCommitTs), | ||
| Option.of(commitMetadata.toJsonString().getBytes(StandardCharsets.UTF_8))); | ||
|
|
||
| metaClient = HoodieTableMetaClient.reload(metaClient); | ||
|
|
||
| List<HoodieCleanStat> hoodieCleanStatsOne = runCleaner(config, simulateFailureRetry); | ||
| assertEquals(0, hoodieCleanStatsOne.size(), "Must not scan any partitions and clean any files"); | ||
| assertTrue(testTable.baseFileExists(p0, firstCommitTs, file1P0C0)); | ||
| assertTrue(testTable.baseFileExists(p1, firstCommitTs, file1P1C0)); | ||
|
|
||
| // make next commit, with 1 insert & 1 update per partition | ||
| int minutesForSecondCommit = 90; | ||
| String secondCommitTs = HoodieActiveTimeline.formatDate(Date.from(commitDateTime.minusMinutes(minutesForSecondCommit).toInstant())); | ||
| Map<String, String> partitionAndFileId002 = testTable.addInflightCommit(secondCommitTs).getFileIdsWithBaseFilesInPartitions(p0, p1); | ||
| String file2P0C1 = partitionAndFileId002.get(p0); | ||
| String file2P1C1 = partitionAndFileId002.get(p1); | ||
| testTable.forCommit(secondCommitTs).withBaseFilesInPartition(p0, file1P0C0).withBaseFilesInPartition(p1, file1P1C0); | ||
| commitMetadata = generateCommitMetadata(secondCommitTs, new HashMap<String, List<String>>() { | ||
| { | ||
| put(p0, CollectionUtils.createImmutableList(file1P0C0, file2P0C1)); | ||
| put(p1, CollectionUtils.createImmutableList(file1P1C0, file2P1C1)); | ||
| } | ||
| }); | ||
| metaClient.getActiveTimeline().saveAsComplete( | ||
| new HoodieInstant(HoodieInstant.State.INFLIGHT, HoodieTimeline.COMMIT_ACTION, secondCommitTs), | ||
| Option.of(commitMetadata.toJsonString().getBytes(StandardCharsets.UTF_8))); | ||
| List<HoodieCleanStat> hoodieCleanStatsTwo = runCleaner(config, simulateFailureRetry); | ||
| assertEquals(2, hoodieCleanStatsTwo.size(), "Should clean one file each from both the partitions"); | ||
| assertTrue(testTable.baseFileExists(p0, secondCommitTs, file2P0C1)); | ||
| assertTrue(testTable.baseFileExists(p1, secondCommitTs, file2P1C1)); | ||
| assertTrue(testTable.baseFileExists(p0, secondCommitTs, file1P0C0)); | ||
| assertTrue(testTable.baseFileExists(p1, secondCommitTs, file1P1C0)); | ||
| assertFalse(testTable.baseFileExists(p0, firstCommitTs, file1P0C0)); | ||
| assertFalse(testTable.baseFileExists(p1, firstCommitTs, file1P1C0)); | ||
| } | ||
| } | ||
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.
Do we know why do have (fileCommitTime.equals(lastVersionBeforeEarliestCommitToRetain) in L318. I would prefer to keep the same logic unless we have strong reasons to remove. As I mentioned, cleaning based on num hours is just a diff way to conveying retain N commits. So, lets try to keep the logic similar across both. Easier to maintain.
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.
The cleaner policies are designed to enable the longest running query to succeed. Let us take a small example where ingestion is happening every 30 minutes and
hoodie.cleaner.commits.retained = 2. This implies the longest running query is going to take 1 hour to complete. Now if I maintain a list of commits, when commit at index=2 in this list (i.e 3rd commit from the beginning) is completed, the query which started when commit at index=0 completed might still be running.list of commits -> 0. 1. 2
time (in mins). -> 0. 30. 60
Hence to allow this query to finish, we take into account
lastVersionBeforeEarliestCommitToRetainin L318.lastVersionin this case is going to be commit at index=1.With the new policy KEEP_LATEST_BY_HOURS, when 3rd commit is completed, 1st commit will be retained automatically by the logic. Hence the code in its current form works fine.