Skip to content

Conversation

@gregns1
Copy link
Contributor

@gregns1 gregns1 commented Jan 30, 2026

CBG-5142

Backports 14787f7

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings January 30, 2026 17:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR backports CBG-5142 to version 4.0.3, fixing an issue with delta sync and backup revision fetching. The change ensures that backup revisions are only fetched for delta sync when necessary, specifically for the fromRev parameter.

Changes:

  • Modified GetWithCV method signature to accept a loadBackup parameter to control whether backup revisions should be loaded
  • Updated delta sync logic to only fetch backup revisions for the source revision (fromRev), not the target revision
  • Updated all call sites of GetWithCV to explicitly specify whether backup revision loading is needed

Reviewed changes

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

Show a summary per file
File Description
db/revision_cache_interface.go Added loadBackup parameter to GetWithCV and getCurrentVersion methods
db/revision_cache_lru.go Updated cache implementation to respect loadBackup flag for CV fetches
db/revision_cache_bypass.go Updated bypass cache to use loadBackup parameter
db/crud.go Updated delta sync to load backup revisions only for fromRev
db/utilities_hlv_testing.go Added optional body parameter to InsertWithHLV helper method
db/revision_cache_test.go Updated tests to use new GetWithCV signature and test backup revision loading
rest/api_test.go Updated tests to verify backup revision fetching behavior through cache API
rest/attachment_test.go Updated tests to handle new behavior where CV fetches without backup loading return not found
xdcr/xdcr_test.go Updated test helper calls with new nil body parameter
rest/blip_api_crud_test.go Updated test helper calls with new nil body parameter
rest/replicatortest/replicator_conflict_test.go Updated cache calls with new loadBackup parameter
rest/blip_api_delta_sync_test.go Added comprehensive tests for delta sync with bypass rev cache scenarios
db/hybrid_logical_vector_test.go Updated test helper calls with new nil body parameter
db/database_test.go Updated tests to use cache API directly for backup revision fetching
db/attachment_test.go Updated test to use cache API directly for backup revision fetching


if err != nil {
rc.removeValue(value) // don't keep failed loads in the cache
rc.removeValue(value, collectionID) // don't keep failed loads in the cache
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The collectionID parameter is passed to removeValue but not used in the function signature prior to this change. However, the function body uses fields from the value parameter to construct keys that should include collectionID. Verify that removeValue properly uses the collectionID parameter throughout the function body.

Copilot uses AI. Check for mistakes.
attachments := body["_attachments"]
assert.Nil(t, attachments, "v1 should have no attachments")

if revType == "CV" && flushCache || revType == "CV" && base.TestDisableRevCache() {
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The boolean logic should use parentheses for clarity. The current expression evaluates as (revType == \"CV\" && flushCache) || (revType == \"CV\" && base.TestDisableRevCache()), but explicit grouping would improve readability.

Suggested change
if revType == "CV" && flushCache || revType == "CV" && base.TestDisableRevCache() {
if revType == "CV" && (flushCache || base.TestDisableRevCache()) {

Copilot uses AI. Check for mistakes.
Comment on lines +484 to 485
hlv = doc.HLV
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The HLV assignment was moved inside the conditional block. However, this means that when the CV doesn't match the current version, hlv will remain nil. The previous code always assigned doc.HLV to hlv. This change could cause issues if code downstream expects hlv to contain the document's HLV even when fetching backup revisions.

Copilot uses AI. Check for mistakes.
// create a few revs
docID := t.Name()
docCVs := make([]string, 0)
docCVs := make([]*Version, 0)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The variable name docCVs is now misleading as it stores *Version pointers rather than CV strings. Consider renaming to docVersions for clarity.

Copilot uses AI. Check for mistakes.
Comment on lines +2843 to +2844
require.Error(t, err)
require.ErrorContains(t, err, "missing")
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

When fetching by CV without loadBackup, the test expects an error. However, the test doesn't verify that backup revision loading works correctly for CV fetches. Consider adding an assertion that fetches with loadBackup=true succeeds after this failure.

Copilot uses AI. Check for mistakes.
@adamcfraser adamcfraser merged commit 51b11b0 into release/4.0.3 Jan 30, 2026
42 checks passed
@adamcfraser adamcfraser deleted the CBG-5142 branch January 30, 2026 21:30
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