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

Method handleDbOnline

rest/admin_api.go:224–258  ·  view source on GitHub ↗

Take a DB online, first reload the DB config

()

Source from the content-addressed store, hash-verified

222
223// Take a DB online, first reload the DB config
224func (h *handler) handleDbOnline() error {
225 h.assertAdminOnly()
226 dbState := atomic.LoadUint32(&h.db.State)
227 // If the DB is already transitioning to: online or is online silently return
228 if dbState == db.DBOnline || dbState == db.DBStarting {
229 return nil
230 }
231
232 // If the DB is currently re-syncing return an error asking the user to retry later
233 if dbState == db.DBResyncing {
234 return base.HTTPErrorf(http.StatusServiceUnavailable, "Database _resync is in progress, this may take some time, try again later")
235 }
236
237 body, err := h.readBody()
238 if err != nil {
239 return err
240 }
241
242 var input struct {
243 Delay int `json:"delay"`
244 }
245
246 input.Delay = kDefaultDBOnlineDelay
247
248 _ = base.JSONUnmarshal(body, &input)
249
250 base.InfofCtx(h.ctx(), base.KeyCRUD, "Taking Database : %v, online in %v seconds", base.MD(h.db.Name), input.Delay)
251 go func() {
252 time.Sleep(time.Duration(input.Delay) * time.Second)
253 h.server.TakeDbOnline(base.NewNonCancelCtx(), h.db.DatabaseContext)
254 }()
255 base.Audit(h.ctx(), base.AuditIDDatabaseOnline, nil)
256
257 return nil
258}
259
260// Take a DB offline
261func (h *handler) handleDbOffline() error {

Callers

nothing calls this directly

Calls 10

assertAdminOnlyMethod · 0.95
readBodyMethod · 0.95
ctxMethod · 0.95
HTTPErrorfFunction · 0.92
JSONUnmarshalFunction · 0.92
InfofCtxFunction · 0.92
MDFunction · 0.92
NewNonCancelCtxFunction · 0.92
AuditFunction · 0.92
TakeDbOnlineMethod · 0.45

Tested by

no test coverage detected