Skip to content

HDDS-14855. Add synchronization in ThrottledAsyncChecker#schedule#9942

Closed
ChenSammi wants to merge 1 commit intoapache:masterfrom
ChenSammi:HDDS-14855
Closed

HDDS-14855. Add synchronization in ThrottledAsyncChecker#schedule#9942
ChenSammi wants to merge 1 commit intoapache:masterfrom
ChenSammi:HDDS-14855

Conversation

@ChenSammi
Copy link
Contributor

What changes were proposed in this pull request?

ThrottledAsyncChecker has checksInProgress and completedChecks to track the check task in running, and the lastest check task result, while both have thread unsafe data type.

Synchronization is added when element is removed from checksInProgress and completedChecks, but there is no synchronization when element in added during schedule() call.
So add synchronization in ThrottledAsyncChecker#schedule to avoid schedule multiple times for same target.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14855

How was this patch tested?

Copy link
Contributor

@Gargi-jais11 Gargi-jais11 left a comment

Choose a reason for hiding this comment

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

Thanks @ChenSammi for the patch. Just one minor comment.

Comment on lines 118 to +121
public Optional<ListenableFuture<V>> schedule(
Checkable<K, V> target, K context) {
if (checksInProgress.containsKey(target)) {
return Optional.empty();
}
synchronized (ThrottledAsyncChecker.this) {
if (checksInProgress.containsKey(target)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply make the method itself synchronized instead of using a block? This has the same effecct and simple to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. The callback uses synchronized (ThrottledAsyncChecker.this) only because it is a different object. Here we can simplify as @Gargi-jais11 suggested.

@adoroszlai
Copy link
Contributor

Thanks @ChenSammi for the patch. Since @ptlrs in #9948 made exactly the same change as suggested here, I merged that one. Thank you both for the fix.

@adoroszlai adoroszlai closed this Mar 19, 2026
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