Add UpdatesOnly query option to fetch data for only changed keys #22108
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.
Description
As mentioned long ago (and roughly outlined) in #2791, a limitation on blocking queries is that all K/V entries matching that prefix are returned, even though only 1 key may have changed. This diff adds a new
UpdatesOnly
option, that when set, introduces server-side filtering to remove all keys/entries (from aKeys()
orList()
query) that have an oldModifyIndex
.It uses
MinQueryIndex
as the threshold here, which follows the effective serialization/deserialization chain:WaitIndex
-->index
-->MinQueryIndex
.WaitIndex
being the client-side parameter, determining the index the "client" waits for on a blocking queryindex
being the serialized HTTP query parameter representing theWaitIndex
MinQueryIndex
being the server-side struct (deserialized result ofindex
)While we (potentially?) wait for the streaming backend: https://developer.hashicorp.com/consul/api-docs/features/blocking#streaming-backend to be implemented for KV endpoints, this can be a good stop-gap solution to enable in-memory, incremental scans or queries over a prefix.
Testing & Reproduction steps
minQueryIndex
passed down the state layer to be 0 (no filtering)state/kvs_test.go
to illustrate the filtering based onModifyIndex
Links
Original GH issue: #2791
PR Checklist