@@ -104,6 +104,7 @@ func (s *SESSION) GoBootWorkers(waitDivider *sync.WaitGroup, workerWGconnReady *
104104 // the check routine may still be activly checking!
105105 s .checkFeedDone = true
106106 s .mux .Unlock ()
107+ close (segmentChanCheck ) // close the chan to signal no more items will come
107108 }(s .segmentChansCheck [provider .Group ])
108109 }
109110 globalmux .Unlock ()
@@ -185,6 +186,7 @@ func (s *SESSION) GoWorker(wid int, provider *Provider, waitWorker *sync.WaitGro
185186 segCC := s .segmentChansCheck [provider .Group ]
186187 go func (wid int , provider * Provider , waitWorker * sync.WaitGroup , sharedCC chan * ConnItem , segCC chan * segmentChanItem ) {
187188 defer waitWorker .Done ()
189+ defer dlog (always , "CheckRoutine: wid=%d provider='%s' exiting" , wid , provider .Name )
188190 forGoCheckRoutine:
189191 for {
190192 item , ok := <- segCC
@@ -216,6 +218,7 @@ func (s *SESSION) GoWorker(wid int, provider *Provider, waitWorker *sync.WaitGro
216218 segCD := s .segmentChansDowns [provider .Group ]
217219 go func (wid int , provider * Provider , waitWorker * sync.WaitGroup , sharedCC chan * ConnItem , segCD chan * segmentChanItem ) {
218220 defer waitWorker .Done ()
221+ defer dlog (always , "GoDownsRoutine: wid=%d provider='%s' exiting" , wid , provider .Name )
219222 forGoDownsRoutine:
220223 for {
221224 dlog (cfg .opt .DebugWorker , "GoDownsRoutine: wid=%d provider='%s' wait on segCD len=%d" , wid , provider .Name , len (segCD ))
@@ -232,7 +235,7 @@ func (s *SESSION) GoWorker(wid int, provider *Provider, waitWorker *sync.WaitGro
232235
233236 start := time .Now ()
234237 who := fmt .Sprintf ("DR=%d@'%s'#'%s' seg.Id='%s'" , wid , provider .Name , provider .Group , item .segment .Id )
235- memlim .MemLockWait (item , who )
238+ memlim .MemLockWait (item , who ) // gets memlock here
236239 dlog (cfg .opt .DebugWorker && cfg .opt .DebugMemlim , "GoDownsRoutine got MemCheckWait who='%s' waited=(%d ms)" , who , time .Since (start ).Milliseconds ())
237240 errStr := ""
238241 StartDowns := time .Now ()
@@ -274,6 +277,7 @@ func (s *SESSION) GoWorker(wid int, provider *Provider, waitWorker *sync.WaitGro
274277 segCR := s .segmentChansReups [provider .Group ]
275278 go func (wid int , provider * Provider , waitWorker * sync.WaitGroup , sharedCC chan * ConnItem , segCR chan * segmentChanItem ) {
276279 defer waitWorker .Done ()
280+ defer dlog (always , "ReupsRoutine: wid=%d provider='%s' exiting" , wid , provider .Name )
277281 forGoReupsRoutine:
278282 for {
279283 item , ok := <- segCR
@@ -304,7 +308,7 @@ func (s *SESSION) GoWorker(wid int, provider *Provider, waitWorker *sync.WaitGro
304308 item .PrintItemFlags (cfg .opt .DebugFlags , true , fmt .Sprintf ("post-GoReupsRoutine: code=%d" , code ))
305309
306310 DecreaseUPQueueCnt ()
307- if err != nil {
311+ if err != nil || code == 0 {
308312 errStr := fmt .Sprintf ("ERROR in GoReupsRoutine code='%d' err='%v' no retry" , code , err )
309313 dlog (always , "%s" , errStr )
310314 memlim .MemReturn ("MemRetOnERR: " + errStr , item ) // memfree GoReupsRoutine on error
@@ -362,9 +366,17 @@ func matchThisDL(item *segmentChanItem) bool {
362366} // end func matchThisDL
363367
364368func (item * segmentChanItem ) FlagError (providerId int ) {
369+ log .Printf ("FlagError called for providerId=%d on segment.Id='%s' waiting to lock item mutex" , providerId , item .segment .Id )
365370 item .mux .Lock ()
366371 defer item .mux .Unlock ()
372+ item .ignoreDlOn [providerId ] = true
373+ item .ignoreUlOn [providerId ] = true
367374 item .errorOn [providerId ] = true
375+ item .flaginUP = false
376+ item .flaginDL = false
377+ item .fails ++
378+ delete (item .availableOn , providerId )
379+ dlog (always , "Flagged item error, will not retry '%s' on providerId=%d" , item .segment .Id , providerId )
368380}
369381
370382func (item * segmentChanItem ) FlagDLFailed (providerList []* Provider , providerGroup string ) {
@@ -377,6 +389,7 @@ func (item *segmentChanItem) FlagDLFailed(providerList []*Provider, providerGrou
377389 item .ignoreDlOn [id ] = true
378390 item .missingOn [id ] = true
379391 item .errorOn [id ] = true
392+ delete (item .availableOn , id )
380393 }
381394}
382395
@@ -418,7 +431,7 @@ func (s *SESSION) pushDL(allowDl bool, item *segmentChanItem) (pushed bool, nodl
418431 return false , 1 , nil // not a match, item is already in DL or UP or has article
419432 }
420433 if ! memlim .MemAvail () {
421- return
434+ return false , 1 , nil // not enough memory available to download
422435 }
423436 // if we are here, we are allowed to push the item to download queue
424437 // loop over the availableOn map and check if we can push the item to download
@@ -436,6 +449,10 @@ providerDl:
436449 dlog (cfg .opt .DebugWorker , " | [DV-pushDL] (nodl) item missingOn but should be avail!? seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
437450 continue providerDl
438451 }
452+ if item .errorOn [pid ] {
453+ dlog (cfg .opt .DebugWorker , " | [DV-pushDL] (nodl) item errorOn seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
454+ continue providerDl
455+ }
439456 if s .providerList [pid ].NoDownload {
440457 nodl ++
441458 item .ignoreDlOn [pid ] = true
@@ -464,7 +481,7 @@ providerDl:
464481 item .pushedDL ++ // mark as pushed to download queue (in pushDL)
465482 IncreaseDLQueueCnt ()
466483 dlog (cfg .opt .DebugWorker , " | [DV-pushDL] pushed to dlchan seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
467- return // return after 1st push!
484+ return pushed , 0 , nil // return after 1st push!
468485 default :
469486 dlog (cfg .opt .BUG , "DEBUG SPAM pushDL: chan is full @ #'%s', retry next" , s .providerList [pid ].Group )
470487 // chan is full means we cannot push the item to the download queue to this provider group
@@ -475,19 +492,19 @@ providerDl:
475492 } // end select
476493 //}
477494 } // end for providerDl
478- return
495+ return false , 1 , nil
479496} // end func pushDL
480497
481498func (s * SESSION ) pushUP (allowUp bool , item * segmentChanItem ) (pushed bool , noup uint64 , inretry uint64 , err error ) {
482499 if ! allowUp {
483- return
500+ return false , 1 , 0 , fmt . Errorf ( "pushUP not allowed" )
484501 }
485502
486503 s .mux .RLock ()
487504 segcheckdone := s .segcheckdone // get the segcheckdone state
488505 s .mux .RUnlock ()
489506 if cfg .opt .CheckFirst && ! segcheckdone {
490- return
507+ return false , 1 , 0 , nil // still checking, do not push to upload yet
491508 }
492509
493510 item .mux .Lock () // LOCK item for the duration of this function
@@ -514,6 +531,11 @@ providerUp:
514531 dlog (cfg .opt .DebugWorker , " | [DV-pushUP] (noup) flagNoUp seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
515532 continue providerUp
516533 }
534+ if item .ignoreUlOn [pid ] {
535+ noup ++
536+ dlog (cfg .opt .DebugWorker , " | [DV-pushUP] (noup) ignoreUlOn seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
537+ continue providerUp
538+ }
517539 if item .uploadedTo [pid ] {
518540 noup ++
519541 dlog (cfg .opt .DebugWorker , " | [DV-pushUP] (noup) uploadedTo seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
@@ -534,6 +556,11 @@ providerUp:
534556 dlog (cfg .opt .DebugWorker , " | [DV-pushUP] (noup) dmcaOn seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
535557 continue providerUp
536558 }
559+ if item .errorOn [pid ] {
560+ noup ++
561+ dlog (cfg .opt .DebugWorker , " | [DV-pushUP] (noup) errorOn seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
562+ continue providerUp
563+ }
537564 if item .retryOn [pid ] {
538565 if item .retryIn > time .Now ().Unix () {
539566 inretry ++
@@ -557,7 +584,7 @@ providerUp:
557584 IncreaseUPQueueCnt () // increment upQueueCnt counter
558585 //GCounter.IncrMax("upQueueCnt", uint64(len(s.segmentList)), "pushUP")
559586 //GCounter.IncrMax("TOTAL_upQueueCnt", uint64(len(s.segmentList)), "pushUP")
560- dlog (cfg . opt . DebugWorker , " | pushUP: in chan seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
587+ dlog (always , " | pushUP: in chan seg.Id='%s' @ #'%s'" , item .segment .Id , s .providerList [pid ].Group )
561588 return true , 0 , 0 , nil // return after 1st push to a group!
562589 default :
563590 //dlog(cfg.opt.BUG "DEBUG SPAM pushUP: chan is full @ '%s'", s.providerList[pid].Name)
@@ -692,36 +719,33 @@ forever:
692719 }
693720 item .mux .RUnlock () // RUNLOCKS HERE #824d
694721
695- if ! testing {
696- pushedUp , nNoUp , nInRetry , a1err := s .pushUP (allowUp , item )
697- if a1err != nil {
698- dlog (always , "ERROR pushUP err='%v' (seg.Id='%s')" , a1err , item .segment .Id )
722+ pushedUp , nNoUp , nInRetry , a1err := s .pushUP (allowUp , item )
723+ if a1err != nil {
724+ dlog (always , "ERROR pushUP err='%v' (seg.Id='%s')" , a1err , item .segment .Id )
725+ continue forsegmentList
726+ }
727+ if pushedUp {
728+ inup ++
729+ dlog (cfg .opt .DebugWorker , " | [DV] PUSHEDup seg.Id='%s' pushedUp=%t inup=%d" , item .segment .Id , pushedUp , inup )
730+ }
731+ noup += nNoUp
732+ inretry += nInRetry
733+
734+ if ! pushedUp && allowDl {
735+ pushedDl , nNoDl , b1err := s .pushDL (allowDl , item )
736+ if b1err != nil {
737+ dlog (always , "ERROR pushDL err='%v' (seg.Id='%s')" , b1err , item .segment .Id )
699738 continue forsegmentList
700739 }
701- if pushedUp {
702- inup ++
703- dlog (cfg .opt .DebugWorker , " | [DV] PUSHEDup seg.Id='%s' pushedUp=%t inup=%d" , item .segment .Id , pushedUp , inup )
740+ nodl += nNoDl
741+ Tnodl += uint64 (len (item .ignoreDlOn ))
742+ if pushedDl {
743+ indl ++
744+ //if cfg.opt.BUG {
745+ dlog (cfg .opt .DebugWorker , " | [DV] PUSHEDdl seg.Id='%s' pushedDl=%t indl=%d" , item .segment .Id , pushedDl , indl )
746+ //}
704747 }
705- noup += nNoUp
706- //Tnoup += len(item.ignoreDlOn)
707- inretry += nInRetry
708-
709- if ! pushedUp && allowDl {
710- pushedDl , nNoDl , b1err := s .pushDL (allowDl , item )
711- if b1err != nil {
712- dlog (always , "ERROR pushDL err='%v' (seg.Id='%s')" , b1err , item .segment .Id )
713- continue forsegmentList
714- }
715- nodl += nNoDl
716- Tnodl += uint64 (len (item .ignoreDlOn ))
717- if pushedDl {
718- indl ++
719- //if cfg.opt.BUG {
720- dlog (cfg .opt .DebugWorker , " | [DV] PUSHEDdl seg.Id='%s' pushedDl=%t indl=%d" , item .segment .Id , pushedDl , indl )
721- //}
722- }
723- } // end pushDL
724- } // if !testing {
748+ } // end pushDL
725749
726750 } // end for forsegmentList
727751 //dlog(cfg.opt.DebugWorker, " | [DV] lastRunTook='%d ms' '%v", lastRunTook.Milliseconds(), lastRunTook)
0 commit comments