mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: add Delete to LDBStore
This commit is contained in:
parent
6f3e02cbbd
commit
60571122d5
2 changed files with 16 additions and 17 deletions
|
|
@ -462,6 +462,18 @@ func (s *LDBStore) ReIndex() {
|
||||||
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
log.Warn(fmt.Sprintf("Found %v errors out of %v entries", errorsFound, total))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LDBStore) Delete(addr Address) {
|
||||||
|
s.lock.Lock()
|
||||||
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
ikey := getIndexKey(addr)
|
||||||
|
|
||||||
|
var indx dpaDBIndex
|
||||||
|
s.tryAccessIdx(ikey, &indx)
|
||||||
|
|
||||||
|
s.delete(indx.Idx, ikey, s.po(addr))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *LDBStore) delete(idx uint64, idxKey []byte, po uint8) {
|
func (s *LDBStore) delete(idx uint64, idxKey []byte, po uint8) {
|
||||||
metrics.GetOrRegisterCounter("ldbstore.delete", nil).Inc(1)
|
metrics.GetOrRegisterCounter("ldbstore.delete", nil).Inc(1)
|
||||||
|
|
||||||
|
|
@ -486,8 +498,8 @@ func (s *LDBStore) CurrentBucketStorageIndex(po uint8) uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LDBStore) Size() uint64 {
|
func (s *LDBStore) Size() uint64 {
|
||||||
s.lock.Lock()
|
s.lock.RLock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.RUnlock()
|
||||||
return s.entryCnt
|
return s.entryCnt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -416,14 +416,7 @@ func TestLDBStoreAddRemove(t *testing.T) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
// delete all even index chunks
|
// delete all even index chunks
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
|
ldb.Delete(chunks[i].Addr)
|
||||||
key := chunks[i].Addr
|
|
||||||
ikey := getIndexKey(key)
|
|
||||||
|
|
||||||
var indx dpaDBIndex
|
|
||||||
ldb.tryAccessIdx(ikey, &indx)
|
|
||||||
|
|
||||||
ldb.delete(indx.Idx, ikey, ldb.po(key))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,13 +470,7 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
|
||||||
|
|
||||||
// delete all chunks
|
// delete all chunks
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
key := chunks[i].Addr
|
ldb.Delete(chunks[i].Addr)
|
||||||
ikey := getIndexKey(key)
|
|
||||||
|
|
||||||
var indx dpaDBIndex
|
|
||||||
ldb.tryAccessIdx(ikey, &indx)
|
|
||||||
|
|
||||||
ldb.delete(indx.Idx, ikey, ldb.po(key))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt)
|
log.Info("ldbstore", "entrycnt", ldb.entryCnt, "accesscnt", ldb.accessCnt)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue