Skip to content

CBG-5475: Don't re-run metadata migration once complete#8410

Merged
bbrks merged 1 commit into
mainfrom
CBG-5475
Jul 2, 2026
Merged

CBG-5475: Don't re-run metadata migration once complete#8410
bbrks merged 1 commit into
mainfrom
CBG-5475

Conversation

@bbrks

@bbrks bbrks commented Jul 2, 2026

Copy link
Copy Markdown
Member

CBG-5475

Ensures migrations are not redundantly re-run after completion and that all nodes in a cluster consistently recognise completed migrations, even if the migration was performed by a peer node.

Still allows a manual reset=true via REST API to force a re-run.

Integration Tests

Metadata migration has two independent start triggers - the ~10s auto-arm
poller (tryStartMetadataMigration) and the manual REST endpoint
(handleMetadataMigration) - and neither re-checked completion before starting.
shouldRunMetadataMigration checked completion only once at DB startup, so a
fast REST-triggered run would complete and then the already-spawned poller
would win the freed heartbeat lease and Init would reset-and-re-run on the
"completed" status, flapping the status doc complete -> in_progress ->
complete and making status assertions flaky.

Add DatabaseContext.MetadataMigrationComplete(ctx), consulted by both start
paths and by shouldRunMetadataMigration: it fast-paths on the process-local
MetadataStore flag and, when that is unset, consults the authoritative
cluster-wide status doc via a new PerDBMetadataMigrationCompleteFunc closure
(isPerDBMigrationComplete). This also closes the multi-node gap - a peer node
that never ran the migration recognises completion and converges its stale
local flag (SetMigrationComplete) so fallback reads stop. The REST path still
honours reset=true as an operator override to force a fresh run.

isPerDBMigrationComplete mirrors isPerDBMigrationInProgress but with the
opposite error bias: on an unreadable/absent doc it returns false (allow the
idempotent start) rather than risk skipping a needed migration.

Adds regression tests for the same-node no-op and the peer-completion
convergence; verified on Rosmar and Couchbase Server.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 2, 2026 12:40
@bbrks bbrks requested a review from gregns1 July 2, 2026 12:41

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

Prevents per-database metadata migrations from being redundantly re-run after they’ve completed by introducing an authoritative, cluster-wide “per-DB migration complete” signal (read from the bucket-level metadata-migration status doc). This ensures nodes that did not execute the migration themselves still recognize completion, avoids status flapping back to in_progress, and keeps the operator override (reset=true) intact.

Changes:

  • Wire a new per-DB completion check into DatabaseContext that consults the bucket-level status doc and converges the local dual-store “migration complete” flag when a peer has finished the migration.
  • Make both the auto-arm poller and the REST action=start path idempotent when the migration is already complete (unless reset=true).
  • Add regression tests covering “no restart after completion” and “peer completion is honored”, and update an existing unit test for the new function signature.

Reviewed changes

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

Show a summary per file
File Description
rest/server_context.go Wires per-DB completion function into DatabaseContext and adds isPerDBMigrationComplete to read authoritative completion from the bucket status doc.
rest/api.go Makes manual /_metadata_migration?action=start a no-op when migration is already complete (unless reset=true).
db/database.go Adds PerDBMetadataMigrationCompleteFunc and MetadataMigrationComplete(ctx); updates auto-arm logic to re-check completion and avoid restarting finished migrations.
rest/metadatamigrationtest/metadata_migration_test.go Adds regression tests for non-restart after completion and peer-completed migration recognition/convergence.
db/background_mgr_metadata_migration_test.go Updates unit test to pass a ctx to shouldRunMetadataMigration.

@bbrks bbrks merged commit 0a5a88d into main Jul 2, 2026
68 of 69 checks passed
@bbrks bbrks deleted the CBG-5475 branch July 2, 2026 14:33
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