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

Use ConcurrentHashMap#computeIfAbsent in JarCacheSupport #713

Merged
merged 1 commit into from Jan 5, 2024

Conversation

basil
Copy link
Member

@basil basil commented Jan 5, 2024

While reading this code recently, I found some complicated logic to deal with a risk of multiple downloads of the same JAR getting scheduled, leading to special code to handle this race condition whose correctness is being challenged in #709. This complicated logic is not necessary if one instead uses ConcurrentHashMap#computeIfAbsent, whose Javadoc states:

The entire method invocation is performed atomically, so the function is applied at most once per key.

Due to these exactly once semantics, we don't have to worry about a race condition, so we can simplify the logic considerably, deleting the logic that is being challenged in the other PR rather than attempting to fix it. We also don't need the retry logic to deal with the executor rejecting the queue submission because (as an existing comment already notes) AtmostOneThreadExecutor never rejects submissions anyway (and any feasible replacement we might choose in the future would likely block rather than rejecting submissions).

Testing done

Ran mvn clean verify as well as running a job on an inbound agent with the Git plugin to load a lot of classes. Verified that the JAR cache was correctly populated after being purged.

@basil basil added the bug For changelog: Fixes a bug. label Jan 5, 2024
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

looks much simpler

@basil basil merged commit 71f9f11 into jenkinsci:master Jan 5, 2024
13 checks passed
@basil basil deleted the inprogress branch January 5, 2024 22:16
@basil
Copy link
Member Author

basil commented Jan 8, 2024

and any feasible replacement we might choose in the future would likely block rather than rejecting submissions

Foreshadowing the use of LinkedBlockingQueue in #717.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Fixes a bug.
Projects
None yet
3 participants