EricJoy2048 commented on code in PR #2472: URL: https://github.com/apache/incubator-seatunnel/pull/2472#discussion_r959136762
########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/worker/WorkerProfile.java: ########## @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.resourcemanager.worker; + +import org.apache.seatunnel.engine.server.resourcemanager.resource.ResourceProfile; +import org.apache.seatunnel.engine.server.resourcemanager.resource.SlotProfile; + +import com.hazelcast.cluster.Address; + +import java.io.Serializable; + +public class WorkerProfile implements Serializable { Review Comment: I suggest use `lombok` to reduce the code. ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/worker/WorkerProfile.java: ########## @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.resourcemanager.worker; + +import org.apache.seatunnel.engine.server.resourcemanager.resource.ResourceProfile; +import org.apache.seatunnel.engine.server.resourcemanager.resource.SlotProfile; + +import com.hazelcast.cluster.Address; + +import java.io.Serializable; + +public class WorkerProfile implements Serializable { Review Comment: Can you add some comments to `SlotProfile` `WorkerProfile` and other similar class? ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/resource/ResourceProfile.java: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.resourcemanager.resource; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.io.Serializable; + +public class ResourceProfile implements Serializable { + + private final CPU cpu; + + private final Memory heapMemory; + + public ResourceProfile() { + this.cpu = CPU.of(0); + this.heapMemory = Memory.of(0); + } + + public ResourceProfile(CPU cpu, Memory heapMemory) { + checkArgument(cpu.getCore() >= 0, "The cpu core cannot be negative"); + checkArgument(heapMemory.getBytes() >= 0, "The heapMemory bytes cannot be negative"); + this.cpu = cpu; + this.heapMemory = heapMemory; + } + + public CPU getCpu() { + return cpu; + } + + public Memory getHeapMemory() { + return heapMemory; + } + + public ResourceProfile merge(ResourceProfile other) { + CPU c = CPU.of(this.cpu.getCore() + other.getCpu().getCore()); + Memory m = Memory.of(this.heapMemory.getBytes() + other.heapMemory.getBytes()); + return new ResourceProfile(c, m); + } + + public ResourceProfile unmerge(ResourceProfile other) { Review Comment: `unmerge` is not an appropriate name. Can you rename to `subtract` ? ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/scheduler/PipelineBaseScheduler.java: ########## @@ -56,18 +68,22 @@ public void startScheduling() { handlePipelineStateUpdateError(pipeline, PipelineState.SCHEDULED); return null; } - if (!applyResourceForPipeline(pipeline)) { - return null; + Map<PhysicalVertex, SlotProfile> slotProfiles; + try { + slotProfiles = applyResourceForPipeline(pipeline); + } catch (Exception e) { + throw new RuntimeException(e); } + pipeline.whenComplete((state, error) -> releasePipelineResource(Lists.newArrayList(slotProfiles.values()))); Review Comment: I don't think we should release resources when the pipeline complete. In design, the state of pipeline is controlled by `taskFuture` in `PhysicalVertex`, so I think we should release resources in `taskFuture.whenComplete()` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
