[4.1.2 Backport] CBG-5591: stop indexes being built on default when not required - #8523
Merged
Conversation
…ot required Cherry-picked from c1008bc (CBG-5586, #8495). Stacked on the CBG-5414 backport, which this builds on. rest/manualbucketpooltest/database_init_manager_test.go doesn't exist on this branch - its TestDatabaseInitConcurrentDatabasesSameBucket lives in rest/, so the InitializeDatabase signature change is applied there instead. Co-authored-by: Gregory Newman-Smith <109068393+gregns1@users.noreply.github.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
gregns1
approved these changes
Aug 4, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Backports the main-branch fix for CBG-5591 to 4.1.2, refining database index initialization so Sync Gateway doesn’t (re)build metadata indexes on _default._default when they’re no longer required—especially after system-metadata migration has completed—avoiding wasted work and initialization failures when _default has been dropped.
Changes:
- Plumbs a
migrationCompletesignal intoDatabaseInitManagerso index initialization can exclude vestigial_defaultmetadata indexes post-migration. - Updates collection-to-index-set planning (
buildCollectionIndexData) to treat_default’s “data role” and “metadata role” independently. - Reduces test bucket pool usage in ISGR test setup by only acquiring buckets when configs don’t already provide one, and adds/updates tests to cover the new index-init behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rest/utilities_testing_isgr.go | Avoids double-reserving bucket-pool buckets by only allocating a test bucket when the caller didn’t supply one. |
| rest/server_context.go | Detects migration completion (via dual metadata store state) and passes it through to index initialization. |
| rest/indextest/index_test.go | Updates async-init tests’ expected collection counts for the new index-init behavior. |
| rest/database_init_manager.go | Extends initialization APIs to accept migrationComplete and updates index planning logic to exclude _default metadata indexes post-migration. |
| rest/database_init_manager_test.go | Adds/updates tests to validate correct collection/index initialization across legacy vs system-metadata modes and migration states. |
| rest/admin_api.go | Ensures manual index-init requests pass migration completion state to the init manager. |
Suppressed comments (1)
rest/indextest/index_test.go:505
- Same as above: without explicitly setting
UseSystemMobileMetadataCollection, this test no longer guarantees it is exercising the system-metadata + migration-complete path (and the updated expected collection count can be satisfied by legacy mode too).
dbConfig := makeDbConfig(t, tb, syncFunc, importFilter)
dbConfig.StartOffline = base.Ptr(true)
dbConfigPayload, err := json.Marshal(dbConfig)
Comment on lines
373
to
375
| dbConfig := makeDbConfig(t, tb, syncFunc, importFilter) | ||
| dbConfig.StartOffline = base.Ptr(true) | ||
| dbConfig.UseSystemMobileMetadataCollection = base.Ptr(true) | ||
| dbConfigPayload, err := json.Marshal(dbConfig) |
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-5591
Unclean cherry pick of #8495 to 4.1.2
Changes from main commit:
rest/manualbucketpooltest/database_init_manager_test.go— package doesn't exist on 4.1.2; itsTestDatabaseInitConcurrentDatabasesSameBucketlives inrest/database_init_manager_test.go, so theInitializeDatabasesignature change was applied there insteadrest/database_init_manager_test.go—dbConfig.setup()takes an extraforcePerBucketAutharg on 4.1.2, so the ported tests use the 6-arg formStacked on #8522 (CBG-5414 backport), which this depends on - with that in place,
rest/database_init_manager.goandTestBuildCollectionIndexDatamatchmainexactly.