Skip to content

Commit

Permalink
fix(txn): ensure that txn hash is set (#7782)
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.
  • Loading branch information
NamanJain8 authored May 5, 2021
1 parent 00a67d5 commit ae029f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 12 additions & 8 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,18 @@ func (s *Server) doQuery(ctx context.Context, req *Request) (
req.req.StartTs = worker.State.GetTimestamp(false)
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 @@ -1437,14 +1449,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
1 change: 0 additions & 1 deletion worker/server_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
CacheDefaults = `size-mb=1024; percentage=0,65,35;`
CDCDefaults = `file=; kafka=; sasl_user=; sasl_password=; ca_cert=; client_cert=; ` +
`client_key=; sasl-mechanism=PLAIN;`
CloudDefaults = `disable-non-galaxy=false;`
GraphQLDefaults = `introspection=true; debug=false; extensions=true; poll-interval=1s; ` +
`lambda-url=;`
LimitDefaults = `mutations=allow; query-edge=1000000; normalize-node=10000; ` +
Expand Down

0 comments on commit ae029f0

Please sign in to comment.