MCPcopy
hub / github.com/dgraph-io/dgraph / commitHandler

Function commitHandler

dgraph/cmd/alpha/http.go:510–558  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

508}
509
510func commitHandler(w http.ResponseWriter, r *http.Request) {
511 if commonHandler(w, r) {
512 return
513 }
514
515 startTs, err := parseUint64(r, "startTs")
516 if err != nil {
517 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
518 return
519 }
520 if startTs == 0 {
521 x.SetStatus(w, x.ErrorInvalidRequest,
522 "startTs parameter is mandatory while trying to commit")
523 return
524 }
525
526 hash := r.URL.Query().Get("hash")
527 abort, err := parseBool(r, "abort")
528 if err != nil {
529 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
530 return
531 }
532
533 ctx := x.AttachAccessJwt(context.Background(), r)
534 var response map[string]interface{}
535 if abort {
536 response, err = handleAbort(ctx, startTs, hash)
537 } else {
538 // Keys are sent as an array in the body.
539 reqText := readRequest(w, r)
540 if reqText == nil {
541 return
542 }
543
544 response, err = handleCommit(ctx, startTs, hash, reqText)
545 }
546 if err != nil {
547 x.SetStatus(w, x.ErrorInvalidRequest, err.Error())
548 return
549 }
550
551 js, err := json.Marshal(response)
552 if err != nil {
553 x.SetStatusWithData(w, x.Error, err.Error())
554 return
555 }
556
557 _, _ = x.WriteResponse(w, r, js)
558}
559
560func handleAbort(ctx context.Context, startTs uint64, hash string) (map[string]interface{}, error) {
561 tc := &api.TxnContext{

Callers

nothing calls this directly

Calls 13

SetStatusFunction · 0.92
AttachAccessJwtFunction · 0.92
SetStatusWithDataFunction · 0.92
WriteResponseFunction · 0.92
commonHandlerFunction · 0.85
parseUint64Function · 0.85
parseBoolFunction · 0.85
handleAbortFunction · 0.85
readRequestFunction · 0.85
handleCommitFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected