Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
fix redundancy for multiple erasure codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jul 3, 2018
1 parent 3ac1266 commit 1d58da8
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions modules/renter/siafile/siafile.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"math"
"os"
"sync"

Expand Down Expand Up @@ -216,8 +217,8 @@ func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[st
return -1
}

minPiecesRenew := ^uint64(0)
minPiecesNoRenew := ^uint64(0)
minRedundancy := math.MaxFloat64
minRedundancyNoRenew := math.MaxFloat64
for _, chunk := range sf.staticChunks {
// Loop over chunks and remember how many unique pieces of the chunk
// were goodForRenew and how many were not.
Expand Down Expand Up @@ -254,13 +255,13 @@ func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[st
numPiecesNoRenew++
}
}
// Remember the smallest number of goodForRenew pieces encountered.
if numPiecesRenew < minPiecesRenew {
minPiecesRenew = numPiecesRenew
redundancy := float64(numPiecesRenew) / float64(chunk.staticErasureCode.MinPieces())
if redundancy < minRedundancy {
minRedundancy = redundancy
}
// Remember the smallest number of !goodForRenew pieces encountered.
if numPiecesNoRenew < minPiecesNoRenew {
minPiecesNoRenew = numPiecesNoRenew
redundancyNoRenew := float64(numPiecesNoRenew) / float64(chunk.staticErasureCode.MinPieces())
if redundancyNoRenew < minRedundancyNoRenew {
minRedundancyNoRenew = redundancyNoRenew
}
}

Expand All @@ -269,12 +270,10 @@ func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[st
// a better user experience. If the renter operates correctly, redundancy
// should never go above numPieces / minPieces and redundancyNoRenew should
// never go below 1.
redundancy := float64(minPiecesRenew) / float64(sf.staticChunks[0].staticErasureCode.MinPieces()) // TODO this shouldn't be chunks[0]
redundancyNoRenew := float64(minPiecesNoRenew) / float64(sf.staticChunks[0].staticErasureCode.MinPieces()) //TODO this shouldn't be chunks[0]
if redundancy < 1 {
return redundancyNoRenew
if minRedundancy < 1 {
return minRedundancyNoRenew
}
return redundancy
return minRedundancy
}

// UID returns a unique identifier for this file.
Expand Down

0 comments on commit 1d58da8

Please sign in to comment.