Skip to content

Handle empty JDBC trace profile segment lists - #14242

Merged
wu-sheng merged 2 commits into
apache:masterfrom
2748109647:fix/jdbc-empty-segment-query-14239
Nov 17, 2026
Merged

wu-sheng merged 2 commits into
apache:masterfrom
2748109647:fix/jdbc-empty-segment-query-14239

Conversation

@2748109647

Copy link
Copy Markdown
Contributor

Fix #14239

  • Add a unit test to verify that the fix works.
  • Explain briefly why the bug exists and how to fix it.

queryBySegmentIdList builds its SQL IN placeholders by joining the provided segment IDs. When the list is empty, that produces an invalid empty IN () predicate. Return an empty result before building or executing the JDBC query; non-empty query behavior stays unchanged.

Validation

  • .\mvnw.cmd -B -q -pl oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin "-Dcheckstyle.skip=true" "-Dtest=JDBCTraceQueryDAOTest" test: BUILD SUCCESS, 5 tests, 0 failures/errors/skips.
  • .\mvnw.cmd -B -q clean checkstyle:check: passed.
  • .\mvnw.cmd clean flatten:flatten install javadoc:javadoc -B -q -Pall "-Dmaven.test.skip=true" "-Dcheckstyle.skip=true" "-Dgpg.skip=true": completed successfully; only existing JDK/Lombok deprecation warnings.
  • git diff --check: passed.

A live MariaDB reproduction and the full test suite were not run; the regression test verifies that an empty input returns an empty result without invoking the JDBC client. The reported IN () shape is inferred from the current query-building code; the issue reporter did not capture the generated SQL.

@wu-sheng wu-sheng added this to the 11.2.0 milestone Nov 16, 2026
@wu-sheng wu-sheng added bug Something isn't working and you are sure it's a bug! backend OAP backend related. labels Nov 16, 2026

@wu-sheng wu-sheng 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.

lgtm, and we will follow up more fix via #14243

@wu-sheng
wu-sheng merged commit e564f75 into apache:master Nov 17, 2026
491 of 495 checks passed
wu-sheng added a commit that referenced this pull request Nov 17, 2026
…t the JDBC DAOs on PostgreSQL and MariaDB

JDBC storage fixes, each proven by a new IT or unit test that fails on the
previous code:
- Empty lists: the continuous profiling targets and the eBPF profiling data
  built `in ()`, an SQL syntax error on MySQL, MariaDB and PostgreSQL; an
  empty list now reads nothing. The segment lookup by trace and instance
  gets the guard #14242 added to the lookup by segment ID.
- Queries across day tables: the trace list pages, the Zipkin search limit
  and traces split at midnight, heatmap columns, Top N (ranked by the exact
  mean of the whole range, values above the int range), slow statements,
  tag autocomplete limits, the async-profiler, pprof and trace profiling
  task lists, and the instances of every day table.
- Trace profiling: Go thread snapshots read as Java, and a day table without
  a segment's snapshots read as sequence 0.
- The process list of an agent ignored the ping time range; browser error
  logs failed without a time range; events filtered by layer failed on
  PostgreSQL, and an event at a time range's first millisecond was left out.
- UI templates: the lookup by ID missed every template, so disabling one
  failed, and changing a missing one reported success.
- A zero-row UPDATE did not drop the metric from OAP's cache, so later
  flushes kept updating its missing row. The failure callback now drops it,
  and a later flush inserts the row again.
- The boot table check logged wrong table and column states.

Async-profiler fixes in shared OAP core:
- On JDBC and Elasticsearch, the check refusing a second task on a service
  compared a minute bucket with the tasks' second buckets and never found
  the running task. It now uses a second bucket.
- A cache refresh could keep the older of two recent tasks for the agent.

Tests and CI:
- New JDBC storage ITs on PostgreSQL 13 and MariaDB 11.4 (Testcontainers),
  40 cases on each, run in the default Integration test job. MariaDB
  Connector/J (LGPL) is a test-scope dependency only.
- The Zipkin and span-attached event ITs of the Elasticsearch storage also
  carry `@Tag("elastic-it")` and run as one slow-IT matrix entry.
wu-sheng added a commit that referenced this pull request Nov 17, 2026
…t the JDBC DAOs on PostgreSQL and MariaDB

