@@ -34,13 +34,11 @@ import (
34
34
35
35
"github.com/dgraph-io/dgraph/graphql/admin"
36
36
37
- "github.com/dgraph-io/dgo/v200"
38
37
"github.com/dgraph-io/dgo/v200/protos/api"
39
38
"github.com/dgraph-io/dgraph/edgraph"
40
39
"github.com/dgraph-io/dgraph/gql"
41
40
"github.com/dgraph-io/dgraph/graphql/schema"
42
41
"github.com/dgraph-io/dgraph/query"
43
- "github.com/dgraph-io/dgraph/worker"
44
42
"github.com/dgraph-io/dgraph/x"
45
43
"github.com/gogo/protobuf/jsonpb"
46
44
"github.com/golang/glog"
@@ -471,17 +469,18 @@ func commitHandler(w http.ResponseWriter, r *http.Request) {
471
469
return
472
470
}
473
471
472
+ ctx := x .AttachAccessJwt (context .Background (), r )
474
473
var response map [string ]interface {}
475
474
if abort {
476
- response , err = handleAbort (startTs )
475
+ response , err = handleAbort (ctx , startTs )
477
476
} else {
478
477
// Keys are sent as an array in the body.
479
478
reqText := readRequest (w , r )
480
479
if reqText == nil {
481
480
return
482
481
}
483
482
484
- response , err = handleCommit (startTs , reqText )
483
+ response , err = handleCommit (ctx , startTs , reqText )
485
484
}
486
485
if err != nil {
487
486
x .SetStatus (w , x .ErrorInvalidRequest , err .Error ())
@@ -497,27 +496,28 @@ func commitHandler(w http.ResponseWriter, r *http.Request) {
497
496
_ , _ = x .WriteResponse (w , r , js )
498
497
}
499
498
500
- func handleAbort (startTs uint64 ) (map [string ]interface {}, error ) {
499
+ func handleAbort (ctx context. Context , startTs uint64 ) (map [string ]interface {}, error ) {
501
500
tc := & api.TxnContext {
502
501
StartTs : startTs ,
503
502
Aborted : true ,
504
503
}
505
504
506
- _ , err := worker . CommitOverNetwork ( context . Background () , tc )
507
- switch err {
508
- case dgo . ErrAborted :
505
+ tctx , err := ( & edgraph. Server {}). CommitOrAbort ( ctx , tc )
506
+ switch {
507
+ case tctx . Aborted :
509
508
return map [string ]interface {}{
510
509
"code" : x .Success ,
511
510
"message" : "Done" ,
512
511
}, nil
513
- case nil :
512
+ case err == nil :
514
513
return nil , errors .Errorf ("transaction could not be aborted" )
515
514
default :
516
515
return nil , err
517
516
}
518
517
}
519
518
520
- func handleCommit (startTs uint64 , reqText []byte ) (map [string ]interface {}, error ) {
519
+ func handleCommit (ctx context.Context , startTs uint64 , reqText []byte ) (map [string ]interface {},
520
+ error ) {
521
521
tc := & api.TxnContext {
522
522
StartTs : startTs ,
523
523
}
@@ -540,14 +540,13 @@ func handleCommit(startTs uint64, reqText []byte) (map[string]interface{}, error
540
540
tc .Preds = reqMap ["preds" ]
541
541
}
542
542
543
- cts , err := worker . CommitOverNetwork ( context . Background () , tc )
543
+ tc , err := ( & edgraph. Server {}). CommitOrAbort ( ctx , tc )
544
544
if err != nil {
545
545
return nil , err
546
546
}
547
547
548
548
resp := & api.Response {}
549
549
resp .Txn = tc
550
- resp .Txn .CommitTs = cts
551
550
e := query.Extensions {
552
551
Txn : resp .Txn ,
553
552
}
0 commit comments