@@ -474,7 +474,6 @@ func (c *wChunk) asyncUpload(key string, block *Page, stagingPath string) {
474474 return
475475 }
476476 blockSize := len (block .Data )
477- defer c .store .bcache .uploaded (key , blockSize )
478477 defer func () {
479478 <- c .store .currentUpload
480479 }()
@@ -495,19 +494,24 @@ func (c *wChunk) asyncUpload(key string, block *Page, stagingPath string) {
495494 block .Release ()
496495
497496 try := 0
498- for c .uploadError == nil {
497+ for try <= 3 { // for async, c.uploadError is always nil
499498 err = c .put (key , buf )
500499 if err == nil {
501500 break
502501 }
503- logger .Warnf ("upload %s: %s (tried %d)" , key , err , try )
504502 try ++
505- time .Sleep (time .Second * time .Duration (try ))
503+ logger .Warnf ("upload %s: %s (tried %d)" , key , err , try )
504+ time .Sleep (time .Second * time .Duration (try * try ))
506505 }
507506 buf .Release ()
508- if err = os .Remove (stagingPath ); err == nil {
509- stageBlocks .Sub (1 )
510- stageBlockBytes .Sub (float64 (blockSize ))
507+ if err == nil {
508+ c .store .bcache .uploaded (key , blockSize )
509+ if os .Remove (stagingPath ) == nil {
510+ stageBlocks .Sub (1 )
511+ stageBlockBytes .Sub (float64 (blockSize ))
512+ }
513+ } else { // add to delay list and wait for later scanning
514+ c .store .addDelayedStaging (key , stagingPath , time .Now ().Add (time .Second * 30 ), false )
511515 }
512516}
513517
@@ -878,7 +882,7 @@ func (store *cachedStore) uploadStagingFile(key string, stagingPath string) {
878882 }
879883 compressed := buf .Data [:n ]
880884 try := 0
881- for {
885+ for try <= 3 {
882886 if store .upLimit != nil {
883887 store .upLimit .Wait (int64 (len (compressed )))
884888 }
@@ -896,15 +900,17 @@ func (store *cachedStore) uploadStagingFile(key string, stagingPath string) {
896900 } else {
897901 objectReqErrors .Add (1 )
898902 }
899- logger .Warnf ("upload %s: %s (try %d)" , key , err , try )
900903 try ++
904+ logger .Warnf ("upload %s: %s (try %d)" , key , err , try )
901905 time .Sleep (time .Second * time .Duration (try * try ))
902906 }
903- store .bcache .uploaded (key , blockSize )
904- store .removeStaging (key )
905- if err = os .Remove (stagingPath ); err == nil {
906- stageBlocks .Sub (1 )
907- stageBlockBytes .Sub (float64 (blockSize ))
907+ if err == nil {
908+ store .bcache .uploaded (key , blockSize )
909+ store .removeStaging (key )
910+ if os .Remove (stagingPath ) == nil {
911+ stageBlocks .Sub (1 )
912+ stageBlockBytes .Sub (float64 (blockSize ))
913+ }
908914 }
909915}
910916
0 commit comments