Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
36efbe0e
Unverified
Commit
36efbe0e
authored
Jul 08, 2021
by
istae
Committed by
GitHub
Jul 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: add to skiplist on error in goroutine (#2311)
parent
8500410a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
15 deletions
+22
-15
pushsync.go
pkg/pushsync/pushsync.go
+11
-6
pushsync_test.go
pkg/pushsync/pushsync_test.go
+4
-7
mock.go
pkg/topology/mock/mock.go
+7
-2
No files found.
pkg/pushsync/pushsync.go
View file @
36efbe0e
...
@@ -318,7 +318,7 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
...
@@ -318,7 +318,7 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
// in which case we should return immediately.
// in which case we should return immediately.
// if ErrWantSelf is returned, it means we are the closest peer.
// if ErrWantSelf is returned, it means we are the closest peer.
if
errors
.
Is
(
err
,
topology
.
ErrWantSelf
)
{
if
errors
.
Is
(
err
,
topology
.
ErrWantSelf
)
{
if
time
.
Now
()
.
Before
(
ps
.
warmupPeriod
)
{
if
!
ps
.
warmedUp
(
)
{
return
nil
,
ErrWarmup
return
nil
,
ErrWarmup
}
}
...
@@ -375,6 +375,12 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
...
@@ -375,6 +375,12 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
}
}
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Debugf
(
"could not push to peer %s: %v"
,
peer
,
err
)
logger
.
Debugf
(
"could not push to peer %s: %v"
,
peer
,
err
)
// if the node has warmed up AND no other closer peer has been tried
if
ps
.
warmedUp
()
&&
!
ps
.
skipList
.
HasChunk
(
ch
.
Address
())
{
ps
.
skipList
.
Add
(
peer
,
ch
.
Address
(),
skipPeerExpiration
)
}
resultC
<-
&
pushResult
{
err
:
err
,
attempted
:
attempted
}
resultC
<-
&
pushResult
{
err
:
err
,
attempted
:
attempted
}
return
return
}
}
...
@@ -393,11 +399,6 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
...
@@ -393,11 +399,6 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
}
}
if
r
.
err
!=
nil
&&
r
.
attempted
{
if
r
.
err
!=
nil
&&
r
.
attempted
{
ps
.
metrics
.
TotalFailedSendAttempts
.
Inc
()
ps
.
metrics
.
TotalFailedSendAttempts
.
Inc
()
// if the node has warmed up AND no other closer peer has been tried
if
time
.
Now
()
.
After
(
ps
.
warmupPeriod
)
&&
!
ps
.
skipList
.
HasChunk
(
ch
.
Address
())
{
ps
.
skipList
.
Add
(
peer
,
ch
.
Address
(),
skipPeerExpiration
)
}
}
}
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
return
nil
,
ctx
.
Err
()
...
@@ -536,6 +537,10 @@ func (ps *PushSync) pushToNeighbour(peer swarm.Address, ch swarm.Chunk, origin b
...
@@ -536,6 +537,10 @@ func (ps *PushSync) pushToNeighbour(peer swarm.Address, ch swarm.Chunk, origin b
err
=
ps
.
accounting
.
Credit
(
peer
,
receiptPrice
,
origin
)
err
=
ps
.
accounting
.
Credit
(
peer
,
receiptPrice
,
origin
)
}
}
func
(
ps
*
PushSync
)
warmedUp
()
bool
{
return
time
.
Now
()
.
After
(
ps
.
warmupPeriod
)
}
type
peerSkipList
struct
{
type
peerSkipList
struct
{
sync
.
Mutex
sync
.
Mutex
chunks
map
[
string
]
struct
{}
chunks
map
[
string
]
struct
{}
...
...
pkg/pushsync/pushsync_test.go
View file @
36efbe0e
...
@@ -130,16 +130,19 @@ func TestReplicateBeforeReceipt(t *testing.T) {
...
@@ -130,16 +130,19 @@ func TestReplicateBeforeReceipt(t *testing.T) {
// it's address is closer to the chunk than secondPeer but it will not receive the chunk
// it's address is closer to the chunk than secondPeer but it will not receive the chunk
psEmpty
,
storerEmpty
,
_
,
_
:=
createPushSyncNode
(
t
,
emptyPeer
,
defaultPrices
,
nil
,
nil
,
defaultSigner
)
psEmpty
,
storerEmpty
,
_
,
_
:=
createPushSyncNode
(
t
,
emptyPeer
,
defaultPrices
,
nil
,
nil
,
defaultSigner
)
defer
storerEmpty
.
Close
()
defer
storerEmpty
.
Close
()
emptyRecorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psEmpty
.
Protocol
()),
streamtest
.
WithBaseAddr
(
secondPeer
))
emptyRecorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psEmpty
.
Protocol
()),
streamtest
.
WithBaseAddr
(
secondPeer
))
// node that is connected to closestPeer
// node that is connected to closestPeer
// will receieve chunk from closestPeer
// will receieve chunk from closestPeer
psSecond
,
storerSecond
,
_
,
secondAccounting
:=
createPushSyncNode
(
t
,
secondPeer
,
defaultPrices
,
emptyRecorder
,
nil
,
defaultSigner
,
mock
.
WithPeers
(
emptyPeer
),
WithinDepthMock
)
psSecond
,
storerSecond
,
_
,
secondAccounting
:=
createPushSyncNode
(
t
,
secondPeer
,
defaultPrices
,
emptyRecorder
,
nil
,
defaultSigner
,
mock
.
WithPeers
(
emptyPeer
),
WithinDepthMock
)
defer
storerSecond
.
Close
()
defer
storerSecond
.
Close
()
secondRecorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psSecond
.
Protocol
()),
streamtest
.
WithBaseAddr
(
closestPeer
))
secondRecorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psSecond
.
Protocol
()),
streamtest
.
WithBaseAddr
(
closestPeer
))
psStorer
,
storerPeer
,
_
,
storerAccounting
:=
createPushSyncNode
(
t
,
closestPeer
,
defaultPrices
,
secondRecorder
,
nil
,
defaultSigner
,
mock
.
WithPeers
(
secondPeer
),
mock
.
WithClosestPeerErr
(
topology
.
ErrWantSelf
),
WithinDepthMock
)
psStorer
,
storerPeer
,
_
,
storerAccounting
:=
createPushSyncNode
(
t
,
closestPeer
,
defaultPrices
,
secondRecorder
,
nil
,
defaultSigner
,
mock
.
WithPeers
(
secondPeer
),
mock
.
WithClosestPeerErr
(
topology
.
ErrWantSelf
),
WithinDepthMock
)
defer
storerPeer
.
Close
()
defer
storerPeer
.
Close
()
recorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psStorer
.
Protocol
()),
streamtest
.
WithBaseAddr
(
pivotNode
))
recorder
:=
streamtest
.
New
(
streamtest
.
WithProtocols
(
psStorer
.
Protocol
()),
streamtest
.
WithBaseAddr
(
pivotNode
))
// pivot node needs the streamer since the chunk is intercepted by
// pivot node needs the streamer since the chunk is intercepted by
...
@@ -163,9 +166,6 @@ func TestReplicateBeforeReceipt(t *testing.T) {
...
@@ -163,9 +166,6 @@ func TestReplicateBeforeReceipt(t *testing.T) {
// this intercepts the incoming receipt message
// this intercepts the incoming receipt message
waitOnRecordAndTest
(
t
,
closestPeer
,
recorder
,
chunk
.
Address
(),
nil
)
waitOnRecordAndTest
(
t
,
closestPeer
,
recorder
,
chunk
.
Address
(),
nil
)
// sleep for a bit to allow the second peer to the store replicated chunk
time
.
Sleep
(
time
.
Millisecond
*
500
)
// this intercepts the outgoing delivery message from storer node to second storer node
// this intercepts the outgoing delivery message from storer node to second storer node
waitOnRecordAndTest
(
t
,
secondPeer
,
secondRecorder
,
chunk
.
Address
(),
chunk
.
Data
())
waitOnRecordAndTest
(
t
,
secondPeer
,
secondRecorder
,
chunk
.
Address
(),
chunk
.
Data
())
...
@@ -262,9 +262,6 @@ func TestFailToReplicateBeforeReceipt(t *testing.T) {
...
@@ -262,9 +262,6 @@ func TestFailToReplicateBeforeReceipt(t *testing.T) {
// this intercepts the incoming receipt message
// this intercepts the incoming receipt message
waitOnRecordAndTest
(
t
,
closestPeer
,
recorder
,
chunk
.
Address
(),
nil
)
waitOnRecordAndTest
(
t
,
closestPeer
,
recorder
,
chunk
.
Address
(),
nil
)
// sleep for a bit to allow the second peer to the store replicated chunk
time
.
Sleep
(
time
.
Millisecond
*
500
)
// this intercepts the outgoing delivery message from storer node to second storer node
// this intercepts the outgoing delivery message from storer node to second storer node
waitOnRecordAndTest
(
t
,
secondPeer
,
secondRecorder
,
chunk
.
Address
(),
chunk
.
Data
())
waitOnRecordAndTest
(
t
,
secondPeer
,
secondRecorder
,
chunk
.
Address
(),
chunk
.
Data
())
...
@@ -929,7 +926,7 @@ func createPushSyncNodeWithAccounting(t *testing.T, addr swarm.Address, prices p
...
@@ -929,7 +926,7 @@ func createPushSyncNodeWithAccounting(t *testing.T, addr swarm.Address, prices p
return
ch
,
nil
return
ch
,
nil
}
}
return
pushsync
.
New
(
addr
,
blockHash
.
Bytes
(),
recorderDisconnecter
,
storer
,
mockTopology
,
mtag
,
true
,
unwrap
,
validStamp
,
logger
,
acct
,
mockPricer
,
signer
,
nil
,
0
),
storer
,
mtag
return
pushsync
.
New
(
addr
,
blockHash
.
Bytes
(),
recorderDisconnecter
,
storer
,
mockTopology
,
mtag
,
true
,
unwrap
,
validStamp
,
logger
,
acct
,
mockPricer
,
signer
,
nil
,
-
1
),
storer
,
mtag
}
}
func
waitOnRecordAndTest
(
t
*
testing
.
T
,
peer
swarm
.
Address
,
recorder
*
streamtest
.
Recorder
,
add
swarm
.
Address
,
data
[]
byte
)
{
func
waitOnRecordAndTest
(
t
*
testing
.
T
,
peer
swarm
.
Address
,
recorder
*
streamtest
.
Recorder
,
add
swarm
.
Address
,
data
[]
byte
)
{
...
...
pkg/topology/mock/mock.go
View file @
36efbe0e
...
@@ -107,7 +107,7 @@ func (d *mock) Peers() []swarm.Address {
...
@@ -107,7 +107,7 @@ func (d *mock) Peers() []swarm.Address {
return
d
.
peers
return
d
.
peers
}
}
func
(
d
*
mock
)
ClosestPeer
(
addr
swarm
.
Address
,
_
bool
,
skipPeers
...
swarm
.
Address
)
(
peerAddr
swarm
.
Address
,
err
error
)
{
func
(
d
*
mock
)
ClosestPeer
(
addr
swarm
.
Address
,
wantSelf
bool
,
skipPeers
...
swarm
.
Address
)
(
peerAddr
swarm
.
Address
,
err
error
)
{
if
len
(
skipPeers
)
==
0
{
if
len
(
skipPeers
)
==
0
{
if
d
.
closestPeerErr
!=
nil
{
if
d
.
closestPeerErr
!=
nil
{
return
d
.
closestPeer
,
d
.
closestPeerErr
return
d
.
closestPeer
,
d
.
closestPeerErr
...
@@ -147,8 +147,13 @@ func (d *mock) ClosestPeer(addr swarm.Address, _ bool, skipPeers ...swarm.Addres
...
@@ -147,8 +147,13 @@ func (d *mock) ClosestPeer(addr swarm.Address, _ bool, skipPeers ...swarm.Addres
}
}
if
peerAddr
.
IsZero
()
{
if
peerAddr
.
IsZero
()
{
if
wantSelf
{
return
peerAddr
,
topology
.
ErrWantSelf
}
else
{
return
peerAddr
,
topology
.
ErrNotFound
return
peerAddr
,
topology
.
ErrNotFound
}
}
}
return
peerAddr
,
nil
return
peerAddr
,
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment