more debug

This commit is contained in:
zelig 2018-01-24 10:11:09 +01:00
parent 172eb9e14d
commit eae4473a81
7 changed files with 39 additions and 28 deletions

View file

@ -161,7 +161,7 @@ type ChunkDeliveryMsg struct {
SData []byte // the stored chunk Data (incl size) SData []byte // the stored chunk Data (incl size)
} }
func (d *Delivery) handleChunkDeliveryMsg(req *ChunkDeliveryMsg) error { func (d *Delivery) handleChunkDeliveryMsg(sp *Peer, req *ChunkDeliveryMsg) error {
d.counterIn++ d.counterIn++
d.receiveC <- req d.receiveC <- req
return nil return nil
@ -172,7 +172,9 @@ R:
for req := range d.receiveC { for req := range d.receiveC {
// this should be has locally // this should be has locally
chunk, err := d.db.Get(req.Key) chunk, err := d.db.Get(req.Key)
log.Error("pick from receiveC", "chunk", chunk.Key.Hex(), "reqC", chunk.ReqC, "err", err)
if err == nil { if err == nil {
log.Error("found existing?", "hash", chunk.Key.Hex())
continue R continue R
} }
if err != storage.ErrFetching { if err != storage.ErrFetching {
@ -180,17 +182,21 @@ R:
} }
select { select {
case <-chunk.ReqC: case <-chunk.ReqC:
log.Error("someone else delivered?", "hash", chunk.Key.Hex())
continue R continue R
default: default:
} }
chunk.SData = req.SData go func() {
d.db.Put(chunk) chunk.SData = req.SData
log.Warn("reecived delivery", "hash", chunk.Key) log.Error("received delivery", "hash", chunk.Key.Hex())
close(chunk.ReqC) d.db.Put(chunk)
chunk.WaitToStore() log.Error("put to db", "hash", chunk.Key.Hex())
//log.Warn("received delivery stored", "hash", chunk.Key) chunk.WaitToStore()
log.Warn("received delivery requesters notified", "hash", chunk.Key) close(chunk.ReqC)
d.counterDone++ //log.Warn("received delivery stored", "hash", chunk.Key)
log.Error("requesters notified", "hash", chunk.Key.Hex())
d.counterDone++
}()
} }
} }

View file

@ -28,7 +28,7 @@ import (
"github.com/ethereum/go-ethereum/swarm/storage" "github.com/ethereum/go-ethereum/swarm/storage"
) )
var sendTimeout = 5 * time.Second var sendTimeout = 1 * time.Second
// Peer is the Peer extention for the streaming protocol // Peer is the Peer extention for the streaming protocol
type Peer struct { type Peer struct {
@ -97,7 +97,11 @@ func (p *Peer) SendOfferedHashes(s *server, f, t uint64) error {
Stream: s.stream, Stream: s.stream,
Key: s.key, Key: s.key,
} }
log.Warn("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "key", s.key, "len", len(hashes), "from", from, "to", to) log.Error("Swarm syncer offer batch", "peer", p.ID(), "stream", s.stream, "key", s.key, "len", len(hashes), "from", from, "to", to)
for i := 0; i < len(hashes); i += HashSize {
hash := hashes[i : i+HashSize]
log.Error("Swarm syncer offer hash", "peer", p.ID(), "stream", s.stream, "hash", storage.Key(hash).Hex(), "len", len(hashes), "from", from, "to", to)
}
return p.SendPriority(msg, s.priority) return p.SendPriority(msg, s.priority)
} }

View file

