Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't pre allocate mutation map #4343

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,19 @@ func (l *List) updateMutationLayer(mpost *pb.Posting) {
if hasDeleteAll(mpost) {
plist := &pb.PostingList{}
plist.Postings = append(plist.Postings, mpost)
if l.mutationMap == nil {
l.mutationMap = make(map[uint64]*pb.PostingList)
}
l.mutationMap[mpost.StartTs] = plist
return
}

plist, ok := l.mutationMap[mpost.StartTs]
if !ok {
plist := &pb.PostingList{}
plist.Postings = append(plist.Postings, mpost)
if l.mutationMap == nil {
l.mutationMap = make(map[uint64]*pb.PostingList)
}
l.mutationMap[mpost.StartTs] = plist
return
}
Expand Down Expand Up @@ -511,6 +516,9 @@ func (l *List) setMutation(startTs uint64, data []byte) {
x.Check(pl.Unmarshal(data))

l.Lock()
if l.mutationMap == nil {
l.mutationMap = make(map[uint64]*pb.PostingList)
}
l.mutationMap[startTs] = pl
l.Unlock()
}
Expand Down
5 changes: 2 additions & 3 deletions posting/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
}
} else {
pl = &List{
key: key,
mutationMap: make(map[uint64]*pb.PostingList),
plist: new(pb.PostingList),
key: key,
plist: new(pb.PostingList),
}
}

Expand Down
4 changes: 3 additions & 1 deletion posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func unmarshalOrCopy(plist *pb.PostingList, item *badger.Item) error {
func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
l := new(List)
l.key = key
l.mutationMap = make(map[uint64]*pb.PostingList)
l.plist = new(pb.PostingList)

// Iterates from highest Ts to lowest Ts
Expand Down Expand Up @@ -180,6 +179,9 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
// stored on disk.
mpost.CommitTs = item.Version()
}
if l.mutationMap == nil {
l.mutationMap = make(map[uint64]*pb.PostingList)
}
l.mutationMap[pl.CommitTs] = pl
return nil
})
Expand Down