From: Matt Joiner Date: Mon, 2 Nov 2020 23:41:47 +0000 (+1100) Subject: Update the readahead window on read failure X-Git-Tag: v1.19.0~47 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=94efdbbded88b7a30b0ce37febe359273d093145;p=btrtrc.git Update the readahead window on read failure --- diff --git a/reader.go b/reader.go index a6a5bc61..8610910d 100644 --- a/reader.go +++ b/reader.go @@ -3,6 +3,7 @@ package torrent import ( "context" "errors" + "fmt" "io" "sync" @@ -230,6 +231,15 @@ func (r *reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err erro if !r.t.updatePieceCompletion(firstPieceIndex) { r.log(log.Fstr("piece %d completion unchanged", firstPieceIndex)) } + // Update the rest of the piece completions in the readahead window, without alerting to + // changes (since only the first piece, the one above, could have generated the read error + // we're currently handling). + if r.pieces.begin != firstPieceIndex { + panic(fmt.Sprint(r.pieces.begin, firstPieceIndex)) + } + for index := r.pieces.begin + 1; index < r.pieces.end; index++ { + r.t.updatePieceCompletion(index) + } r.t.cl.unlock() } }