@ -38,8 +38,8 @@ const (
Mid Mid
High High
Top Top
PriorityQueue // number of queues PriorityQueue // number of queues
PriorityQueueCap = 32 // queue capacity PriorityQueueCap = 3 // queue capacity
HashSize = 32 HashSize = 32
) )
@ -227,7 +227,7 @@ func (p *Peer) HandleMsg(msg interface{}) error {
return p.handleWantedHashesMsg(msg) return p.handleWantedHashesMsg(msg)
case *ChunkDeliveryMsg: case *ChunkDeliveryMsg:
return p.streamer.delivery.handleChunkDeliveryMsg(msg) return p.streamer.delivery.handleChunkDeliveryMsg(p, msg)
case *RetrieveRequestMsg: case *RetrieveRequestMsg:
return p.streamer.delivery.handleRetrieveRequestMsg(p, msg) return p.streamer.delivery.handleRetrieveRequestMsg(p, msg)

View file

@ -186,7 +186,6 @@ func (s *SwarmSyncerClient) NeedData(key []byte) (wait func()) {
chunk, _ := s.db.GetOrCreateRequest(key) chunk, _ := s.db.GetOrCreateRequest(key)
// TODO: we may want to request from this peer anyway even if the request exists // TODO: we may want to request from this peer anyway even if the request exists
if chunk.ReqC == nil { if chunk.ReqC == nil {
log.Error("oops this is found")
return nil return nil
} }
// create request and wait until the chunk data arrives and is stored // create request and wait until the chunk data arrives and is stored

View file

@ -22,6 +22,7 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"runtime/debug"
"testing" "testing"
"time" "time"
@ -203,7 +204,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
conf.Step = &simulations.Step{ conf.Step = &simulations.Step{
Action: action, Action: action,
Trigger: streamTesting.PivotTrigger(100*time.Millisecond, checkC, sim.IDs[0]), Trigger: streamTesting.PivotTrigger(500*time.Millisecond, checkC, sim.IDs[0]),
Expect: &simulations.Expectation{ Expect: &simulations.Expectation{
Nodes: sim.IDs[0:1], Nodes: sim.IDs[0:1],
Check: check, Check: check,
@ -220,6 +221,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
} }
if result.Error != nil { if result.Error != nil {
t.Fatalf("Simulation failed: %s", result.Error) t.Fatalf("Simulation failed: %s", result.Error)
streamTesting.CheckResult(t, result, startedAt, finishedAt)
debug.PrintStack()
} }
streamTesting.CheckResult(t, result, startedAt, finishedAt)
} }

View file

@ -538,6 +538,7 @@ func (s *DbStore) CurrentStorageIndex() uint64 {
} }
func (s *DbStore) Put(chunk *Chunk) { func (s *DbStore) Put(chunk *Chunk) {
log.Error("DbStore.Put", "hash", chunk.Key.Hex())
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
@ -549,17 +550,23 @@ func (s *DbStore) Put(chunk *Chunk) {
idata, err := s.db.Get(ikey) idata, err := s.db.Get(ikey)
if err != nil { if err != nil {
s.doPut(chunk, ikey, &index, po) s.doPut(chunk, ikey, &index, po)
batchC := s.batchC
go func() {
<-batchC
close(chunk.dbStored)
}()
log.Error("DbStore.Put doPut", "hash", chunk.Key.Hex(), "dataIdx", s.dataIdx)
} else { } else {
log.Trace(fmt.Sprintf("DbStore: chunk already exists, only update access")) log.Trace(fmt.Sprintf("DbStore: chunk already exists, only update access"))
decodeIndex(idata, &index) decodeIndex(idata, &index)
close(chunk.dbStored) close(chunk.dbStored)
log.Error("DbStore.Put already found", "hash", chunk.Key.Hex())
} }
index.Access = s.accessCnt index.Access = s.accessCnt
s.accessCnt++ s.accessCnt++
idata = encodeIndex(&index) idata = encodeIndex(&index)
s.batch.Put(ikey, idata) s.batch.Put(ikey, idata)
select { select {
case <-s.quit:
case s.batchesC <- struct{}{}: case s.batchesC <- struct{}{}:
default: default:
} }
@ -579,13 +586,6 @@ func (s *DbStore) doPut(chunk *Chunk, ikey []byte, index *dpaDBIndex, po uint8)
cntKey[1] = po cntKey[1] = po
s.batch.Put(cntKey, U64ToBytes(s.bucketCnt[po])) s.batch.Put(cntKey, U64ToBytes(s.bucketCnt[po]))
batchC := s.batchC
go func() {
<-batchC
close(chunk.dbStored)
}()
log.Trace(fmt.Sprintf("DbStore.Put: %v. db storage counter: %v ", chunk.Key.Log(), s.dataIdx))
} }
func (s *DbStore) writeBatches() { func (s *DbStore) writeBatches() {

View file

@ -96,9 +96,9 @@ func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error)
func (self *LocalStore) Put(chunk *Chunk) { func (self *LocalStore) Put(chunk *Chunk) {
chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8])) chunk.Size = int64(binary.LittleEndian.Uint64(chunk.SData[0:8]))
self.memStore.Put(chunk) self.memStore.Put(chunk)
go func() { log.Error("put to memstore", "hash", chunk.Key.Hex())
self.DbStore.Put(chunk) self.DbStore.Put(chunk)
}() log.Error("put to dbstore", "hash", chunk.Key.Hex())
} }
// Get(chunk *Chunk) looks up a chunk in the local stores // Get(chunk *Chunk) looks up a chunk in the local stores