Skip to content

Commit

Permalink
Fix a StartTs Mismatch bug which happens when running multiple best e…
Browse files Browse the repository at this point in the history
…ffort queries using the same txn. Reuse the same timestamp instead of allocating a new one. (dgraph-io#3187)
  • Loading branch information
manishrjain authored and dna2github committed Jul 19, 2019
1 parent 59b09d1 commit 75f9664
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions dgraph/cmd/counter/increment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,17 @@ func TestBestEffortOnly(t *testing.T) {
}
t.Logf("Best-Effort only reads with multiple preds OK.")
}

func TestBestEffortTs(t *testing.T) {
dg := setup(t)
pred := "counter.val"
incrementInLoop(t, dg, 1)
readBestEffort(t, dg, pred, 1)
txn := dg.NewReadOnlyTxn().BestEffort()
_, err := queryCounter(txn, pred)
require.NoError(t, err)

incrementInLoop(t, dg, 1) // Increment the MaxAssigned ts at Alpha.
_, err = queryCounter(txn, pred) // The timestamp here shouldn't change.
require.NoError(t, err)
}
4 changes: 3 additions & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ func (s *Server) doQuery(ctx context.Context, req *api.Request) (resp *api.Respo
if !req.ReadOnly {
return resp, x.Errorf("A best effort query must be read-only.")
}
req.StartTs = posting.Oracle().MaxAssigned()
if req.StartTs == 0 {
req.StartTs = posting.Oracle().MaxAssigned()
}
queryRequest.Cache = worker.NoTxnCache
}
if req.StartTs == 0 {
Expand Down

0 comments on commit 75f9664

Please sign in to comment.