baiyangtx commented on code in PR #3924:
URL: https://github.com/apache/amoro/pull/3924#discussion_r2544672538


##########
amoro-ams/src/main/java/org/apache/amoro/server/process/ActionCoordinator.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.amoro.server.process;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ActivePlugin;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.process.TableProcess;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.utils.SnowflakeIdGenerator;
+
+public interface ActionCoordinator extends ActivePlugin {
+
+  String PROPERTY_PARALLELISM = "parallelism";
+
+  SnowflakeIdGenerator SNOWFLAKE_ID_GENERATOR = new SnowflakeIdGenerator();
+
+  boolean formatSupported(TableFormat format);
+
+  int parallelism();
+
+  Action action();
+
+  String executionEngine();
+
+  long getNextExecutingTime(TableRuntime tableRuntime);
+
+  boolean enabled(TableRuntime tableRuntime);
+
+  long getExecutorDelay();
+
+  TableProcess<TableProcessState> getTableProcess(TableRuntime tableRuntime);

Review Comment:
   The active process is managed by ProcessService or TableRuntime.
   
   ActionCoordinator should be  stateless.



##########
amoro-common/src/main/java/org/apache/amoro/process/TableProcessStore.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.amoro.process;
+
+import org.apache.amoro.Action;
+
+import java.util.Map;
+
+public interface TableProcessStore {
+
+  TableProcessState create(Action action);
+
+  long getProcessId();
+
+  int getRetryNumber();
+
+  ProcessStatus getStatus();
+
+  String getProcessType();
+
+  String getExecutionEngine();
+
+  String getExternalProcessIdentifier();
+
+  Map<String, String> getProcessParameters();
+
+  void dispose();
+
+  void synchronizedInvoke(Runnable runnable);
+
+  TableProcessOperation begin();
+
+  interface TableProcessOperation {
+
+    TableProcessOperation insertTableProcess(TableProcessState state);

Review Comment:
   NO INSERT. 



##########
amoro-common/src/main/java/org/apache/amoro/process/TableProcessStore.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.amoro.process;
+
+import org.apache.amoro.Action;
+
+import java.util.Map;
+
+public interface TableProcessStore {
+
+  TableProcessState create(Action action);
+
+  long getProcessId();
+
+  int getRetryNumber();
+
+  ProcessStatus getStatus();
+
+  String getProcessType();
+
+  String getExecutionEngine();
+
+  String getExternalProcessIdentifier();
+
+  Map<String, String> getProcessParameters();
+
+  void dispose();
+
+  void synchronizedInvoke(Runnable runnable);
+
+  TableProcessOperation begin();
+
+  interface TableProcessOperation {
+
+    TableProcessOperation insertTableProcess(TableProcessState state);
+
+    TableProcessOperation updateTableProcess(TableProcessState state);

Review Comment:
   Refer to TableRuntimeStore. 



##########
amoro-common/src/main/java/org/apache/amoro/process/TableProcess.java:
##########
@@ -29,18 +29,30 @@ public abstract class TableProcess<T extends 
TableProcessState> implements Amoro
 
   protected final T state;
   protected final TableRuntime tableRuntime;
+  protected final TableProcessStore tableProcessStore;

Review Comment:
   
   Remove `T state` from TableProcess.



##########
amoro-ams/src/main/java/org/apache/amoro/server/process/ActionCoordinatorScheduler.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.amoro.server.process;
+
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.process.ProcessStatus;
+import org.apache.amoro.process.TableProcess;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.scheduler.PeriodicTableScheduler;
+import org.apache.amoro.server.table.TableService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ActionCoordinatorScheduler extends PeriodicTableScheduler {
+
+  public static final Logger LOG = 
LoggerFactory.getLogger(ActionCoordinatorScheduler.class);
+  public static final int PROCESS_MAX_RETRY_NUMBER = 3;
+
+  private final ActionCoordinator coordinator;
+  private final ProcessService processService;
+
+  public ActionCoordinatorScheduler(
+      ActionCoordinator coordinator, TableService tableService, ProcessService 
processService) {
+    super(coordinator.action(), tableService, coordinator.parallelism());
+    this.coordinator = coordinator;
+    this.processService = processService;
+  }
+
+  public ActionCoordinator getCoordinator() {
+    return coordinator;
+  }
+
+  @Override
+  protected boolean formatSupported(TableFormat format) {
+    return coordinator.formatSupported(format);
+  }
+
+  @Override
+  protected long getNextExecutingTime(TableRuntime tableRuntime) {
+    return coordinator.getNextExecutingTime(tableRuntime);
+  }
+
+  @Override
+  protected boolean enabled(TableRuntime tableRuntime) {
+    return coordinator.enabled(tableRuntime);
+  }
+
+  @Override
+  protected void execute(TableRuntime tableRuntime) {
+    if (hasAliveTableProcess(tableRuntime)) {
+      TableProcess<TableProcessState> process = 
coordinator.getTableProcess(tableRuntime);
+      LOG.warn(
+          "Detect table process: {} with status: {} exists for table runtime: 
{}, skip schedule {} action this time.",
+          process.getId(),
+          process.getStatus(),
+          tableRuntime.getTableIdentifier(),
+          getAction());
+    } else {
+      TableProcess<TableProcessState> process = 
coordinator.createTableProcess(tableRuntime);
+      processService.register(process);
+    }
+  }
+
+  protected void recover(TableRuntime tableRuntime, TableProcessMeta 
processMeta) {
+    if (hasAliveTableProcess(tableRuntime)) {
+      TableProcess<TableProcessState> process = 
coordinator.getTableProcess(tableRuntime);
+      LOG.warn(
+          "Detect table process: {} with status: {} exists for table runtime: 
{}, skip recover {} action this time.",
+          process.getId(),
+          process.getStatus(),
+          tableRuntime.getTableIdentifier(),
+          getAction());
+    } else {
+      TableProcess<TableProcessState> process =
+          coordinator.recoverTableProcess(tableRuntime, processMeta);
+      processService.recover(process);
+    }
+  }
+
+  protected void retry(TableRuntime tableRuntime, 
TableProcess<TableProcessState> process) {
+    TableProcess<TableProcessState> existProcess = 
coordinator.getTableProcess(tableRuntime);
+    if (existProcess != null && existProcess.getId() == process.getId()) {
+      process = coordinator.retryTableProcess(process);
+      processService.retry(process);
+    } else {
+      LOG.warn(
+          "Detect no table process exists or exist table process id is 
different from retry process for table runtime: {}, skip retry {} action this 
time.",
+          tableRuntime.getTableIdentifier(),
+          getAction());
+    }
+  }
+
+  protected void cancel(TableRuntime tableRuntime, 
TableProcess<TableProcessState> process) {
+    process = coordinator.cancelTableProcess(tableRuntime, process);
+    processService.cancel(process);
+  }
+
+  protected boolean hasAliveTableProcess(TableRuntime tableRuntime) {
+    TableProcess<TableProcessState> process = 
coordinator.getTableProcess(tableRuntime);

Review Comment:
   Should not fetch active process from coordinator.



##########
amoro-common/src/main/java/org/apache/amoro/process/TableProcessStore.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.amoro.process;
+
+import org.apache.amoro.Action;
+
+import java.util.Map;
+
+public interface TableProcessStore {
+
+  TableProcessState create(Action action);
+
+  long getProcessId();
+
+  int getRetryNumber();
+
+  ProcessStatus getStatus();
+
+  String getProcessType();
+
+  String getExecutionEngine();
+
+  String getExternalProcessIdentifier();
+
+  Map<String, String> getProcessParameters();
+
+  void dispose();
+
+  void synchronizedInvoke(Runnable runnable);
+
+  TableProcessOperation begin();
+
+  interface TableProcessOperation {
+
+    TableProcessOperation insertTableProcess(TableProcessState state);
+
+    TableProcessOperation updateTableProcess(TableProcessState state);

Review Comment:
   Updatable fields.
   - Parameters 



-- 
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]

Reply via email to