xxubai commented on code in PR #4100:
URL: https://github.com/apache/amoro/pull/4100#discussion_r2884296225
##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableRuntimeFactory.java:
##########
@@ -28,45 +29,108 @@
import org.apache.amoro.table.TableRuntimeFactory;
import org.apache.amoro.table.TableRuntimeStore;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+/**
+ * Default {@link TableRuntimeFactory} implementation used by AMS.
+ *
+ * <p>Besides creating {@link DefaultTableRuntime} instances for mixed/iceberg
formats, this factory
+ * also aggregates {@link ProcessFactory} declarations to expose {@link
ActionCoordinator} plugins
+ * for different {@link TableFormat}/{@link Action} combinations.
+ */
public class DefaultTableRuntimeFactory implements TableRuntimeFactory {
- @Override
- public void open(Map<String, String> properties) {}
- @Override
- public void close() {}
+ /** Mapping from table format to its supported actions and corresponding
process factory. */
+ private final Map<TableFormat, Map<Action, ProcessFactory>>
factoriesByFormat = new HashMap<>();
- @Override
- public String name() {
- return "default";
- }
+ /** Coordinators derived from all installed process factories. */
+ private final List<ActionCoordinator> supportedCoordinators =
Lists.newArrayList();
Review Comment:
Callers can accidentally mutate the internal supportedCoordinators list.
Return Collections.unmodifiableList(supportedCoordinators) instead.
##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableRuntimeFactory.java:
##########
@@ -28,45 +29,108 @@
import org.apache.amoro.table.TableRuntimeFactory;
import org.apache.amoro.table.TableRuntimeStore;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+/**
+ * Default {@link TableRuntimeFactory} implementation used by AMS.
+ *
+ * <p>Besides creating {@link DefaultTableRuntime} instances for mixed/iceberg
formats, this factory
+ * also aggregates {@link ProcessFactory} declarations to expose {@link
ActionCoordinator} plugins
+ * for different {@link TableFormat}/{@link Action} combinations.
+ */
public class DefaultTableRuntimeFactory implements TableRuntimeFactory {
- @Override
- public void open(Map<String, String> properties) {}
- @Override
- public void close() {}
+ /** Mapping from table format to its supported actions and corresponding
process factory. */
+ private final Map<TableFormat, Map<Action, ProcessFactory>>
factoriesByFormat = new HashMap<>();
- @Override
- public String name() {
- return "default";
- }
+ /** Coordinators derived from all installed process factories. */
+ private final List<ActionCoordinator> supportedCoordinators =
Lists.newArrayList();
@Override
public List<ActionCoordinator> supportedCoordinators() {
- return Lists.newArrayList();
+ return supportedCoordinators;
}
@Override
- public void initialize(List<ProcessFactory> factories) {}
+ public void initialize(List<ProcessFactory> factories) {
+ factoriesByFormat.clear();
+ supportedCoordinators.clear();
+
+ for (ProcessFactory factory : factories) {
+ Map<TableFormat, Set<Action>> supported = factory.supportedActions();
+ if (supported == null || supported.isEmpty()) {
+ continue;
+ }
+
+ for (Map.Entry<TableFormat, Set<Action>> entry : supported.entrySet()) {
+ TableFormat format = entry.getKey();
+ Map<Action, ProcessFactory> byAction =
+ factoriesByFormat.computeIfAbsent(format, k -> new HashMap<>());
+
+ for (Action action : entry.getValue()) {
+ ProcessFactory existed = byAction.get(action);
+ if (existed != null && existed != factory) {
+ throw new IllegalArgumentException(
+ String.format(
+ "ProcessFactory conflict for format %s and action %s,
existing: %s, new: %s",
+ format, action, existed.name(), factory.name()));
+ }
+ byAction.put(action, factory);
+ supportedCoordinators.add(new DefaultActionCoordinator(format,
action, factory));
+ }
+ }
+ }
+ }
@Override
public Optional<TableRuntimeCreator> accept(
ServerTableIdentifier tableIdentifier, Map<String, String>
tableProperties) {
- if (tableIdentifier
- .getFormat()
- .in(TableFormat.MIXED_ICEBERG, TableFormat.MIXED_HIVE,
TableFormat.ICEBERG)) {
- return Optional.of(new TableRuntimeCreatorImpl());
+ TableFormat format = tableIdentifier.getFormat();
+ boolean defaultSupported =
+ format.in(TableFormat.MIXED_ICEBERG, TableFormat.MIXED_HIVE,
TableFormat.ICEBERG);
+ boolean hasProcessFactories = factoriesByFormat.containsKey(format);
+
+ if (!defaultSupported && !hasProcessFactories) {
+ return Optional.empty();
}
- return Optional.empty();
+
+ return Optional.of(new TableRuntimeCreatorImpl(format));
}
- private static class TableRuntimeCreatorImpl implements
TableRuntimeFactory.TableRuntimeCreator {
+ private class TableRuntimeCreatorImpl implements
TableRuntimeFactory.TableRuntimeCreator {
+
+ private final TableFormat format;
+
+ private TableRuntimeCreatorImpl(TableFormat format) {
+ this.format = format;
+ }
+
@Override
public List<StateKey<?>> requiredStateKeys() {
- return DefaultTableRuntime.REQUIRED_STATES;
+ Map<String, StateKey<?>> merged = new LinkedHashMap<>();
+ // 1) DefaultTableRuntime required states
+ for (StateKey<?> stateKey : DefaultTableRuntime.REQUIRED_STATES) {
+ merged.put(stateKey.getKey(), stateKey);
+ }
+
+ // 2) Extra states from all process factories for this format (if any)
+ Map<Action, ProcessFactory> byAction = factoriesByFormat.get(format);
Review Comment:
If `DefaultTableRuntime.REQUIRED_STATES` declares a state key with the same
name as a `ProcessFactory`'s required state but with a different type or
default value, the factory's key silently overwrites the built-in one.
Suggestion: Add a type-compatibility check or throw on conflicting keys:
##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultActionCoordinator.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.process.ActionCoordinator;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.ProcessTriggerStrategy;
+import org.apache.amoro.process.RecoverProcessFailedException;
+import org.apache.amoro.process.TableProcess;
+import org.apache.amoro.process.TableProcessStore;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Default implementation of {@link ActionCoordinator} that bridges {@link
ProcessFactory}
+ * declarations to the AMS scheduling framework.
+ */
+public class DefaultActionCoordinator implements ActionCoordinator {
+
+ private final Action action;
+ private final TableFormat format;
+ private final ProcessFactory factory;
+ private final ProcessTriggerStrategy strategy;
+
+ public DefaultActionCoordinator(TableFormat format, Action action,
ProcessFactory factory) {
+ this.action = action;
+ this.format = format;
+ this.factory = factory;
+ this.strategy = factory.triggerStrategy(format, action);
+ Preconditions.checkArgument(
+ strategy != null,
+ "ProcessTriggerStrategy cannot be null for format %s, action %s,
factory %s",
+ format,
+ action,
+ factory.name());
+ }
+
+ @Override
+ public String name() {
+ // No need to be globally unique, this coordinator is not discovered via
plugin manager.
+ return String.format("%s-%s-coordinator", format.name().toLowerCase(),
action.getName());
+ }
+
+ @Override
+ public void open(Map<String, String> properties) {
+ // No-op: lifecycle is managed by owning TableRuntimeFactory.
+ }
+
+ @Override
+ public void close() {
+ // No-op: nothing to close.
+ }
+
+ @Override
+ public boolean formatSupported(TableFormat format) {
+ return this.format.equals(format);
+ }
+
+ @Override
+ public int parallelism() {
+ return strategy.getTriggerParallelism();
+ }
+
+ @Override
+ public Action action() {
+ return action;
+ }
+
+ @Override
+ public long getNextExecutingTime(TableRuntime tableRuntime) {
+ // Fixed-rate scheduling based on configured trigger interval.
+ return strategy.getTriggerInterval().toMillis();
Review Comment:
The method returns strategy.getTriggerInterval().toMillis() — a duration,
not an absolute timestamp.
Do you mean `System.currentTimeMillis() + interval`?
--
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]