mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-23 07:08:24 +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) {
|
func TestActivityMap(t *testing.T) {
|
||||||
|
isValid := func(protocol.NodeID) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
m := make(activityMap)
|
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)
|
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)
|
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)
|
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)
|
t.Errorf("Incorrect least busy node %q", node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ type openFile struct {
|
|||||||
|
|
||||||
type activityMap map[protocol.NodeID]int
|
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 low int = 2<<30 - 1
|
||||||
var selected protocol.NodeID
|
var selected protocol.NodeID
|
||||||
for _, node := range availability {
|
for _, node := range availability {
|
||||||
usage := m[node]
|
usage := m[node]
|
||||||
if usage < low {
|
if usage < low && isValid(node) {
|
||||||
low = usage
|
low = usage
|
||||||
selected = node
|
selected = node
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ func (p *puller) handleRequestBlock(b bqBlock) bool {
|
|||||||
panic("bug: request for non-open file")
|
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{}) {
|
if node == (protocol.NodeID{}) {
|
||||||
of.err = errNoNode
|
of.err = errNoNode
|
||||||
if of.file != nil {
|
if of.file != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user