@@ -3,6 +3,7 @@ package sls
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "time"
6
7
7
8
"io/ioutil"
8
9
"net/http"
@@ -635,6 +636,70 @@ func (s *LogStore) GetLogs(topic string, from int64, to int64, queryExp string,
635
636
return s .GetLogsV2 (& req )
636
637
}
637
638
639
+ func (s * LogStore ) getToCompleted (f func () (bool , error ), retryCount int64 ) {
640
+ interval := 100 * time .Millisecond
641
+ if retryCount > 20 {
642
+ retryCount = 20
643
+ }
644
+ if retryCount < 0 {
645
+ retryCount = 0
646
+ }
647
+ retryCount ++
648
+ isTimeout := false
649
+ go func () {
650
+ <- time .After (5 * time .Minute )
651
+ isTimeout = true
652
+ }()
653
+ isCompleted := false
654
+ for retryCount > 0 && ! isTimeout {
655
+ var err error
656
+ isCompleted , err = f ()
657
+ if err != nil || isCompleted {
658
+ return
659
+ }
660
+ time .Sleep (interval )
661
+ retryCount --
662
+ if interval < 10 * time .Second {
663
+ interval = interval * 2
664
+ }
665
+ if interval > 10 * time .Second {
666
+ interval = 10 * time .Second
667
+ }
668
+ }
669
+ return
670
+ }
671
+
672
+ // GetLogsToCompleted query logs with [from, to) time range to completed
673
+ func (s * LogStore ) GetLogsToCompleted (topic string , from int64 , to int64 , queryExp string ,
674
+ maxLineNum int64 , offset int64 , reverse bool , retryCount int64 ) (* GetLogsResponse , error ) {
675
+ var res * GetLogsResponse
676
+ var err error
677
+ f := func () (bool , error ) {
678
+ res , err = s .GetLogs (topic , from , to , queryExp , maxLineNum , offset , reverse )
679
+ if err == nil {
680
+ return res .IsComplete (), nil
681
+ }
682
+ return false , err
683
+ }
684
+ s .getToCompleted (f , retryCount )
685
+ return res , err
686
+ }
687
+
688
+ // GetHistogramsToCompleted query logs with [from, to) time range to completed
689
+ func (s * LogStore ) GetHistogramsToCompleted (topic string , from int64 , to int64 , queryExp string , retryCount int64 ) (* GetHistogramsResponse , error ) {
690
+ var res * GetHistogramsResponse
691
+ var err error
692
+ f := func () (bool , error ) {
693
+ res , err = s .GetHistograms (topic , from , to , queryExp )
694
+ if err == nil {
695
+ return res .IsComplete (), nil
696
+ }
697
+ return false , err
698
+ }
699
+ s .getToCompleted (f , retryCount )
700
+ return res , err
701
+ }
702
+
638
703
// GetLogsV2 query logs with [from, to) time range
639
704
func (s * LogStore ) GetLogsV2 (req * GetLogRequest ) (* GetLogsResponse , error ) {
640
705
rsp , b , logRsp , err := s .getLogs (req )
0 commit comments