You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(QTDI-3029): Share JsonProvider and JsonbProvider instances - #1291
Any code change adding any logic MUST be tested through a unit test executed with the default build
Any API addition MUST be done with a documentation update if relevant
Why this PR is needed?
Jira: QTDI-3029. JsonProvider.provider() and JsonbProvider.provider() create a new ServiceLoader on each call, which leads to thread locks when many jobs run in parallel (e.g. a massively parallel Studio job). ContainerFinder.Instance.get also re-ran its ServiceLoader lookup on every call when no ContainerFinder service exists.
What does this PR adds (design/code thoughts)?
New SharedJsonProviders holder (component-runtime-impl): one lazily initialized JsonProvider and one JsonbProvider (initialization-on-demand idiom). They are resolved with the framework classloader as TCCL, so the first caller inside an isolated container cannot bind the global instance to that container's JSON-P implementation.
Used only by framework-internal call sites with no container context: PayloadMapper, ReflectionService, ComponentManager fallbacks, SchemaConverter, RecordImpl, CheckpointState, ProcessorImpl, JobImpl, DiRecordVisitor, DiRowStructVisitor, RecordJsonMapper. Per-container providers are unchanged.
ContainerFinder.Instance.get records that the lookup was done so the ServiceLoader is not re-run on every call.
New tests: SharedJsonProvidersTest, ContainerFinderInstanceTest. No existing test was modified.
Review notes (Minor, not changed):
JohnzonBuilder.build via AutoChunkProcessor.onElement was not investigated or changed; to be reported on the Jira ticket.
ContainerFinder lookup is not reset if a ContainerFinder service appears on the classpath later (set() still overrides).
SharedJsonProvidersTest cannot cover the TCCL isolation, since the singleton is initialized once per JVM.
Out of scope: tXSDValidator_main.javajet, the JDBC service ServiceLoader case (QTDI-2530), other non-JSON ServiceLoader uses, migration of existing test code.
Manual validation (baseline vs fix on a massively parallel Studio job) is tracked in Zephyr QTDI-T13907 and QTDI-T13908.
AI contribution metrics
Code Generation % (this PR): 100% (320/316 AI-tagged changed lines; capped at 100% because the two commits overlap)
Code Generation % (ticket-wide cumulative): 100%
Technical Design % (ticket-wide cumulative): ~85% (estimated from the draft and approved plan; not word-diffed)
JsonProvider.provider() and JsonbProvider.provider() create a new
ServiceLoader at each call, which leads to thread locks under heavy
parallel load. Add SharedJsonProviders holding one lazily initialized
instance of each, and use it in framework internal call sites without
container context. Also stop ContainerFinder.Instance.get from running
the ServiceLoader lookup again once it was done.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Avoid binding the global instances to the classloader of the isolated
container which triggers the first lookup.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
provider() resolves via TCCL; the first caller inside an isolated container could bind the global singleton to that container's JSON-P implementation / classloader
Fixed (commit 2): resolve with the framework classloader as TCCL during init; build green
2
MINOR
ContainerFinder
lookupDone is never reset if a ContainerFinder service appears later on the classpath (acceptable; set() still overrides)
None
3
MINOR
plan
JohnzonBuilder.build / AutoChunkProcessor.onElement investigation not done
Noted in PR and Jira
4
MINOR
tests
SharedJsonProvidersTest cannot test the TCCL isolation (singleton initialized once per JVM)
None
Round 2 — APPROVED. No Blocker or Major findings; 3 Minor noted.
17 files reviewed (11 main modified, 1 new holder, 2 new tests, ContainerFinder). Spotless applied; no wildcard imports; Apache license headers present (RAT passed); tests are JUnit5 *Test classes in the same package; no logging or exception-handling issues.
Critical: 0
Warnings: 1. SharedJsonProvidersTest uses the fully-qualified javax.json.bind.Jsonb inline, and its import order is off (cosmetic).
Info: 1. The impl module jacoco ratio is 0.72, below 0.75. This is a pre-existing, non-failing warning.
Fixed in 17e0b280e36 — added tests for ProcessorImpl default Jsonb path, CheckpointState.toJson, JobImpl DataInputFactory (POJO→Record jsonb), SchemaConverter.toObjectImpl
#2 — SharedJsonProvidersTest#L67: use assertEquals
Code fix
Fixed in 17e0b280e36
Fixes pushed: 17e0b280e36 — fix(QTDI-3029): address review round 1 Pending clarifications: 0 Rebase: not done — branch already contains a master merge; rebasing would require a force-push. Not needed for these test-only changes.
Round summary generated by AI. Please resolve threads after verifying the fixes.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Several runtime call sites still use static JSON-P helpers that perform repeated ServiceLoader lookups and can preserve the lock contention this change targets, while the isolated-classloader behavior also lacks coverage.
… through shared provider
Replace Json.create* static calls in CheckpointState, RecordImpl,
SchemaConverter, DiRecordVisitor and RecordJsonMapper with
SharedJsonProviders.jsonProvider(), and add a test checking that
initialization ignores an isolated context classloader.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Fixes pushed: 38823c01a5e Pending clarifications: 0 Rebase: not done — master is ahead, but a rebase would require a force-push, so the branch was left as is. Verification: component-runtime-impl and SchemaConverterTest pass. component-runtime-di and component-kitap could not be built offline (unresolved SNAPSHOT dependencies); CI will verify them.
Round summary generated by AI. Please resolve threads after verifying the fixes.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved moderate issues leave provider lookups on fallback serialization paths, and a critical test-classloader flaw can prevent the new isolation test from running reliably.
The processor's no-container JSON-P fallback still calls Json.createBuilderFactory(emptyMap()) in jsonBuilderFactory(). That convenience method performs another provider ServiceLoader lookup whenever the fallback is used, leaving this ProcessorImpl path subject to the contention this change is intended to remove. Use SharedJsonProviders.jsonProvider().createBuilderFactory(emptyMap()) there as well and remove the now-only Json import.
Use shared JSON-B provider for record serialization
This change now routes the JSON-P conversion through the shared provider, but toString() still constructs its Jsonb with JsonbBuilder.create(...) above. That convenience call performs a fresh ServiceLoader lookup and uses the current TCCL on every record serialization, so this path can still reintroduce the lock contention (and can bind to an isolated container provider). Build the configured instance from SharedJsonProviders.jsonbProvider().create().withConfig(...).build() as well.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Two moderate active findings remain: the no-container builder-factory fallback and RecordImpl.toString() still perform per-call ServiceLoader/provider lookups, leaving the lock contention and provider-consistency issues unresolved.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Use shared JSON provider for builder-factory fallback
This fallback now avoids the JSON-B lookup, but the sibling jsonBuilderFactory() fallback in the same class still calls Json.createBuilderFactory(emptyMap()) (line 242). That convenience API creates a fresh JSON-P ServiceLoader lookup for each processor, so parallel processors can still contend on the lock this change is intended to remove. Use SharedJsonProviders.jsonProvider().createBuilderFactory(emptyMap()) for that no-container fallback as well.
Use shared JSON-B provider in toString serialization
The provider and builder-factory suppliers are shared now, but toString() still constructs its Jsonb with JsonbBuilder.create(...) above. That static helper performs a fresh JsonbProvider/ServiceLoader lookup on every record serialization and can also resolve against an isolated TCCL, so this path still has the lock contention and provider mismatch the new SharedJsonProviders usage is meant to avoid. Create the builder through SharedJsonProviders.jsonbProvider().create().withConfig(...).build() instead.
Rewritten: package-private withFrameworkClassLoader(Supplier, ClassLoader), jsonb covered, fallback + init-failure/retry tests, assertSame across calls and threads, reset hook + @ResourceLock instead of reflection
14
Call-site tests
Checked: CheckpointStateTest, ProcessorImplTest, JobImplDataInputFactoryTest, SchemaConverterTest are behavioural but the change is a pure performance refactor, so they would still pass if call sites were reverted. They are regression guards, not revert-sensitive; the revert-sensitive part is covered at the SharedJsonProviders level.
15
PR description
Not agent-permitted (description edits). Suggested cleanup: drop the work-log/metrics sections, keep: problem (per-call ServiceLoader), solution (SharedJsonProviders, framework CL + TCCL fallback), call sites, out-of-scope list above with follow-up tickets
16
Squash
Not agent-permitted (force-push); use squash-merge or squash manually
17
Changelog
No changelog/doc file found in the repo for this kind of change
minor
debug log, JobImpl.jsonb volatile, imports
Debug log added in ComponentManager fallbacks; field already volatile; spotless applied
Tests: impl (SharedJsonProvidersTest 8, ContainerFinderInstanceTest 3, record/processor/checkpoint tests), manager (SchemaConverterTest, JobImplDataInputFactoryTest, ComponentManager), di and kitap targeted tests: all green.
Round summary generated by AI. Please resolve threads after verifying the fixes.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The fallback can globally cache a container-specific provider, exposing it to other containers and retaining its classloader, while the existing test does not exercise unsuccessful lookup caching.
… array collectors
JsonCollectors.toJsonArray() resolves a JsonProvider through ServiceLoader on
each call, which still caused lock contention in PayloadMapper.onArray. Use a
collector built on the shared JsonProvider instead.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Why this PR is needed?
Jira: QTDI-3029.
JsonProvider.provider()andJsonbProvider.provider()create a newServiceLoaderon each call, which leads to thread locks when many jobs run in parallel (e.g. a massively parallel Studio job).ContainerFinder.Instance.getalso re-ran itsServiceLoaderlookup on every call when noContainerFinderservice exists.What does this PR adds (design/code thoughts)?
SharedJsonProvidersholder (component-runtime-impl): one lazily initializedJsonProviderand oneJsonbProvider(initialization-on-demand idiom). They are resolved with the framework classloader as TCCL, so the first caller inside an isolated container cannot bind the global instance to that container's JSON-P implementation.PayloadMapper,ReflectionService,ComponentManagerfallbacks,SchemaConverter,RecordImpl,CheckpointState,ProcessorImpl,JobImpl,DiRecordVisitor,DiRowStructVisitor,RecordJsonMapper. Per-container providers are unchanged.ContainerFinder.Instance.getrecords that the lookup was done so theServiceLoaderis not re-run on every call.SharedJsonProvidersTest,ContainerFinderInstanceTest. No existing test was modified.Review notes (Minor, not changed):
JohnzonBuilder.buildviaAutoChunkProcessor.onElementwas not investigated or changed; to be reported on the Jira ticket.ContainerFinderlookup is not reset if aContainerFinderservice appears on the classpath later (set()still overrides).SharedJsonProvidersTestcannot cover the TCCL isolation, since the singleton is initialized once per JVM.Out of scope:
tXSDValidator_main.javajet, the JDBC serviceServiceLoadercase (QTDI-2530), other non-JSONServiceLoaderuses, migration of existing test code.Manual validation (baseline vs fix on a massively parallel Studio job) is tracked in Zephyr QTDI-T13907 and QTDI-T13908.
AI contribution metrics
100%(320/316 AI-tagged changed lines; capped at 100% because the two commits overlap)100%~85%(estimated from the draft and approved plan; not word-diffed)AI generated code
https://internal.qlik.dev/general/ways-of-working/code-reviews/#guidelines-for-ai-generated-code