Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/file/redundancy/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
var (
errStrategyNotAllowed = errors.New("strategy not allowed")
errStrategyFailed = errors.New("strategy failed")
errShouldNeverHappen = errors.New("should never happen")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a sort of defensive programming that suggests that the code does not do proper error handling. if one cannot reason about values that function calls return, you end up in this sort of situation. i am approving just because i trust that the scope of the change is known (but also because this package is completely unreadable to me)

)

// decoder is a private implementation of storage.Getter
Expand Down Expand Up @@ -240,16 +241,24 @@ func (g *decoder) runStrategy(s Strategy) error {
c := make(chan error, len(m))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
completed := 0
defer func() {
cancel()
remaining := len(m) - completed
for i := 0; i < remaining; i++ {
<-c
}
}()

for _, i := range m {
go func(i int) {
c <- g.fetch(ctx, i, false)
}(i)
}

for range len(m) {
for completed < len(m) {
<-c
completed++
if g.fetchedCnt.Load() >= int32(g.shardCnt) {
return nil
}
Expand All @@ -258,7 +267,7 @@ func (g *decoder) runStrategy(s Strategy) error {
}
}

return errStrategyFailed
return errShouldNeverHappen
}

// recover wraps the stages of data shard recovery:
Expand Down
Loading