-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2685] Support scheduling online compaction plan when there are … #3928
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,14 +75,16 @@ public static void main(String[] args) throws Exception { | |
| // judge whether have operation | ||
| // to compute the compaction instant time and do compaction. | ||
| if (cfg.schedule) { | ||
| String compactionInstantTime = CompactionUtil.getCompactionInstantTime(metaClient); | ||
| boolean scheduled = writeClient.scheduleCompactionAtInstant(compactionInstantTime, Option.empty()); | ||
| if (!scheduled) { | ||
| // do nothing. | ||
| LOG.info("No compaction plan for this job "); | ||
| return; | ||
| Option<String> compactionInstantTimeOption = CompactionUtil.getCompactionInstantTime(metaClient); | ||
| if (compactionInstantTimeOption.isPresent()) { | ||
|
||
| boolean scheduled = writeClient.scheduleCompactionAtInstant(compactionInstantTimeOption.get(), Option.empty()); | ||
| if (!scheduled) { | ||
| // do nothing. | ||
| LOG.info("No compaction plan for this job "); | ||
| return; | ||
| } | ||
| table.getMetaClient().reloadActiveTimeline(); | ||
| } | ||
| table.getMetaClient().reloadActiveTimeline(); | ||
| } | ||
|
|
||
| // fetch the instant based on the configured execution sequence | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| package org.apache.hudi.util; | ||
|
|
||
| import org.apache.hudi.client.HoodieFlinkWriteClient; | ||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.table.HoodieTableMetaClient; | ||
| import org.apache.hudi.common.table.TableSchemaResolver; | ||
|
|
@@ -46,10 +47,36 @@ public class CompactionUtil { | |
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(CompactionUtil.class); | ||
|
|
||
| /** | ||
| * Schedules a new compaction instant. | ||
| * | ||
| * @param metaClient The metadata client | ||
| * @param writeClient The write client | ||
| * @param deltaTimeCompaction Whether the compaction is trigger by elapsed delta time | ||
| * @param committed Whether the last instant was committed successfully | ||
| */ | ||
| public static void scheduleCompaction( | ||
| HoodieTableMetaClient metaClient, | ||
| HoodieFlinkWriteClient<?> writeClient, | ||
| boolean deltaTimeCompaction, | ||
| boolean committed) { | ||
| if (committed) { | ||
| writeClient.scheduleCompaction(Option.empty()); | ||
| } else if (deltaTimeCompaction) { | ||
| // if there are no new commits and the compaction trigger strategy is based on elapsed delta time, | ||
| // schedules the compaction anyway. | ||
| metaClient.reloadActiveTimeline(); | ||
| Option<String> compactionInstantTime = CompactionUtil.getCompactionInstantTime(metaClient); | ||
| if (compactionInstantTime.isPresent()) { | ||
| writeClient.scheduleCompactionAtInstant(compactionInstantTime.get(), Option.empty()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets compaction Instant time. | ||
| */ | ||
| public static String getCompactionInstantTime(HoodieTableMetaClient metaClient) { | ||
| public static Option<String> getCompactionInstantTime(HoodieTableMetaClient metaClient) { | ||
| Option<HoodieInstant> firstPendingInstant = metaClient.getCommitsTimeline() | ||
| .filterPendingExcludingCompaction().firstInstant(); | ||
| Option<HoodieInstant> lastCompleteInstant = metaClient.getActiveTimeline().getWriteTimeline() | ||
|
|
@@ -59,8 +86,11 @@ public static String getCompactionInstantTime(HoodieTableMetaClient metaClient) | |
| String lastCompleteTimestamp = lastCompleteInstant.get().getTimestamp(); | ||
| // Committed and pending compaction instants should have strictly lower timestamps | ||
| return StreamerUtil.medianInstantTime(firstPendingTimestamp, lastCompleteTimestamp); | ||
| } else if (!lastCompleteInstant.isPresent()) { | ||
|
||
| LOG.info("No instants to schedule the compaction plan"); | ||
| return Option.empty(); | ||
| } else { | ||
| return HoodieActiveTimeline.createNewInstantTime(); | ||
| return Option.of(HoodieActiveTimeline.createNewInstantTime()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
can we also add a UT here, for both commits with / without data.