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

Method FetchConfigs

rest/config.go:1978–2045  ·  view source on GitHub ↗

FetchConfigs retrieves all database configs from the ServerContext's bootstrapConnection.

(ctx context.Context, isInitialStartup bool)

Source from the content-addressed store, hash-verified

1976
1977// FetchConfigs retrieves all database configs from the ServerContext's bootstrapConnection.
1978func (sc *ServerContext) FetchConfigs(ctx context.Context, isInitialStartup bool) (dbNameConfigs map[string]DatabaseConfig, err error) {
1979
1980 buckets, err := sc.GetBucketNames()
1981 if err != nil {
1982 return nil, err
1983 }
1984
1985 allConfigsFound := make(map[string]bool)
1986 fetchedConfigs := make(map[string]DatabaseConfig, len(buckets))
1987 for _, bucket := range buckets {
1988 ctx := base.BucketNameCtx(ctx, bucket)
1989 base.TracefCtx(ctx, base.KeyConfig, "Checking for configs for group %q", sc.Config.Bootstrap.ConfigGroupID)
1990 configs, err := sc.BootstrapContext.GetDatabaseConfigs(ctx, bucket, sc.Config.Bootstrap.ConfigGroupID)
1991 if err != nil {
1992 // Unexpected error fetching config - SDK has already performed retries, so we'll treat it as a registry removal
1993 // this could be due to invalid JSON or some other non-recoverable error.
1994 if isInitialStartup {
1995 base.WarnfCtx(ctx, "Unable to fetch configs for group %q on startup: %v", sc.Config.Bootstrap.ConfigGroupID, err)
1996 } else {
1997 base.DebugfCtx(ctx, base.KeyConfig, "Unable to fetch configs for group %q: %v", sc.Config.Bootstrap.ConfigGroupID, err)
1998 }
1999 continue
2000 }
2001 if len(configs) == 0 {
2002 base.DebugfCtx(ctx, base.KeyConfig, "Bucket %q did not contain any configs for group %q", base.MD(bucket), sc.Config.Bootstrap.ConfigGroupID)
2003 continue
2004 }
2005 for _, cnf := range configs {
2006 allConfigsFound[cnf.Name] = true
2007 // Handle invalid database registry entries. Either:
2008 // - CBG-3292: Bucket in config doesn't match the actual bucket
2009 // - CBG-3742: Registry entry marked invalid (due to rollback causing collection conflict)
2010 if isRegistryDbConfigVersionInvalid(cnf.Version) || bucket != cnf.GetBucketName() {
2011 sc.handleInvalidDatabaseConfig(ctx, bucket, *cnf)
2012 continue
2013 }
2014
2015 bucketCopy := bucket
2016 // no corruption detected carry on as usual
2017 cnf.Bucket = &bucketCopy
2018
2019 // inherit properties the bootstrap config
2020 cnf.CACertPath = sc.Config.Bootstrap.CACertPath
2021
2022 // stamp per-database credentials if set
2023 if dbCredentials, ok := sc.Config.DatabaseCredentials[cnf.Name]; ok && dbCredentials != nil {
2024 cnf.setDatabaseCredentials(*dbCredentials)
2025 }
2026
2027 // any authentication fields defined on the dbconfig take precedence over any in the bootstrap config
2028 if cnf.Username == "" && cnf.Password == "" && cnf.CertPath == "" && cnf.KeyPath == "" {
2029 cnf.Username = sc.Config.Bootstrap.Username
2030 cnf.Password = sc.Config.Bootstrap.Password
2031 cnf.CertPath = sc.Config.Bootstrap.X509CertPath
2032 cnf.KeyPath = sc.Config.Bootstrap.X509KeyPath
2033 }
2034
2035 base.DebugfCtx(ctx, base.KeyConfig, "Got config for group %q with cas %d", sc.Config.Bootstrap.ConfigGroupID, cnf.cfgCas)

Callers 3

fetchAndLoadConfigsMethod · 0.95
TestPerDBCredsOverrideFunction · 0.80

Calls 12

GetBucketNamesMethod · 0.95
BucketNameCtxFunction · 0.92
TracefCtxFunction · 0.92
WarnfCtxFunction · 0.92
DebugfCtxFunction · 0.92
MDFunction · 0.92
GetBucketNameMethod · 0.80
GetDatabaseConfigsMethod · 0.65

Tested by 2

TestPerDBCredsOverrideFunction · 0.64