Skip to content

Commit

Permalink
fix(txn): ensure that txn hash is set (#7782) (#7784)
Browse files Browse the repository at this point in the history
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 ae029f0)
  • Loading branch information
NamanJain8 authored May 5, 2021
1 parent 5b34231 commit 6985dd0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6985dd0

Please sign in to comment.