CBG-5286 [3.3.5 backport] fix missing changes with active_only=true and limit=#8231
Merged
torcolvin merged 2 commits intorelease/3.3.5from May 6, 2026
Merged
CBG-5286 [3.3.5 backport] fix missing changes with active_only=true and limit=#8231torcolvin merged 2 commits intorelease/3.3.5from
torcolvin merged 2 commits intorelease/3.3.5from
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This backport addresses a changes feed edge case where active_only=true combined with a limit could cause GetChanges to omit relevant cached entries (especially when backfill/query results include only channel removals), leading to missing active changes.
Changes:
- Adjusted
singleChannelCacheImpl.GetChangesto always consider appending cache results whenActiveOnlyis enabled, and to avoid applying a naive limit at the concatenation step in that mode. - Added targeted channel cache tests covering
active_only+limitinteractions across several scenarios, including “query returns only removals but cache has an active rev”.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| db/channel_cache_single.go | Ensures cache entries are appended for ActiveOnly requests even when query results exceed the requested limit due to inactive entries. |
| db/channel_cache_test.go | Adds regression tests to validate correct behavior for active_only=true with/without limit across mixed active/removal scenarios. |
Comment on lines
+611
to
+620
| // doc1: active (seq 1) - will be in backing store, not cache | ||
| _, _, _ = collection.Put(ctx, "doc1", Body{"channels": activeChannel}) | ||
|
|
||
| // doc2: active (seq 2) -> inactive (seq 3) - seq 3 in cache | ||
| revID2, _, _ := collection.Put(ctx, "doc2", Body{"channels": activeChannel}) | ||
| _, _, _ = collection.Put(ctx, "doc2", Body{"channels": "other", "_rev": revID2}) | ||
|
|
||
| // doc3: active (seq 4) -> inactive (seq 5) - seq 5 in cache | ||
| revID3, _, _ := collection.Put(ctx, "doc3", Body{"channels": activeChannel}) | ||
| _, _, _ = collection.Put(ctx, "doc3", Body{"channels": "other", "_rev": revID3}) |
Comment on lines
+647
to
+654
| _, _, _ = collection.Put(ctx, "doc1", Body{"channels": activeChannel}) | ||
|
|
||
| // doc2: active (seq 2) -> inactive (seq 3) - cache | ||
| revID2, _, _ := collection.Put(ctx, "doc2", Body{"channels": activeChannel}) | ||
| _, _, _ = collection.Put(ctx, "doc2", Body{"channels": "other", "_rev": revID2}) | ||
|
|
||
| // doc3: active (seq 4) - cache | ||
| _, _, _ = collection.Put(ctx, "doc3", Body{"channels": activeChannel}) |
Comment on lines
+682
to
+687
| revID1, _, _ := collection.Put(ctx, "doc1", Body{"channels": activeChannel}) | ||
| _, _, _ = collection.Put(ctx, "doc1", Body{"channels": "other", "_rev": revID1}) | ||
|
|
||
| // doc2: active (seq 3) -> inactive (seq 4) | ||
| revID2, _, _ := collection.Put(ctx, "doc2", Body{"channels": activeChannel}) | ||
| _, _, _ = collection.Put(ctx, "doc2", Body{"channels": "other", "_rev": revID2}) |
Comment on lines
+624
to
+639
| // With limit 1 (before) | ||
| changesOptions := ChangesOptions{Since: SequenceID{Seq: 0}, ActiveOnly: true, Limit: 1, ChangesCtx: base.TestCtx(t)} | ||
| changes := getChanges(t, collection, base.SetOf(activeChannel), changesOptions) | ||
| require.Len(t, changes, 1) | ||
| assert.Equal(t, "doc1", changes[0].ID) | ||
|
|
||
| // No limit | ||
| changesOptions.Limit = 0 | ||
| changes = getChanges(t, collection, base.SetOf(activeChannel), changesOptions) | ||
| require.Len(t, changes, 1) | ||
| assert.Equal(t, "doc1", changes[0].ID) | ||
|
|
||
| // With limit 1 (after) | ||
| changesOptions.Limit = 1 | ||
| changes = getChanges(t, collection, base.SetOf(activeChannel), changesOptions) | ||
| require.Len(t, changes, 1) |
torcolvin
approved these changes
May 6, 2026
torcolvin
approved these changes
May 6, 2026
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.
CBG-5286
Backports #8144
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests