Skip to content

CBG-5038 allow metadata id to be nil while syncinfo exists#8059

Merged
torcolvin merged 5 commits intomainfrom
CBG-5038-test-repro
Mar 24, 2026
Merged

CBG-5038 allow metadata id to be nil while syncinfo exists#8059
torcolvin merged 5 commits intomainfrom
CBG-5038-test-repro

Conversation

@torcolvin
Copy link
Copy Markdown
Collaborator

@torcolvin torcolvin commented Feb 6, 2026

CBG-5038 allow metadata id to be nil while syncinfo exists

Fix a gap where setting up a non persistent configuration database and running attachment migration would cause the next start of the database to require resync.

attachment migration will write metadata_version and will preserve metadataID, but the metadata id might not exist if non persistent config is used.

With non persistent config, metadataID is not written, but running attachment migration will write a metadata_version.

Turn metadataID into an optional value.

Copilot AI review requested due to automatic review settings February 6, 2026 15:29
Copy link
Copy Markdown
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 adds commented-out code to reproduce a timing-related test failure associated with CBG-5038. The changes prepare tests to verify fixes for attachment migration race conditions without breaking current test execution.

Changes:

  • Added stub code in two test functions to reproduce timing issues related to attachment migration

Comment thread rest/upgradetest/upgrade_registry_test.go Outdated
Comment thread rest/upgradetest/upgrade_registry_test.go Outdated
Fix a gap where setting up a non persistent configuration database and running attachment migrration would cause the
next start of the database to require resync.

attachment migration will write metadata_version and will preserve metadataID

With non persistent config, metadataID is not written, but running attachment migration will write a metadata_version.

Turn metadataID into an optional value.
@torcolvin torcolvin force-pushed the CBG-5038-test-repro branch from 2979928 to bdad9d1 Compare March 20, 2026 21:24
@torcolvin torcolvin changed the title CBG-5038 stub code to repro test failure CBG-5038 allow metadata id to be nil while syncinfo exists Mar 23, 2026
@torcolvin torcolvin requested a review from Copilot March 23, 2026 00:34
Copy link
Copy Markdown
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

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

Comment thread base/constants_syncdocs.go Outdated
Comment on lines +415 to +417
requiresAttachmentMigration, err = CompareMetadataVersion(ctx, syncInfo.MetaDataVersion)
if err != nil {
return syncInfo.MetadataID != metadataID, true, err
return *syncInfo.MetadataID != metadataID, true, err
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

In InitSyncInfo, the error path after CompareMetadataVersion dereferences syncInfo.MetadataID (*syncInfo.MetadataID) even though syncInfo.MetadataID can be nil (e.g., when the document was just added and syncInfo wasn't refreshed, or after a CAS mismatch refetch where the stored syncInfo omits metadataID). This can panic during error handling. Compute requiresResync with a nil check (or use metadataID/newSyncInfo in the add-success path) and avoid dereferencing nil pointers here.

Copilot uses AI. Check for mistakes.
Comment thread rest/config_manager.go Outdated

if exists && syncInfo.MetadataID != defaultMetadataID {
if exists && (syncInfo.MetadataID != nil && *syncInfo.MetadataID != defaultMetadataID) {
base.InfofCtx(ctx, base.KeyConfig, "Using metadata ID %q for db %q because db uses the default collection, and _sync:syncInfo in the default collection specifies the non-default metadata ID %q", base.MD(standardMetadataID), base.MD(config.Name), base.MD(syncInfo.MetadataID))
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This log argument uses base.MD(syncInfo.MetadataID), but MetadataID is now a *string. base.MD will fall back to fmt.Sprintf for *string and log the pointer address rather than the metadata ID value. Log the dereferenced value (with a nil guard) so the message reports the actual metadata ID.

Suggested change
base.InfofCtx(ctx, base.KeyConfig, "Using metadata ID %q for db %q because db uses the default collection, and _sync:syncInfo in the default collection specifies the non-default metadata ID %q", base.MD(standardMetadataID), base.MD(config.Name), base.MD(syncInfo.MetadataID))
base.InfofCtx(ctx, base.KeyConfig, "Using metadata ID %q for db %q because db uses the default collection, and _sync:syncInfo in the default collection specifies the non-default metadata ID %q", base.MD(standardMetadataID), base.MD(config.Name), base.MD(*syncInfo.MetadataID))

Copilot uses AI. Check for mistakes.
@torcolvin torcolvin assigned gregns1 and unassigned RIT3shSapata Mar 23, 2026
Copy link
Copy Markdown
Contributor

@gregns1 gregns1 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me just one minor test nit

Comment thread rest/upgradetest/upgrade_registry_test.go Outdated
Co-authored-by: Gregory Newman-Smith <109068393+gregns1@users.noreply.github.com>
@torcolvin torcolvin merged commit de6b8e7 into main Mar 24, 2026
48 checks passed
@torcolvin torcolvin deleted the CBG-5038-test-repro branch March 24, 2026 14:16
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