Skip to content

make sure time incremental#4074

Open
Leavrth wants to merge 1 commit intopingcap:masterfrom
Leavrth:make_sure_time_incremental
Open

make sure time incremental#4074
Leavrth wants to merge 1 commit intopingcap:masterfrom
Leavrth:make_sure_time_incremental

Conversation

@Leavrth
Copy link

@Leavrth Leavrth commented Jan 28, 2026

What problem does this PR solve?

Issue Number: close #4073

What is changed and how it works?

use PD physical time and UTC location instead.

Check List

Tests

  • Unit test

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

None

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. release-note-none Denotes a PR that doesn't merit a release note. labels Jan 28, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 28, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hicqu for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pingcap-cla-assistant
Copy link

pingcap-cla-assistant bot commented Jan 28, 2026

CLA assistant check
All committers have signed the CLA.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Leavrth, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new mechanism to retrieve the physical timestamp from PD, ensuring that time-dependent operations, particularly those related to generating date strings for cloud storage, use a consistent and incrementally reliable time source. By switching to PD physical time and UTC, the system enhances the accuracy and predictability of time-based functionalities, addressing potential issues with non-incremental time or timezone discrepancies.

Highlights

  • New Interface Method: A new method, CurrentPhysicalTS() time.Time, has been added to the Clock interface in pkg/pdutil/clock.go. This method is designed to return the physical timestamp obtained from PD.
  • Implementation Across Clock Types: The CurrentPhysicalTS() method has been implemented for the clock, Clock4Test, and monotonicClock structs, ensuring consistent behavior across different clock implementations.
  • Cloud Storage Path Generation Update: The GenerateDateStr() function in pkg/sink/cloudstorage/path.go now utilizes the new CurrentPhysicalTS().UTC() method instead of CurrentTime(). This change ensures that date strings for cloud storage paths are generated using the PD physical time and are consistently in UTC.
  • New Test Case: A new test case has been added to pkg/pdutil/clock_test.go to verify that CurrentPhysicalTS() returns an incrementally increasing time, ensuring the reliability of the new functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 28, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new method CurrentPhysicalTS to the Clock interface to provide a time based on PD's physical timestamp. This is then used in the cloud storage sink to generate date-based file paths. The main goal seems to be to use a non-extrapolated, UTC-based time for this purpose.

My review has identified a few areas for improvement:

  • The new CurrentPhysicalTS method in the main clock implementation is not strictly incremental, which can be misleading given the PR title. I've provided a suggestion to make it strictly incremental if that's the desired behavior.
  • The test implementations of CurrentPhysicalTS in Clock4Test and monotonicClock are inconsistent with the main implementation regarding the timezone (they return local time instead of UTC). I've suggested changes to align them.
  • A comment in pkg/sink/cloudstorage/path.go has become outdated due to the changes and should be removed or updated.

Comment on lines +138 to +142
func (c *clock) CurrentPhysicalTS() time.Time {
c.mu.RLock()
defer c.mu.RUnlock()
return time.UnixMilli(c.mu.physicalTs)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function CurrentPhysicalTS is not strictly incremental as implemented, which contradicts the PR title "make sure time incremental". It returns the last physical timestamp from PD, so two successive calls within the PD update interval can return the same value.

If a strictly incremental UTC time is desired, you should add the elapsed time since the last update.

If a non-extrapolated, "safe" timestamp is the goal, the implementation is fine, but the test in clock_test.go should assert non-decreasing time (!pt1.After(pt2)) instead of strict increment to avoid flakiness.

Assuming strictly incremental time is desired, here is a suggestion:

Suggested change
func (c *clock) CurrentPhysicalTS() time.Time {
c.mu.RLock()
defer c.mu.RUnlock()
return time.UnixMilli(c.mu.physicalTs)
}
func (c *clock) CurrentPhysicalTS() time.Time {
c.mu.RLock()
defer c.mu.RUnlock()
elapsed := time.Since(c.mu.tsProcessingTime).Milliseconds()
physical := c.mu.physicalTs + elapsed
return time.UnixMilli(physical)
}

}

func (c *Clock4Test) CurrentPhysicalTS() time.Time {
return c.CurrentTime()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The main clock implementation of CurrentPhysicalTS returns a time.Time in UTC. However, this test implementation returns c.CurrentTime(), which returns a time in the local timezone. This inconsistency can lead to subtle issues in tests. To be consistent, this should also return a UTC time.

Suggested change
return c.CurrentTime()
return c.CurrentTime().UTC()

}

func (c *monotonicClock) CurrentPhysicalTS() time.Time {
return c.clock.Now()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The main clock implementation of CurrentPhysicalTS returns a time.Time in UTC. However, this implementation returns c.clock.Now(), which is in the local timezone. This inconsistency can lead to subtle issues. To be consistent, this should also return a UTC time.

Suggested change
return c.clock.Now()
return c.clock.Now().UTC()


currTime := f.pdClock.CurrentTime()
currTime := f.pdClock.CurrentPhysicalTS().UTC()
// Note: `dateStr` is formatted using local TZ.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment is no longer accurate. currTime is now explicitly in UTC on the line above. This comment should be updated or removed to avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-triage-completed first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the s3 date prefix may not be monotonically incremental

1 participant