@@ -91,7 +91,7 @@ func uploadBin(ctx *cli.Context) error {
91
91
var errNet error
92
92
net , errNet = p .NetworkInfo (ctx .Context , client.PrmNetworkInfo {})
93
93
return errNet
94
- }, maxRetries )
94
+ }, maxRetries , debug )
95
95
if err != nil {
96
96
return cli .Exit (fmt .Errorf ("failed to get network info: %w" , err ), 1 )
97
97
}
@@ -101,7 +101,7 @@ func uploadBin(ctx *cli.Context) error {
101
101
err = retry (func () error {
102
102
containerObj , err = p .ContainerGet (ctx .Context , containerID , client.PrmContainerGet {})
103
103
return err
104
- }, maxRetries )
104
+ }, maxRetries , debug )
105
105
if err != nil {
106
106
return cli .Exit (fmt .Errorf ("failed to get container with ID %s: %w" , containerID , err ), 1 )
107
107
}
@@ -121,7 +121,7 @@ func uploadBin(ctx *cli.Context) error {
121
121
return cli .Exit (fmt .Sprintf ("failed to get current block height from RPC: %v" , err ), 1 )
122
122
}
123
123
fmt .Fprintln (ctx .App .Writer , "Chain block height:" , currentBlockHeight )
124
- i , buf , err := searchIndexFile (ctx , pWrapper , containerID , acc , signer , indexFileSize , attr , indexAttrKey , maxParallelSearches , maxRetries )
124
+ i , buf , err := searchIndexFile (ctx , pWrapper , containerID , acc , signer , indexFileSize , attr , indexAttrKey , maxParallelSearches , maxRetries , debug )
125
125
if err != nil {
126
126
return cli .Exit (fmt .Errorf ("failed to find objects: %w" , err ), 1 )
127
127
}
@@ -134,13 +134,16 @@ func uploadBin(ctx *cli.Context) error {
134
134
}
135
135
136
136
// retry function with exponential backoff.
137
- func retry (action func () error , maxRetries uint ) error {
137
+ func retry (action func () error , maxRetries uint , debug bool ) error {
138
138
var err error
139
139
backoff := neofs .InitialBackoff
140
- for range maxRetries {
140
+ for i := range maxRetries {
141
141
if err = action (); err == nil {
142
142
return nil // Success, no retry needed.
143
143
}
144
+ if debug {
145
+ fmt .Printf ("Retry %d: %v\n " , i , err )
146
+ }
144
147
time .Sleep (backoff ) // Backoff before retrying.
145
148
backoff *= time .Duration (neofs .BackoffFactor )
146
149
if backoff > neofs .MaxBackoff {
@@ -185,7 +188,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
185
188
return fmt .Errorf ("failed to fetch block %d: %w" , blockIndex , errGetBlock )
186
189
}
187
190
return nil
188
- }, maxRetries )
191
+ }, maxRetries , debug )
189
192
if errGet != nil {
190
193
select {
191
194
case errCh <- errGet :
@@ -225,7 +228,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
225
228
fmt .Fprintf (ctx .App .Writer , "Uploaded block %d with object ID: %s\n " , blockIndex , resOid .String ())
226
229
}
227
230
return errUpload
228
- }, maxRetries )
231
+ }, maxRetries , debug )
229
232
if errRetr != nil {
230
233
select {
231
234
case errCh <- errRetr :
@@ -265,7 +268,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
265
268
var errUpload error
266
269
_ , errUpload = uploadObj (ctx .Context , p , signer , acc .PrivateKey ().GetScriptHash (), containerID , buf , attrs , homomorphicHashingDisabled )
267
270
return errUpload
268
- }, maxRetries )
271
+ }, maxRetries , debug )
269
272
if err != nil {
270
273
return fmt .Errorf ("failed to upload index file: %w" , err )
271
274
}
@@ -277,7 +280,7 @@ func uploadBlocksAndIndexFiles(ctx *cli.Context, p poolWrapper, rpc *rpcclient.C
277
280
}
278
281
279
282
// searchIndexFile returns the ID and buffer for the next index file to be uploaded.
280
- func searchIndexFile (ctx * cli.Context , p poolWrapper , containerID cid.ID , account * wallet.Account , signer user.Signer , indexFileSize uint , blockAttributeKey , attributeKey string , maxParallelSearches , maxRetries uint ) (uint , []byte , error ) {
283
+ func searchIndexFile (ctx * cli.Context , p poolWrapper , containerID cid.ID , account * wallet.Account , signer user.Signer , indexFileSize uint , blockAttributeKey , attributeKey string , maxParallelSearches , maxRetries uint , debug bool ) (uint , []byte , error ) {
281
284
var (
282
285
// buf is used to store OIDs of the uploaded blocks.
283
286
buf = make ([]byte , indexFileSize * neofs .OIDSize )
@@ -292,7 +295,7 @@ func searchIndexFile(ctx *cli.Context, p poolWrapper, containerID cid.ID, accoun
292
295
// Search for existing index files.
293
296
filters .AddFilter ("IndexSize" , fmt .Sprintf ("%d" , indexFileSize ), object .MatchStringEqual )
294
297
for i := 0 ; ; i ++ {
295
- indexIDs := searchObjects (ctx .Context , p , containerID , account , attributeKey , uint (i ), uint (i + 1 ), 1 , maxRetries , errCh , filters )
298
+ indexIDs := searchObjects (ctx .Context , p , containerID , account , attributeKey , uint (i ), uint (i + 1 ), 1 , maxRetries , debug , errCh , filters )
296
299
count := 0
297
300
for range indexIDs {
298
301
count ++
@@ -329,7 +332,7 @@ func searchIndexFile(ctx *cli.Context, p poolWrapper, containerID cid.ID, accoun
329
332
var errGet error
330
333
obj , _ , errGet = p .ObjectGetInit (ctx .Context , containerID , id , signer , client.PrmObjectGet {})
331
334
return errGet
332
- }, maxRetries )
335
+ }, maxRetries , debug )
333
336
if errRetr != nil {
334
337
select {
335
338
case errCh <- fmt .Errorf ("failed to fetch object %s: %w" , id .String (), errRetr ):
@@ -354,7 +357,7 @@ func searchIndexFile(ctx *cli.Context, p poolWrapper, containerID cid.ID, accoun
354
357
}
355
358
356
359
// Search for blocks within the index file range.
357
- objIDs := searchObjects (ctx .Context , p , containerID , account , blockAttributeKey , existingIndexCount * indexFileSize , (existingIndexCount + 1 )* indexFileSize , maxParallelSearches , maxRetries , errCh )
360
+ objIDs := searchObjects (ctx .Context , p , containerID , account , blockAttributeKey , existingIndexCount * indexFileSize , (existingIndexCount + 1 )* indexFileSize , maxParallelSearches , maxRetries , debug , errCh )
358
361
for id := range objIDs {
359
362
oidCh <- id
360
363
}
@@ -373,7 +376,7 @@ func searchIndexFile(ctx *cli.Context, p poolWrapper, containerID cid.ID, accoun
373
376
// searchObjects searches in parallel for objects with attribute GE startIndex and LT
374
377
// endIndex. It returns a buffered channel of resulting object IDs and closes it once
375
378
// OID search is finished. Errors are sent to errCh in a non-blocking way.
376
- func searchObjects (ctx context.Context , p poolWrapper , containerID cid.ID , account * wallet.Account , blockAttributeKey string , startIndex , endIndex , maxParallelSearches , maxRetries uint , errCh chan error , additionalFilters ... object.SearchFilters ) chan oid.ID {
379
+ func searchObjects (ctx context.Context , p poolWrapper , containerID cid.ID , account * wallet.Account , blockAttributeKey string , startIndex , endIndex , maxParallelSearches , maxRetries uint , debug bool , errCh chan error , additionalFilters ... object.SearchFilters ) chan oid.ID {
377
380
var res = make (chan oid.ID , 2 * neofs .DefaultSearchBatchSize )
378
381
go func () {
379
382
var wg sync.WaitGroup
@@ -413,7 +416,7 @@ func searchObjects(ctx context.Context, p poolWrapper, containerID cid.ID, accou
413
416
var errBlockSearch error
414
417
objIDs , errBlockSearch = neofs .ObjectSearch (ctx , p , account .PrivateKey (), containerID .String (), prm )
415
418
return errBlockSearch
416
- }, maxRetries )
419
+ }, maxRetries , debug )
417
420
if err != nil {
418
421
select {
419
422
case errCh <- fmt .Errorf ("failed to search for block(s) from %d to %d: %w" , start , end , err ):
0 commit comments