Conversation
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>
Contributor
There was a problem hiding this comment.
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
DatabaseContextthat 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=startpath idempotent when the migration is already complete (unlessreset=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. |
gregns1
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=truevia REST API to force a re-run.Integration Tests