Skip to content

Conversation

torcolvin
Copy link
Collaborator

@torcolvin torcolvin commented Sep 23, 2025

CBG-4864 make sure to import document if cv changes

  • Check _sync.rev.ver and _sync.rev.src against _vv.ver and _vv.src to decide to do an import even if there is a matching body.

Note: this causes behavior change in CBG-4878.

Notes for reviewer:

  • Do I need to care about when HLV is nil, and whether I should include implicit CV in these cases?
  • Did I test legacy rev sufficiently?
  • Are there unit tests that would work better?

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

Integration Tests

@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 21:18
Copy link
Contributor

@Copilot 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 implements CBG-4864 to ensure documents are imported when the current version (CV) changes, even if the document body hasn't changed. The change compares HLV version vector fields (_vv.ver and _vv.src) against sync metadata fields (_sync.rev.ver and _sync.rev.src) to determine if an import is needed.

Key changes:

  • Enhanced IsSGWrite logic to compare current version vectors with sync metadata
  • Added CVOutdated method to detect version mismatches
  • Updated import logic to handle CV changes separately from body changes

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
db/document.go Core logic for CV comparison and enhanced IsSGWrite methods
db/crud.go Updated IsSGWrite calls to use new collection-level method
db/import.go Modified import logic to use new needsImport method
db/import_listener.go Updated feed-based import to use needsImport method
db/crud_test.go Added comprehensive tests for IsSGWrite and CVOutdated functionality
db/util_testing.go Added SafeDocumentName utility for test document naming
db/utilities_hlv_testing.go Updated IsSGWrite call to use collection method
rest/blip_legacy_revid_test.go Added removeHLV helper function and updated test calls
xdcr/xdcr_test.go Updated test expectations due to behavior change

@adamcfraser adamcfraser changed the title CBG-4864 make sure to import document if cv changes CBG-4864 Import document if cv changes, even if body is unchanged Sep 23, 2025
db/document.go Outdated
if !isSGWrite || rawHLV == nil {
return isSGWrite, crc32Match
}
limitedHLV := struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we define 'limitedHLV' in hybrid_logical_version, and maybe a helper function there to just unmarshal cv?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call.

db/document.go Outdated
return true, true, false
}
if !s.CVEqual(*extractedCV) {
return false, true, false
Copy link
Collaborator

Choose a reason for hiding this comment

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

When this function returns crc32match=true, we increment the Crc32MatchCount stat. I think the intention of that stat is to track the number of documents that aren't imported because the body hasn't changed. Given that, I wonder if we should be returning false, false, false here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that's why the UserXattr comparison returns crc32 match = false even though the crc32 match was true. I thought that was a bug, but I didn't want to change for UserXattr comparison, but I'll change and add a comment here.

return &currVersion
}

// ExtractCV is used to sastify CV only interface. Since it can never return an error, consider ExtractCurrentVersionFromHLV or GetCurrentVersion instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment here (about never returning an error) needs updating.

db/document.go Outdated
extractedCV, err := cv.ExtractCV()
if !errors.Is(err, base.ErrNotFound) {
if err != nil {
base.WarnfCtx(ctx, "Error extracting cv during IsSGWrite write check: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think info level logging here is sufficient, and we should remove the word 'error'. Maybe something like "Unable to extract cv during IsSGWrite check - skipping matching cv check: %v"

@torcolvin torcolvin force-pushed the CBG-4864 branch 2 times, most recently from cd998b1 to 6cab66f Compare September 25, 2025 03:19
Copy link
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

LGTM - thanks

@torcolvin torcolvin merged commit 2052ad6 into main Sep 26, 2025
42 checks passed
@torcolvin torcolvin deleted the CBG-4864 branch September 26, 2025 12:56
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.

2 participants