MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / _findDuplicateCollections

Method _findDuplicateCollections

rest/config.go:2267–2288  ·  view source on GitHub ↗

_findDuplicateCollections checks whether any of the collections defined in the specified DatabaseConfig are already in use by different databases running on this node. The persisted collection registry (_sync:registry) is the final source of truth (as we need to check across config groups), but che

(cnf DatabaseConfig)

Source from the content-addressed store, hash-verified

2265// source of truth (as we need to check across config groups), but checking the serverContext's collectionRegistry
2266// is useful to catch conflicts earlier (before reloading/rolling back the database)
2267func (sc *ServerContext) _findDuplicateCollections(cnf DatabaseConfig) []string {
2268 duplicatedCollections := make([]string, 0)
2269 // If scopes aren't defined, check the default collection
2270 if cnf.Scopes == nil {
2271 defaultFQName := base.FullyQualifiedCollectionName(*cnf.Bucket, base.DefaultScope, base.DefaultCollection)
2272 existingDbName, ok := sc._collectionRegistry[defaultFQName]
2273 if ok && existingDbName != cnf.Name {
2274 duplicatedCollections = append(duplicatedCollections, defaultFQName)
2275 }
2276 } else {
2277 for scopeName, scope := range cnf.Scopes {
2278 for collectionName, _ := range scope.Collections {
2279 fqName := base.FullyQualifiedCollectionName(*cnf.Bucket, scopeName, collectionName)
2280 existingDbName, ok := sc._collectionRegistry[fqName]
2281 if ok && existingDbName != cnf.Name {
2282 duplicatedCollections = append(duplicatedCollections, fqName)
2283 }
2284 }
2285 }
2286 }
2287 return duplicatedCollections
2288}
2289
2290// PersistentConfigKey returns a document key to use to store database configs
2291func PersistentConfigKey(ctx context.Context, groupID string, metadataID string) string {

Callers 1

_applyConfigMethod · 0.95

Calls 1

Tested by

no test coverage detected