-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Enable recursive updates to NamespacedHierarchicalStore #5231
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
Open
mpkorstanje
wants to merge
13
commits into
main
Choose a base branch
from
rien/enable-store-recursive-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Co-authored-by: martinfrancois <[email protected]>
Co-authored-by: martinfrancois <[email protected]>
164169b to
708bb35
Compare
🔎 No tests executed 🔎🏷️ Commit: d40ae31 Learn more about TestLens at testlens.app. |
46f2099 to
be7ab95
Compare
be7ab95 to
1808119
Compare
b0e3f2d to
3c5a571
Compare
6 tasks
Contributor
Author
|
@martinfrancois would you have time to review this? |
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.
Users of the extension context may occasionally want to build a non-trivial object graph, of which the individual components are also stored in the extension context store. This naturally leads to a pattern where the store is updated recursively. For example:
While the backing
ConcurrentHashMapdoes not support recursive updates this does work asgetOrComputeIfAbsentdefers the recursive update until the after the map has been updated. This is not the case forcomputeIfAbsentwhich immediately calls the default creator. This poses a problem ascomputeIfAbsentis supposed to be a drop-in replacement forgetOrComputeIfAbsentwith better null and exception semantics.The solution is to defer the execution of the default value creator until after the map has been updated. This is handled by the
DeferredSupplierwhich uses aFutureTaskto support a nice separation of compute and get operations.Because there are some different between both compute methods in how deferred values are to be handled, this PR introduces a
StoredValue.Value,.DeferredValueand.DeferredOptionalValuecontainers forput,getOrComputeIfAbsentandcomputeIfAbsentrespectively. This allows:DeferredOptionalValuecontaining an exception to be treated as absent ingetStoredValue.DeferredOptionalValuecontaining a a value to return its contents on evaluation.DeferredValueto throw an exception or returns its contents on evaluationValueto simply return its contents on evaluationThis PR does introduce a small change in behavior. Previously any of the concurrent callers of
getOrComputeIfAbsentcould be the one executing the default creator. This can now only be done by the caller that created the stored value that was actually inserted. I don't expect this will break anything.The PR is also slightly bigger than it needs to be.
StoredValue.Valuecould be replaced with.DeferredValue. But asDeferredValueonly exists to support a deprecated method, this makes for easier clean up in the future.Thanks to @martinfrancois who contributed the
CollidingKey,DeferredSupplierand several other useful concepts in #5209.Fixes: #5171
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations