]> Sergey Matveev's repositories - btrtrc.git/commitdiff
cherry-pick v1.52.8-beta
authorMark Holt <mark@distributed.vision>
Sat, 20 Apr 2024 07:17:09 +0000 (08:17 +0100)
committeralex.sharov <AskAlexSharov@gmail.com>
Thu, 25 Apr 2024 05:03:06 +0000 (12:03 +0700)
requesting.go

index 8b9db971b537630e65dd41ca9618f8a708f6a698..117d447b883a56db7e15194e9737e2160a83177b 100644 (file)
@@ -266,13 +266,25 @@ func (p *Peer) applyRequestState(next desiredRequestState) {
        }
        for requestHeap.Len() != 0 && maxRequests(current.Requests.GetCardinality()+current.Cancelled.GetCardinality()) < p.nominalMaxRequests() {
                req := heap.Pop(requestHeap)
+               if cap(next.Requests.requestIndexes) != cap(orig) {
+                       panic("changed")
+               }
+
+               if p.needRequestUpdate == "Peer.remoteRejectedRequest" {
+                       continue
+               }
+
                existing := t.requestingPeer(req)
                if existing != nil && existing != p {
+                       if p.needRequestUpdate == "Peer.cancel" {
+                               continue
+                       }
+
                        // Don't steal from the poor.
                        diff := int64(current.Requests.GetCardinality()) + 1 - (int64(existing.uncancelledRequests()) - 1)
                        // Steal a request that leaves us with one more request than the existing peer
                        // connection if the stealer more recently received a chunk.
-                       if diff > 1 || (diff == 1 && p.lastUsefulChunkReceived.Before(existing.lastUsefulChunkReceived)) {
+                       if diff > 1 || (diff == 1 && !p.lastUsefulChunkReceived.After(existing.lastUsefulChunkReceived)) {
                                continue
                        }
                        t.cancelRequest(req)