Skip to content

Commit

Permalink
cli: refactor search of first full batch of blocks in util upload-bin
Browse files Browse the repository at this point in the history
As we put the results of a search in corresponding to batch results[i].
We can not finish the check as soon as we find the full batch, all
errors should be checked.

Ref #3634

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Oct 21, 2024
1 parent 29bb3ff commit 7f1ac43
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cli/util/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ type searchResult struct {
// starting from the currentHeight and going backwards.
func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID cid.ID, priv *keys.PrivateKey, attributeKey string, currentHeight int) (int, error) {
var (
wg sync.WaitGroup
numBatches = currentHeight/searchBatchSize + 1
emptyBatchFound bool
wg sync.WaitGroup
numBatches = currentHeight/searchBatchSize + 1
lastFullBatchEnd = 0
)

for batch := numBatches; batch > -maxParallelSearches; batch -= maxParallelSearches {
Expand Down Expand Up @@ -266,21 +266,17 @@ func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID
}(i, startIndex, endIndex)
}
wg.Wait()

//results is sorted so we can iterate from the end to find the last full batch.
for i := len(results) - 1; i >= 0; i-- {
if results[i].err != nil {
return 0, fmt.Errorf("search of index files failed for batch with indexes from %d to %d: %w", results[i].startIndex, results[i].endIndex-1, results[i].err)
}
if results[i].numOIDs < searchBatchSize {
emptyBatchFound = true
continue
}
if emptyBatchFound || (batch == numBatches && i == len(results)-1) {
return results[i].startIndex + searchBatchSize, nil
if results[i].numOIDs == searchBatchSize {
lastFullBatchEnd = max(lastFullBatchEnd, results[i].endIndex)
}
}
}
return 0, nil
return lastFullBatchEnd, nil
}

// updateIndexFiles updates the index files in the container.
Expand Down

0 comments on commit 7f1ac43

Please sign in to comment.