Repository navigation
Fix merge-queue approval IT timeouts: build Jdbi SQL object handlers on first call, not on every attach - #35469
Conversation
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.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
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. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
… (#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]>
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 fullConfigRegistry.createCopy(), whenever the object is attached, and an on-demand DAO is attached on every call.getCollectionDAO().tableDAO().m()attachesCollectionDAO(~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
WorkflowEventConsumerthread, 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 inJdbiUtils(server and ops paths) in front of Jdbi'sSqlObjectFactory:ExtensionMetadataJdbi builds, so every method behaves exactly as before; only when its handler is built changes;@CreateSqlObjectgetters on a handle (transactions,withExtension) attach the nested DAO the same lazy way; on-demand getters already reach this factory;putIfAbsent), so attaching never pins a virtual thread;SqlObjectFactory.accepts(scans all method annotations on every attach) is memoized per class with aClassValue.Collate gets it too:
CollateApplication.getDaoisjdbi.onDemand(DaoExtension.class)on the Jdbi OM builds throughJdbiUtils, 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's2026-10-13-jdbi-never-pins-virtual-threads-...record. cc @harshach @mohityadav766 (owner of #35374).Type of change:
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 aroundtriggerWithSignal):1473a2b5cd~1)1473a2b5cd)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, realCollectionDAO, Jdbi 3.49.5): on-demandtableDAO()query 747 KB → 22 KB;tableDAO()attach on a handle 393 KB → 6 KB.Risks. Uses
@AlphaJdbi APIs (Extensions.findMetadata,ExtensionMetadata.createExtensionHandlerInvoker) andOnDemandHandleSupplier; a Jdbi upgrade must runLazySqlObjectFactoryTest. 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
@ConnectionAwareSqlQuerywith@Definerenders byte-identical SQL through this factory and Jdbi's own, on demand and on a handle.equals/hashCode/toStringbehave like Jdbi's proxies.jdk.VirtualThreadPinned).Unit tests
LazySqlObjectFactoryTest(6), new case inJdbiVirtualThreadPinningTest.LazySqlObjectFactoryTest,JdbiVirtualThreadPinningTest,ConnectionAwareAnnotationSqlLocatorTest,CollectionDAOCompositionTest: Tests run: 14, Failures: 0. Withinstall()made a no-op, the two allocation tests fail as expected.LazyMethodHandlersis package-private and exercised only throughLazySqlObjectFactoryin those tests.Backend integration tests
47e400a33f):MetricResourceIT77/77 (incl.rejectMetricUpdateRollsBackPreviousApprovedVersion) andGlossaryTermInheritedReviewerApprovalIT5/5 passed on MySQL. Workflow consumer in the MySQL parallel lane, measured as on the baseline runs:6b8aab0415)dc3981b71e)Locally:
MetricResourceIT+GlossaryTermInheritedReviewerApprovalITwith the fix applied, 269 run, 0 failures.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
UI screen recording:
Not applicable — backend-only change.
Checklist:
Fixes <issue-number>: <short explanation>— CI-failure fix, no issue (labelledskip-pr-checks).Fixes #<issue-number>above — see above.docs/decisions/2026-10-14-sql-objects-build-method-handlers-on-first-call.md+ amendment.