mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Handle disconnected nodes better in puller
This commit is contained in:
parent
75d4d2df8b
commit
0fcc193197
@ -242,17 +242,20 @@ func BenchmarkRequest(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestActivityMap(t *testing.T) {
|
||||
isValid := func(protocol.NodeID) bool {
|
||||
return true
|
||||
}
|
||||
m := make(activityMap)
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1}); node != node1 {
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1}, isValid); node != node1 {
|
||||
t.Errorf("Incorrect least busy node %q", node)
|
||||
}
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node2}); node != node2 {
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node2}, isValid); node != node2 {
|
||||
t.Errorf("Incorrect least busy node %q", node)
|
||||
}
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1, node2}); node != node1 {
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1, node2}, isValid); node != node1 {
|
||||
t.Errorf("Incorrect least busy node %q", node)
|
||||
}
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1, node2}); node != node2 {
|
||||
if node := m.leastBusyNode([]protocol.NodeID{node1, node2}, isValid); node != node2 {
|
||||
t.Errorf("Incorrect least busy node %q", node)
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ type openFile struct {
|
||||
|
||||
type activityMap map[protocol.NodeID]int
|
||||
|
||||
func (m activityMap) leastBusyNode(availability []protocol.NodeID) protocol.NodeID {
|
||||
func (m activityMap) leastBusyNode(availability []protocol.NodeID, isValid func(protocol.NodeID) bool) protocol.NodeID {
|
||||
var low int = 2<<30 - 1
|
||||
var selected protocol.NodeID
|
||||
for _, node := range availability {
|
||||
usage := m[node]
|
||||
if usage < low {
|
||||
if usage < low && isValid(node) {
|
||||
low = usage
|
||||
selected = node
|
||||
}
|
||||
@ -533,7 +533,7 @@ func (p *puller) handleRequestBlock(b bqBlock) bool {
|
||||
panic("bug: request for non-open file")
|
||||
}
|
||||
|
||||
node := p.oustandingPerNode.leastBusyNode(of.availability)
|
||||
node := p.oustandingPerNode.leastBusyNode(of.availability, p.model.ConnectedTo)
|
||||
if node == (protocol.NodeID{}) {
|
||||
of.err = errNoNode
|
||||
if of.file != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user