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

Method GetDatabaseConfigs

rest/config_manager.go:356–421  ·  view source on GitHub ↗

GetDatabaseConfigs returns all configs for the bucket and config group.

(ctx context.Context, bucketName, groupID string)

Source from the content-addressed store, hash-verified

354
355// GetDatabaseConfigs returns all configs for the bucket and config group.
356func (b *bootstrapContext) GetDatabaseConfigs(ctx context.Context, bucketName, groupID string) ([]*DatabaseConfig, error) {
357
358 var attempt int
359 for attempt = 1; attempt <= configFetchMaxRetryAttempts; attempt++ {
360 msg := fmt.Sprintf("Checking for database config (attempt %d/%d)", attempt, configFetchMaxRetryAttempts)
361 if attempt == 1 {
362 base.DebugfCtx(ctx, base.KeyConfig, "%s", msg)
363 } else {
364 base.InfofCtx(ctx, base.KeyConfig, "%s", msg)
365 }
366 registry, err := b.getGatewayRegistry(ctx, bucketName)
367 if err != nil {
368 return nil, err
369 }
370
371 // Check for legacy config file
372 var legacyConfig DatabaseConfig
373 var legacyDbName string
374 cas, legacyErr := b.Connection.GetMetadataDocument(ctx, bucketName, PersistentConfigKey(ctx, groupID, ""), &legacyConfig)
375 if legacyErr != nil && !base.IsDocNotFoundError(legacyErr) {
376 return nil, base.RedactErrorf("Error checking for legacy config for %s, %s: %w", base.MD(bucketName), base.MD(groupID), legacyErr)
377 }
378 if legacyErr == nil {
379 legacyConfig.cfgCas = cas
380 legacyDbName = legacyConfig.Name
381 }
382
383 configGroup, ok := registry.ConfigGroups[groupID]
384 if !ok {
385 // no configs defined for this config group
386 return nil, nil
387 }
388
389 dbConfigs := make([]*DatabaseConfig, 0)
390 legacyFoundInRegistry := false
391 reloadRequired := false
392 for dbName, registryDb := range configGroup.Databases {
393 // Ignore databases with deleted version - represents an in-progress delete
394 if registryDb.IsDeleted() {
395 continue
396 }
397 dbConfig, err := b.getDatabaseConfig(ctx, bucketName, groupID, dbName, registryDb.Version, registry)
398 if err == base.ErrConfigRegistryReloadRequired {
399 reloadRequired = true
400 break
401 } else if err != nil {
402 return nil, err
403 }
404 dbConfigs = append(dbConfigs, dbConfig)
405 if dbConfig.Name == legacyDbName {
406 legacyFoundInRegistry = true
407 }
408 }
409
410 // If we don't need to reload, append any legacy config found and return
411 if !reloadRequired {
412 if legacyDbName != "" && !legacyFoundInRegistry {
413 dbConfigs = append(dbConfigs, &legacyConfig)

Callers

nothing calls this directly

Calls 11

getGatewayRegistryMethod · 0.95
getDatabaseConfigMethod · 0.95
DebugfCtxFunction · 0.92
InfofCtxFunction · 0.92
IsDocNotFoundErrorFunction · 0.92
RedactErrorfFunction · 0.92
MDFunction · 0.92
WarnfCtxFunction · 0.92
PersistentConfigKeyFunction · 0.85
GetMetadataDocumentMethod · 0.65
IsDeletedMethod · 0.65

Tested by

no test coverage detected