diff --git a/datastore/memory/txn.go b/datastore/memory/txn.go index f1086332b6..27b6292d06 100644 --- a/datastore/memory/txn.go +++ b/datastore/memory/txn.go @@ -179,13 +179,17 @@ func (t *basicTxn) Query(ctx context.Context, q dsq.Query) (dsq.Results, error) iter := t.ds.values.Iter() iterOps := t.ops.Iter() iterOpsHasValue := iterOps.Next() + dsVersion := t.getDSVersion() // iterate over the underlying store and ensure that ops with keys smaller than or equal to // the key of the underlying store are added with priority. for iter.Next() { // fast forward to last inserted version item := iter.Item() + if item.version > dsVersion { + continue + } for iter.Next() { - if item.key == iter.Item().key { + if item.key == iter.Item().key && iter.Item().version <= dsVersion { item = iter.Item() continue } diff --git a/datastore/memory/txn_test.go b/datastore/memory/txn_test.go index 5a0d1a2d8c..d1861e7d87 100644 --- a/datastore/memory/txn_test.go +++ b/datastore/memory/txn_test.go @@ -661,7 +661,7 @@ func TestTxnQueryWithOnlyOneOperation(t *testing.T) { tx, err := s.NewTransaction(ctx, false) require.NoError(t, err) - err = s.Put(ctx, testKey4, testValue4) + err = tx.Put(ctx, testKey4, testValue4) require.NoError(t, err) results, err := tx.Query(ctx, dsq.Query{}) diff --git a/datastore/txn_test.go b/datastore/txn_test.go index d4f29e845b..d3c3e5a15b 100644 --- a/datastore/txn_test.go +++ b/datastore/txn_test.go @@ -486,8 +486,7 @@ func TestMemoryStoreTxn_TwoTransactionsWithQueryAndPut_ShouldOmmitNewPut(t *test for r := range qResults.Next() { docs = append(docs, r.Entry.Value) } - // This is wrong. The new put should not be visible. - require.Equal(t, [][]byte{[]byte("value"), []byte("other-value")}, docs) + require.Equal(t, [][]byte{[]byte("value")}, docs) txn1.Discard(ctx) }