Skip to content

[FLINK-40467] Randomise application result store paths - #1199

Open
dalelane wants to merge 2 commits into
apache:mainfrom
dalelane:flink-40467
Open

[FLINK-40467] Randomise application result store paths#1199
dalelane wants to merge 2 commits into
apache:mainfrom
dalelane:flink-40467

Conversation

@dalelane

@dalelane dalelane commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Flink 2.3 gives every application-mode execution an ApplicationResultStore, which defaults to
{high-availability.storage-path}/application-result-store/{ha.cluster-id}. That path is consistent across deployments (and not included in HA cleanup) so entries written by a terminated application outlive the upgrade that replaced it.

SessionDispatcherLeaderProcess recovers dirty results unkeyed, so the replacement cluster picks up the previous deployment's entry, and Dispatcher#maybeSubmitApplicationInApplicationMode then deliberately submits nothing when execution.shutdown-on-application-finish is false. This results in healthy JobManagers with no jobs.

Brief change log

This commit makes the storage path unique on each cluster launch so nothing stale can be recovered.

Verifying this change

Added a unit test that recreates the scenario

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changes to the CustomResourceDescriptors: no
  • Core observer or reconciler logic that is regularly executed: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable
Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

@james-kan-shopify james-kan-shopify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for opening this up! happen to encounter this and attempting to patch the same thing here.

}

private static void setRandomApplicationResultStorePath(Configuration effectiveConfig) {
if (effectiveConfig.contains(HighAvailabilityOptions.HA_STORAGE_PATH)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I've encountered the same bug, and have been working in a fork regarding this. Thanks for opening up a PR here!

Suggesting to consider also setting application-result-store.delete-on-commit=false, mirroringsetRandomJobResultStorePath.

maybeSubmitApplicationInApplicationMode skips submission on a clean result entry, but per its javadoc that lookup only works when DELETE_ON_COMMIT=false. Since the operator sets shutdown-on-application-finish=false, a terminal app's JM lives on until the shutdown TTL, and a restart in that window re-bootstraps it: main() re-runs, and multi-job apps fail outright. FLINK-27569 one level up.

@dalelane dalelane Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think that's worth fixing, but IMO it's a separate enough issue that it'd be better in a separate pull request (maybe a separate Jira bug issue too)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need delete on commit false here as well same way as the job result store then we should fix it in the same PR / issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gyfora I'm happy to do that if you're okay with the approach in the code here

James fairly highlighted the resource leak implication of the approach I took on the dev@ list where I said:

re: resource leak
Yeah, I agree that what I'm proposing in FLINK-40467 doubles down on the deal made in FLINK-27573, and maybe that's not a good thing. I used a random UUID because that's what I saw setRandomJobResultStorePath do, but in hindsight making directories anonymous makes the admin cleanup task harder as you can't derive the deployment from a directory name to know what is safe to remove. Perhaps the operator should record the path it generates in status - this would let us automate cleaning up the path for previous launches?

if you want to discuss that aspect first, I'll hold off on adding to the PR. But if you're okay with the approach, I'll add the delete on commit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have the exact same result leak already for the job result store logic. Not setting this config means that we have an inconsistent behaviour between different flink versions. We can consider how to avoid the resource leak as the next step but for now I think it makes sense to follow the currently established approach

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in a0fe7fb

@Dennis-Mircea Dennis-Mircea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, @dalelane! I posted a detailed analysis on the dev thread (https://lists.apache.org/thread/tyw45k5ww3yzfmfkmhz241nm82swlrsm) arguing that the current issue, unlike FLINK-27569, is an ordering problem (the operator tears the JM down before Flink deletes the dirty application result) and can be solved without introducing a second permanent leak. I would suggest holding this PR until the direction is agreed.

@gyfora

gyfora commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Can you please rebase on main to pull in the e2e fix?

Flink 2.3 gives every application-mode execution an
ApplicationResultStore, which defaults to
{high-availability.storage-path}/application-result-store/{ha.cluster-id}.
That path is consistent across deployments (and not included in HA
cleanup) so entries written by a terminated application outlive the
upgrade that replaced it.

SessionDispatcherLeaderProcess recovers dirty results unkeyed, so the
replacement cluster picks up the previous deployment's entry, and
Dispatcher#maybeSubmitApplicationInApplicationMode then deliberately
submits nothing when execution.shutdown-on-application-finish is false.
This results in healthy JobManagers with no jobs.

This commit makes the storage path unique on each cluster launch so
nothing stale can be recovered.

Signed-off-by: Dale Lane <dale.lane@uk.ibm.com>
job-result-store.delete-on-commit is currently set to false so the
terminal result survives for applications with HA storage configured,
to protect against terminated jobs inappropriately being restarted.

This commit applies the application-mode equivalent of the same thing
so that Job Manager restarts after an application has reached don't
get resubmitted.

This does result in a resource leak that needs manual cleanup, which
is described in a docs update.

Signed-off-by: Dale Lane <dale.lane@uk.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants