Skip to content

Commit

Permalink
added bytes flushed
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Jul 21, 2024
1 parent 4838a83 commit db0b955
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
5 changes: 5 additions & 0 deletions conn_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ConnStats struct {
BytesReadUsefulIntendedData Count

BytesHashed Count
BytesFlushed Count
BytesCompleted Count

ChunksWritten Count
Expand Down Expand Up @@ -95,6 +96,10 @@ func (cs *ConnStats) pieceCompleted(size int64) {
cs.BytesCompleted.Add(size)
}

func (cs *ConnStats) pieceFlushed(size int64) {
cs.BytesFlushed.Add(size)
}

func (cs *ConnStats) incrementPiecesDirtiedGood() {
cs.PiecesDirtiedGood.Add(1)
}
Expand Down
21 changes: 8 additions & 13 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2634,26 +2634,21 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {

hasDirtyChunks := p.hasDirtyChunks(true)

var err error

if hasDirtyChunks {
p.Flush(func(size int64) {
t.allStats(func(cs *ConnStats) {
cs.pieceCompleted(size)
cs.pieceFlushed(size)
})
})

err = p.Storage().MarkComplete(true)
} else {
err = p.Storage().MarkComplete(!hasDirtyChunks)
if err == nil {
t.allStats(func(cs *ConnStats) {
cs.pieceCompleted(int64(p.length(true)))
})
}
}

if err != nil {
err := p.Storage().MarkComplete(!hasDirtyChunks)

if err == nil {
t.allStats(func(cs *ConnStats) {
cs.pieceCompleted(int64(p.length(true)))
})
} else {
t.logger.Levelf(log.Warning, "%T: error marking piece complete %d: %s", t.storage, piece, err)
}

Expand Down

0 comments on commit db0b955

Please sign in to comment.