mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
dpa
- store/retrieve on a chunk async in itss own go routine - retrieve breaks if found unless chunk update needed, see memstore - notFound error - fix dpa Chunkstore interface
This commit is contained in:
parent
2c464282cd
commit
cb0ffe392e
1 changed files with 30 additions and 16 deletions
24
bzz/dpa.go
24
bzz/dpa.go
|
|
@ -1,6 +1,7 @@
|
||||||
package bzz
|
package bzz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
// "time"
|
// "time"
|
||||||
|
|
||||||
|
|
@ -22,17 +23,22 @@ const (
|
||||||
retrieveChanCapacity = 100
|
retrieveChanCapacity = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
notFound = errors.New("not found")
|
||||||
|
)
|
||||||
|
|
||||||
var dpaLogger = ethlogger.NewLogger("BZZ")
|
var dpaLogger = ethlogger.NewLogger("BZZ")
|
||||||
|
|
||||||
type DPA struct {
|
type DPA struct {
|
||||||
Chunker Chunker
|
Chunker Chunker
|
||||||
Stores []ChunkStore
|
Stores []ChunkStore
|
||||||
wg sync.WaitGroup
|
|
||||||
quitC chan bool
|
|
||||||
storeC chan *Chunk
|
storeC chan *Chunk
|
||||||
retrieveC chan *Chunk
|
retrieveC chan *Chunk
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
running bool
|
running bool
|
||||||
|
wg sync.WaitGroup
|
||||||
|
quitC chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChunkStore interface {
|
type ChunkStore interface {
|
||||||
|
|
@ -92,13 +98,13 @@ func (self *DPA) Store(data SectionReader) (key Key, err error) {
|
||||||
|
|
||||||
// DPA is itself a chunk store , to stores a chunk only
|
// DPA is itself a chunk store , to stores a chunk only
|
||||||
// its integrity is checked ?
|
// its integrity is checked ?
|
||||||
func (self *DPA) Put(*Chunk) (found bool, err error) {
|
func (self *DPA) Put(*Chunk) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveChunk looks up Chunk in the local stores
|
// Get(chunk *Chunk) looks up a chunk in the local stores
|
||||||
// This method is blocking until the chunk is retrieved so additional timeout is needed to wrap this call
|
// This method is blocking until the chunk is retrieved so additional timeout is needed to wrap this call
|
||||||
func (self *DPA) Get(*Chunk) (found bool, err error) {
|
func (self *DPA) Get(*Chunk) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,11 +136,17 @@ func (self *DPA) retrieveLoop() {
|
||||||
go func() {
|
go func() {
|
||||||
LOOP:
|
LOOP:
|
||||||
for chunk := range self.retrieveC {
|
for chunk := range self.retrieveC {
|
||||||
|
go func() {
|
||||||
for _, store := range self.Stores {
|
for _, store := range self.Stores {
|
||||||
if err := store.Get(chunk); err != nil { // no waiting/blocking here
|
if err := store.Get(chunk); err != nil { // no waiting/blocking here
|
||||||
dpaLogger.DebugDetailf("%v retrieving chunk %x: %v", store, chunk.Key, err)
|
dpaLogger.DebugDetailf("%v retrieving chunk %x: %v", store, chunk.Key, err)
|
||||||
|
} else {
|
||||||
|
if !chunk.update {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
select {
|
select {
|
||||||
case <-self.quitC:
|
case <-self.quitC:
|
||||||
break LOOP
|
break LOOP
|
||||||
|
|
@ -149,11 +161,13 @@ func (self *DPA) storeLoop() {
|
||||||
go func() {
|
go func() {
|
||||||
LOOP:
|
LOOP:
|
||||||
for chunk := range self.storeC {
|
for chunk := range self.storeC {
|
||||||
|
go func() {
|
||||||
for _, store := range self.Stores {
|
for _, store := range self.Stores {
|
||||||
if err := store.Put(chunk); err != nil { // no waiting/blocking here
|
if err := store.Put(chunk); err != nil { // no waiting/blocking here
|
||||||
dpaLogger.DebugDetailf("%v storing chunk %x: %v", store, chunk.Key, err)
|
dpaLogger.DebugDetailf("%v storing chunk %x: %v", store, chunk.Key, err)
|
||||||
} // no waiting/blocking here
|
} // no waiting/blocking here
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
select {
|
select {
|
||||||
case <-self.quitC:
|
case <-self.quitC:
|
||||||
break LOOP
|
break LOOP
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue