Skip to content

feat: add sys.stack_trace system table to dump druid nodes threads - #19855

Open
FrankChen021 wants to merge 4 commits into
apache:masterfrom
FrankChen021:codex/sys-stack-trace
Open

feat: add sys.stack_trace system table to dump druid nodes threads#19855
FrankChen021 wants to merge 4 commits into
apache:masterfrom
FrankChen021:codex/sys-stack-trace

Conversation

@FrankChen021

@FrankChen021 FrankChen021 commented Aug 2, 2026

Copy link
Copy Markdown
Member

Summary

  • add the sys.stack_trace system table for collecting live Java platform-thread snapshots from explicitly selected Druid nodes
  • add the /status/stack endpoint and a stateless collector with jstack-style formatting, CPU timing, lock, and deadlock information
  • support the maxStackTraceFrameDepth SQL query context and HTTP parameter with a default of 100 and a valid range of 10–1000
  • document the table, endpoint, conversion behavior, and virtual-thread limitation

Motivation

Expose targeted runtime diagnostics through SQL so operators and diagnostic AI agents can investigate thread contention, deadlocks, and CPU-heavy threads without collecting stack traces from an entire cluster unintentionally.

Validation

image image
  • StatusResourceTest (10 tests)
  • SystemSchemaTest (28 tests)
  • SystemStackTraceTableTest embedded HTTP/SQL coverage (7 tests)
  • CalciteQueryTest#testInformationSchemaTables
  • Checkstyle for server, sql, and embedded-tests
  • documentation spellcheck
  • git diff --check
  • Tested on a test cluter

Copilot AI review requested due to automatic review settings August 2, 2026 08:53
@FrankChen021 FrankChen021 changed the title feat: add stack trace system table feat: add sys.stack_trace system table to dump druid nodes Aug 2, 2026
@FrankChen021 FrankChen021 changed the title feat: add sys.stack_trace system table to dump druid nodes feat: add sys.stack_trace system table to dump druid nodes threads Aug 2, 2026

Copilot AI 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.

Pull request overview

Adds a new operational diagnostics capability to Apache Druid by exposing live JVM platform-thread stack snapshots via both an HTTP status endpoint and a new sys.stack_trace SQL system table, enabling targeted investigation of contention/deadlocks/CPU-heavy threads on explicitly selected nodes.

Changes:

  • Introduces /status/stack and a stateless StackTraceCollector that produces jstack-style formatted stack traces with optional CPU/lock/deadlock details and configurable frame depth.
  • Adds sys.stack_trace system table with required server filter pushdown and support for maxStackTraceFrameDepth via SQL query context / HTTP parameter.
  • Updates SQL metadata discovery tests and adds dedicated unit + embedded integration test coverage, plus user-facing documentation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
website/.spelling Adds new table/field terms to the website spellcheck allowlist.
sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java Extends system schema tests to include and validate the new stack_trace table behavior and context conversion.
sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java Updates information-schema table enumeration to include sys.stack_trace.
sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemStackTraceTable.java Implements the sys.stack_trace system table, including server-filter requirement and HTTP collection from selected nodes.
sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java Registers the new stack_trace system table in the system schema.
sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java Propagates maxStackTraceFrameDepth from SQL query context into the Calcite DataContext.
server/src/test/java/org/apache/druid/server/StatusResourceTest.java Adds unit tests for /status/stack response shape, validation, and formatting details.
server/src/main/java/org/apache/druid/server/StatusResource.java Adds the /status/stack endpoint, guarded by state-read authorization and with query-param validation.
server/src/main/java/org/apache/druid/server/StackTraceCollector.java New collector producing thread snapshot DTOs and jstack-style formatted stack output.
embedded-tests/src/test/java/org/apache/druid/testing/embedded/schema/SystemStackTraceTableTest.java Adds embedded end-to-end coverage for the endpoint and the sys.stack_trace SQL table.
docs/querying/sql-metadata-tables.md Documents the sys.stack_trace table, its required server filter, and frame-depth conversion semantics.
docs/api-reference/service-status-api.md Documents the new /status/stack endpoint and its request/response behavior.
Suppressed comments (1)

server/src/main/java/org/apache/druid/server/StackTraceCollector.java:398

  • These lock-related getters can return null (the backing fields are annotated @nullable), but the methods are not annotated @nullable. Aligning the nullability annotations on the getters makes the contract explicit to callers and matches the project’s typical JSON DTO style.
    @JsonProperty
    public String getLockName()
    {
      return lockName;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1
Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

Reviewed 12 of 12 changed files. Found one cancellation and resource-lifecycle issue in the remote stack-trace request path.


This is an automated review by Codex GPT-5.6-Sol

Comment thread sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemStackTraceTable.java Outdated
@jtuglu1

jtuglu1 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Can you outline the benefits of this approach compared to simply running perf, etc on the Druid process itself? Is this supposed to mirror: https://clickhouse.com/docs/reference/system-tables/trace_log?

@FrankChen021

Copy link
Copy Markdown
Member Author

Can you outline the benefits of this approach compared to simply running perf, etc on the Druid process itself? Is this supposed to mirror: https://clickhouse.com/docs/reference/system-tables/trace_log?

It's not similar to the trace_log in clickhouse, but similar to the system.stack_trace table in clickhouse.
This provides an easier and simpler way to dump a stack trace to analyze thread usage/potential contention.
With this SQL support, AI agents can get thread dump to do the analysis for us.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

Reviewed 12 of 12 changed files. Found one P2 issue: the updated code marks the future cancelled, but does not abort the production Netty HTTP exchange, so interrupted queries can retain transport resources.


This is an automated review by Codex GPT-5.6-Sol

new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8)
)
) {
while (!in.readLine().equals("")) {
);
OutputStream out = clientSocket.getOutputStream()
) {
while (!in.readLine().equals("")) {
final ListenableFuture<StatusResponseHolder> future = client.go(
new Request(
HttpMethod.GET,
new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))
() -> client.go(
new Request(
HttpMethod.GET,
new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants