7070import org .apache .seatunnel .engine .server .task .operation .GetTaskGroupMetricsOperation ;
7171import org .apache .seatunnel .engine .server .utils .NodeEngineUtil ;
7272
73- import com .google .common .collect .Lists ;
7473import com .hazelcast .cluster .Address ;
7574import com .hazelcast .core .HazelcastInstanceNotActiveException ;
7675import com .hazelcast .flakeidgen .FlakeIdGenerator ;
9291import java .util .Map ;
9392import java .util .Optional ;
9493import java .util .concurrent .CompletableFuture ;
94+ import java .util .concurrent .ConcurrentHashMap ;
95+ import java .util .concurrent .CopyOnWriteArrayList ;
9596import java .util .concurrent .ExecutorService ;
9697import java .util .stream .Collectors ;
9798
@@ -146,6 +147,8 @@ public class JobMaster {
146147
147148 private Map <Integer , CheckpointPlan > checkpointPlanMap ;
148149
150+ private final Map <Integer , List <SlotProfile >> releasedSlotWhenTaskGroupFinished ;
151+
149152 private final IMap <Long , JobInfo > runningJobInfoIMap ;
150153
151154 private final IMap <Long , HashMap <TaskLocation , SeaTunnelMetricsContext >> metricsImap ;
@@ -190,6 +193,7 @@ public JobMaster(
190193 this .engineConfig = engineConfig ;
191194 this .metricsImap = metricsImap ;
192195 this .seaTunnelServer = seaTunnelServer ;
196+ this .releasedSlotWhenTaskGroupFinished = new ConcurrentHashMap <>();
193197 }
194198
195199 public synchronized void init (long initializationTimestamp , boolean restart ) throws Exception {
@@ -464,13 +468,17 @@ public void releaseTaskGroupResource(
464468 jobImmutableInformation .getJobId (),
465469 Collections .singletonList (taskGroupSlotProfile ))
466470 .join ();
467-
471+ releasedSlotWhenTaskGroupFinished
472+ .computeIfAbsent (
473+ pipelineLocation .getPipelineId (),
474+ k -> new CopyOnWriteArrayList <>())
475+ .add (taskGroupSlotProfile );
468476 return null ;
469477 },
470478 new RetryUtils .RetryMaterial (
471479 Constant .OPERATION_RETRY_TIME ,
472480 true ,
473- exception -> ExceptionUtil . isOperationNeedRetryException ( exception ) ,
481+ ExceptionUtil :: isOperationNeedRetryException ,
474482 Constant .OPERATION_RETRY_SLEEP ));
475483 } catch (Exception e ) {
476484 LOGGER .warning (
@@ -487,6 +495,11 @@ public void releasePipelineResource(SubPlan subPlan) {
487495 if (taskGroupLocationSlotProfileMap == null ) {
488496 return ;
489497 }
498+ List <SlotProfile > alreadyReleased = new ArrayList <>();
499+ if (releasedSlotWhenTaskGroupFinished .containsKey (subPlan .getPipelineId ())) {
500+ alreadyReleased .addAll (
501+ releasedSlotWhenTaskGroupFinished .get (subPlan .getPipelineId ()));
502+ }
490503
491504 RetryUtils .retryWithException (
492505 () -> {
@@ -497,10 +510,12 @@ public void releasePipelineResource(SubPlan subPlan) {
497510 resourceManager
498511 .releaseResources (
499512 jobImmutableInformation .getJobId (),
500- Lists .newArrayList (
501- taskGroupLocationSlotProfileMap .values ()))
513+ taskGroupLocationSlotProfileMap .values ().stream ()
514+ .filter (p -> !alreadyReleased .contains (p ))
515+ .collect (Collectors .toList ()))
502516 .join ();
503517 ownedSlotProfilesIMap .remove (subPlan .getPipelineLocation ());
518+ releasedSlotWhenTaskGroupFinished .remove (subPlan .getPipelineId ());
504519 return null ;
505520 },
506521 new RetryUtils .RetryMaterial (
0 commit comments