diff --git a/posting/list.go b/posting/list.go index c029721f167..0ed73feae78 100644 --- a/posting/list.go +++ b/posting/list.go @@ -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 } @@ -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() } diff --git a/posting/lists.go b/posting/lists.go index 9f8ec721301..9a2ecfa242e 100644 --- a/posting/lists.go +++ b/posting/lists.go @@ -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), } } diff --git a/posting/mvcc.go b/posting/mvcc.go index 33432535101..1b7dd489ae9 100644 --- a/posting/mvcc.go +++ b/posting/mvcc.go @@ -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 @@ -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 })