cli: fix fetchLatestMissingBlockIndex in upload-bin command

Close #3667

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-11-15 02:18:13 +03:00
parent c2b4d32224
commit 6e863e9a06

View file

@ -185,7 +185,7 @@ type searchResult struct {
func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID cid.ID, priv *keys.PrivateKey, attributeKey string, currentHeight int, maxParallelSearches, maxRetries int) (int, error) { func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID cid.ID, priv *keys.PrivateKey, attributeKey string, currentHeight int, maxParallelSearches, maxRetries int) (int, error) {
var ( var (
wg sync.WaitGroup wg sync.WaitGroup
numBatches = currentHeight/searchBatchSize + 1 numBatches = currentHeight / searchBatchSize
emptyBatchFound bool emptyBatchFound bool
) )
@ -228,12 +228,12 @@ func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID
if results[i].err != nil { if results[i].err != nil {
return 0, fmt.Errorf("blocks search failed for batch with indexes from %d to %d: %w", results[i].startIndex, results[i].endIndex-1, results[i].err) return 0, fmt.Errorf("blocks search 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 { if results[i].numOIDs == 0 {
emptyBatchFound = true emptyBatchFound = true
continue continue
} }
if emptyBatchFound || (batch == numBatches && i == len(results)-1) { if emptyBatchFound || (batch == numBatches && i == len(results)-1) {
return results[i].startIndex + searchBatchSize, nil return results[i].startIndex, nil
} }
} }
} }