1919
2020package org .apache .iotdb .db .pipe .event .common .terminate ;
2121
22+ import org .apache .iotdb .commons .concurrent .IoTThreadFactory ;
23+ import org .apache .iotdb .commons .concurrent .ThreadName ;
24+ import org .apache .iotdb .commons .concurrent .threadpool .WrappedThreadPoolExecutor ;
2225import org .apache .iotdb .commons .consensus .index .ProgressIndex ;
2326import org .apache .iotdb .commons .consensus .index .impl .MinimumProgressIndex ;
2427import org .apache .iotdb .commons .pipe .agent .task .meta .PipeTaskMeta ;
2528import org .apache .iotdb .commons .pipe .datastructure .pattern .PipePattern ;
2629import org .apache .iotdb .commons .pipe .event .EnrichedEvent ;
30+ import org .apache .iotdb .db .conf .IoTDBDescriptor ;
2731import org .apache .iotdb .db .pipe .agent .PipeDataNodeAgent ;
2832import org .apache .iotdb .db .pipe .agent .task .PipeDataNodeTask ;
2933import org .apache .iotdb .db .pipe .event .common .tsfile .PipeTsFileInsertionEvent ;
3034
31- import java .util .concurrent .CompletableFuture ;
35+ import java .util .concurrent .ArrayBlockingQueue ;
36+ import java .util .concurrent .ExecutorService ;
37+ import java .util .concurrent .TimeUnit ;
3238
3339/**
3440 * The {@link PipeTerminateEvent} is an {@link EnrichedEvent} that controls the termination of pipe,
@@ -40,13 +46,29 @@ public class PipeTerminateEvent extends EnrichedEvent {
4046
4147 private final int dataRegionId ;
4248
49+ private final boolean shouldMark ;
50+
51+ // Do not use call run policy to avoid deadlock
52+ private static final ExecutorService terminateExecutor =
53+ new WrappedThreadPoolExecutor (
54+ 0 ,
55+ IoTDBDescriptor .getInstance ().getConfig ().getPipeTaskThreadCount (),
56+ 0L ,
57+ TimeUnit .SECONDS ,
58+ new ArrayBlockingQueue <>(
59+ IoTDBDescriptor .getInstance ().getConfig ().getPipeTaskThreadCount ()),
60+ new IoTThreadFactory (ThreadName .PIPE_TERMINATE_EXECUTION_POOL .getName ()),
61+ ThreadName .PIPE_TERMINATE_EXECUTION_POOL .getName ());
62+
4363 public PipeTerminateEvent (
4464 final String pipeName ,
4565 final long creationTime ,
4666 final PipeTaskMeta pipeTaskMeta ,
47- final int dataRegionId ) {
67+ final int dataRegionId ,
68+ final boolean shouldMark ) {
4869 super (pipeName , creationTime , pipeTaskMeta , null , Long .MIN_VALUE , Long .MAX_VALUE );
4970 this .dataRegionId = dataRegionId ;
71+ this .shouldMark = shouldMark ;
5072 }
5173
5274 @ Override
@@ -74,7 +96,7 @@ public EnrichedEvent shallowCopySelfAndBindPipeTaskMetaForProgressReport(
7496 final long endTime ) {
7597 // Should record PipeTaskMeta, for the terminateEvent shall report progress to
7698 // notify the pipeTask it's completed.
77- return new PipeTerminateEvent (pipeName , creationTime , pipeTaskMeta , dataRegionId );
99+ return new PipeTerminateEvent (pipeName , creationTime , pipeTaskMeta , dataRegionId , shouldMark );
78100 }
79101
80102 @ Override
@@ -95,13 +117,16 @@ public boolean mayEventPathsOverlappedWithPattern() {
95117 @ Override
96118 public void reportProgress () {
97119 // To avoid deadlock
98- CompletableFuture .runAsync (
99- () -> PipeDataNodeAgent .task ().markCompleted (pipeName , dataRegionId ));
120+ if (shouldMark ) {
121+ terminateExecutor .submit (
122+ () -> PipeDataNodeAgent .task ().markCompleted (pipeName , dataRegionId ));
123+ }
100124 }
101125
102126 @ Override
103127 public String toString () {
104- return String .format ("PipeTerminateEvent{dataRegionId=%s}" , dataRegionId )
128+ return String .format (
129+ "PipeTerminateEvent{dataRegionId=%s, shouldMark=%s}" , dataRegionId , shouldMark )
105130 + " - "
106131 + super .toString ();
107132 }
0 commit comments