improve: use the default list methods with read-cache-after-write consistency#3336
Open
csviri wants to merge 5 commits intooperator-framework:nextfrom
Open
improve: use the default list methods with read-cache-after-write consistency#3336csviri wants to merge 5 commits intooperator-framework:nextfrom
csviri wants to merge 5 commits intooperator-framework:nextfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the “strong consistency” list/index variants by folding read-cache-after-write consistency behavior into the default list(...) / byIndexStream(...) methods on ManagedInformerEventSource, and updates tests to use the new API surface.
Changes:
- Replaced
listWithStrongConsistency(...)withlist(...)implementations that merge informer results with the temporary cache for read-cache-after-write consistency. - Replaced
byIndexStreamWithStrongConsistency(...)withbyIndexStream(...)and updatedbyIndex(...)to return merged results. - Updated informer event source tests to call the renamed/default methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java | Removes “strong consistency” variants, makes default list/index methods merge with the temp cache, and adjusts index lookup behavior. |
| operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java | Updates tests to use list(...) / byIndexStream(...) instead of the removed “strong consistency” methods. |
| public List<R> byIndex(String indexName, String indexKey) { | ||
| return mergeWithWithTempCacheResources( | ||
| manager().byIndexStream(indexName, indexKey), indexName, indexKey) | ||
| .toList(); |
Comment on lines
+242
to
245
| public Stream<R> list(String namespace, Predicate<R> predicate) { | ||
| return mergeWithWithTempCacheResources( | ||
| manager().list(namespace, predicate), namespace, predicate); | ||
| } |
| * Like {@link #list(Predicate)} but for read-cache-after-write consistency. This is useful when | ||
| * resources are updated using {@link | ||
| * io.javaoperatorsdk.operator.api.reconciler.ResourceOperations}. | ||
| */ |
Comment on lines
+261
to
264
| public Stream<R> byIndexStream(String indexName, String indexKey) { | ||
| return mergeWithWithTempCacheResources( | ||
| manager().byIndexStream(indexName, indexKey), indexName, indexKey); | ||
| } |
Comment on lines
+278
to
+282
| @Override | ||
| public List<R> byIndex(String indexName, String indexKey) { | ||
| return mergeWithWithTempCacheResources( | ||
| manager().byIndexStream(indexName, indexKey), indexName, indexKey); | ||
| manager().byIndexStream(indexName, indexKey), indexName, indexKey) | ||
| .toList(); |
Comment on lines
+238
to
+242
| * {@inheritDoc} | ||
| * | ||
| * <p>This implementation is read-cache-after-write consistent. Results are merged with the | ||
| * temporary resource cache to ensure recently written resources are reflected in the output. | ||
| */ |
…sistency Remove the index and list related methods "strong consistency variant". The rational behind this change is that the user either uses read-cache-after-write consistency feature, than the "strong read" should be used. If on the other hand tha feature, is not used, the current implementation does not impose any overhead. In addition to that strong consistency is not a good name, we call this feature as read-cache-after-write consistency, that might be too long though. Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
| return manager().keys(); | ||
| } | ||
| var tempKeys = temporaryResourceCache.getResources().keySet(); | ||
| return Stream.concat(manager().keys(), tempKeys.stream().filter(k -> !manager().contains(k))); |
Comment on lines
+237
to
+246
| /** | ||
| * {@inheritDoc} | ||
| * | ||
| * <p>This implementation is read-cache-after-write consistent. Results are merged with the | ||
| * temporary resource cache to ensure recently written resources are reflected in the output. | ||
| */ | ||
| @Override | ||
| public Stream<R> list(String namespace, Predicate<R> predicate) { | ||
| return manager().list(namespace, predicate); | ||
| return mergeWithWithTempCacheResources( | ||
| manager().list(namespace, predicate), namespace, predicate); |
Comment on lines
260
to
270
| /** | ||
| * Like {@link #list(String, Predicate)} but for read-cache-after-write consistency. This is | ||
| * useful when resources are updated using {@link | ||
| * io.javaoperatorsdk.operator.api.reconciler.ResourceOperations}. | ||
| * {@inheritDoc} | ||
| * | ||
| * <p>This implementation is read-cache-after-write consistent. Results are merged with the | ||
| * temporary resource cache to ensure recently written resources are reflected in the output. | ||
| */ | ||
| public Stream<R> listWithStrongConsistency(String namespace, Predicate<R> predicate) { | ||
| @Override | ||
| public Stream<R> byIndexStream(String indexName, String indexKey) { | ||
| return mergeWithWithTempCacheResources( | ||
| manager().list(namespace, predicate), namespace, predicate); | ||
| } | ||
|
|
||
| /** | ||
| * Like {@link #list(Predicate)} but for read-cache-after-write consistency. This is useful when | ||
| * resources are updated using {@link | ||
| * io.javaoperatorsdk.operator.api.reconciler.ResourceOperations}. | ||
| */ | ||
| public Stream<R> listWithStrongConsistency(Predicate<R> predicate) { | ||
| return mergeWithWithTempCacheResources(cache.list(predicate), null, predicate); | ||
| manager().byIndexStream(indexName, indexKey), indexName, indexKey); | ||
| } |
Comment on lines
+245
to
247
| return mergeWithWithTempCacheResources( | ||
| manager().list(namespace, predicate), namespace, predicate); | ||
| } |
xstefank
approved these changes
May 7, 2026
Collaborator
xstefank
left a comment
There was a problem hiding this comment.
Do we have a policy that public methods should be first deprecated before they are removed?
Collaborator
Author
This is against |
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.
Remove the index and list related methods "strong consistency variant".
The rational behind this change is that the user either uses read-cache-after-write consistency feature,
than the "strong read" should be used. If on the other hand tha feature,
is not used, the current implementation does not impose any overhead.
In addition to that strong consistency is not a good name, we call this feature
as read-cache-after-write consistency, that might be too long though.
Adds ghost resource handling for
keys().Add also missing javadocs.
Signed-off-by: Attila Mészáros a_meszaros@apple.com