simple fetchers (#1492)
* network: disable shouldNOTRequestAgain * vendor singleflight * network: disable shouldNOTRequestAgain * network, storage: fix tests * network/storage: remove HopCount and SkipCheck * network/stream: use localstore when providing chunks a node has offered * storage: refactor lnetstore * storage: rename FetcherItem to Fetcher * storage/feed: no distinction between catastrophic err or chunk not found * network/stream: remove TestDeliveryFromNodes, as FindPeer is changed, and Swarm connectivity is not a chain * network/stream: fixed intervals tests * swarm: fixes for linter * storage: use LRU cache for fetchers * network, storage: better godoc * storage/netstore: explicit errors * storage/feed/lookup: Clarify ReadFunc expected return error values * storage: address comments by elad
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethersphere/swarm/chunk"
|
||||
"github.com/ethersphere/swarm/log"
|
||||
"github.com/ethersphere/swarm/network/timeouts"
|
||||
"github.com/ethersphere/swarm/storage"
|
||||
)
|
||||
|
||||
@@ -73,7 +74,7 @@ func (s *SwarmSyncerServer) Close() {
|
||||
|
||||
// GetData retrieves the actual chunk from netstore
|
||||
func (s *SwarmSyncerServer) GetData(ctx context.Context, key []byte) ([]byte, error) {
|
||||
ch, err := s.netStore.Get(ctx, chunk.ModeGetSync, storage.Address(key))
|
||||
ch, err := s.netStore.Store.Get(ctx, chunk.ModeGetSync, storage.Address(key))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -198,9 +199,24 @@ func RegisterSwarmSyncerClient(streamer *Registry, netStore *storage.NetStore) {
|
||||
})
|
||||
}
|
||||
|
||||
// NeedData
|
||||
func (s *SwarmSyncerClient) NeedData(ctx context.Context, key []byte) (wait func(context.Context) error) {
|
||||
return s.netStore.FetchFunc(ctx, key)
|
||||
func (s *SwarmSyncerClient) NeedData(ctx context.Context, key []byte) (loaded bool, wait func(context.Context) error) {
|
||||
start := time.Now()
|
||||
|
||||
fi, loaded, ok := s.netStore.GetOrCreateFetcher(ctx, key, "syncer")
|
||||
if !ok {
|
||||
return loaded, nil
|
||||
}
|
||||
|
||||
return loaded, func(ctx context.Context) error {
|
||||
select {
|
||||
case <-fi.Delivered:
|
||||
metrics.GetOrRegisterResettingTimer(fmt.Sprintf("fetcher.%s.syncer", fi.CreatedBy), nil).UpdateSince(start)
|
||||
case <-time.After(timeouts.SyncerClientWaitTimeout):
|
||||
metrics.GetOrRegisterCounter("fetcher.syncer.timeout", nil).Inc(1)
|
||||
return fmt.Errorf("chunk not delivered through syncing after %dsec. ref=%s", timeouts.SyncerClientWaitTimeout, fmt.Sprintf("%x", key))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SwarmSyncerClient) Close() {}
|
||||
|
Reference in New Issue
Block a user