23
23
import org .apache .doris .thrift .TStatus ;
24
24
import org .apache .doris .thrift .TStatusCode ;
25
25
26
+ import java .util .ArrayList ;
27
+ import java .util .List ;
26
28
import java .util .TreeSet ;
29
+ import java .util .stream .Collectors ;
27
30
28
31
public class BinlogUtils {
29
- public static Pair <TStatus , TBinlog > getBinlog (TreeSet <TBinlog > binlogs , long prevCommitSeq ) {
32
+ public static Pair <TStatus , List <TBinlog >> getBinlog (
33
+ TreeSet <TBinlog > binlogs , long prevCommitSeq , long numAcquired ) {
30
34
TStatus status = new TStatus (TStatusCode .OK );
31
35
TBinlog firstBinlog = binlogs .first ();
32
36
33
37
// all commitSeq > commitSeq
34
38
if (firstBinlog .getCommitSeq () > prevCommitSeq ) {
35
39
status .setStatusCode (TStatusCode .BINLOG_TOO_OLD_COMMIT_SEQ );
36
- return Pair .of (status , firstBinlog );
40
+ List <TBinlog > array = new ArrayList <>();
41
+ array .add (firstBinlog );
42
+ return Pair .of (status , array );
37
43
}
38
44
39
45
// find first binlog whose commitSeq > commitSeq
@@ -46,7 +52,12 @@ public static Pair<TStatus, TBinlog> getBinlog(TreeSet<TBinlog> binlogs, long pr
46
52
status .setStatusCode (TStatusCode .BINLOG_TOO_NEW_COMMIT_SEQ );
47
53
return Pair .of (status , null );
48
54
} else {
49
- return Pair .of (status , binlog );
55
+ numAcquired = Math .min (Math .max (numAcquired , 1 ), 255 );
56
+ List <TBinlog > obtain = binlogs .tailSet (binlog )
57
+ .stream ()
58
+ .limit (numAcquired )
59
+ .collect (Collectors .toList ());
60
+ return Pair .of (status , obtain );
50
61
}
51
62
}
52
63
0 commit comments