add pending write check before tracking the object in Has
This commit is contained in:
parent
982867317e
commit
13a674330f
@ -233,6 +233,11 @@ func (s *SplitStore) Has(c cid.Cid) (bool, error) {
|
|||||||
// writes on Flush. When we have options in the API, the vm can explicitly signal that this is
|
// writes on Flush. When we have options in the API, the vm can explicitly signal that this is
|
||||||
// an implicit Write.
|
// an implicit Write.
|
||||||
// we also walk dags for links so that the reference applies transitively to children.
|
// we also walk dags for links so that the reference applies transitively to children.
|
||||||
|
// but first check if it is already a pending write to avoid unnecessary work
|
||||||
|
if s.isPendingWrite(c) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
if c.Prefix().Codec != cid.DagCBOR {
|
if c.Prefix().Codec != cid.DagCBOR {
|
||||||
s.trackWrite(c)
|
s.trackWrite(c)
|
||||||
} else {
|
} else {
|
||||||
@ -245,7 +250,8 @@ func (s *SplitStore) Has(c cid.Cid) (bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// also make sure the object is considered live during compaction
|
// also make sure the object is considered live during compaction in case we have already
|
||||||
|
// flushed pending writes and started compaction
|
||||||
if s.txnProtect != nil {
|
if s.txnProtect != nil {
|
||||||
if c.Prefix().Codec != cid.DagCBOR {
|
if c.Prefix().Codec != cid.DagCBOR {
|
||||||
err = s.txnProtect.Mark(c)
|
err = s.txnProtect.Mark(c)
|
||||||
@ -640,6 +646,14 @@ func (s *SplitStore) trackWriteMany(cids []cid.Cid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SplitStore) isPendingWrite(c cid.Cid) bool {
|
||||||
|
s.mx.Lock()
|
||||||
|
defer s.mx.Unlock()
|
||||||
|
|
||||||
|
_, ok := s.pendingWrites[c]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SplitStore) flushPendingWrites(locked bool) {
|
func (s *SplitStore) flushPendingWrites(locked bool) {
|
||||||
if !locked {
|
if !locked {
|
||||||
s.mx.Lock()
|
s.mx.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user