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. (#3187)
  • Loading branch information
manishrjain authored and danielmai committed Apr 2, 2019
1 parent 5cc3a41 commit eeaee91
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 @@ -221,3 +221,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 @@ -501,7 +501,9 @@ func (s *Server) Query(ctx context.Context, req *api.Request) (resp *api.Respons
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 eeaee91

Please sign in to comment.