mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
swarm/storage: Fix chunk overwrite on store restart
- Upon re-open of store, last chunk got overwritten - Underlying db never closed from dpa and localstore - LocalDPA used different hash algo for verification than chunk hasher
This commit is contained in:
parent
8f35e3086c
commit
df27fe7391
3 changed files with 18 additions and 3 deletions
|
|
@ -95,10 +95,19 @@ func NewDbStore(path string, hash SwarmHasher, capacity uint64, radius int) (s *
|
||||||
|
|
||||||
data, _ := s.db.Get(keyEntryCnt)
|
data, _ := s.db.Get(keyEntryCnt)
|
||||||
s.entryCnt = BytesToU64(data)
|
s.entryCnt = BytesToU64(data)
|
||||||
|
if len(data) > 0 {
|
||||||
|
s.entryCnt++
|
||||||
|
}
|
||||||
data, _ = s.db.Get(keyAccessCnt)
|
data, _ = s.db.Get(keyAccessCnt)
|
||||||
s.accessCnt = BytesToU64(data)
|
s.accessCnt = BytesToU64(data)
|
||||||
|
if len(data) > 0 {
|
||||||
|
s.accessCnt++
|
||||||
|
}
|
||||||
data, _ = s.db.Get(keyDataIdx)
|
data, _ = s.db.Get(keyDataIdx)
|
||||||
s.dataIdx = BytesToU64(data)
|
s.dataIdx = BytesToU64(data)
|
||||||
|
if len(data) > 0 {
|
||||||
|
s.dataIdx++
|
||||||
|
}
|
||||||
s.gcPos, _ = s.db.Get(keyGCPos)
|
s.gcPos, _ = s.db.Get(keyGCPos)
|
||||||
if s.gcPos == nil {
|
if s.gcPos == nil {
|
||||||
s.gcPos = s.gcStartPos
|
s.gcPos = s.gcStartPos
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,12 @@ type DPA struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for testing locally
|
// for testing locally
|
||||||
func NewLocalDPA(datadir string) (*DPA, error) {
|
func NewLocalDPA(datadir string, hashalgorithm string) (*DPA, error) {
|
||||||
|
|
||||||
hash := MakeHashFunc("SHA256")
|
if hashalgorithm == "" {
|
||||||
|
hashalgorithm = "SHA3"
|
||||||
|
}
|
||||||
|
hash := MakeHashFunc(hashalgorithm)
|
||||||
|
|
||||||
dbStore, err := NewDbStore(datadir, hash, singletonSwarmDbCapacity, 0)
|
dbStore, err := NewDbStore(datadir, hash, singletonSwarmDbCapacity, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -116,6 +119,7 @@ func (self *DPA) Start() {
|
||||||
|
|
||||||
func (self *DPA) Stop() {
|
func (self *DPA) Stop() {
|
||||||
self.lock.Lock()
|
self.lock.Lock()
|
||||||
|
self.Close()
|
||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
if !self.running {
|
if !self.running {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -74,4 +74,6 @@ func (self *LocalStore) Get(key Key) (chunk *Chunk, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close local store
|
// Close local store
|
||||||
func (self *LocalStore) Close() {}
|
func (self *LocalStore) Close() {
|
||||||
|
self.DbStore.Close()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue