From 638bc6d36403fcc4534bd37ed79ee25ea2b6f50f Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 13 May 2015 20:10:16 +0200 Subject: [PATCH] memStore chunk protection added, no chunk removed without being written to disk --- bzz/dbstore.go | 3 +++ bzz/dpa.go | 13 +++++++------ bzz/localstore.go | 1 + bzz/memstore.go | 10 ++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bzz/dbstore.go b/bzz/dbstore.go index 680c9d6d39..78fcb6ec0b 100644 --- a/bzz/dbstore.go +++ b/bzz/dbstore.go @@ -287,6 +287,9 @@ func (s *dbStore) Put(chunk *Chunk) { batch.Put(ikey, idata) s.db.Write(batch) + if chunk.dbStored != nil { + close(chunk.dbStored) + } } // try to find index; if found, update access cnt and return true diff --git a/bzz/dpa.go b/bzz/dpa.go index 85d77ff047..b93f17c283 100644 --- a/bzz/dpa.go +++ b/bzz/dpa.go @@ -54,12 +54,13 @@ type DPA struct { // but the size of the subtree encoded in the chunk // 0 if request, to be supplied by the dpa type Chunk struct { - SData []byte // nil if request, to be supplied by dpa - Size int64 // size of the data covered by the subtree encoded in this chunk - Key Key // always - C chan bool // to signal data delivery by the dpa - req *requestStatus // - wg *sync.WaitGroup + SData []byte // nil if request, to be supplied by dpa + Size int64 // size of the data covered by the subtree encoded in this chunk + Key Key // always + C chan bool // to signal data delivery by the dpa + req *requestStatus // + wg *sync.WaitGroup + dbStored chan bool } type ChunkStore interface { diff --git a/bzz/localstore.go b/bzz/localstore.go index 7cb506d89a..7f6a4eabd8 100644 --- a/bzz/localstore.go +++ b/bzz/localstore.go @@ -9,6 +9,7 @@ type localStore struct { // localStore is itself a chunk store , to stores a chunk only // its integrity is checked ? func (self *localStore) Put(chunk *Chunk) { + chunk.dbStored = make(chan bool) self.memStore.Put(chunk) if chunk.wg != nil { chunk.wg.Add(1) diff --git a/bzz/memstore.go b/bzz/memstore.go index 0c5f17d5be..6204a067db 100644 --- a/bzz/memstore.go +++ b/bzz/memstore.go @@ -314,8 +314,14 @@ func (s *memStore) removeOldest() { } - node.entry = nil - s.entryCnt-- + if node.entry.dbStored != nil { + <-node.entry.dbStored + } + if node.entry.SData != nil { + node.entry = nil + s.entryCnt-- + } + node.access[0] = 0 //---