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

Method handlePostResync

rest/api.go:369–453  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

367}
368
369func (h *handler) handlePostResync() error {
370
371 action := h.getQuery("action")
372 regenerateSequences, _ := h.getOptBoolQuery("regenerate_sequences", false)
373 reset := h.getBoolQuery("reset")
374
375 body, err := h.readBody()
376 if err != nil {
377 return err
378 }
379
380 resyncPostReqBody := ResyncPostReqBody{}
381 if len(body) != 0 {
382 if err := json.Unmarshal(body, &resyncPostReqBody); err != nil {
383 return err
384 }
385 }
386
387 if action != "" && action != string(db.BackgroundProcessActionStart) && action != string(db.BackgroundProcessActionStop) {
388 return base.HTTPErrorf(http.StatusBadRequest, "Unknown parameter for 'action'. Must be start or stop")
389 }
390
391 if action == "" {
392 action = string(db.BackgroundProcessActionStart)
393 }
394
395 // Regenerate sequences if it is set true via query param or via request body
396 regenerateSequences = regenerateSequences || resyncPostReqBody.RegenerateSequences
397
398 if action == string(db.BackgroundProcessActionStart) {
399 if atomic.CompareAndSwapUint32(&h.db.State, db.DBOffline, db.DBResyncing) {
400 err := h.db.ResyncManager.Start(h.ctx(), map[string]interface{}{
401 "database": h.db,
402 "regenerateSequences": regenerateSequences,
403 "collections": resyncPostReqBody.Scope,
404 "reset": reset,
405 })
406 if err != nil {
407 return err
408 }
409
410 status, err := h.db.ResyncManager.GetStatus(h.ctx())
411 if err != nil {
412 return err
413 }
414 h.writeRawJSON(status)
415 base.Audit(h.ctx(), base.AuditIDDatabaseResyncStart, base.AuditFields{
416 "collections": resyncPostReqBody.Scope,
417 "regenerate_sequences": regenerateSequences,
418 "reset": reset,
419 })
420 } else {
421 dbState := atomic.LoadUint32(&h.db.State)
422 if dbState == db.DBResyncing {
423 return base.HTTPErrorf(http.StatusServiceUnavailable, "Database _resync already in progress")
424 }
425
426 if dbState != db.DBOffline {

Callers

nothing calls this directly

Calls 12

getQueryMethod · 0.95
getOptBoolQueryMethod · 0.95
getBoolQueryMethod · 0.95
readBodyMethod · 0.95
ctxMethod · 0.95
writeRawJSONMethod · 0.95
HTTPErrorfFunction · 0.92
AuditFunction · 0.92
StartMethod · 0.65
StopMethod · 0.65
UnmarshalMethod · 0.45
GetStatusMethod · 0.45

Tested by

no test coverage detected