Skip to content

Commit

Permalink
Merge pull request #1236 from giuseppe/correctly-recreate-request-par…
Browse files Browse the repository at this point in the history
…tial-pulls

chunked: recalculate correctly the chunks to request
  • Loading branch information
flouthoc authored May 11, 2022
2 parents 10d3891 + 75fd4d6 commit 1ec5cc8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/chunked/storage_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ func (c *chunkedDiffer) storeMissingFiles(streams chan io.ReadCloser, errs chan
case p := <-streams:
part = p
case err := <-errs:
if err == nil {
return errors.New("not enough data returned from the server")
}
return err
}
if part == nil {
Expand Down Expand Up @@ -1081,12 +1084,18 @@ func mergeMissingChunks(missingParts []missingPart, target int) []missingPart {

func (c *chunkedDiffer) retrieveMissingFiles(dest string, dirfd int, missingParts []missingPart, options *archive.TarOptions) error {
var chunksToRequest []ImageSourceChunk
for _, c := range missingParts {
if c.OriginFile == nil && !c.Hole {
chunksToRequest = append(chunksToRequest, *c.SourceChunk)

calculateChunksToRequest := func() {
chunksToRequest = []ImageSourceChunk{}
for _, c := range missingParts {
if c.OriginFile == nil && !c.Hole {
chunksToRequest = append(chunksToRequest, *c.SourceChunk)
}
}
}

calculateChunksToRequest()

// There are some missing files. Prepare a multirange request for the missing chunks.
var streams chan io.ReadCloser
var err error
Expand All @@ -1106,6 +1115,7 @@ func (c *chunkedDiffer) retrieveMissingFiles(dest string, dirfd int, missingPart

// Merge more chunks to request
missingParts = mergeMissingChunks(missingParts, requested/2)
calculateChunksToRequest()
continue
}
return err
Expand Down Expand Up @@ -1575,6 +1585,8 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions) (gra
wg.Wait()

for _, res := range copyResults[:filesToWaitFor] {
r := &mergedEntries[res.index]

if res.err != nil {
return output, res.err
}
Expand All @@ -1584,8 +1596,6 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions) (gra
continue
}

r := &mergedEntries[res.index]

missingPartsSize += r.Size

remainingSize := r.Size
Expand Down

0 comments on commit 1ec5cc8

Please sign in to comment.