Skip to content

CBG-5397: On-demand import should consider mou when updating HLV#8349

Merged
adamcfraser merged 5 commits into
mainfrom
CBG-5397
Jun 12, 2026
Merged

CBG-5397: On-demand import should consider mou when updating HLV#8349
adamcfraser merged 5 commits into
mainfrom
CBG-5397

Conversation

@RIT3shSapata

@RIT3shSapata RIT3shSapata commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

CBG-5397

Describe your PR here...

  • change the xattr keys used by GetDocumentWithRaw and GetDocSyncData
  • Add test coverage

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

@RIT3shSapata RIT3shSapata requested a review from adamcfraser June 9, 2026 12:37
Copilot AI review requested due to automatic review settings June 9, 2026 12:37

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

Updates on-demand import read paths to ensure metadata-only update (MOU) state and rev-seq information are available when reloading documents prior to import, preventing incorrect HLV/MOU updates. Adds targeted test coverage to catch regressions around _mou and PreviousRevSeqNo population.

Changes:

  • Update GetDocumentWithRaw reload to request _mou and $document.revid alongside existing SG xattrs.
  • Update GetDocSyncData to fetch $document.revid (and _mou) so on-demand import can populate MetadataOnlyUpdate.PreviousRevSeqNo correctly.
  • Add tests validating _mou is included in the reload path and that GetDocSyncData-triggered import sets correct MOU pRev.

Reviewed changes

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

File Description
db/import_test.go Adds regression tests covering _mou presence during reload and correct PreviousRevSeqNo after on-demand import triggered by GetDocSyncData.
db/crud.go Expands xattr keysets used during on-demand import-related reads to include _mou and $document.revid.

Comment thread db/crud.go
@@ -86,7 +86,7 @@ func (c *DatabaseCollection) GetDocumentWithRaw(ctx context.Context, docid strin
// If existing doc wasn't an SG Write, import the doc.
if !isSgWrite {
// reload to get revseqno for on-demand import
Comment thread db/import_test.go
Comment on lines +286 to +288
// rawBucketDoc.Xattrs reflects the pre-import state fetched at the reload step.
// Without the fix, _mou was absent from the reload xattr list, so this would be nil
// even though the bucket has a _mou xattr from the first import.

@adamcfraser adamcfraser left a comment

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.

Have a look at the recommendation around when to fetch mou for the GetDocSyncData case.

Comment thread db/crud.go Outdated
// Retrieve doc and xattr from bucket, unmarshal only xattr.
// Triggers on-demand import when document xattr doesn't match cas.
rawDoc, xattrs, cas, getErr := c.dataStore.GetWithXattrs(ctx, key, c.syncGlobalSyncAndUserXattrKeys())
rawDoc, xattrs, cas, getErr := c.dataStore.GetWithXattrs(ctx, key, c.syncGlobalSyncMouRevSeqNoAndUserXattrKeys())

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.

In the ticket it's mentioned that we only want to do this additional work (to fetch mou, revSeqno) when we determine we need to do an on-demand import (i.e. after line 190). It's better to pay the larger performance overhead in the corner case (on-demand import), and avoid the incremental performance hit for the more common case (no import required).

- use mou and revSeq only for on demand import

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

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

Comment thread db/crud.go Outdated
Comment on lines +198 to +203
// Re-unmarshal with the full xattr set so doc.RevSeqNo and doc.MetadataOnlyUpdate
// are populated for use by OnDemandImportForGet.
doc, unmarshalErr = c.unmarshalDocumentWithXattrs(ctx, docid, nil, xattrs, cas, DocUnmarshalSync)
if unmarshalErr != nil {
return emptySyncData, unmarshalErr
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

another SG node cannot import it, so this comment is not really relevant

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.

@RIT3shSapata Another node could import it. We're doing an on-demand import here, another node could perform an import by either:

  • the import feed
  • a different on-demand import

It's correct that you need to re-check isSGWrite after the new fetch.

Comment thread db/crud.go Outdated
Comment on lines +198 to +203
// Re-unmarshal with the full xattr set so doc.RevSeqNo and doc.MetadataOnlyUpdate
// are populated for use by OnDemandImportForGet.
doc, unmarshalErr = c.unmarshalDocumentWithXattrs(ctx, docid, nil, xattrs, cas, DocUnmarshalSync)
if unmarshalErr != nil {
return emptySyncData, unmarshalErr
}

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.

@RIT3shSapata Another node could import it. We're doing an on-demand import here, another node could perform an import by either:

  • the import feed
  • a different on-demand import

It's correct that you need to re-check isSGWrite after the new fetch.

- check if document is imported before performing on demand import
@RIT3shSapata RIT3shSapata requested a review from Copilot June 12, 2026 06:14

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

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

Comment thread db/crud.go Outdated
Comment thread db/crud.go Outdated
Comment thread db/import_test.go Outdated
@RIT3shSapata RIT3shSapata requested a review from Copilot June 12, 2026 06:27

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@adamcfraser adamcfraser merged commit 76cd3df into main Jun 12, 2026
49 checks passed
@adamcfraser adamcfraser deleted the CBG-5397 branch June 12, 2026 15:09
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.

3 participants