mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: use validators to cleanup LevelDB
This commit is contained in:
parent
f638f8e148
commit
aacbec8a99
3 changed files with 20 additions and 10 deletions
|
|
@ -37,7 +37,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage/mock"
|
"github.com/ethereum/go-ethereum/swarm/storage/mock"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
|
@ -61,7 +60,7 @@ var (
|
||||||
keyDataIdx = []byte{4}
|
keyDataIdx = []byte{4}
|
||||||
keyData = byte(6)
|
keyData = byte(6)
|
||||||
keyDistanceCnt = byte(7)
|
keyDistanceCnt = byte(7)
|
||||||
keySchema = byte(8)
|
keySchema = []byte{8}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -419,7 +418,7 @@ func (s *LDBStore) Import(in io.Reader) (int64, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LDBStore) Cleanup() {
|
func (s *LDBStore) Cleanup(f func(*chunk) bool) {
|
||||||
//Iterates over the database and checks that there are no chunks bigger than 4kb
|
//Iterates over the database and checks that there are no chunks bigger than 4kb
|
||||||
var errorsFound, removed, total int
|
var errorsFound, removed, total int
|
||||||
|
|
||||||
|
|
@ -472,7 +471,8 @@ func (s *LDBStore) Cleanup() {
|
||||||
cs := int64(binary.LittleEndian.Uint64(c.sdata[:8]))
|
cs := int64(binary.LittleEndian.Uint64(c.sdata[:8]))
|
||||||
log.Trace("chunk", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
log.Trace("chunk", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
||||||
|
|
||||||
if len(c.sdata) > ch.DefaultSize+8 {
|
// if chunk is to be removed
|
||||||
|
if f(c) {
|
||||||
log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
||||||
s.delete(index.Idx, getIndexKey(key[1:]), po)
|
s.delete(index.Idx, getIndexKey(key[1:]), po)
|
||||||
removed++
|
removed++
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,17 @@ func (ls *LocalStore) Migrate() error {
|
||||||
if schema == "" {
|
if schema == "" {
|
||||||
log.Debug("running migrations for", "schema", schema, "runtime-schema", CurrentDbSchema)
|
log.Debug("running migrations for", "schema", schema, "runtime-schema", CurrentDbSchema)
|
||||||
|
|
||||||
ls.DbStore.Cleanup()
|
cleanupFunc := func(c *chunk) bool {
|
||||||
|
valid := false
|
||||||
|
for _, v := range ls.Validators {
|
||||||
|
if valid = v.Validate(c.Address(), c.Data()); valid {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
|
ls.DbStore.Cleanup(cleanupFunc)
|
||||||
|
|
||||||
err := ls.DbStore.PutSchema(DbSchemaHive)
|
err := ls.DbStore.PutSchema(DbSchemaHive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -169,11 +169,6 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = lstore.Migrate()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
self.netStore, err = storage.NewNetStore(lstore, nil)
|
self.netStore, err = storage.NewNetStore(lstore, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -207,6 +202,11 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||||
resourceHandler,
|
resourceHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = lstore.Migrate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug("Setup local storage")
|
log.Debug("Setup local storage")
|
||||||
|
|
||||||
self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run)
|
self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue