-
Notifications
You must be signed in to change notification settings - Fork 376
[Improvement]: Load process factories via DefaultTableRuntimeFactory #4100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
020e3e7
935f399
8fb278a
7c7617c
0ca943c
4d81a08
425326a
bc8175d
9e43534
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| import org.apache.amoro.ServerTableIdentifier; | ||
| import org.apache.amoro.TableFormat; | ||
| import org.apache.amoro.TableRuntime; | ||
| import org.apache.amoro.config.Configurations; | ||
| import org.apache.amoro.config.TableConfiguration; | ||
| import org.apache.amoro.process.ActionCoordinator; | ||
| import org.apache.amoro.process.ProcessEvent; | ||
|
|
@@ -64,26 +63,25 @@ public class ProcessService extends PersistentBase { | |
| new ConcurrentHashMap<>(); | ||
| private final Map<EngineType, ExecuteEngine> executeEngines = new ConcurrentHashMap<>(); | ||
|
|
||
| private final ActionCoordinatorManager actionCoordinatorManager; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the |
||
| private final ExecuteEngineManager executeEngineManager; | ||
| private final List<ActionCoordinator> actionCoordinatorList; | ||
| private final ProcessRuntimeHandler tableRuntimeHandler = new ProcessRuntimeHandler(); | ||
| private final ThreadPoolExecutor processExecutionPool = | ||
| new ThreadPoolExecutor(10, 100, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); | ||
|
|
||
| private final Map<ServerTableIdentifier, Map<Long, TableProcess>> activeTableProcess = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| public ProcessService(Configurations serviceConfig, TableService tableService) { | ||
| this(serviceConfig, tableService, new ActionCoordinatorManager(), new ExecuteEngineManager()); | ||
| public ProcessService(TableService tableService) { | ||
| this(tableService, Collections.emptyList(), new ExecuteEngineManager()); | ||
| } | ||
|
|
||
| public ProcessService( | ||
| Configurations serviceConfig, | ||
| TableService tableService, | ||
| ActionCoordinatorManager actionCoordinatorManager, | ||
| List<ActionCoordinator> actionCoordinators, | ||
| ExecuteEngineManager executeEngineManager) { | ||
| this.tableService = tableService; | ||
| this.actionCoordinatorManager = actionCoordinatorManager; | ||
| this.actionCoordinatorList = actionCoordinators; | ||
| this.executeEngineManager = executeEngineManager; | ||
| } | ||
|
|
||
|
|
@@ -148,24 +146,19 @@ public void cancel(TableProcess process) { | |
|
|
||
| /** Dispose the service, shutdown engines and clear active processes. */ | ||
| public void dispose() { | ||
| actionCoordinatorManager.close(); | ||
| executeEngineManager.close(); | ||
| processExecutionPool.shutdown(); | ||
| activeTableProcess.clear(); | ||
| } | ||
|
|
||
| private void initialize(List<TableRuntime> tableRuntimes) { | ||
| LOG.info("Initializing process service"); | ||
| actionCoordinatorManager.initialize(); | ||
| actionCoordinatorManager | ||
| .installedPlugins() | ||
| .forEach( | ||
| actionCoordinator -> { | ||
| actionCoordinators.put( | ||
| actionCoordinator.action().getName(), | ||
| new ActionCoordinatorScheduler( | ||
| actionCoordinator, tableService, ProcessService.this)); | ||
| }); | ||
| // Pre-configured coordinators built from TableRuntimeFactory / ProcessFactory | ||
| for (ActionCoordinator actionCoordinator : actionCoordinatorList) { | ||
| actionCoordinators.put( | ||
| actionCoordinator.action().getName(), | ||
| new ActionCoordinatorScheduler(actionCoordinator, tableService, ProcessService.this)); | ||
| } | ||
| executeEngineManager.initialize(); | ||
| executeEngineManager | ||
| .installedPlugins() | ||
|
|
@@ -553,13 +546,6 @@ protected void doDispose() { | |
| } | ||
| } | ||
|
|
||
| /** Manager for {@link ActionCoordinator} plugins. */ | ||
| public static class ActionCoordinatorManager extends AbstractPluginManager<ActionCoordinator> { | ||
| public ActionCoordinatorManager() { | ||
| super("action-coordinators"); | ||
| } | ||
| } | ||
|
|
||
| /** Manager for {@link ExecuteEngine} plugins. */ | ||
| public static class ExecuteEngineManager extends AbstractPluginManager<ExecuteEngine> { | ||
| public ExecuteEngineManager() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method returns strategy.getTriggerInterval().toMillis() — a duration, not an absolute timestamp.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The getNextExecutingTime method actually returns the duration. This is a legacy issue.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should update the interface in a separate PR? |
||
| } | ||
|
|
||
| @Override | ||
| public boolean enabled(TableRuntime tableRuntime) { | ||
| return formatSupported(tableRuntime.getFormat()); | ||
| } | ||
|
|
||
| @Override | ||
| public long getExecutorDelay() { | ||
| return strategy.getTriggerInterval().toMillis(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<TableProcess> trigger(TableRuntime tableRuntime) { | ||
| return factory.trigger(tableRuntime, action); | ||
| } | ||
|
|
||
| @Override | ||
| public TableProcess recoverTableProcess( | ||
| TableRuntime tableRuntime, TableProcessStore processStore) { | ||
| try { | ||
| return factory.recover(tableRuntime, processStore); | ||
| } catch (RecoverProcessFailedException e) { | ||
| throw new IllegalStateException( | ||
| String.format( | ||
| "Failed to recover table process for format %s, action %s, table %s", | ||
| format, action, tableRuntime.getTableIdentifier()), | ||
| e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing the code structure like this?