Skip to content

[FLINK-39984][runtime][webUI] Support LITE/FULL thread dump modes#28732

Open
xingsuo-zbz wants to merge 1 commit into
apache:masterfrom
xingsuo-zbz:zbz/thread-dump-safe-mode
Open

[FLINK-39984][runtime][webUI] Support LITE/FULL thread dump modes#28732
xingsuo-zbz wants to merge 1 commit into
apache:masterfrom
xingsuo-zbz:zbz/thread-dump-safe-mode

Conversation

@xingsuo-zbz

@xingsuo-zbz xingsuo-zbz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes FLINK-39984. Clicking "Thread Dump" on a JobManager or TaskManager in the Web UI can cause the targeted process to miss heartbeats and be marked dead by the JobManager, taking down otherwise healthy running jobs.

The dominant cost is not the RPC dispatch but the underlying JVM safepoint: JvmUtils#createThreadDump unconditionally calls ThreadMXBean.dumpAllThreads(true, true), which requires walking every thread's locked-monitor and j.u.c. synchronizer state inside a single JVM-wide safepoint. On JVMs with many threads (Netty + RocksDB + async I/O + user threads — 10k+ in production is not uncommon) this pauses the entire JVM (including the heartbeat dispatcher) for seconds to tens of seconds. If the pause exceeds heartbeat.timeout (default 50 s), the JM triggers an unnecessary TaskManager failover on what was intended as a purely diagnostic action.

This PR makes the dump granularity configurable so operators can pick a mode whose safepoint pause is bounded well
below heartbeat.timeout. A companion PR under the same JIRA additionally offloads the dump construction to
ioExecutor so the RPC mailbox no longer stalls behind the dump; the two fixes are complementary but independent.

Brief change log

  • Introduce ThreadDumpMode {LITE, FULL} and thread it through RestfulGateway / TaskExecutorGateway /
    ResourceManagerGateway / TaskExecutorGatewayDecoratorBase / NonLeaderRetrievalRestfulGateway.
    • LITE → dumpAllThreads(false, false) — stack traces only, negligible JVM pause.
    • FULL → dumpAllThreads(true, true) — current behavior, retains locked-monitor / synchronizer info for deadlock analysis.
  • Expose the mode as an optional REST query parameter ?mode=lite|full on both /jobmanager/thread-dump and /taskmanagers/{id}/thread-dump via a new ThreadDumpModeQueryParameter and two new MessageParameters classes; unknown values become HTTP 400.
  • Add config option cluster.thread-dump.default-mode (default FULL) that controls the fallback when no query parameter is supplied. Default is deliberately FULL to preserve the existing on-upgrade behavior; the description flags LITE as the recommended value for large clusters. A separate dev@ discussion will decide whether to flip the default in a future release.
  • Web UI: add a Lite / Full toggle to both thread-dump pages
    (flink-runtime-web/web-dashboard/.../{job,task}-manager/thread-dump/). Selecting a mode does not auto-fetch; the user must press the refresh button (avoids surprising the operator when they merely click the toggle). The download link tracks the current selection so exported dumps match the on-screen content.
image

Verifying this change

This change added tests and can be verified as follows:
New unit tests

  • ThreadDumpModeQueryParameterTest — 6 cases covering key name, optionality, case-insensitive parsing of LITE/FULL,
    unknown value → IllegalArgumentException, and lower-case serialization.
  • TaskExecutorThreadDumpTest — spins up a real TaskExecutor and verifies that (a) requestThreadDump returns a
    non-empty dump for null, LITE, and FULL, and (b) when mode is omitted the request honors
    cluster.thread-dump.default-mode (the test overrides it to LITE and asserts the "Number of locked synchronizers"
    section is absent, which only appears in FULL).

Existing tests updated

  • TestingResourceManagerGateway, TestingTaskExecutorGateway, TestingRestfulGateway — signature updates for the new
    ThreadDumpMode parameter.
  • rest_api_v1.snapshot — new mode query parameter recorded for both endpoints; RuntimeRestAPIStabilityTest passes
    against the updated snapshot.

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 changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: yes (Before this change, requesting a thread dump on a busy TM could cause a spurious Heartbeat of TaskManager timed out. After this change the
    request no longer blocks the RPC mailbox and when the operator selects LITE, the
    safepoint pause is short enough not to trip heartbeat.timeout.)
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes — the new ThreadDumpMode REST parameter and cluster.thread-dump.default-mode config option.
  • If yes, how is the feature documented? docs

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Claude Opus 4.7)

@flinkbot

flinkbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@spuru9

spuru9 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

A few minor comments before the review:

  1. The commit message can a co-author reference contradiction the PR guidelines.
  2. Can you fix the test issue. They appear to be genuine issues.

@xingsuo-zbz
xingsuo-zbz force-pushed the zbz/thread-dump-safe-mode branch 3 times, most recently from bc6b4a8 to 36f9795 Compare July 15, 2026 12:26
@xingsuo-zbz

Copy link
Copy Markdown
Contributor Author

@flinkbot run azure

@xingsuo-zbz

Copy link
Copy Markdown
Contributor Author

@spuru9 done,please continue to review

@Myasuka Myasuka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should split this PR into two PRs, one is to use ioExecutor instead of main thread; one is to introduce new feature that we can have options to select when creating thread dumps.

@xingsuo-zbz
xingsuo-zbz force-pushed the zbz/thread-dump-safe-mode branch from 36f9795 to 117a668 Compare July 20, 2026 11:05
@xingsuo-zbz xingsuo-zbz changed the title [FLINK-39984][runtime][webUI] Dispatch thread dump to ioExecutor and support SAFE/FULL modes [FLINK-39984][runtime][webUI] Support LITE/FULL thread dump modes Jul 20, 2026
@xingsuo-zbz
xingsuo-zbz force-pushed the zbz/thread-dump-safe-mode branch from 117a668 to 86388ac Compare July 20, 2026 13:09
@xingsuo-zbz

xingsuo-zbz commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

I think we should split this PR into two PRs, one is to use ioExecutor instead of main thread; one is to introduce new feature that we can have options to select when creating thread dumps.

@Myasuka The ioExecutor offload lives in a companion PR#28778 under the same JIRA.

ThreadMXBean.dumpAllThreads(true, true) enters a single JVM-wide
safepoint to collect monitor/synchronizer state; on busy JVMs the pause
can exceed heartbeat.timeout and cause unnecessary TaskManager failover.

- Introduce ThreadDumpMode {LITE, FULL}: LITE = dumpAllThreads(false,
  false), FULL preserves today's (true, true) behavior. Exposed via an
  optional query parameter `?mode=lite|full` on the JM/TM thread-dump
  endpoints.
- Add config cluster.thread-dump.default-mode (default FULL to preserve
  upgrade behavior; LITE recommended for large clusters).
- Add a Lite/Full toggle to both Web UI thread-dump pages; selecting a
  mode does not auto-fetch, the download link tracks the selection.
@xingsuo-zbz
xingsuo-zbz force-pushed the zbz/thread-dump-safe-mode branch from 86388ac to a12f903 Compare July 23, 2026 11:33
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