bobpaulin commented on code in PR #11872:
URL: https://github.com/apache/nifi/pull/11872#discussion_r4556543931
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/components/connector/StandardConnectorNode.java:
##########
@@ -1619,6 +1783,623 @@ public boolean isExtensionMissing() {
return extensionMissing;
}
+ @Override
+ public boolean isPendingFlowEvolution() {
+ synchronized (flowEvolutionLock) {
+ if (extensionMissing) {
+ return false;
+ }
+
+ final ConnectorFlowSnapshot snapshot = authoritativeFlowSnapshot;
+ final Bundle snapshotBundle = snapshot == null ? null :
snapshot.bundle();
+ return (snapshotBundle != null && !sameBundle(snapshotBundle,
bundleCoordinate)) || isFlowEvolutionPhaseOneComplete();
+ }
+ }
+
+ @Override
+ public FlowEvolutionStatus getFlowEvolutionStatus() {
+ return hasFlowEvolutionFailed() ? FlowEvolutionStatus.FAILED :
flowEvolutionStatus.get();
+ }
+
+ boolean isFlowEvolutionPhaseOneComplete() {
+ synchronized (flowEvolutionLock) {
+ return hasCompletedFlowEvolutionHookProgress()
+ && (hasFlowEvolutionFailed() ||
isFlowEvolutionInProgress());
+ }
+ }
+
+ private boolean hasCompletedFlowEvolutionHookProgress() {
+ final FlowEvolutionStatus status = flowEvolutionStatus.get();
+ return status == FlowEvolutionStatus.PHASE_ONE_COMPLETE || status ==
FlowEvolutionStatus.PHASE_TWO_COMPLETE;
+ }
+
+ boolean hasFlowEvolutionFailed() {
+ return flowEvolutionFailure.get() != null;
+ }
+
+ private void verifyFlowEvolutionActive() throws FlowUpdateException {
+ if (hasFlowEvolutionFailed() || getCurrentState() !=
ConnectorState.DRAINING) {
+ throw new FlowUpdateException("Flow evolution was cancelled for "
+ this);
+ }
+ }
+
+ private VersionedProcessGroup getAuthoritativeManagedProcessGroup() {
+ final ConnectorFlowSnapshot snapshot = authoritativeFlowSnapshot;
+ return snapshot == null ? null : snapshot.flow();
+ }
+
+ @Override
+ public ConnectorFlowSnapshot getAuthoritativeFlowSnapshot() {
+ return authoritativeFlowSnapshot;
+ }
+
+ @Override
+ public boolean restorePendingFlowEvolution(final VersionedConnector
persisted, final List<VersionedConfigurationStep> activeConfiguration,
+ final List<VersionedConfigurationStep> workingConfiguration)
throws FlowUpdateException {
+ final Bundle managedFlowBundle = resolveManagedFlowBundle(persisted);
+ final VersionedProcessGroup persistedManagedGroup =
persisted.getManagedProcessGroup();
+ final Map<String, SecretReference> parameterSecretReferences =
ParameterSecretReferences.convertManagedParameterSecretReferences(persisted);
+ // Components in the persisted group may name NAR versions that are no
longer installed. A missing coordinate
+ // is rewritten only when exactly one compatible bundle is installed.
A ghost has no initialization context,
+ // and its coordinates have to stay as persisted.
+ if (!extensionMissing) {
+ resolvePersistedBundles(persistedManagedGroup);
+ }
+
+ if (extensionMissing && persistedManagedGroup != null) {
+ // Adopt before inheritConfiguration. A flow save with no snapshot
omits the managed group, and inherit
+ // rebuilds the live group before the persisted one is installed
below.
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ return false;
+ }
+
+ if (!extensionMissing && !sameManagedBundle(managedFlowBundle) &&
persistedManagedGroup != null) {
+ // Skip inheritConfiguration. Its applyUpdate would replace the
pre-upgrade group with the new bundle's
+ // flow. The restored group keeps the previous bundle, so the next
start evolves it.
+ restorePersistedFlow(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences, true);
+ loadConfigurationsWithoutRebuildingFlow(activeConfiguration,
workingConfiguration);
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void restorePersistedManagedFlow(final VersionedConnector
persisted) {
+ final Bundle managedFlowBundle = resolveManagedFlowBundle(persisted);
+ final VersionedProcessGroup persistedManagedGroup =
persisted.getManagedProcessGroup();
+ final Map<String, SecretReference> parameterSecretReferences =
ParameterSecretReferences.convertManagedParameterSecretReferences(persisted);
+
+ if (extensionMissing && persistedManagedGroup != null) {
+ // Install the persisted flow while ghosted so queues exist before
the FlowFile repository recovers.
+ // Components stay stopped: a ghost cannot start, and resuming
would run them under a missing extension.
+ try {
+ restorePersistedFlow(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences, false);
+ } catch (final Exception e) {
+ logger.error("{} failed to restore the persisted managed flow
while ghosted; "
+ + "queued FlowFiles may not rejoin until NiFi restarts
after the Connector becomes loadable again", this, e);
+ markManagedFlowMissingAtStartup();
+ }
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ return;
+ }
+
+ if (sameManagedBundle(managedFlowBundle) && persistedManagedGroup !=
null) {
+ // The bundles match, so this is a restart rather than an upgrade.
inheritConfiguration has already
+ // replaced the group; install the persisted one so connection
identifiers still match the flow file.
+ restorePersistedFlow(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences, true);
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ return;
+ }
+
+ captureInheritedFlowSnapshot();
+ }
+
+ @Override
+ public void restoreTroubleshootingManagedFlow(final VersionedConnector
persisted) throws FlowUpdateException {
+ final Bundle managedFlowBundle = resolveManagedFlowBundle(persisted);
+ final VersionedProcessGroup persistedManagedGroup =
persisted.getManagedProcessGroup();
+ final Map<String, SecretReference> parameterSecretReferences =
ParameterSecretReferences.convertManagedParameterSecretReferences(persisted);
+
+ if (extensionMissing && persistedManagedGroup != null) {
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ restoreTroubleshootingFlow(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences);
+ return;
+ }
+
+ if (sameManagedBundle(managedFlowBundle) && persistedManagedGroup !=
null) {
+ try {
+ restorePersistedFlow(persistedManagedGroup, null, Map.of(),
true);
+ adoptAuthoritativeSnapshot(persistedManagedGroup,
persisted.getManagedParameterContext(), parameterSecretReferences,
managedFlowBundle);
+ } catch (final Exception e) {
+ logger.error("{} failed to restore the managed flow while
restoring Troubleshooting", this, e);
+ throw new FlowUpdateException("Failed to restore Managed
Process Group from persisted flow: " + e.getMessage(), e);
+ }
+ return;
+ }
+
+ captureInheritedFlowSnapshot();
+ }
+
+ private void captureInheritedFlowSnapshot() {
+ if (getAuthoritativeManagedProcessGroup() == null &&
!extensionMissing) {
+ // No group was persisted, so the group inherit just built is this
connector's flow. Capture it, or a
+ // later NAR upgrade has no pre-upgrade flow to evolve.
+ captureAuthoritativeSnapshot();
+ }
+ }
+
+ private void restoreTroubleshootingFlow(final VersionedProcessGroup
persistedManagedGroup, final VersionedParameterContext parameterContext,
+ final Map<String, SecretReference> parameterSecretReferences)
throws FlowUpdateException {
+ logger.info("{} was persisted in Troubleshooting mode; restoring
Managed Process Group from persisted snapshot", this);
+ try {
+ restorePersistedFlow(persistedManagedGroup, parameterContext,
parameterSecretReferences, false);
+ } catch (final Exception e) {
+ logger.error("{} failed to restore the managed flow while
restoring Troubleshooting", this, e);
+ throw new FlowUpdateException("Failed to restore Managed Process
Group from persisted flow: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * A group saved before managedFlowBundle existed is attributed to the
connector bundle stored in the flow definition.
+ */
+ private static Bundle resolveManagedFlowBundle(final VersionedConnector
versionedConnector) {
+ if (versionedConnector.getManagedFlowBundle() != null) {
+ return versionedConnector.getManagedFlowBundle();
+ }
+ if (versionedConnector.getManagedProcessGroup() != null) {
+ return versionedConnector.getBundle();
+ }
+ return null;
+ }
+
+ private boolean sameManagedBundle(final Bundle managedFlowBundle) {
+ if (managedFlowBundle == null || bundleCoordinate == null) {
+ return true;
+ }
+ return sameBundle(managedFlowBundle, bundleCoordinate);
+ }
+
+ /**
+ * Rewrites processor and controller service bundles in a persisted group
to the only installed alternative when
+ * the exact coordinate is missing. A ghost Connector keeps the snapshot
exactly as persisted.
+ */
+ void resolvePersistedBundles(final VersionedProcessGroup group) {
+ if (extensionMissing || group == null || initializationContext ==
null) {
+ return;
+ }
+
+ initializationContext.resolveBundles(group,
BundleCompatibility.RESOLVE_BUNDLE);
+ }
+
+ void adoptAuthoritativeSnapshot(final VersionedProcessGroup flow, final
VersionedParameterContext parameterContext,
+ final Map<String, SecretReference> parameterSecretReferences,
final Bundle managedFlowBundle) {
+ authoritativeFlowSnapshot = new ConnectorFlowSnapshot(flow,
parameterContext, parameterSecretReferences, managedFlowBundle,
+
activeFlowContext.getConfigurationContext().toConnectorConfiguration());
+ }
+
+ void restorePersistedFlow(final VersionedProcessGroup flow, final
VersionedParameterContext parameterContext,
+ final Map<String, SecretReference> parameterSecretReferences,
final boolean resumeComponents) {
+ final ParameterSecretReferences.Resolution resolution =
resolvePersistedParameterSecrets(parameterContext, parameterSecretReferences);
+ if (resumeComponents && unresolvedParameterSecretReferences.isEmpty())
{
+ activeFlowContext.restorePersistedFlow(flow,
resolution.parameterContext());
+ } else {
+ activeFlowContext.restorePersistedFlow(flow,
resolution.parameterContext(), false);
+ }
+ }
+
+ private ParameterSecretReferences.Resolution
resolvePersistedParameterSecrets(final VersionedParameterContext
parameterContext,
+ final Map<String, SecretReference> parameterSecretReferences) {
+ final ParameterSecretReferences.Resolution resolution =
+ ParameterSecretReferences.resolve(parameterContext,
parameterSecretReferences, initializationContext.getSecretsManager());
+ unresolvedParameterSecretReferences =
Map.copyOf(resolution.unresolvedReferences());
+ return resolution;
+ }
+
+ @Override
+ public void prepareFlowEvolution() {
+ synchronized (flowEvolutionLock) {
+ if (!isPendingFlowEvolution()) {
+ throw new IllegalStateException("Cannot prepare flow evolution
for " + this + " because no evolution is pending");
+ }
+ final boolean resumeAfterHook = hasFlowEvolutionFailed() &&
hasCompletedFlowEvolutionHookProgress();
+ if (!stateTransition.trySetCurrentState(ConnectorState.STOPPED,
ConnectorState.DRAINING)) {
+ throw new IllegalStateException("Cannot prepare flow evolution
for " + this + " from state " + getCurrentState());
+ }
+
+ clearFlowEvolutionFailure();
+ final Bundle postUpgradeBundle = loadedBundle();
+ final ConnectorFlowSnapshot outgoingSnapshot =
authoritativeFlowSnapshot;
+ final Bundle preUpgradeBundle = outgoingSnapshot == null ||
outgoingSnapshot.bundle() == null ? postUpgradeBundle :
outgoingSnapshot.bundle();
+ flowEvolutionContext = new StandardFlowEvolutionContext(new
PreUpgradeFlowContext(activeFlowContext, preUpgradeBundle), postUpgradeBundle);
+ prepareForFlowEvolutionFuture = null;
+ evolveFlowFuture = null;
+ flowEvolutionStatus.set(resumeAfterHook
+ ? FlowEvolutionStatus.PHASE_ONE_COMPLETE
+ : FlowEvolutionStatus.PHASE_ONE_PENDING);
+ // A node that joins while this connector is draining inherits the
flow mapped from the desired state.
+ // RUNNING makes that node start, and therefore enter the same
evolution, instead of treating the drain as stopped.
+ stateTransition.setDesiredState(ConnectorState.RUNNING);
+ }
+ }
+
+ private boolean isFlowEvolutionInProgress() {
+ synchronized (flowEvolutionLock) {
+ // Desired state cannot say this. stop() sets the desired state to
STOPPED before it aborts the evolution.
+ final FlowEvolutionStatus status = flowEvolutionStatus.get();
+ return getCurrentState() == ConnectorState.DRAINING
+ && !hasFlowEvolutionFailed()
+ && (status == FlowEvolutionStatus.PHASE_ONE_PENDING
+ || status == FlowEvolutionStatus.PHASE_ONE_COMPLETE
+ || status == FlowEvolutionStatus.PHASE_TWO_COMPLETE);
+ }
+ }
+
+ private void runFlowEvolutionPreflight(final StandardFlowEvolutionContext
context) throws FlowUpdateException {
+ verifyFlowEvolutionContext(context);
+ if (!isFlowEvolutionPhaseOneComplete()) {
+ refreshPreUpgradeParameterSecrets(context);
+ }
+
+ final List<ValidationResult> ghostResults = new ArrayList<>();
+ validateManagedFlowComponents(ghostResults);
+ if (!ghostResults.isEmpty()) {
+ final String explanation =
ghostResults.getFirst().getExplanation();
+ failFlowEvolution(context, explanation, null);
+ throw new FlowUpdateException(explanation);
+ }
+
+ verifyFlowEvolutionContext(context);
+ }
+
+ private void refreshPreUpgradeParameterSecrets(final
StandardFlowEvolutionContext context) throws FlowUpdateException {
+ final ConnectorFlowSnapshot snapshot = authoritativeFlowSnapshot;
+ if (snapshot == null || snapshot.parameterContext() == null) {
+ verifyFlowEvolutionContext(context);
+ unresolvedParameterSecretReferences = Map.of();
+ return;
+ }
+
+ final ParameterSecretReferences.Resolution resolution =
ParameterSecretReferences.resolve(
+ snapshot.parameterContext(), snapshot.parameterSecretReferences(),
initializationContext.getSecretsManager());
+ if (!resolution.unresolvedReferences().isEmpty()) {
+ final Map.Entry<String, SecretReference> unresolved =
resolution.unresolvedReferences().entrySet().stream()
+ .sorted(Map.Entry.comparingByKey())
+ .findFirst()
+ .orElseThrow();
+ final SecretReference reference = unresolved.getValue();
+ final String secretName = reference.getFullyQualifiedName() ==
null ? reference.getSecretName() : reference.getFullyQualifiedName();
+ final String explanation = "Flow evolution cannot start: secret
[%s] used by parameter [%s] could not be resolved. "
+ .formatted(secretName, unresolved.getKey())
+ + "Restore the secret in its provider, then start the
Connector to resume the upgrade.";
+ verifyFlowEvolutionContext(context);
+ unresolvedParameterSecretReferences =
Map.copyOf(resolution.unresolvedReferences());
+ failFlowEvolution(context, explanation, null);
+ throw new FlowUpdateException(explanation);
+ }
+
+ verifyFlowEvolutionContext(context);
+ unresolvedParameterSecretReferences = Map.of();
+ if (!resolution.parameterValues().isEmpty()) {
+
activeFlowContext.getParameterContext().updateParameters(resolution.parameterValues());
+ }
+ }
+
+ @Override
+ public Future<Void> evolveFlow(final ExecutorService executor) throws
FlowUpdateException {
+ Objects.requireNonNull(executor, "Executor Service is required");
+
+ synchronized (flowEvolutionLock) {
+ final StandardFlowEvolutionContext context = flowEvolutionContext;
+ verifyFlowEvolutionContext(context);
+ if (evolveFlowFuture != null) {
+ return evolveFlowFuture;
+ }
+
+ evolveFlowFuture = executor.submit(() -> {
+ runFlowEvolutionPhaseOne(context);
+ return null;
+ });
+ return evolveFlowFuture;
+ }
+ }
+
+ private void runFlowEvolutionPhaseOne(final StandardFlowEvolutionContext
context) throws FlowUpdateException {
+ runFlowEvolutionPreflight(context);
+ if (isFlowEvolutionPhaseOneComplete()) {
+ return;
+ }
+
+ verifyFlowEvolutionContext(context);
+ final CompletableFuture<Void> connectorFuture;
+ try {
+ connectorFuture = invokeFlowEvolutionHook(context);
+ } catch (final FlowUpdateException e) {
+ failFlowEvolution(context, e.getMessage(), e);
+ throw e;
+ }
+
+ try {
+ synchronized (flowEvolutionLock) {
+ verifyFlowEvolutionContext(context);
+ prepareForFlowEvolutionFuture = connectorFuture;
+ }
+ } catch (final FlowUpdateException e) {
+ connectorFuture.cancel(true);
+ throw e;
+ }
+
+ try {
+ connectorFuture.get();
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new FlowUpdateException("Interrupted while waiting for flow
evolution hook for " + this, e);
+ } catch (final CancellationException e) {
+ throw new FlowUpdateException("Flow evolution hook was cancelled
for " + this, e);
+ } catch (final ExecutionException e) {
+ final Throwable cause = e.getCause() == null ? e : e.getCause();
+ failFlowEvolution(context, cause.getMessage(), cause);
+ throw new FlowUpdateException("Flow evolution hook failed for " +
this, cause);
+ }
+
+ completeFlowEvolutionPhaseOne(context);
+ }
+
+ private void completeFlowEvolutionPhaseOne(final
StandardFlowEvolutionContext context) throws FlowUpdateException {
+ verifyFlowEvolutionContext(context);
+ final VersionedExternalFlow proposedFlow;
+ try (final NarCloseable ignored =
NarCloseable.withComponentNarLoader(getConnector().getClass().getClassLoader()))
{
+ proposedFlow =
getConnector().getActiveFlow(getWorkingFlowContext());
+ } catch (final Exception failure) {
+ failFlowEvolution(context, failure.getMessage(), failure);
+ throw new FlowUpdateException("Failed to determine the upgraded
flow for " + this, failure);
+ }
+ if (proposedFlow == null || proposedFlow.getFlowContents() == null) {
+ failFlowEvolution(context, "Upgraded flow was not returned", null);
+ throw new FlowUpdateException("Upgraded flow was not returned for
" + this);
+ }
+
+ verifyFlowEvolutionContext(context);
+ try {
+ activeFlowContext.verifyUpdateFlow(proposedFlow);
+ } catch (final FlowUpdateException e) {
+ failFlowEvolution(context, e.getMessage(), e);
+ throw e;
+ }
+
+ // The hook may start processors so queues can empty. Those processors
must be stopped before the upgraded
+ // flow is installed, because a connection cannot be removed while its
source or destination is running.
+ verifyFlowEvolutionContext(context);
+ if (!stopPreUpgradeFlow()) {
+ failFlowEvolution(context, "Failed to stop the pre-upgrade flow",
null);
+ throw new FlowUpdateException("Failed to stop the pre-upgrade flow
for " + this);
+ }
+
+ synchronized (flowEvolutionLock) {
+ verifyFlowEvolutionContext(context);
+ flowEvolutionStatus.set(FlowEvolutionStatus.PHASE_ONE_COMPLETE);
+ }
+ }
+
+ private void verifyFlowEvolutionContext(final StandardFlowEvolutionContext
context) throws FlowUpdateException {
+ if (flowEvolutionContext != context || context == null ||
context.isFailed()) {
+ throw new FlowUpdateException("Flow evolution was cancelled for "
+ this);
+ }
+ verifyFlowEvolutionActive();
+ }
+
+ private CompletableFuture<Void> invokeFlowEvolutionHook(final
FlowEvolutionContext evolutionContext) throws FlowUpdateException {
+ try (final NarCloseable ignored =
NarCloseable.withComponentNarLoader(getConnector().getClass().getClassLoader()))
{
+ return Objects.requireNonNull(
+ getConnector().prepareForFlowEvolution(evolutionContext),
+ "Connector prepareForFlowEvolution must return a
CompletableFuture");
+ }
+ }
+
+ /**
+ * Installs the upgraded flow and records it as persisted in memory. A
failure leaves the partly updated flow in place.
+ * {@link Connector#applyUpdate} must be safe to run again on a flow it
has already partly updated, because the next
+ * start retries this method and does not return to phase one.
+ *
+ * @throws FlowUpdateException if the upgraded flow cannot be installed
+ */
+ private void installEvolvedFlow() throws FlowUpdateException {
+ if (authoritativeFlowSnapshot == null) {
+ throw new FlowUpdateException("Cannot install the upgraded flow
for " + this + " without an authoritative pre-upgrade snapshot");
+ }
+
+ final WorkingFlowContextState workingContextState =
acquireWorkingFlowContext();
+ final FrameworkFlowContext workingFlowContext =
workingContextState.getContext();
+ try (final NarCloseable ignored =
NarCloseable.withComponentNarLoader(getConnector().getClass().getClassLoader()))
{
+ getConnector().applyUpdate(workingFlowContext, activeFlowContext);
+
+ final ConnectorConfiguration workingConfiguration =
workingFlowContext.getConfigurationContext().toConnectorConfiguration();
+
activeFlowContext.getConfigurationContext().replaceConfiguration(toConfigurationMap(workingConfiguration));
+
+ verifyFlowEvolutionActive();
+ // STOPPED is written so a restart does not start the new flow
before every node has persisted it.
+ authoritativeFlowSnapshot = createAuthoritativeSnapshot();
+ stateTransition.setDesiredState(ConnectorState.STOPPED);
+ } catch (final Exception failure) {
+ failFlowEvolution(failure.getMessage(), failure);
+ throw new FlowUpdateException("Failed to install the upgraded flow
for " + this, failure);
+ } finally {
+ releaseWorkingFlowContext(workingContextState);
+ }
+
+ if (!isFlowEvolutionPhaseOneComplete()) {
+ throw new FlowUpdateException("Cannot mark the upgraded flow
persisted for " + this + " from status " + flowEvolutionStatus.get());
+ }
+
+ verifyFlowEvolutionActive();
+ flowEvolutionStatus.set(FlowEvolutionStatus.PHASE_TWO_COMPLETE);
+ }
+
+ private void commitEvolvedFlow() {
+ synchronized (flowEvolutionLock) {
+ if (flowEvolutionStatus.get() !=
FlowEvolutionStatus.PHASE_TWO_COMPLETE || getCurrentState() !=
ConnectorState.DRAINING || hasFlowEvolutionFailed()) {
+ return;
+ }
+
+ // Leaving DRAINING closes the attempt. The status stays at phase
two until the connector is RUNNING so a
+ // peer that has not yet observed the barrier still sees it.
+ stateTransition.setCurrentState(ConnectorState.STOPPED);
+ stateTransition.setDesiredState(ConnectorState.RUNNING);
+ }
+ }
+
+ /**
+ * Marks this evolution failed and cancels its hook after releasing the
evolution lock. The hook future is copied
+ * under the lock so a newer evolution is not cancelled. This does not
cancel the phase-one task, because it runs
+ * on that task and cancelling it would interrupt the task before it stops
the pre-upgrade flow.
+ *
+ * @param expectedContext the evolution to close
+ * @return false when the context is already closed or has been replaced
+ */
+ private boolean closeFlowEvolutionContext(final
StandardFlowEvolutionContext expectedContext) {
+ final CompletableFuture<Void> prepareFuture;
+ synchronized (flowEvolutionLock) {
+ final StandardFlowEvolutionContext context = flowEvolutionContext;
+ if (context == null || context.isFailed() || context !=
expectedContext) {
+ return false;
+ }
+
+ context.fail();
+ prepareFuture = prepareForFlowEvolutionFuture;
+ }
+
+ cancel(prepareFuture);
+ return true;
+ }
+
+ /**
+ * Marks the current evolution failed and cancels its hook and phase-one
task. The futures are copied under the
+ * evolution lock so a newer evolution started after this close is not
cancelled.
+ */
+ private void closeCurrentFlowEvolution() {
+ final CompletableFuture<Void> prepareFuture;
+ final Future<Void> phaseOneTask;
+ synchronized (flowEvolutionLock) {
+ final StandardFlowEvolutionContext context = flowEvolutionContext;
+ if (context == null || context.isFailed()) {
+ return;
+ }
+
+ context.fail();
+ prepareFuture = prepareForFlowEvolutionFuture;
+ phaseOneTask = evolveFlowFuture;
+ }
+
+ cancel(prepareFuture);
+ cancel(phaseOneTask);
+ }
+
+ private void cancel(final Future<?> future) {
+ if (future != null) {
+ future.cancel(true);
+ }
+ }
+
+ private void failFlowEvolution(final StandardFlowEvolutionContext context,
final String explanation, final Throwable cause) {
+ if (!closeFlowEvolutionContext(context)) {
+ return;
+ }
+
+ finishFlowEvolutionFailure(explanation, cause);
+ }
+
+ void failFlowEvolution(final String explanation, final Throwable cause) {
+ closeCurrentFlowEvolution();
+ finishFlowEvolutionFailure(explanation, cause);
+ }
+
+ private void finishFlowEvolutionFailure(final String explanation, final
Throwable cause) {
Review Comment:
[Claude Opus 5.5] Fixed. If the pre-upgrade flow doesn't stop, the evolution
fails and the Connector stays STOPPING. `retryPreUpgradeStop` keeps retrying
with backoff up to 60 seconds, and the Connector moves to STOPPED only once the
processors have stopped. If the Connector was asked to run in the meantime, it
starts again after that.
--
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]