CBG-5414: Create indexes in mobile collection only if mobile collections is enabled#8351
CBG-5414: Create indexes in mobile collection only if mobile collections is enabled#8351RIT3shSapata wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts database index initialization to avoid creating _system._mobile collection indexes unless the system metadata collection feature is enabled for the database, reducing unnecessary index creation when the feature is off.
Changes:
- Gate
_system._mobileindex initialization onUseSystemMobileMetadataCollectioninbuildCollectionIndexData. - Expand
TestBuildCollectionIndexDatato cover enabled/disabled combinations for default and named-collection configs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| rest/database_init_manager.go | Conditionally includes _system._mobile in the collection/index initialization set based on config. |
| rest/database_init_manager_test.go | Adds/updates unit tests for buildCollectionIndexData under enabled/disabled system metadata collection scenarios. |
| name: "implicit default collection with mobile collection enabled", | ||
| config: &DatabaseConfig{ | ||
| DbConfig: DbConfig{ | ||
| Scopes: nil, | ||
| Scopes: nil, | ||
| UseSystemMobileMetadataCollection: base.Ptr(true), | ||
| }, |
- use startup/bootstrap config to check if systemMetadataCollection is enabled or not - add test coverage
gregns1
left a comment
There was a problem hiding this comment.
I think we should also pass down whether migration is complete or not. Obviously if the _default collection is in use for the db we still need indexes created on it. But if its not and migration is set to complete on the metadata store, we should be able to avoid making metadata indexes on the default given this won't be in use at all for this scenario.
To do this we can maybe slightly change this code here
sync_gateway/rest/server_context.go
Line 940 in 65f9749
metadataMigrationComplete = dual.MigrationComplete() in this block and pass down this into InitializeDatabaseWithStatusCallback then buildCollectionIndexData?
| useLegacySyncDocsIndex := h.db.UseLegacySyncDocsIndex() | ||
| if req.SeparatePrincipalIndexes != nil { | ||
| useLegacySyncDocsIndex = !(*req.SeparatePrincipalIndexes) | ||
| } | ||
| done, err := h.server.DatabaseInitManager.InitializeDatabaseWithStatusCallback(h.ctx(), h.server.initialStartupConfig, &newDbConfig, statusCallback, useLegacySyncDocsIndex) | ||
| done, err := h.server.DatabaseInitManager.InitializeDatabaseWithStatusCallback(h.ctx(), h.server.initialStartupConfig, &newDbConfig, statusCallback, useLegacySyncDocsIndex, false) |
CBG-5414
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests