[FIXED] Improve KeyValue and ObjectStore watchers: Fix watching past history replay #644
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.
Overview
This PR enhances the KeyValue and ObjectStore watchers in
nats.py
by introducing a few key improvements:1. StopIterSentinel for Watchers
StopIterSentinel
) and enqueue it on the watcher’s queue to signal termination (e.g., whenstop()
is called).StopAsyncIteration
) without conflating aNone
marker with an end-of-stream condition.2. Ensure Watchers Do Not Break on
None
None
in the queue as a termination signal. But for the JetStream KV watchers,None
is also used internally to indicate “no more pending updates” as part of the initial replay.StopIterSentinel
.3. Minor Cleanups in Watchers
KeyWatcher
andObjectWatcher
push theStopIterSentinel
to their_updates
queue and raiseStopAsyncIteration
inside__anext__()
if the sentinel is dequeued.Note
test_kv_simple
that doesassert 2 == 1
. That specific test (from the official suite) checks behavior around purge vs. expected message count, which can differ in certain server versions. If this is not due to the version mismatch I will fix or close this.Linked Issues
This PR might relate to or address:
(References and discussion around ephemeral watchers,
None
handling, or improvements to KV watchers.)Impact and Compatibility
test_kv_simple
mismatch.Usage Example
Below is an example of usage for a KV watcher now that watchers keep running beyond the initial replay:
Contributing Statement
• This contribution is my original work.
• I license the work to the NATS project under the project’s Apache 2.0 license.
Thanks for your consideration! If any further adjustments or clarifications are needed, please let me know. I tried to adhere to the ADR and existing code practices as closely as possible.
Cheers,
Fielding