mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
memStore chunk protection added, no chunk removed without being written to disk
This commit is contained in:
parent
53a00eeb41
commit
638bc6d364
4 changed files with 19 additions and 8 deletions
|
|
@ -287,6 +287,9 @@ func (s *dbStore) Put(chunk *Chunk) {
|
||||||
batch.Put(ikey, idata)
|
batch.Put(ikey, idata)
|
||||||
|
|
||||||
s.db.Write(batch)
|
s.db.Write(batch)
|
||||||
|
if chunk.dbStored != nil {
|
||||||
|
close(chunk.dbStored)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to find index; if found, update access cnt and return true
|
// try to find index; if found, update access cnt and return true
|
||||||
|
|
|
||||||
13
bzz/dpa.go
13
bzz/dpa.go
|
|
@ -54,12 +54,13 @@ type DPA struct {
|
||||||
// but the size of the subtree encoded in the chunk
|
// but the size of the subtree encoded in the chunk
|
||||||
// 0 if request, to be supplied by the dpa
|
// 0 if request, to be supplied by the dpa
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
SData []byte // nil if request, to be supplied by dpa
|
SData []byte // nil if request, to be supplied by dpa
|
||||||
Size int64 // size of the data covered by the subtree encoded in this chunk
|
Size int64 // size of the data covered by the subtree encoded in this chunk
|
||||||
Key Key // always
|
Key Key // always
|
||||||
C chan bool // to signal data delivery by the dpa
|
C chan bool // to signal data delivery by the dpa
|
||||||
req *requestStatus //
|
req *requestStatus //
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
|
dbStored chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChunkStore interface {
|
type ChunkStore interface {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ type localStore struct {
|
||||||
// localStore is itself a chunk store , to stores a chunk only
|
// localStore is itself a chunk store , to stores a chunk only
|
||||||
// its integrity is checked ?
|
// its integrity is checked ?
|
||||||
func (self *localStore) Put(chunk *Chunk) {
|
func (self *localStore) Put(chunk *Chunk) {
|
||||||
|
chunk.dbStored = make(chan bool)
|
||||||
self.memStore.Put(chunk)
|
self.memStore.Put(chunk)
|
||||||
if chunk.wg != nil {
|
if chunk.wg != nil {
|
||||||
chunk.wg.Add(1)
|
chunk.wg.Add(1)
|
||||||
|
|
|
||||||
|
|
@ -314,8 +314,14 @@ func (s *memStore) removeOldest() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node.entry = nil
|
if node.entry.dbStored != nil {
|
||||||
s.entryCnt--
|
<-node.entry.dbStored
|
||||||
|
}
|
||||||
|
if node.entry.SData != nil {
|
||||||
|
node.entry = nil
|
||||||
|
s.entryCnt--
|
||||||
|
}
|
||||||
|
|
||||||
node.access[0] = 0
|
node.access[0] = 0
|
||||||
|
|
||||||
//---
|
//---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue