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

Method StartOnlineProcesses

db/database.go:2263–2499  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

2261}
2262
2263func (db *DatabaseContext) StartOnlineProcesses(ctx context.Context) (returnedError error) {
2264
2265 defer func() {
2266 if returnedError != nil {
2267 // indicate something has gone wrong in the online processes
2268 db.DatabaseStartupError = NewDatabaseError(DatabaseOnlineProcessError)
2269 // grab bucket lock so stopOnlineProcesses is not called at the same time as db.Close()
2270 db.BucketLock.RLock()
2271 defer db.BucketLock.RUnlock()
2272 db._stopOnlineProcesses(ctx)
2273 }
2274 }()
2275
2276 // Create config-based principals
2277 // Create default users & roles:
2278 if db.Options.ConfigPrincipals != nil {
2279 if err := db.InstallPrincipals(ctx, db.Options.ConfigPrincipals.Roles, "role"); err != nil {
2280 return err
2281 }
2282 if err := db.InstallPrincipals(ctx, db.Options.ConfigPrincipals.Users, "user"); err != nil {
2283 return err
2284 }
2285
2286 if db.Options.ConfigPrincipals.Guest != nil {
2287 guest := map[string]*auth.PrincipalConfig{base.GuestUsername: db.Options.ConfigPrincipals.Guest}
2288 if err := db.InstallPrincipals(ctx, guest, "user"); err != nil {
2289 return err
2290 }
2291 }
2292 }
2293
2294 // Callback that is invoked whenever a set of channels is changed in the ChangeCache
2295 notifyChange := func(ctx context.Context, changedChannels channels.Set) {
2296 db.mutationListener.Notify(ctx, changedChannels)
2297 }
2298
2299 // Initialize the ChangeCache. Will be locked and unusable until .Start() is called (SG #3558)
2300 if err := db.changeCache.Init(
2301 ctx,
2302 db,
2303 db.channelCache,
2304 notifyChange,
2305 db.Options.CacheOptions,
2306 db.MetadataKeys,
2307 ); err != nil {
2308 base.InfofCtx(ctx, base.KeyCache, "Error initializing the change cache: %s", err)
2309 return err
2310 }
2311
2312 db.mutationListener.OnChangeCallback = db.changeCache.DocChanged
2313
2314 if base.IsEnterpriseEdition() {
2315 cfgSG, ok := db.CfgSG.(*base.CfgSG)
2316 if !ok {
2317 return fmt.Errorf("Could not cast %V to CfgSG", db.CfgSG)
2318 }
2319 db.changeCache.cfgEventCallback = cfgSG.FireEvent
2320 }

Calls 15

_stopOnlineProcessesMethod · 0.95
InstallPrincipalsMethod · 0.95
UseXattrsMethod · 0.95
CloseMethod · 0.95
startReplicationsMethod · 0.95
InfofCtxFunction · 0.92
IsEnterpriseEditionFunction · 0.92
NewCouchbaseHeartbeaterFunction · 0.92
MDFunction · 0.92