JDBC storage fixes, each proven by a new IT or unit test that fails on the
previous code:
- Empty lists: the continuous profiling targets and the eBPF profiling data
  built `in ()`, an SQL syntax error on MySQL, MariaDB and PostgreSQL; an
  empty list now reads nothing. The segment lookup by trace and instance
  gets the guard #14242 added to the lookup by segment ID.
- Queries across day tables: the trace list pages, the Zipkin search limit
  and traces split at midnight, heatmap columns, Top N (ranked by the exact
  mean of the whole range, values above the int range), slow statements,
  tag autocomplete limits, the async-profiler, pprof and trace profiling
  task lists, and the instances of every day table.
- Trace profiling: Go thread snapshots read as Java, and a day table without
  a segment's snapshots read as sequence 0.
- The process list of an agent ignored the ping time range; browser error
  logs failed without a time range; events filtered by layer failed on
  PostgreSQL, and an event at a time range's first millisecond was left out.
- UI templates: the lookup by ID missed every template, so disabling one
  failed, and changing a missing one reported success.
- A zero-row UPDATE did not drop the metric from OAP's cache, so later
  flushes kept updating its missing row. The failure callback now drops it,
  and a later flush inserts the row again.
- The boot table check logged wrong table and column states.

Async-profiler fixes in shared OAP core:
- On JDBC and Elasticsearch, the check refusing a second task on a service
  compared a minute bucket with the tasks' second buckets and never found
  the running task. It now uses a second bucket.
- A cache refresh could keep the older of two recent tasks for the agent.

Tests and CI:
- New JDBC storage ITs on PostgreSQL 13 and MariaDB 11.4 (Testcontainers),
  40 cases on each, run in the default Integration test job. MariaDB
  Connector/J (LGPL) is a test-scope dependency only.
- The Zipkin and span-attached event ITs of the Elasticsearch storage also
  carry `@Tag("elastic-it")` and run as one slow-IT matrix entry.
wu-sheng added a commit that referenced this pull request Nov 17, 2026
…t the JDBC DAOs on PostgreSQL and MariaDB (#14243)

JDBC storage fixes, each proven by a new IT or unit test that fails on the
previous code:
- Empty lists: the continuous profiling targets and the eBPF profiling data
  built `in ()`, an SQL syntax error on MySQL, MariaDB and PostgreSQL; an
  empty list now reads nothing. The segment lookup by trace and instance
  gets the guard #14242 added to the lookup by segment ID.
- Queries across day tables: the trace list pages, the Zipkin search limit
  and traces split at midnight, heatmap columns, Top N (ranked by the exact
  mean of the whole range, values above the int range), slow statements,
  tag autocomplete limits, the async-profiler, pprof and trace profiling
  task lists, and the instances of every day table.
- Trace profiling: Go thread snapshots read as Java, and a day table without
  a segment's snapshots read as sequence 0.
- The process list of an agent ignored the ping time range; browser error
  logs failed without a time range; events filtered by layer failed on
  PostgreSQL, and an event at a time range's first millisecond was left out.
- UI templates: the lookup by ID missed every template, so disabling one
  failed, and changing a missing one reported success.
- A zero-row UPDATE did not drop the metric from OAP's cache, so later
  flushes kept updating its missing row. The failure callback now drops it,
  and a later flush inserts the row again.
- The boot table check logged wrong table and column states.

Async-profiler fixes in shared OAP core:
- On JDBC and Elasticsearch, the check refusing a second task on a service
  compared a minute bucket with the tasks' second buckets and never found
  the running task. It now uses a second bucket.
- A cache refresh could keep the older of two recent tasks for the agent.

Tests and CI:
- New JDBC storage ITs on PostgreSQL 13 and MariaDB 11.4 (Testcontainers),
  40 cases on each, run in the default Integration test job. MariaDB
  Connector/J (LGPL) is a test-scope dependency only.
- The Zipkin and span-attached event ITs of the Elasticsearch storage also
  carry `@Tag("elastic-it")` and run as one slow-IT matrix entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend OAP backend related. bug Something isn't working and you are sure it's a bug!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] JDBC trace profiling query fails with SQL syntax error when the segment list is empty

2 participants