(ctx context.Context)
| 2149 | } |
| 2150 | |
| 2151 | func (sc *ServerContext) initializeBootstrapConnection(ctx context.Context) error { |
| 2152 | if !sc.persistentConfig { |
| 2153 | return nil |
| 2154 | } |
| 2155 | base.InfofCtx(ctx, base.KeyAll, "Initializing bootstrap connection..") |
| 2156 | // Fetch database configs from bucket and start polling for new buckets and config updates. |
| 2157 | couchbaseCluster, err := CreateBootstrapConnectionFromStartupConfig(ctx, sc.Config, base.CachedClusterConnections) |
| 2158 | if err != nil { |
| 2159 | return err |
| 2160 | } |
| 2161 | |
| 2162 | sc.BootstrapContext.Connection = couchbaseCluster |
| 2163 | |
| 2164 | // Check for v3.0 persisted configs, migrate to registry format if found |
| 2165 | err = sc.migrateV30Configs(ctx) |
| 2166 | if err != nil { |
| 2167 | base.InfofCtx(ctx, base.KeyConfig, "Unable to migrate v3.0 config to registry - will not be migrated: %v", err) |
| 2168 | } |
| 2169 | |
| 2170 | count, err := sc.fetchAndLoadConfigs(ctx, true) |
| 2171 | if err != nil { |
| 2172 | return err |
| 2173 | } |
| 2174 | |
| 2175 | if count > 0 { |
| 2176 | base.InfofCtx(ctx, base.KeyConfig, "Successfully fetched %d database configs for group %q from buckets in cluster", count, sc.Config.Bootstrap.ConfigGroupID) |
| 2177 | } else { |
| 2178 | base.WarnfCtx(ctx, "Config: No database configs for group %q. Continuing startup to allow REST API database creation", sc.Config.Bootstrap.ConfigGroupID) |
| 2179 | } |
| 2180 | |
| 2181 | if sc.Config.Bootstrap.ConfigUpdateFrequency.Value() > 0 { |
| 2182 | sc.BootstrapContext.terminator = make(chan struct{}) |
| 2183 | sc.BootstrapContext.doneChan = make(chan struct{}) |
| 2184 | |
| 2185 | base.InfofCtx(ctx, base.KeyConfig, "Starting background polling for new configs/buckets: %s", sc.Config.Bootstrap.ConfigUpdateFrequency.Value().String()) |
| 2186 | go func() { |
| 2187 | defer close(sc.BootstrapContext.doneChan) |
| 2188 | t := time.NewTicker(sc.Config.Bootstrap.ConfigUpdateFrequency.Value()) |
| 2189 | for { |
| 2190 | select { |
| 2191 | case <-sc.BootstrapContext.terminator: |
| 2192 | base.InfofCtx(ctx, base.KeyConfig, "Stopping background config polling loop") |
| 2193 | t.Stop() |
| 2194 | return |
| 2195 | case <-t.C: |
| 2196 | base.DebugfCtx(ctx, base.KeyConfig, "Fetching configs from buckets in cluster for group %q", sc.Config.Bootstrap.ConfigGroupID) |
| 2197 | count, err := sc.fetchAndLoadConfigs(ctx, false) |
| 2198 | if err != nil { |
| 2199 | base.WarnfCtx(ctx, "Couldn't load configs from bucket for group %q when polled: %v", sc.Config.Bootstrap.ConfigGroupID, err) |
| 2200 | } |
| 2201 | if count > 0 { |
| 2202 | base.InfofCtx(ctx, base.KeyConfig, "Successfully fetched %d database configs for group %q from buckets in cluster", count, sc.Config.Bootstrap.ConfigGroupID) |
| 2203 | } |
| 2204 | } |
| 2205 | } |
| 2206 | }() |
| 2207 | } else { |
| 2208 | base.InfofCtx(ctx, base.KeyConfig, "Disabled background polling for new configs/buckets") |
no test coverage detected