@@ -267,7 +267,7 @@ func (cr *Cluster) checkFileFor(
267267 mpb .AppendDecorators (
268268 decor .CountersNoUnit ("%d / %d" , decor .WCSyncSpaceR ),
269269 decor .NewPercentage ("%d" , decor .WCSyncSpaceR ),
270- decor .EwmaETA (decor .ET_STYLE_GO , 30 ),
270+ decor .EwmaETA (decor .ET_STYLE_GO , 60 ),
271271 ),
272272 mpb .BarExtender ((mpb .BarFillerFunc )(func (w io.Writer , _ decor.Statistics ) (err error ) {
273273 if checkingHashMux .TryLock () {
@@ -489,7 +489,7 @@ func (cr *Cluster) syncFiles(ctx context.Context, files []FileInfo, heavyCheck b
489489 var stats syncStats
490490 stats .pg = pg
491491 stats .noOpen = syncCfg .Source == "center"
492- stats .slots = limited .NewBufSlots (syncCfg .Concurrency )
492+ stats .slots = limited .NewBufSlots (syncCfg .Concurrency + 1 )
493493 stats .totalFiles = totalFiles
494494 for _ , f := range missing {
495495 stats .totalSize += f .Size
@@ -669,15 +669,15 @@ func (cr *Cluster) fetchFile(ctx context.Context, stats *syncStats, f FileInfo)
669669 defer close (pathRes )
670670
671671 var barUnit decor.SizeB1024
672- var trycount atomic.Int32
673- trycount .Store (1 )
672+ var tried atomic.Int32
673+ tried .Store (1 )
674674 bar := stats .pg .AddBar (f .Size ,
675675 mpb .BarRemoveOnComplete (),
676676 mpb .BarPriority (slotId ),
677677 mpb .PrependDecorators (
678678 decor .Name (Tr ("hint.sync.downloading" )),
679679 decor .Any (func (decor.Statistics ) string {
680- tc := trycount .Load ()
680+ tc := tried .Load ()
681681 if tc <= 1 {
682682 return ""
683683 }
@@ -688,22 +688,23 @@ func (cr *Cluster) fetchFile(ctx context.Context, stats *syncStats, f FileInfo)
688688 mpb .AppendDecorators (
689689 decor .NewPercentage ("%d" , decor .WCSyncSpace ),
690690 decor .Counters (barUnit , "[%.1f / %.1f]" , decor .WCSyncSpace ),
691- decor .EwmaSpeed (barUnit , "%.1f" , 10 , decor .WCSyncSpace ),
691+ decor .EwmaSpeed (barUnit , "%.1f" , 30 , decor .WCSyncSpace ),
692692 decor .OnComplete (
693- decor .EwmaETA (decor .ET_STYLE_GO , 10 , decor .WCSyncSpace ), "done" ,
693+ decor .EwmaETA (decor .ET_STYLE_GO , 30 , decor .WCSyncSpace ), "done" ,
694694 ),
695695 ),
696696 )
697697 defer bar .Abort (true )
698698
699699 noOpen := stats .noOpen
700+ badOpen := false
700701 interval := time .Second
701702 for {
702703 bar .SetCurrent (0 )
703704 hashMethod , err := getHashMethod (len (f .Hash ))
704705 if err == nil {
705706 var path string
706- if path , err = cr .fetchFileWithBuf (ctx , f , hashMethod , buf , noOpen , func (r io.Reader ) io.Reader {
707+ if path , err = cr .fetchFileWithBuf (ctx , f , hashMethod , buf , noOpen , badOpen , func (r io.Reader ) io.Reader {
707708 return ProxyReader (r , bar , stats .totalBar , & stats .lastInc )
708709 }); err == nil {
709710 pathRes <- path
@@ -716,14 +717,15 @@ func (cr *Cluster) fetchFile(ctx context.Context, stats *syncStats, f FileInfo)
716717 }
717718 bar .SetRefill (bar .Current ())
718719
719- log .Errorf (Tr ("error.sync.download.failed" ), f .Path , err )
720- c := trycount .Add (1 )
720+ c := tried .Add (1 )
721721 if c > maxRetryCount {
722+ log .Errorf (Tr ("error.sync.download.failed" ), f .Path , err )
722723 break
723724 }
724725 if c > maxTryWithOpen {
725- noOpen = true
726+ badOpen = true
726727 }
728+ log .Errorf (Tr ("error.sync.download.failed.retry" ), f .Path , interval , err )
727729 select {
728730 case <- time .After (interval ):
729731 interval *= 2
@@ -739,20 +741,25 @@ func (cr *Cluster) fetchFile(ctx context.Context, stats *syncStats, f FileInfo)
739741func (cr * Cluster ) fetchFileWithBuf (
740742 ctx context.Context , f FileInfo ,
741743 hashMethod crypto.Hash , buf []byte ,
742- noOpen bool ,
744+ noOpen bool , badOpen bool ,
743745 wrapper func (io.Reader ) io.Reader ,
744746) (path string , err error ) {
745747 var (
746748 reqPath = f .Path
749+ query url.Values
747750 req * http.Request
748751 res * http.Response
749752 fd * os.File
750753 r io.Reader
751754 )
752- if noOpen {
755+ if badOpen {
753756 reqPath = "/openbmclapi/download/" + f .Hash
757+ } else if noOpen {
758+ query = url.Values {
759+ "noopen" : {"1" },
760+ }
754761 }
755- if req , err = cr .makeReqWithAuth (ctx , http .MethodGet , reqPath , nil ); err != nil {
762+ if req , err = cr .makeReqWithAuth (ctx , http .MethodGet , reqPath , query ); err != nil {
756763 return
757764 }
758765 req .Header .Set ("Accept-Encoding" , "gzip, deflate" )
@@ -904,7 +911,7 @@ func (cr *Cluster) DownloadFile(ctx context.Context, hash string) (err error) {
904911 }
905912 defer free ()
906913
907- path , err := cr .fetchFileWithBuf (ctx , f , hashMethod , buf , true , nil )
914+ path , err := cr .fetchFileWithBuf (ctx , f , hashMethod , buf , true , true , nil )
908915 if err != nil {
909916 return
910917 }
0 commit comments