phet commented on code in PR #3899: URL: https://github.com/apache/gobblin/pull/3899#discussion_r1538692136
########## gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/FlowLaunchMultiActiveLeaseArbiterFactory.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.gobblin.runtime.api; + +import java.io.IOException; +import java.util.Objects; + +import com.typesafe.config.Config; + +import javax.inject.Inject; +import javax.inject.Provider; +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.configuration.ConfigurationKeys; + + +/** + * A factory implementation that returns a {@link InstrumentedLeaseArbiter} instance used by the + * {@link FlowLaunchHandler} in multi-active scheduler mode + */ +@Slf4j +public class FlowLaunchMultiActiveLeaseArbiterFactory implements Provider<InstrumentedLeaseArbiter> { + private final Config config; + + @Inject + public FlowLaunchMultiActiveLeaseArbiterFactory(Config config) { + this.config = Objects.requireNonNull(config); + } + + @Override + public InstrumentedLeaseArbiter get() { Review Comment: being a Decorator, the name `InstrumentedLeaseArbiter` should be mostly invisible. more customary would be to return a `MultiActiveLeaseArbiter` (the interface). is it really necessary to return `InstrumetedLeaseArbiter`? ########## gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/DagActionExecutionMultiActiveLeaseArbiterFactory.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.gobblin.runtime.api; + +import java.io.IOException; +import java.util.Objects; + +import com.typesafe.config.Config; + +import javax.inject.Inject; +import javax.inject.Provider; +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.configuration.ConfigurationKeys; + + +/** + * A factory implementation that returns a {@link InstrumentedLeaseArbiter} instance used by the + * {@link DagManagementTaskStreamImpl} in multi-active execution mode + */ +@Slf4j +public class DagActionExecutionMultiActiveLeaseArbiterFactory implements Provider<InstrumentedLeaseArbiter> { Review Comment: here again, why `InstrumentedLeaseArbiter` rather than simply `MultiActiveLeaseArbiter`? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManagementTaskStreamImpl.java: ########## @@ -53,18 +75,29 @@ public class DagManagementTaskStreamImpl implements DagManagement, DagTaskStream @Inject(optional=true) protected Optional<DagActionStore> dagActionStore; - protected Optional<ReminderSettingDagProcLeaseArbiter> reminderSettingDagProcLeaseArbiter; + @Inject + @Named(ConfigurationKeys.EXECUTOR_LEASE_ARBITER_NAME) + protected InstrumentedLeaseArbiter dagActionExecutionLeaseArbiter; + protected Optional<DagActionReminderScheduler> dagActionReminderScheduler; + @Inject + @Named(InjectionNames.MULTI_ACTIVE_EXECUTION_ENABLED) + private final boolean isMultiActiveExecutionEnabled; @Inject private static final int MAX_HOUSEKEEPING_THREAD_DELAY = 180; private final BlockingQueue<DagActionStore.DagAction> dagActionQueue = new LinkedBlockingQueue<>(); + private final String MISSING_OPTIONAL_ERROR_MESSAGE = String.format("Multi-active execution enabled but required " + + "instance %s is absent.", DagActionReminderScheduler.class.getSimpleName()); - // TODO: need to pass reference to DagProcLeaseArbiter without creating a circular reference in Guice @Inject public DagManagementTaskStreamImpl(Config config, Optional<DagActionStore> dagActionStore, - Optional<ReminderSettingDagProcLeaseArbiter> reminderSettingDagProcLeaseArbiter) { + @Named(ConfigurationKeys.EXECUTOR_LEASE_ARBITER_NAME) InstrumentedLeaseArbiter dagActionExecutionLeaseArbiter, + Optional<DagActionReminderScheduler> dagActionReminderScheduler, + @Named(InjectionNames.MULTI_ACTIVE_EXECUTION_ENABLED) boolean isMultiActiveExecutionEnabled) { Review Comment: seems redundant to need these on both the member decls as well as the corresponding ctor params. I wonder why... `FlowLaunchHandler` seemed to have it only on the ctor param ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/proc/LaunchDagProc.java: ########## @@ -192,6 +193,15 @@ private void submitJobToExecutor(DagManagementStateStore dagManagementStateStore } } + @Override protected void sendNotification(Optional<Dag<JobExecutionPlan>> result, EventSubmitter eventSubmitter) { } + + @Override + protected void commit(DagManagementStateStore dagManagementStateStore, Optional<Dag<JobExecutionPlan>> result) { + // Only call conclude method if multi-active execution enabled + if (this.isMultiActiveExecutionEnabled) { + this.launchDagTask.conclude(); + } + } Review Comment: actually, why shouldn't it be safe to call `DagTask::conclude` even if not MA exec? (could we drop the `isMAExecEnabled` member?) ########## gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/MysqlMultiActiveLeaseArbiter.java: ########## @@ -181,17 +179,20 @@ public MysqlMultiActiveLeaseArbiter(Config config) throws IOException { + "before all properties", ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX)); } - // TODO: create two tables or take in table name as parameter to have scheduler and executor table - this.leaseArbiterTableName = ConfigUtils.getString(config, ConfigurationKeys.SCHEDULER_LEASE_DETERMINATION_STORE_DB_TABLE_KEY, - ConfigurationKeys.DEFAULT_SCHEDULER_LEASE_DETERMINATION_STORE_DB_TABLE); - this.constantsTableName = ConfigUtils.getString(config, ConfigurationKeys.MULTI_ACTIVE_SCHEDULER_CONSTANTS_DB_TABLE_KEY, - ConfigurationKeys.DEFAULT_MULTI_ACTIVE_SCHEDULER_CONSTANTS_DB_TABLE); + if (!config.hasPath(ConfigurationKeys.LEASE_DETERMINATION_STORE_DB_TABLE_KEY) + || !config.hasPath(ConfigurationKeys.MULTI_ACTIVE_CONSTANTS_DB_TABLE_KEY)) { + throw new RuntimeException(String.format("Table names %s and %s are required to be configured so multiple instances do not " + + "utilize the same table name", ConfigurationKeys.LEASE_DETERMINATION_STORE_DB_TABLE_KEY, + ConfigurationKeys.MULTI_ACTIVE_CONSTANTS_DB_TABLE_KEY)); + } + this.leaseArbiterTableName = ConfigUtils.emptyIfNotPresent(config, ConfigurationKeys.LEASE_DETERMINATION_STORE_DB_TABLE_KEY); + this.constantsTableName = ConfigUtils.emptyIfNotPresent(config, ConfigurationKeys.MULTI_ACTIVE_CONSTANTS_DB_TABLE_KEY); Review Comment: since you just verified they're both here, why use `emptyIfNotPresent` rather than simply `getString`? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java: ########## @@ -251,12 +252,23 @@ public static GobblinServiceManager create(String serviceName, String serviceId, } public static GobblinServiceManager create(GobblinServiceConfiguration serviceConfiguration) { - GobblinServiceGuiceModule guiceModule = new GobblinServiceGuiceModule(serviceConfiguration); + GOBBLIN_SERVICE_GUICE_MODULE = new GobblinServiceGuiceModule(serviceConfiguration); Review Comment: I'm probably being paranoid, but given this class is not a `@Singleton`, I'd make this method `synchronized` and then check whether `GOBBLIN_SERVICE_GUICE_MODULE` has already been initialized (by making it an `Optional`). alternatively, I'd use `AtomicReference` ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java: ########## @@ -251,12 +252,23 @@ public static GobblinServiceManager create(String serviceName, String serviceId, } public static GobblinServiceManager create(GobblinServiceConfiguration serviceConfiguration) { - GobblinServiceGuiceModule guiceModule = new GobblinServiceGuiceModule(serviceConfiguration); + GOBBLIN_SERVICE_GUICE_MODULE = new GobblinServiceGuiceModule(serviceConfiguration); - Injector injector = Guice.createInjector(Stage.PRODUCTION, guiceModule); + Injector injector = Guice.createInjector(Stage.PRODUCTION, GOBBLIN_SERVICE_GUICE_MODULE); return injector.getInstance(GobblinServiceManager.class); } + /** + * + * @param classToGet + * @return a new object if the class type is not marked with @Singleton, otherwise the same instance of the class + * @param <T> + */ + public static <T> T getClass(Class<T> classToGet) { + Injector injector = Guice.createInjector(Stage.PRODUCTION, GOBBLIN_SERVICE_GUICE_MODULE); + return injector.getInstance(classToGet); + } Review Comment: how can we be certain this will be called following `create`, such that `GOBBLIN_SERVICE_GUICE_MODULE` is definitely initialized? ########## gobblin-runtime/src/main/java/org/apache/gobblin/runtime/api/DagActionExecutionMultiActiveLeaseArbiterFactory.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.gobblin.runtime.api; + +import java.io.IOException; +import java.util.Objects; + +import com.typesafe.config.Config; + +import javax.inject.Inject; +import javax.inject.Provider; +import lombok.extern.slf4j.Slf4j; + +import org.apache.gobblin.configuration.ConfigurationKeys; + + +/** + * A factory implementation that returns a {@link InstrumentedLeaseArbiter} instance used by the + * {@link DagManagementTaskStreamImpl} in multi-active execution mode + */ +@Slf4j +public class DagActionExecutionMultiActiveLeaseArbiterFactory implements Provider<InstrumentedLeaseArbiter> { + private final Config config; + + @Inject + public DagActionExecutionMultiActiveLeaseArbiterFactory(Config config) { + this.config = Objects.requireNonNull(config); + } + + @Override + public InstrumentedLeaseArbiter get() { + try { + Config dagProcLeaseArbiterConfig = this.config.getConfig(ConfigurationKeys.EXECUTOR_LEASE_ARBITER_NAME); + log.info("{} lease arbiter will be initialized with config {}", ConfigurationKeys.EXECUTOR_LEASE_ARBITER_NAME, + dagProcLeaseArbiterConfig); + + return new InstrumentedLeaseArbiter(dagProcLeaseArbiterConfig, + new MysqlMultiActiveLeaseArbiter(dagProcLeaseArbiterConfig), ConfigurationKeys.EXECUTOR_LEASE_ARBITER_NAME); Review Comment: could the two factories share a common (likely semantically `abstract`) base class impl? e.g. whose ctor takes in an arbiter name config key ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java: ########## @@ -251,12 +252,23 @@ public static GobblinServiceManager create(String serviceName, String serviceId, } public static GobblinServiceManager create(GobblinServiceConfiguration serviceConfiguration) { - GobblinServiceGuiceModule guiceModule = new GobblinServiceGuiceModule(serviceConfiguration); + GOBBLIN_SERVICE_GUICE_MODULE = new GobblinServiceGuiceModule(serviceConfiguration); - Injector injector = Guice.createInjector(Stage.PRODUCTION, guiceModule); + Injector injector = Guice.createInjector(Stage.PRODUCTION, GOBBLIN_SERVICE_GUICE_MODULE); return injector.getInstance(GobblinServiceManager.class); Review Comment: replace with ``` return getClass(GobblinServiceManager.class); ``` ? ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManagementTaskStreamImpl.java: ########## @@ -108,6 +137,36 @@ public DagTask next() { return null; } + /** + * Returns a {@link org.apache.gobblin.runtime.api.MultiActiveLeaseArbiter.LeaseAttemptStatus} associated with the + * `dagAction`. If in multi-active execution mode, it retrieves the status from calling + * {@link MultiActiveLeaseArbiter#tryAcquireLease(DagActionStore.DagAction, long, boolean, boolean)}, otherwise + * it returns a {@link org.apache.gobblin.runtime.api.MultiActiveLeaseArbiter.LeaseObtainedStatus} that will not + * expire for a very long time to the current instance. + * @param dagAction + * @return + * @throws IOException + * @throws SchedulerException + */ + private MultiActiveLeaseArbiter.LeaseAttemptStatus retrieveLeaseStatus(DagActionStore.DagAction dagAction) + throws IOException, SchedulerException { + MultiActiveLeaseArbiter.LeaseAttemptStatus leaseAttemptStatus; + if (!this.isMultiActiveExecutionEnabled) { + leaseAttemptStatus = new MultiActiveLeaseArbiter.LeaseObtainedStatus(dagAction, System.currentTimeMillis(), Long.MAX_VALUE, null); + } else { Review Comment: why the complexity of the either-or as opposed to just initializing the ctor w/ a MALA that might always return a `LeaseObtainedStatus`. (to use that in conjunction w/ an absent `DagActionReminderScheduler`) ########## gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManagementTaskStreamImpl.java: ########## @@ -86,19 +119,15 @@ public boolean hasNext() { @Override public DagTask next() { - /*TODO: this requires use of lease arbiter, in single-active execution lease arbiter will not be present and we can - provide a dummy LeaseObtainedStatus or create alternate route - */ - if (!this.reminderSettingDagProcLeaseArbiter.isPresent()) { - throw new RuntimeException("DagManagement not initialized in multi-active execution mode when required."); + if (this.isMultiActiveExecutionEnabled && !this.dagActionReminderScheduler.isPresent()) { + throw new RuntimeException(MISSING_OPTIONAL_ERROR_MESSAGE); Review Comment: could this pre-condition-style check not happen in the ctor? -- 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]
