_applyConfig loads the given database, failFast=true will not attempt to retry connecting/loading
(nonContextStruct base.NonCancellableContext, cnf DatabaseConfig, failFast, isInitialStartup, loadFromBucket bool)
| 2068 | |
| 2069 | // _applyConfig loads the given database, failFast=true will not attempt to retry connecting/loading |
| 2070 | func (sc *ServerContext) _applyConfig(nonContextStruct base.NonCancellableContext, cnf DatabaseConfig, failFast, isInitialStartup, loadFromBucket bool) (applied bool, err error) { |
| 2071 | ctx := nonContextStruct.Ctx |
| 2072 | |
| 2073 | nodeSGVersion := sc.BootstrapContext.sgVersion |
| 2074 | err = sc.BootstrapContext.CheckMinorDowngrade(ctx, *cnf.Bucket, nodeSGVersion) |
| 2075 | if err != nil { |
| 2076 | return false, err |
| 2077 | } |
| 2078 | // 3.0.0 doesn't write a SGVersion, but everything else will |
| 2079 | configSGVersionStr := "3.0.0" |
| 2080 | if cnf.SGVersion != "" { |
| 2081 | configSGVersionStr = cnf.SGVersion |
| 2082 | } |
| 2083 | |
| 2084 | configSGVersion, err := base.NewComparableBuildVersionFromString(configSGVersionStr) |
| 2085 | if err != nil { |
| 2086 | return false, err |
| 2087 | } |
| 2088 | |
| 2089 | if !isInitialStartup { |
| 2090 | // Skip applying if the config is from a newer SG version than this node and we're not just starting up |
| 2091 | if nodeSGVersion.Less(configSGVersion) { |
| 2092 | base.WarnfCtx(ctx, "Cannot apply config update from server for db %q, this SG version is older than config's SG version (%s < %s)", cnf.Name, nodeSGVersion.String(), configSGVersion.String()) |
| 2093 | return false, nil |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | // Check for collections already in use by other databases |
| 2098 | duplicateCollections := sc._findDuplicateCollections(cnf) |
| 2099 | if len(duplicateCollections) > 0 { |
| 2100 | return false, fmt.Errorf("%w: Collection(s) %v already in use by other database(s)", base.ErrAlreadyExists, duplicateCollections) |
| 2101 | } |
| 2102 | |
| 2103 | // skip if we already have this config loaded, and we've got a cas value to compare with |
| 2104 | _, exists := sc._dbRegistry[cnf.Name] |
| 2105 | if exists { |
| 2106 | if cnf.cfgCas == 0 { |
| 2107 | // force an update when the new config's cas was set to zero prior to load |
| 2108 | base.InfofCtx(ctx, base.KeyConfig, "Forcing update of config for database %q bucket %q", cnf.Name, *cnf.Bucket) |
| 2109 | } else { |
| 2110 | if sc._dbConfigs[cnf.Name].cfgCas >= cnf.cfgCas { |
| 2111 | base.DebugfCtx(ctx, base.KeyConfig, "Database %q bucket %q config has not changed since last update", cnf.Name, *cnf.Bucket) |
| 2112 | return false, nil |
| 2113 | } |
| 2114 | base.InfofCtx(ctx, base.KeyConfig, "Updating database %q for bucket %q with new config from bucket", cnf.Name, *cnf.Bucket) |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | // Strip out version as we have no use for this locally and we want to prevent it being stored and being returned |
| 2119 | // by any output |
| 2120 | cnf.Version = "" |
| 2121 | |
| 2122 | err = sc.BootstrapContext.SetSGVersion(ctx, *cnf.Bucket, nodeSGVersion) |
| 2123 | if err != nil { |
| 2124 | return false, nil |
| 2125 | } |
| 2126 | |
| 2127 | // Prevent database from being unsuspended when it is suspended |
no test coverage detected