Take a DB online, first reload the DB config
()
| 222 | |
| 223 | // Take a DB online, first reload the DB config |
| 224 | func (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 |
| 261 | func (h *handler) handleDbOffline() error { |
nothing calls this directly
no test coverage detected