-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-6170] Use correct zone id while calculating earliestTimeToRetain #8631
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,6 @@ | |
| import java.io.IOException; | ||
| import java.io.Serializable; | ||
| import java.time.Instant; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
|
|
@@ -510,7 +509,7 @@ public Option<HoodieInstant> getEarliestCommitToRetain() { | |
| } | ||
| } else if (config.getCleanerPolicy() == HoodieCleaningPolicy.KEEP_LATEST_BY_HOURS) { | ||
| Instant instant = Instant.now(); | ||
| ZonedDateTime currentDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); | ||
| ZonedDateTime currentDateTime = ZonedDateTime.ofInstant(instant, hoodieTable.getMetaClient().getTableConfig().getTimelineTimezone().getZoneId()); | ||
| String earliestTimeToRetain = HoodieActiveTimeline.formatDate(Date.from(currentDateTime.minusHours(hoursRetained).toInstant())); | ||
|
Contributor
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. The code only works when
Contributor
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. tableConfig is generated for the first time when table is created and the time zone is set right then. after that, we can't alter the time zone. not sure if we need any fixes here. can you help clarify
Contributor
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.
Can we always ensure table config is initialized first? How to guard this sequence dependency.
Contributor
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 see the issue. may be we should not set any default value for commitTimeZone in HoodieInstantTimeGenerator. we can set it to null infact. And so unless the table properties are instantiation whcih in turn will call into setCommitTimeZone, if any other callers tries to access the commit time zone, will fail fast.
Collaborator
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 made it an option in the latest commit but I see some failures in Azure CI where option value is not present for timeline timezone. Its in hudi-cli and
Contributor
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. Yeah, that means the code is prone to making misusages, let's fix all those test falures by initialzing the zoneId manually.
Collaborator
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 changed the PR to use metaClient's tableConfig. Please take a look.
Contributor
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.
Yes, maybe we should pass in the table path as param and triggers a lazy initialization for the zoneId if necessary.
Collaborator
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. Yeah. We can handle it in a separate jira though. |
||
| earliestCommitToRetain = Option.fromJavaOptional(commitTimeline.getInstantsAsStream().filter(i -> HoodieTimeline.compareTimestamps(i.getTimestamp(), | ||
| HoodieTimeline.GREATER_THAN_OR_EQUALS, earliestTimeToRetain)).findFirst()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,29 @@ | |
|
|
||
| package org.apache.hudi.common.model; | ||
|
|
||
| import java.time.ZoneId; | ||
| import java.util.TimeZone; | ||
|
|
||
| /** | ||
| * Hoodie TimelineZone. | ||
| */ | ||
| public enum HoodieTimelineTimeZone { | ||
| LOCAL("local"), | ||
| UTC("utc"); | ||
| LOCAL("local", ZoneId.systemDefault()), | ||
| UTC("utc", TimeZone.getTimeZone("UTC").toZoneId()); | ||
|
|
||
| private final String timeZone; | ||
| private final ZoneId zoneId; | ||
|
Contributor
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. Don't think we need a zoneId member, can we calculate it on the fly in method
Collaborator
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 can do a switch-case but I feel this is better. WDYT?
Contributor
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. Fine, it's just a preference. |
||
|
|
||
| HoodieTimelineTimeZone(String timeZone) { | ||
| HoodieTimelineTimeZone(String timeZone, ZoneId zoneId) { | ||
| this.timeZone = timeZone; | ||
| this.zoneId = zoneId; | ||
| } | ||
|
|
||
| public String getTimeZone() { | ||
| return timeZone; | ||
| } | ||
|
|
||
| public ZoneId getZoneId() { | ||
| return zoneId; | ||
| } | ||
| } | ||
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 code only works when
HoodieInstantTimeGenerator.setCommitTimeZoneis executed in the same JVM process, we must asure that. Either set it up explicitly or instantiate aHoodieTableConfigwithin which the timezone is set up.