From 6985dd0957e228e29de7b80588278c2cb2ca2d5b Mon Sep 17 00:00:00 2001 From: Naman Jain Date: Wed, 5 May 2021 18:14:41 +0530 Subject: [PATCH] fix(txn): ensure that txn hash is set (#7782) (#7784) We were setting the hash after completing the transaction successfully. This leads to the failure of the commit as it won't contain the hash. This PR fixes that issue. (cherry picked from commit ae029f0e24189fc28c1dbc0e81bfc3078d4370a1) --- edgraph/server.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/edgraph/server.go b/edgraph/server.go index b6b57e38091..06baa81051f 100644 --- a/edgraph/server.go +++ b/edgraph/server.go @@ -1252,6 +1252,18 @@ func (s *Server) doQuery(ctx context.Context, req *Request) ( qc.latency.AssignTimestamp = time.Since(start) } } + if x.WorkerConfig.AclEnabled { + ns, err := x.ExtractNamespace(ctx) + if err != nil { + return nil, err + } + defer func() { + if resp != nil && resp.Txn != nil { + // attach the hash, user must send this hash when further operating on this startTs. + resp.Txn.Hash = getHash(ns, resp.Txn.StartTs) + } + }() + } var gqlErrs error if resp, rerr = processQuery(ctx, qc); rerr != nil { @@ -1285,14 +1297,6 @@ func (s *Server) doQuery(ctx context.Context, req *Request) ( EncodingNs: uint64(l.Json.Nanoseconds()), TotalNs: uint64((time.Since(l.Start)).Nanoseconds()), } - if x.WorkerConfig.AclEnabled { - // attach the hash, user should send this hash when further operating on this startTs. - ns, err := x.ExtractNamespace(ctx) - if err != nil { - return nil, err - } - resp.Txn.Hash = getHash(ns, resp.Txn.StartTs) - } md := metadata.Pairs(x.DgraphCostHeader, fmt.Sprint(resp.Metrics.NumUids["_total"])) grpc.SendHeader(ctx, md) return resp, gqlErrs