Repository navigation
GH-173: Preserve concurrent JDK cache updates - #204
Open
efegokdemir wants to merge 3 commits into
Open
efegokdemir wants to merge 3 commits into
efegokdemir wants to merge 3 commits into
Conversation
elharo
requested changes
Oct 17, 2026
| try { | ||
| Path cacheFile = getCacheFile(); | ||
| Files.createDirectories(cacheFile.getParent()); | ||
| try (Writer w = Files.newBufferedWriter(cacheFile)) { |
| Path cacheFile = getCacheFile(); | ||
| Files.createDirectories(cacheFile.getParent()); | ||
| try (Writer w = Files.newBufferedWriter(cacheFile)) { | ||
| PersistedToolchains pt = new PersistedToolchains(); |
Contributor
There was a problem hiding this comment.
don't abbreviate variable names
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test needs stronger synchronization because it can pass against the original implementation.
1 open issue
What changed in this PR
Addresses #173 by coordinating JDK cache updates with persistence snapshots to prevent lost concurrent updates.
Changes:
- Synchronizes snapshot creation and cache insertion, reusing existing models.
- Keeps the cache dirty after failed writes.
- Adds a latch-controlled concurrency regression test.
| File | Description |
|---|---|
| src/test/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscovererTest.java | Adds concurrent cache-persistence regression coverage. |
| src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java | Coordinates updates and snapshots and preserves retry state. |
Review effort: Balanced
Comment on lines
+112
to
+113
| assertTrue(discoverer.secondModelCreated.await(10, TimeUnit.SECONDS), "cache update did not start"); | ||
| cache.allowSnapshot.countDown(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #173.
Concurrent JDK discovery can add a cache entry while another call is writing the cache. The write then clears the modified flag, so that entry is not persisted.
Cache updates now coordinate with the snapshot used for persistence. A failed write leaves the cache marked dirty, and concurrent discoveries of the same JDK reuse the first cached model. A latch-controlled regression test reproduces the lost update and verifies that the next write persists it.
Validation:
JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn clean -Dspotless.skip=true -Dtest=ToolchainDiscovererTest test— passed (2 tests).JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn spotless:check— passed.JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -Prun-its verify— passed (8 integration tests).git diff --check— passed.To make clear that you license your contribution under the Apache License Version 2.0, January 2004, check one of the following: