Skip to content

CBG-5225: sg-bucket KV range scan implementations#8084

Merged
bbrks merged 9 commits into
mainfrom
rosmar_kv_range_scan
May 19, 2026
Merged

CBG-5225: sg-bucket KV range scan implementations#8084
bbrks merged 9 commits into
mainfrom
rosmar_kv_range_scan

Conversation

@bbrks

@bbrks bbrks commented Feb 26, 2026

Copy link
Copy Markdown
Member

Note: This was coded primarily using Opus 4.6 - with manual guidance/verification/review.

Adds a test that can do a KV range scan on both Couchbase via Gocb and Rosmar via an sg-bucket interface.

Dependencies

Integration Tests

Copilot AI review requested due to automatic review settings February 26, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds KV (Key-Value) range scan functionality to Sync Gateway through the sg-bucket abstraction layer, enabling both Couchbase Server (via gocb) and Rosmar to perform efficient range scans over document keys.

Changes:

  • Adds Scan() method implementation for Collection that bridges sg-bucket's RangeScanStore interface to gocb's range scan API
  • Adds AsRangeScanStore() helper function following the existing pattern for feature-checking datastore capabilities
  • Implements RangeScanStore interface in LeakyDataStore to support testing with leaky bucket

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
base/collection_rangescan.go New file implementing the Scan() method for Collection, converting sg-bucket scan types to gocb scan types, and providing an iterator wrapper for scan results
base/collection_rangescan_test.go Comprehensive test coverage for range scan functionality including full range, partial range, IDs-only, prefix scans, empty ranges, and tombstone exclusion
base/leaky_datastore.go Implements RangeScanStore.Scan() by delegating to underlying datastore, adds interface assertion for RangeScanStore
base/collection.go Adds feature flag BucketStoreFeatureRangeScan with version check (7.6+)
base/bucket.go Adds AsRangeScanStore() helper function to check if a datastore supports range scan operations

Comment thread base/collection_rangescan.go Outdated
Comment thread base/bucket.go Outdated
Comment thread base/collection_rangescan.go Outdated
@bbrks bbrks force-pushed the rosmar_kv_range_scan branch 2 times, most recently from ea06bac to 07ed2f8 Compare February 26, 2026 21:51
Comment thread base/collection_rangescan.go Outdated
Comment thread base/collection_rangescan.go Outdated
Comment thread base/collection_rangescan_test.go Outdated

allDocIDs := []string{"doc_a", "doc_b", "doc_c", "doc_d", "doc_e"}

// CBS range scan may not immediately reflect recent writes (requires persistence).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? This seems perilous if so. Does this depend of the type of storage used by the backing bucket?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no simple scan consistency setting available to use to guard against this. We could pass in vb snapshots to avoid - but I don't think it's worth it given we're not expecting to one-shot the range scan to migrate all data in one go

it will be an iterative process until no eligible data is remaining to move (i.e. guard against any writes that may be coming in underneath a running range scan)

Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/collection_rangescan_test.go Outdated
Comment thread base/leaky_datastore.go
@bbrks bbrks force-pushed the rosmar_kv_range_scan branch from 69ae861 to 639b7a6 Compare May 18, 2026 19:43
Wrap gocb.Collection.Scan() in the SG collection adapter, converting
sgbucket types to gocb types with RawJSONTranscoder. Add AsRangeScanStore
helper, LeakyDataStore passthrough, and IsSupported for CBS 7.5+.
Includes dual-backend test covering full range, partial range, IDsOnly,
sampling, empty range, prefix, and tombstone exclusion.
@bbrks bbrks force-pushed the rosmar_kv_range_scan branch from 18021a8 to 089bdba Compare May 18, 2026 21:05
gregns1
gregns1 previously approved these changes May 19, 2026

@gregns1 gregns1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will let you update dependencies where and will re-approve

@bbrks bbrks changed the title Add Gocb KV range scan via sg-bucket abstraction with Rosmar support CBG-5225: sg-bucket KV range scan implementations May 19, 2026
@bbrks bbrks force-pushed the rosmar_kv_range_scan branch from 6694dab to 54032d9 Compare May 19, 2026 13:28
@bbrks bbrks requested a review from gregns1 May 19, 2026 15:13
@bbrks bbrks assigned gregns1 and unassigned bbrks May 19, 2026
@bbrks bbrks merged commit b6a2142 into main May 19, 2026
28 checks passed
@bbrks bbrks deleted the rosmar_kv_range_scan branch May 19, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants