Skip to content

Fix merge-queue approval IT timeouts: build Jdbi SQL object handlers on first call, not on every attach - #35469

Merged
mohityadav766 merged 1 commit into
mainfrom
fix/jdbi-lazy-sqlobject-attach
Oct 14, 2026
Merged

mohityadav766 merged 1 commit into
mainfrom
fix/jdbi-lazy-sqlobject-attach

Conversation

@yan-3005

@yan-3005 yan-3005 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes the approval-workflow IT timeouts and parallel-lane timeouts that have been ejecting PRs from the merge queue since #35374 landed (e.g. MetricResourceIT.rejectMetricUpdateRollsBackPreviousApprovedVersion, GlossaryTermInheritedReviewerApprovalIT.*, lanes hitting the 60-minute fork limit with 0 test failures). In #ci-cleanup, Oct 7–13 had 1 approval-timeout ejection; Oct 14 had 5 of 6 IT ejections with that signature, plus 3 lane timeouts.

Root cause. #35374 moved Jdbi 3.37.1 → 3.49.5 for the virtual-thread pinning fix. From Jdbi 3.38, ExtensionFactoryDelegate.attach (3.49.5, lines 137–138) builds a handler for every method of a SQL object, each with a full ConfigRegistry.createCopy(), whenever the object is attached, and an on-demand DAO is attached on every call. getCollectionDAO().tableDAO().m() attaches CollectionDAO (~150 methods) and the entity DAO (~80), so one query paid for ~230 configuration copies. 3.37.1 built only the called method's handler. Every pin-free Jdbi does this, and upstream keeps it by design, so changing the Jdbi version doesn't help.

It shows up as approval timeouts because the approval ITs are the ones that wait on the single WorkflowEventConsumer thread, which runs each workflow inline with 39 (metric) to 110 (glossary term) uncached DAO calls per event. The extra allocation also slows the whole server, hence the lane timeouts.

Fix. LazySqlObjectFactory, registered in JdbiUtils (server and ops paths) in front of Jdbi's SqlObjectFactory:

  • reuses the same ExtensionMetadata Jdbi builds, so every method behaves exactly as before; only when its handler is built changes;
  • one instance-configuration copy per attach, one handler per method actually called;
  • @CreateSqlObject getters on a handle (transactions, withExtension) attach the nested DAO the same lazy way; on-demand getters already reach this factory;
  • handlers are built outside any lock (get → build → putIfAbsent), so attaching never pins a virtual thread;
  • SqlObjectFactory.accepts (scans all method annotations on every attach) is memoized per class with a ClassValue.

Collate gets it too: CollateApplication.getDao is jdbi.onDemand(DaoExtension.class) on the Jdbi OM builds through JdbiUtils, and Collate registers no extension factories of its own.

Decision record: docs/decisions/2026-10-14-sql-objects-build-method-handlers-on-first-call.md; amendment added to #35374's 2026-10-13-jdbi-never-pins-virtual-threads-... record. cc @harshach @mohityadav766 (owner of #35374).

Type of change:

  • Bug fix

High-level design:

Evidence: controlled local A/B (MetricResourceIT + GlossaryTermInheritedReviewerApprovalIT, MySQL+ES, server JVM limited to 4 CPUs, JFR on, same 888 workflow events per run, timing and SQL counted around triggerWithSignal):

Jdbi 3.37.1 (1473a2b5cd~1) Jdbi 3.49.5 (1473a2b5cd) 3.49.5 + this fix
Total server allocation 19.9 GB 53.8 GB 19.1 GB
Share inside SQL-object attach 8% 66% —
GC runs 88 170 93
SQL statements per metric / glossary event 39 / 110 39 / 110 39 / 110
Consumer time per metric event 87.9 ms 89.9–101.5 ms 68.9–74.8 ms
Consumer time per glossary-term event 262 ms 308 ms 221 ms
Workflow-event queue delay p50 / p95 28.6 / 41.7 s 35.6 / 47.1 s 23.0 / 34.3 s

Same SQL, same DB time; only the Java-side cost per DAO call changed. In CI (12 runs before #35374, 6 after), the consumer's cost per glossary/metric signal went from 0.22–0.52 s to 0.48–0.65 s with no overlap.

Per DAO call (LazySqlObjectFactoryTest, real CollectionDAO, Jdbi 3.49.5): on-demand tableDAO() query 747 KB → 22 KB; tableDAO() attach on a handle 393 KB → 6 KB.

Risks. Uses @Alpha Jdbi APIs (Extensions.findMetadata, ExtensionMetadata.createExtensionHandlerInvoker) and OnDemandHandleSupplier; a Jdbi upgrade must run LazySqlObjectFactoryTest. A misconfigured DAO method now fails on first call rather than on attach (3.37.1 behaviour). Remove once Jdbi builds handlers lazily upstream.

Tests:

Use cases covered

  • An on-demand DAO query and a nested DAO attached inside a handle allocate a fraction of the eager attach (fail without the fix: 747 KB vs 747 KB, 393 KB vs 393 KB).
  • The same MySQL @ConnectionAwareSqlQuery with @Define renders byte-identical SQL through this factory and Jdbi's own, on demand and on a handle.
  • Nested DAOs keep their type; equals/hashCode/toString behave like Jdbi's proxies.
  • A DAO call through the lazy factory that waits for a connection on a virtual thread does not pin it (JFR jdk.VirtualThreadPinned).

Unit tests

  • Added LazySqlObjectFactoryTest (6), new case in JdbiVirtualThreadPinningTest.
  • Ran: LazySqlObjectFactoryTest, JdbiVirtualThreadPinningTest, ConnectionAwareAnnotationSqlLocatorTest, CollectionDAOCompositionTest: Tests run: 14, Failures: 0. With install() made a no-op, the two allocation tests fail as expected.
  • LazyMethodHandlers is package-private and exercised only through LazySqlObjectFactory in those tests.

Backend integration tests

  • Not applicable for new endpoints. The planner selects the full IT suite (every DAO call goes through this). Dispatched on this branch (47e400a33f):
Engine Run Result Parallel lane
MySQL + Elasticsearch 38589880033 all 5 lanes passed; parallel lane 16,987 tests, 0 failures 51 min
PostgreSQL + OpenSearch 38589886691 all 5 lanes passed 51 min
PostgreSQL + Elasticsearch + Redis 38594898184 all 4 lanes passed 54 min

MetricResourceIT 77/77 (incl. rejectMetricUpdateRollsBackPreviousApprovedVersion) and GlossaryTermInheritedReviewerApprovalIT 5/5 passed on MySQL. Workflow consumer in the MySQL parallel lane, measured as on the baseline runs:

before #35374 (6b8aab0415) after #35374, failing (dc3981b71e) this PR
Consumer busy time 1,508 s 2,545 s 1,374 s
glossaryTerm / metric cost per signal 0.30 / 0.28 s 0.65 / 0.54 s 0.28 / 0.23 s
Parallel lane duration — 69 min (fork limit) 51 min

Locally: MetricResourceIT + GlossaryTermInheritedReviewerApprovalIT with the fix applied, 269 run, 0 failures.

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable.

Manual testing performed

  1. Ran the A/B above three times (3.37.1, 3.49.5, 3.49.5 + fix) with JFR and per-event SQL/timing instrumentation (instrumentation not in this PR).

UI screen recording:

Not applicable — backend-only change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation> — CI-failure fix, no issue (labelled skip-pr-checks).
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above — see above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable.
  • For a UI feature or feature task: not applicable.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Decision check: docs/decisions/2026-10-14-sql-objects-build-method-handlers-on-first-call.md + amendment.
  • I have added a test that covers the exact scenario we are fixing.

Jdbi 3.38+ builds a handler, each with its own configuration copy, for
every method of a SQL object whenever it is attached, and an on-demand
DAO is attached on every call. After the 3.37.1 -> 3.49.5 bump (#35374)
one getCollectionDAO().tableDAO() query allocated ~747 KB; the server
allocated 2.7x more overall and the single workflow-event consumer fell
behind, timing out approval ITs on every engine.

LazySqlObjectFactory sits in front of Jdbi's SqlObjectFactory, reuses
the same ExtensionMetadata, makes one instance configuration per attach
and builds a method's handler the first time it is called. Nested
@CreateSqlObject DAOs on a handle are attached the same way. Handlers
are built outside any lock, so attaching never pins a virtual thread.
@yan-3005
yan-3005 requested a review from a team as a code owner October 14, 2026 15:30
@yan-3005
yan-3005 requested review from IceS2 and a balanced review from Copilot October 14, 2026 15:30
@yan-3005 yan-3005 added the skip-pr-checks Bypass PR metadata validation check label Oct 14, 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 14, 2026
@gitar-bot

gitar-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Applying lazy handler creation to server and ops DAOs could defer misconfiguration errors until a specific method runs.

Replaces per-attach Jdbi SQL object handler construction with a lazy factory that builds each method handler on first call, restoring approval-workflow IT timing after the Jdbi 3.49.5 upgrade. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@yan-3005
yan-3005 removed the request for review from IceS2 October 14, 2026 16:12
@mohityadav766
mohityadav766 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 9e74219 Oct 14, 2026
148 of 149 checks passed
@mohityadav766
mohityadav766 deleted the fix/jdbi-lazy-sqlobject-attach branch October 14, 2026 17:59
@yan-3005 yan-3005 self-assigned this Nov 19, 2026
manerow added a commit that referenced this pull request Nov 23, 2026
… (#38520)

* Fixes #35373: Stop Jdbi pinning virtual threads and the test suite summary 404 on deleted test cases (#35374)

* Build Jdbi SQL object handlers on first call, not on every attach (#35469)

* Fixes #35428: Stop cache-miss loads pinning virtual threads (#35429)

---------

Co-authored-by: Mohit Yadav <[email protected]>
Co-authored-by: Ram Narayan Balaji <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants