Skip to content
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

KAFKA-16879 SystemTime should use singleton mode #16266

Merged
merged 10 commits into from
Jun 14, 2024

Conversation

dujian0068
Copy link
Contributor

Currently, the SystemTime class, which provides system time-related functionalities such as getting the current timestamp 、sleep、and await can be instantiated multiple times.

Howerver, system time is unique,In an application, the time obtained in different places should be consistent, But now the time obtained by using the Java System class to interact with the underlying layer is the same。

So I suggest changing it to a singleton mode, reflect the uniqueness of system time in design

Use inline implementation to ensure there is only one SystemTime,avoid large-scale changes

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

SystemTime should use singleton mode
SystemTime should use singleton mode
SystemTime should use singleton mode--update UT
SystemTime should use singleton mode--update UT
SystemTime should use singleton mode
@@ -60,7 +60,7 @@

public class SustainedConnectionWorker implements TaskWorker {
private static final Logger log = LoggerFactory.getLogger(SustainedConnectionWorker.class);
private static final SystemTime SYSTEM_TIME = new SystemTime();
private static final Time SYSTEM_TIME = Time.SYSTEM;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can inline this variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right,
After updating SystemTime to singleton mode, many class attributes time can be modified inline, but I am not sure whether to modify it because it is a large-scale change to modify many files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mean the local variables and instance variables time, those can stay as-is, as they can be useful later if someone wants to replace the Time instance for the whole test.

I meant this duplicate static final variable. Either it should be an instance variable like the rest, or inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you
I have made an update , and update ConnectionStressWorker that also use static final Time time = Time.SYSTEM.

@@ -60,7 +60,7 @@

public class SustainedConnectionWorker implements TaskWorker {
private static final Logger log = LoggerFactory.getLogger(SustainedConnectionWorker.class);
private static final SystemTime SYSTEM_TIME = new SystemTime();
private static final Time SYSTEM_TIME = Time.SYSTEM;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mean the local variables and instance variables time, those can stay as-is, as they can be useful later if someone wants to replace the Time instance for the whole test.

I meant this duplicate static final variable. Either it should be an instance variable like the rest, or inlined.

* A time implementation that uses the system clock and sleep call. Use `Time.SYSTEM` instead of creating an instance
* of this class.
* A time implementation that uses the system clock and sleep call.
* Every kafka process has a single instance of class <code>SystemTime</code> that allows the process to interface
Copy link
Contributor

@gharris1727 gharris1727 Jun 12, 2024

Choose a reason for hiding this comment

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

nit: I think the mention of "process" here is more confusing than helpful. If you want to mention this is a singleton, say "Use the singleton Time.SYSTEM", or just leave the javadoc as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you
I have restored it

Copy link
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @dujian0068!

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants