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
8d961da1
Unverified
Commit
8d961da1
authored
May 28, 2021
by
acud
Committed by
GitHub
May 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: improve puller cancellations (#1890)
parent
0ce90358
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
puller.go
pkg/puller/puller.go
+23
-24
No files found.
pkg/puller/puller.go
View file @
8d961da1
...
...
@@ -134,14 +134,15 @@ func (p *Puller) manage() {
// way that it returns an error - the value must be checked.
_
=
p
.
topology
.
EachPeerRev
(
func
(
peerAddr
swarm
.
Address
,
po
uint8
)
(
stop
,
jumpToNext
bool
,
err
error
)
{
bp
:=
p
.
syncPeers
[
po
]
if
_
,
ok
:=
bp
[
peerAddr
.
String
()];
ok
{
delete
(
peersDisconnected
,
peerAddr
.
String
())
}
if
po
>=
depth
{
// delete from peersDisconnected since we'd like to sync
// with this peer
delete
(
peersDisconnected
,
peerAddr
.
ByteString
())
// within depth, sync everything
if
_
,
ok
:=
bp
[
peerAddr
.
String
()];
!
ok
{
if
_
,
ok
:=
bp
[
peerAddr
.
Byte
String
()];
!
ok
{
// we're not syncing with this peer yet, start doing so
bp
[
peerAddr
.
String
()]
=
newSyncPeer
(
peerAddr
,
p
.
bins
)
bp
[
peerAddr
.
Byte
String
()]
=
newSyncPeer
(
peerAddr
,
p
.
bins
)
peerEntry
:=
peer
{
addr
:
peerAddr
,
po
:
po
}
peersToSync
=
append
(
peersToSync
,
peerEntry
)
}
else
{
...
...
@@ -149,14 +150,12 @@ func (p *Puller) manage() {
peerEntry
:=
peer
{
addr
:
peerAddr
,
po
:
po
}
peersToRecalc
=
append
(
peersToRecalc
,
peerEntry
)
}
}
else
{
if
_
,
ok
:=
bp
[
peerAddr
.
String
()];
ok
{
// already syncing, recalc so that existing streams get cleaned up
peerEntry
:=
peer
{
addr
:
peerAddr
,
po
:
po
}
peersToRecalc
=
append
(
peersToRecalc
,
peerEntry
)
}
}
// if peer is outside of depth, do nothing here, this
// will cause the peer to stay in the peersDisconnected
// map, leading to cancelling of its running syncing contexts.
return
false
,
false
,
nil
})
...
...
@@ -171,13 +170,13 @@ func (p *Puller) manage() {
// stopgap solution for peers that dont return the correct
// amount of cursors we expect
if
dontSync
{
peersDisconnected
[
v
.
addr
.
String
()]
=
v
peersDisconnected
[
v
.
addr
.
Byte
String
()]
=
v
}
}
p
.
syncPeersMtx
.
Lock
()
for
_
,
v
:=
range
peersDisconnected
{
p
.
disconnectPeer
(
ctx
,
v
.
addr
,
v
.
po
)
p
.
disconnectPeer
(
v
.
addr
,
v
.
po
)
}
p
.
syncPeersMtx
.
Unlock
()
...
...
@@ -187,15 +186,15 @@ func (p *Puller) manage() {
}
}
func
(
p
*
Puller
)
disconnectPeer
(
ctx
context
.
Context
,
peer
swarm
.
Address
,
po
uint8
)
{
func
(
p
*
Puller
)
disconnectPeer
(
peer
swarm
.
Address
,
po
uint8
)
{
if
logMore
{
p
.
logger
.
Debugf
(
"puller disconnect cleanup peer %s po %d"
,
peer
,
po
)
}
if
syncCtx
,
ok
:=
p
.
syncPeers
[
po
][
peer
.
String
()];
ok
{
if
syncCtx
,
ok
:=
p
.
syncPeers
[
po
][
peer
.
Byte
String
()];
ok
{
// disconnectPeer is called under lock, this is safe
syncCtx
.
gone
()
}
delete
(
p
.
syncPeers
[
po
],
peer
.
String
())
delete
(
p
.
syncPeers
[
po
],
peer
.
Byte
String
())
}
func
(
p
*
Puller
)
recalcPeer
(
ctx
context
.
Context
,
peer
swarm
.
Address
,
po
,
d
uint8
)
(
dontSync
bool
)
{
...
...
@@ -204,14 +203,14 @@ func (p *Puller) recalcPeer(ctx context.Context, peer swarm.Address, po, d uint8
}
p
.
syncPeersMtx
.
Lock
()
syncCtx
:=
p
.
syncPeers
[
po
][
peer
.
String
()]
syncCtx
:=
p
.
syncPeers
[
po
][
peer
.
Byte
String
()]
p
.
syncPeersMtx
.
Unlock
()
syncCtx
.
Lock
()
defer
syncCtx
.
Unlock
()
p
.
cursorsMtx
.
Lock
()
c
:=
p
.
cursors
[
peer
.
String
()]
c
:=
p
.
cursors
[
peer
.
Byte
String
()]
p
.
cursorsMtx
.
Unlock
()
if
len
(
c
)
!=
int
(
p
.
bins
)
{
...
...
@@ -252,14 +251,14 @@ func (p *Puller) recalcPeer(ctx context.Context, peer swarm.Address, po, d uint8
func
(
p
*
Puller
)
syncPeer
(
ctx
context
.
Context
,
peer
swarm
.
Address
,
po
,
d
uint8
)
{
p
.
syncPeersMtx
.
Lock
()
syncCtx
:=
p
.
syncPeers
[
po
][
peer
.
String
()]
syncCtx
:=
p
.
syncPeers
[
po
][
peer
.
Byte
String
()]
p
.
syncPeersMtx
.
Unlock
()
syncCtx
.
Lock
()
defer
syncCtx
.
Unlock
()
p
.
cursorsMtx
.
Lock
()
c
,
ok
:=
p
.
cursors
[
peer
.
String
()]
c
,
ok
:=
p
.
cursors
[
peer
.
Byte
String
()]
p
.
cursorsMtx
.
Unlock
()
if
!
ok
{
...
...
@@ -269,7 +268,7 @@ func (p *Puller) syncPeer(ctx context.Context, peer swarm.Address, po, d uint8)
p
.
logger
.
Debugf
(
"could not get cursors from peer %s: %v"
,
peer
.
String
(),
err
)
}
p
.
syncPeersMtx
.
Lock
()
delete
(
p
.
syncPeers
[
po
],
peer
.
String
())
delete
(
p
.
syncPeers
[
po
],
peer
.
Byte
String
())
p
.
syncPeersMtx
.
Unlock
()
return
...
...
@@ -277,7 +276,7 @@ func (p *Puller) syncPeer(ctx context.Context, peer swarm.Address, po, d uint8)
// maybe blacklist for some time
}
p
.
cursorsMtx
.
Lock
()
p
.
cursors
[
peer
.
String
()]
=
cursors
p
.
cursors
[
peer
.
Byte
String
()]
=
cursors
p
.
cursorsMtx
.
Unlock
()
c
=
cursors
}
...
...
@@ -286,7 +285,7 @@ func (p *Puller) syncPeer(ctx context.Context, peer swarm.Address, po, d uint8)
// what we expect it to be - dont do anything
if
len
(
c
)
!=
int
(
p
.
bins
)
{
p
.
syncPeersMtx
.
Lock
()
delete
(
p
.
syncPeers
[
po
],
peer
.
String
())
delete
(
p
.
syncPeers
[
po
],
peer
.
Byte
String
())
p
.
syncPeersMtx
.
Unlock
()
return
}
...
...
@@ -543,7 +542,7 @@ func isSyncing(p *Puller, addr swarm.Address) bool {
defer
p
.
syncPeersMtx
.
Unlock
()
for
_
,
bin
:=
range
p
.
syncPeers
{
for
peer
:=
range
bin
{
if
addr
.
String
()
==
peer
{
if
addr
.
Byte
String
()
==
peer
{
return
true
}
}
...
...
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