mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
swarm/storage: names fixup
This commit is contained in:
parent
49214d72d2
commit
69e1361566
4 changed files with 16 additions and 36 deletions
|
|
@ -48,10 +48,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultDbCapacity = 5000000
|
|
||||||
defaultRadius = 0 // not yet used
|
|
||||||
|
|
||||||
gcArrayFreeRatio = 0.1
|
gcArrayFreeRatio = 0.1
|
||||||
|
maxGCitems = 5000 // max number of items to be gc'd per call to collectGarbage()
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -82,9 +80,6 @@ type LDBStore struct {
|
||||||
capacity uint64
|
capacity uint64
|
||||||
bucketCnt []uint64
|
bucketCnt []uint64
|
||||||
|
|
||||||
gcPos []byte
|
|
||||||
gcStartPos []byte
|
|
||||||
|
|
||||||
hashfunc SwarmHasher
|
hashfunc SwarmHasher
|
||||||
po func(Key) uint8
|
po func(Key) uint8
|
||||||
|
|
||||||
|
|
@ -138,7 +133,6 @@ func NewLDBStore(path string, hash SwarmHasher, capacity uint64, po func(Key) ui
|
||||||
data, _ := s.db.Get(keyEntryCnt)
|
data, _ := s.db.Get(keyEntryCnt)
|
||||||
s.entryCnt = BytesToU64(data)
|
s.entryCnt = BytesToU64(data)
|
||||||
s.entryCnt++
|
s.entryCnt++
|
||||||
log.Trace("NewLDBStore s.entryCnt++", "entryCnt", s.entryCnt)
|
|
||||||
data, _ = s.db.Get(keyAccessCnt)
|
data, _ = s.db.Get(keyAccessCnt)
|
||||||
s.accessCnt = BytesToU64(data)
|
s.accessCnt = BytesToU64(data)
|
||||||
s.accessCnt++
|
s.accessCnt++
|
||||||
|
|
@ -146,12 +140,6 @@ func NewLDBStore(path string, hash SwarmHasher, capacity uint64, po func(Key) ui
|
||||||
s.dataIdx = BytesToU64(data)
|
s.dataIdx = BytesToU64(data)
|
||||||
s.dataIdx++
|
s.dataIdx++
|
||||||
|
|
||||||
s.gcStartPos = make([]byte, 1)
|
|
||||||
s.gcStartPos[0] = keyIndex
|
|
||||||
s.gcPos, _ = s.db.Get(keyGCPos)
|
|
||||||
if s.gcPos == nil {
|
|
||||||
s.gcPos = s.gcStartPos
|
|
||||||
}
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,14 +242,18 @@ func (s *LDBStore) collectGarbage(ratio float32) {
|
||||||
garbage := []*gcItem{}
|
garbage := []*gcItem{}
|
||||||
gcnt := 0
|
gcnt := 0
|
||||||
|
|
||||||
for ok := it.Seek([]byte{keyIndex}); ok && (gcnt < 5000) && (uint64(gcnt) < s.entryCnt); ok = it.Next() {
|
for ok := it.Seek([]byte{keyIndex}); ok && (gcnt < maxGCitems) && (uint64(gcnt) < s.entryCnt); ok = it.Next() {
|
||||||
key := it.Key()
|
itkey := it.Key()
|
||||||
val := it.Value()
|
|
||||||
if (key == nil) || (key[0] != keyIndex) {
|
if (itkey == nil) || (itkey[0] != keyIndex) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("iterator", "key", fmt.Sprintf("%x", key), "value", fmt.Sprintf("%x", val))
|
// it.Key() contents change on next call to it.Next(), so we must copy it
|
||||||
|
key := make([]byte, len(it.Key()))
|
||||||
|
copy(key, it.Key())
|
||||||
|
|
||||||
|
val := it.Value()
|
||||||
|
|
||||||
var index dpaDBIndex
|
var index dpaDBIndex
|
||||||
|
|
||||||
|
|
@ -269,35 +261,23 @@ func (s *LDBStore) collectGarbage(ratio float32) {
|
||||||
decodeIndex(val, &index)
|
decodeIndex(val, &index)
|
||||||
po := s.po(hash)
|
po := s.po(hash)
|
||||||
|
|
||||||
kkey := make([]byte, len(key))
|
|
||||||
copy(kkey, key)
|
|
||||||
|
|
||||||
gci := &gcItem{
|
gci := &gcItem{
|
||||||
idxKey: kkey,
|
idxKey: key,
|
||||||
idx: index.Idx,
|
idx: index.Idx,
|
||||||
value: index.Access,
|
value: index.Access, // the smaller, the more likely to be gc'd. see sort comparator below.
|
||||||
po: po,
|
po: po,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("gci.idxKey", "gcnt", gcnt, "idxKey", fmt.Sprintf("%x", gci.idxKey), "idx", gci.idx, "gci.value", gci.value)
|
|
||||||
|
|
||||||
garbage = append(garbage, gci)
|
garbage = append(garbage, gci)
|
||||||
gcnt++
|
gcnt++
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(garbage[:gcnt], func(i, j int) bool { return garbage[i].value < garbage[j].value })
|
sort.Slice(garbage[:gcnt], func(i, j int) bool { return garbage[i].value < garbage[j].value })
|
||||||
|
|
||||||
for k := 0; k < gcnt; k++ {
|
|
||||||
log.Trace("gcArray[]", "k", k, "idx", garbage[k].idx, "idxKey", fmt.Sprintf("%x", garbage[k].idxKey), "value", garbage[k].value)
|
|
||||||
}
|
|
||||||
|
|
||||||
cutoff := int(float32(gcnt) * ratio)
|
cutoff := int(float32(gcnt) * ratio)
|
||||||
log.Trace("cutoff", "cut", cutoff, "gcnt", gcnt)
|
|
||||||
for i := 0; i < cutoff; i++ {
|
for i := 0; i < cutoff; i++ {
|
||||||
s.delete(garbage[i].idx, garbage[i].idxKey, garbage[i].po)
|
s.delete(garbage[i].idx, garbage[i].idxKey, garbage[i].po)
|
||||||
}
|
}
|
||||||
|
|
||||||
//s.db.Put(keyGCPos, s.gcPos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export writes all chunks from the store to a tar archive, returning the
|
// Export writes all chunks from the store to a tar archive, returning the
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ func newTestDbStore(mock bool) (*testDbStore, error) {
|
||||||
addr := common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
|
addr := common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
|
||||||
mockStore := globalStore.NewNodeStore(addr)
|
mockStore := globalStore.NewNodeStore(addr)
|
||||||
|
|
||||||
db, err = NewMockDbStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc, mockStore)
|
db, err = NewMockDbStore(dir, MakeHashFunc(SHA3Hash), defaultLDBCapacity, testPoFunc, mockStore)
|
||||||
} else {
|
} else {
|
||||||
db, err = NewLDBStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc)
|
db, err = NewLDBStore(dir, MakeHashFunc(SHA3Hash), defaultLDBCapacity, testPoFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &testDbStore{db, dir}, err
|
return &testDbStore{db, dir}, err
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ type StoreParams struct {
|
||||||
//create params with default values
|
//create params with default values
|
||||||
func NewDefaultStoreParams() (self *StoreParams) {
|
func NewDefaultStoreParams() (self *StoreParams) {
|
||||||
return &StoreParams{
|
return &StoreParams{
|
||||||
DbCapacity: defaultDbCapacity,
|
DbCapacity: defaultLDBCapacity,
|
||||||
CacheCapacity: defaultCacheCapacity,
|
CacheCapacity: defaultCacheCapacity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func newLDBStore(t *testing.T) (*LDBStore, func()) {
|
||||||
}
|
}
|
||||||
log.Trace("memstore.tempdir", "dir", dir)
|
log.Trace("memstore.tempdir", "dir", dir)
|
||||||
|
|
||||||
db, err := NewLDBStore(dir, MakeHashFunc(SHA3Hash), defaultDbCapacity, testPoFunc)
|
db, err := NewLDBStore(dir, MakeHashFunc(SHA3Hash), defaultLDBCapacity, testPoFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue