1010import org .elasticsearch .core .Tuple ;
1111import org .elasticsearch .persistent .AllocatedPersistentTask ;
1212import org .elasticsearch .tasks .TaskId ;
13- import org .elasticsearch .threadpool .ThreadPool ;
1413
1514import java .util .ArrayList ;
1615import java .util .List ;
1716import java .util .Map ;
17+ import java .util .concurrent .atomic .AtomicInteger ;
1818
1919public class ReindexDataStreamTask extends AllocatedPersistentTask {
2020 public static final String TASK_NAME = "reindex-data-stream" ;
2121 private final long persistentTaskStartTime ;
2222 private final int totalIndices ;
2323 private final int totalIndicesToBeUpgraded ;
24- private final ThreadPool threadPool ;
2524 private boolean complete = false ;
2625 private Exception exception ;
27- private List < String > inProgress = new ArrayList <>( );
28- private List < String > pending = List . of ();
26+ private AtomicInteger inProgress = new AtomicInteger ( 0 );
27+ private AtomicInteger pending = new AtomicInteger ();
2928 private List <Tuple <String , Exception >> errors = new ArrayList <>();
3029
3130 public ReindexDataStreamTask (
3231 long persistentTaskStartTime ,
3332 int totalIndices ,
3433 int totalIndicesToBeUpgraded ,
35- ThreadPool threadPool ,
3634 long id ,
3735 String type ,
3836 String action ,
@@ -44,7 +42,6 @@ public ReindexDataStreamTask(
4442 this .persistentTaskStartTime = persistentTaskStartTime ;
4543 this .totalIndices = totalIndices ;
4644 this .totalIndicesToBeUpgraded = totalIndicesToBeUpgraded ;
47- this .threadPool = threadPool ;
4845 }
4946
5047 @ Override
@@ -55,30 +52,36 @@ public ReindexDataStreamStatus getStatus() {
5552 totalIndicesToBeUpgraded ,
5653 complete ,
5754 exception ,
58- inProgress .size (),
59- pending .size (),
55+ inProgress .get (),
56+ pending .get (),
6057 errors
6158 );
6259 }
6360
64- public void reindexSucceeded () {
61+ public void allReindexesCompleted () {
6562 this .complete = true ;
6663 }
6764
68- public void reindexFailed (Exception e ) {
65+ public void taskFailed (Exception e ) {
6966 this .complete = true ;
7067 this .exception = e ;
7168 }
7269
73- public void setInProgressIndices (List <String > inProgressIndices ) {
74- this .inProgress = inProgressIndices ;
70+ public void reindexSucceeded () {
71+ inProgress .decrementAndGet ();
72+ }
73+
74+ public void reindexFailed (String index , Exception error ) {
75+ this .errors .add (Tuple .tuple (index , error ));
76+ inProgress .decrementAndGet ();
7577 }
7678
77- public void setPendingIndices (List <String > pendingIndices ) {
78- this .pending = pendingIndices ;
79+ public void incrementInProgressIndicesCount () {
80+ inProgress .incrementAndGet ();
81+ pending .decrementAndGet ();
7982 }
8083
81- public void addErrorIndex ( String index , Exception error ) {
82- this . errors . add ( Tuple . tuple ( index , error ) );
84+ public void setPendingIndicesCount ( int size ) {
85+ pending . set ( size );
8386 }
8487}
0 commit comments