Browse Source

Handle disconnected nodes better in puller

Jakob Borg 11 years ago
parent
commit
0fcc193197
2 changed files with 10 additions and 7 deletions
  1. 7 4
      model/model_test.go
  2. 3 3
      model/puller.go

+ 7 - 4
model/model_test.go

@@ -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)
 	}
 	}
 }
 }

+ 3 - 3
model/puller.go

@@ -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 {