Skip to content

Commit 2c765e9

Browse files
authored
Use MaxAssigned for ReadOnly TS (#3071)
* worker/mutation.go: use max assigned value from delta in readonly ts We store the max assigned value when processing deltas, we can use that to save an extra network call to zero when getting read-only ts. * worker/draft.go: fixed broken error * worker/mutation.go: ts off by one The real readTs is MaxTxnTs + 1 not nextTxnTs - 1. * edgraph/server.go: add support for best effort request query * worker/mutation.go: read only ts was correct before as maxTxnTs. * worker/mutation.go: expand Timestamps() to support best effort flag When the best effort flag is enabled, worker.Timestamps() will try to get the ts from memory. * edgraph/server.go: add best effort to ts request and enable if needed. Add support to the best effort request flag and update the worker.Timestamps() call to use it. * update for change in worker.Timestamps() func signature, using safe defaults. * edgraph/server.go: revert change to getTimestamp(), use best effort from doQuery() * revert change to worker.Timestamps() * edgraph/server.go: simplify logic a bit * edgraph/server.go: make it simpler
1 parent 80557ab commit 2c765e9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

edgraph/server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/dgraph-io/dgraph/chunker/rdf"
3737
"github.com/dgraph-io/dgraph/conn"
3838
"github.com/dgraph-io/dgraph/gql"
39+
"github.com/dgraph-io/dgraph/posting"
3940
"github.com/dgraph-io/dgraph/protos/pb"
4041
"github.com/dgraph-io/dgraph/query"
4142
"github.com/dgraph-io/dgraph/schema"
@@ -569,6 +570,16 @@ func (s *Server) doQuery(ctx context.Context, req *api.Request) (resp *api.Respo
569570
return resp, err
570571
}
571572

573+
// Here we try our best effort to not contact Zero for a timestamp. If we succeed,
574+
// then we use the max known transaction ts value (from ProcessDelta) for a read-only query.
575+
// If we haven't processed any updates yet then fall back to getting TS from Zero.
576+
if req.BestEffort {
577+
// Sanity: check that request is read-only too.
578+
if !req.ReadOnly {
579+
return resp, x.Errorf("A best effort query must be read-only.")
580+
}
581+
req.StartTs = posting.Oracle().MaxAssigned()
582+
}
572583
if req.StartTs == 0 {
573584
req.StartTs = State.getTimestamp(req.ReadOnly)
574585
}

worker/draft.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ func (n *node) commitOrAbort(pkey string, delta *pb.OracleDelta) error {
520520
n.lastCommitTs = status.CommitTs
521521
}
522522
if err := writer.Flush(); err != nil {
523-
x.Errorf("Error while flushing to disk: %v", err)
524-
return err
523+
return x.Errorf("Error while flushing to disk: %v", err)
525524
}
526525

527526
g := groups()

0 commit comments

Comments
 (0)