Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Aug 12, 2024
1 parent 6642a76 commit f2443ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,8 @@ func (l *List) findStaticValue(readTs uint64) *pb.PostingList {
// This means that maxTs > readTs. Go through the map to find the closest value to readTs
mutation = nil
ts_found := uint64(0)
for ts, mutation_i := range l.mutationMap {
for _, mutation_i := range l.mutationMap {
ts := mutation_i.CommitTs
if ts <= readTs && ts > ts_found {
ts_found = ts
mutation = mutation_i
Expand Down
27 changes: 22 additions & 5 deletions posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ func TestGetSinglePosting(t *testing.T) {

create_pl := func(startTs uint64) *pb.PostingList {
return &pb.PostingList{
Postings: []*pb.Posting{{
Uid: 1,
Op: 1,
StartTs: startTs,
}},
Postings: []*pb.Posting{
{
Uid: 1,
Op: 1,
StartTs: startTs,
CommitTs: startTs,
},
},
CommitTs: startTs,
}
}

Expand Down Expand Up @@ -169,6 +173,19 @@ func TestGetSinglePosting(t *testing.T) {
res, err = l.StaticValue(4)
require.NoError(t, err)
require.Equal(t, res.Postings[0].StartTs, uint64(3))

// Create txn from 4->6. It could be stored as 4 or 6 in the map.
l.mutationMap[4] = create_pl(6)
l.mutationMap[4].Postings[0].StartTs = 4
l.maxTs = 6

res, err = l.StaticValue(5)
require.NoError(t, err)
require.Equal(t, res.Postings[0].StartTs, uint64(3))

res, err = l.StaticValue(6)
require.NoError(t, err)
require.Equal(t, res.Postings[0].StartTs, uint64(4))
}

func TestAddMutation(t *testing.T) {
Expand Down

0 comments on commit f2443ca

Please sign in to comment.