Skip to content

Commit

Permalink
Remove size calculation in posting list.
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed May 2, 2019
1 parent b47986a commit 0716dc4
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"math"
"sort"
"sync/atomic"
"unsafe"

"github.com/dgryski/go-farm"
"github.com/golang/glog"
Expand Down Expand Up @@ -68,27 +67,15 @@ const (

type List struct {
x.SafeMutex
key []byte
plist *pb.PostingList
mutationMap map[uint64]*pb.PostingList
minTs uint64 // commit timestamp of immutable layer, reject reads before this ts.
estimatedSize int32
key []byte
plist *pb.PostingList
mutationMap map[uint64]*pb.PostingList
minTs uint64 // commit timestamp of immutable layer, reject reads before this ts.

pendingTxns int32 // Using atomic for this, to avoid locking in SetForDeletion operation.
deleteMe int32 // Using atomic for this, to avoid expensive SetForDeletion operation.
}

// calculateSize would give you the size estimate. This is expensive, so run it carefully.
func (l *List) calculateSize() int32 {
sz := int(unsafe.Sizeof(l))
sz += l.plist.Size()
sz += cap(l.key)
for _, pl := range l.mutationMap {
sz += 8 + pl.Size()
}
return int32(sz)
}

type PIterator struct {
pl *pb.PostingList
uidPosting *pb.Posting
Expand Down Expand Up @@ -184,14 +171,6 @@ func NewPosting(t *pb.DirectedEdge) *pb.Posting {
}
}

func (l *List) EstimatedSize() int32 {
size := atomic.LoadInt32(&l.estimatedSize)
if size < 0 {
return 0
}
return size
}

// SetForDeletion will mark this List to be deleted, so no more mutations can be applied to this.
// Ensure that we don't acquire any locks during a call to this function, so the LRU cache can
// proceed smoothly.
Expand Down Expand Up @@ -328,7 +307,6 @@ func (l *List) addMutation(ctx context.Context, txn *Txn, t *pb.DirectedEdge) er
}

l.updateMutationLayer(mpost)
atomic.AddInt32(&l.estimatedSize, int32(mpost.Size()+16 /* various overhead */))
atomic.AddInt32(&l.pendingTxns, 1)
txn.AddKeys(string(l.key), conflictKey)
return nil
Expand Down Expand Up @@ -375,7 +353,6 @@ func (l *List) commitMutation(startTs, commitTs uint64) error {
}
if commitTs == 0 {
// Abort mutation.
atomic.AddInt32(&l.estimatedSize, -1*int32(plist.Size()))
delete(l.mutationMap, startTs)
return nil
}
Expand Down Expand Up @@ -688,7 +665,6 @@ func (l *List) rollup(readTs uint64) error {

l.minTs = maxCommitTs
l.plist = final
atomic.StoreInt32(&l.estimatedSize, l.calculateSize())
return nil
}

Expand Down

0 comments on commit 0716dc4

Please sign in to comment.