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

Method GetInactiveDatabase

rest/server_context.go:345–381  ·  view source on GitHub ↗

GetInactiveDatabase attempts to load the database and return it's DatabaseContext. It will first attempt to unsuspend the database, and if that fails, try to load the database from the buckets. This should be used if GetActiveDatabase fails. Turns the database context, a variable to say if the confi

(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

343// database, and if that fails, try to load the database from the buckets.
344// This should be used if GetActiveDatabase fails. Turns the database context, a variable to say if the config exists, and an error.
345func (sc *ServerContext) GetInactiveDatabase(ctx context.Context, name string) (*db.DatabaseContext, bool, error) {
346 dbc, err := sc.unsuspendDatabase(ctx, name)
347 if err != nil && err != base.ErrNotFound && err != ErrSuspendingDisallowed {
348 return nil, false, err
349 } else if err == nil {
350 return dbc, true, nil
351 }
352
353 var dbConfigFound bool
354 // database not loaded, fallback to fetching it from cluster
355 if sc.BootstrapContext.Connection != nil {
356 if sc.Config.IsServerless() {
357 dbConfigFound, _ = sc.fetchAndLoadDatabaseSince(ctx, name, sc.Config.Unsupported.Serverless.MinConfigFetchInterval)
358
359 } else {
360 dbConfigFound, _ = sc.fetchAndLoadDatabase(base.NewNonCancelCtx(), name, false)
361 }
362 if dbConfigFound {
363 sc._databasesLock.RLock()
364 defer sc._databasesLock.RUnlock()
365 dbc := sc._databases[name]
366 if dbc != nil {
367 return dbc, dbConfigFound, nil
368 }
369 }
370 }
371 // handle the correct error message being returned for a corrupt database config
372 var httpErr *base.HTTPError
373 invalidConfig, ok := sc.invalidDatabaseConfigTracking.exists(name)
374 if !dbConfigFound && ok {
375 httpErr = sc.buildErrorMessage(name, invalidConfig)
376 } else {
377 httpErr = base.HTTPErrorf(http.StatusNotFound, "no such database %q", name)
378 }
379
380 return nil, dbConfigFound, httpErr
381}
382
383// buildErrorMessage will build appropriate http error message based on the invalidConfig
384func (sc *ServerContext) buildErrorMessage(dbName string, invalidConfig *invalidConfigInfo) *base.HTTPError {

Callers 2

GetDatabaseMethod · 0.95

Calls 10

unsuspendDatabaseMethod · 0.95
fetchAndLoadDatabaseMethod · 0.95
buildErrorMessageMethod · 0.95
NewNonCancelCtxFunction · 0.92
HTTPErrorfFunction · 0.92
IsServerlessMethod · 0.80
RLockMethod · 0.80
RUnlockMethod · 0.80
existsMethod · 0.80

Tested by

no test coverage detected