Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a pagination correctness issue in Sync Gateway’s channel cache path when ActiveOnly=true is used together with Limit, ensuring the changes feed doesn’t prematurely append cached results before the query has reached the cache boundary.
Changes:
- Update
singleChannelCacheImpl.GetChangesto only append cache results forActiveOnly+Limitwhen the query has reached the cache boundary. - Add new regression subtests to cover “cache populated + query pagination” scenarios (with and without a request limit).
- Add a fuzz test to validate
ActiveOnlychange enumeration properties across randomized cache/query/limit configurations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
db/channel_cache_single.go |
Adds a guard (queryReachedCache) to prevent prematurely appending cache results during ActiveOnly+Limit pagination. |
db/channel_cache_test.go |
Adds regression tests and a fuzz test to exercise ActiveOnly pagination across query batches and cache boundary behavior. |
| // If we've reached limit before exhausting the range up to endSeq, we're done, but the | ||
| // range beyond the last returned entry hasn't been fully scanned. | ||
| if limit != 0 && activeEntryCount >= limit { | ||
| reachedEnd = endSeq > 0 && highSeq >= endSeq |
There was a problem hiding this comment.
Here highSeq is the highest sequence returned by the query, and endSeq is the upper boundary of the query boundary, correct? There's no guarantee that there's a sequence in this channel (and so in the query results) greater than or equal to endSeq, so it seems like there will be many cases where reachedEnd will be incorrectly set to false here?
CBG-5555 better fix for activeOnly+limit
This is a reimplementation of #8144 CBG-5262 without a regression that occured:
Approach:
** If not active_only, we have always received the full backfill
** If active_only and the number of results is less than limit, we have reached the end of the query backfill
** If active_only and the number of results or the sequence value expected by pagination is equal to the last row (last entry is on pagination boundary)
** If activeOnly, only append cache results if the query has reached the start of the cached results and is less than the value of limit.
** If not active only, preserve existing behavior
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests