Skip to content

fix(QTDI-3029): Share JsonProvider and JsonbProvider instances - #1291

Merged
thboileau merged 19 commits into
masterfrom
thboileau/QTDI-3029_share_json_providers
Nov 17, 2026
Merged

thboileau merged 19 commits into
masterfrom
thboileau/QTDI-3029_share_json_providers

Conversation

@thboileau

Copy link
Copy Markdown
Contributor

Requirements

  • 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)

AI generated code

https://internal.qlik.dev/general/ways-of-working/code-reviews/#guidelines-for-ai-generated-code

  • this PR has been written with the help of GitHub Copilot or another generative AI tool

thboileau and others added 2 commits October 12, 2026 17:46
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>
@thboileau

Copy link
Copy Markdown
Contributor Author

Scope & Design Review — QTDI-3029

Round 1 — REJECTED (1 Major, fixed)

# Severity File Description Resolution
1 MAJOR SharedJsonProviders 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.

Signed: Claude Sonnet 5.5

@thboileau

Copy link
Copy Markdown
Contributor Author

Compliance report (review-changes) — QTDI-3029

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.

Signed: Claude Sonnet 5.5

thboileau and others added 3 commits October 12, 2026 17:54
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
…age on new code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thboileau

Copy link
Copy Markdown
Contributor Author

Review round 1 — summary

Comment Class Action
#1 — Sonar: 64.40% Coverage on New Code (< 80%) Code fix 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.

Signed: Claude Sonnet 5.5

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.

🟡 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.

6 open issues
What changed in this PR

This pull request reduces ServiceLoader contention by sharing framework-scoped JSON-P/JSON-B providers and caching the ContainerFinder lookup.

Changes:

  • Added lazy, framework-classloader-scoped SharedJsonProviders.
  • Migrated framework, manager, Studio DI, and Singer call sites to shared providers.
  • Added caching and tests for provider reuse, container lookup, and JSON conversion paths.
  • Documented provider and ServiceLoader guidance.

Several moderate findings remain around static JSON-P lookups in affected serialization and conversion paths.

This pull request requires changes.

File Reviewed change
singer-parent/​component-kitap/​src/​main/​java/​org/​talend/​sdk/​component/​singer/​kitap/​RecordJsonMapper.java Uses shared providers for Singer record JSON mapping; remaining static JSON-P factory lookups were identified.
repository-knowledge.md Documents JSON provider, classloader, and ServiceLoader guidance.
component-studio/​component-runtime-di/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​di/​record/​DiRowStructVisitor.java Uses the shared JSON-B provider for row conversion.
component-studio/​component-runtime-di/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​di/​record/​DiRecordVisitor.java Uses shared providers for DI record services; remaining static JSON-P factory lookups were identified.
component-runtime-manager/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​manager/​xbean/​converter/​SchemaConverterTest.java Adds schema conversion round-trip and empty-input coverage.
component-runtime-manager/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​manager/​chain/​internal/​JobImplDataInputFactoryTest.java Tests POJO and primitive input conversion.
component-runtime-manager/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​manager/​xbean/​converter/​SchemaConverter.java Uses the shared JSON-P provider for schema deserialization; remaining static JSON-P construction was identified.
component-runtime-manager/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​manager/​reflect/​visibility/​PayloadMapper.java Uses the shared JSON-P provider for payload mapping.
component-runtime-manager/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​manager/​reflect/​ReflectionService.java Uses the shared provider for visibility validation.
component-runtime-manager/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​manager/​ComponentManager.java Uses shared providers in fallback loading paths.
component-runtime-manager/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​manager/​chain/​internal/​JobImpl.java Builds fallback JSON-B instances from the shared provider.
component-runtime-impl/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​serialization/​ContainerFinderInstanceTest.java Tests one-time ContainerFinder lookup behavior.
component-runtime-impl/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​record/​SharedJsonProvidersTest.java Tests provider identity, concurrency, and usability; TCCL isolation coverage remains limited.
component-runtime-impl/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​output/​ProcessorImplTest.java Tests processor input conversion; fallback-provider execution coverage was identified as incomplete.
component-runtime-impl/​src/​test/​java/​org/​talend/​sdk/​component/​runtime/​input/​CheckpointStateTest.java Tests checkpoint JSON serialization.
component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​serialization/​ContainerFinder.java Caches completion of the framework service lookup.
component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​record/​SharedJsonProviders.java Adds lazy shared JSON-P and JSON-B providers with framework-classloader handling.
component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​record/​RecordImpl.java Uses the shared JSON-P provider during record conversion; remaining static factory lookup was identified.
component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​output/​ProcessorImpl.java Uses the shared JSON-B provider for fallback conversion; remaining JSON-P factory lookup was identified.
component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​input/​CheckpointState.java Uses the shared JSON-B provider for checkpoint serialization; remaining static JSON-P lookups were identified.

Review effort: Lite

… 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>
@thboileau

Copy link
Copy Markdown
Contributor Author

Review round 3 — summary

Comment Class Action
CheckpointState.java:35 Code fix Fixed in 38823c01a5e
RecordImpl.java Code fix Fixed in 38823c01a5e
SchemaConverter.java:78 Code fix Fixed in 38823c01a5e
DiRecordVisitor.java Code fix Fixed in 38823c01a5e
RecordJsonMapper.java Code fix Fixed in 38823c01a5e
SharedJsonProviders.java:61 Code fix (test) Fixed in 38823c01a5e

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.

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.

🟡 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.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Use shared JSON provider in no-container builder fallback

component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​output/​ProcessorImpl.java:209

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.

Medium severity Use shared JSON-B provider for record serialization

component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​record/​RecordImpl.java:105

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.

6 resolved since last review

Review effort: Lite

…rom test classloader and code sources

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thboileau

Copy link
Copy Markdown
Contributor Author

Review round 4 — summary

Comment Class Action
#1 — initializationIgnoresIsolatedContextClassLoader rebuilds loader URLs only from java.class.path Code fix Fixed in 5d06a2fbb7a

Fixes pushed: 5d06a2fbb7a — fix(QTDI-3029): address review round 4
Pending clarifications: 0

Round summary generated by AI. Please resolve threads after verifying the fixes.

Signed: Claude Sonnet 5.5

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.

🔵 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

Medium severity Use shared JSON provider for builder-factory fallback

component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​output/​ProcessorImpl.java:209

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.

Medium severity Use shared JSON-B provider in toString serialization

component-runtime-impl/​src/​main/​java/​org/​talend/​sdk/​component/​runtime/​record/​RecordImpl.java:105

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.

1 resolved since last review

Review effort: Lite

… ProcessorImpl fallback and RecordImpl.toString

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thboileau

Copy link
Copy Markdown
Contributor Author

Review round 5 — summary

Comment Class Action
#1 — Use shared JSON provider for builder-factory fallback (ProcessorImpl) Code fix Fixed in 64b0c6347fd
#2 — Use shared JSON-B provider in RecordImpl.toString Code fix Fixed in 64b0c6347fd

Fixes pushed: 64b0c6347fd — fix(QTDI-3029): address review round 5
Pending clarifications: 0

Round summary generated by AI. Please resolve threads after verifying the fixes.

Signed: Claude Sonnet 5.5

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.

🟡 Changes recommended

The isolated-classloader test does not exercise the separate JsonbProviderHolder path, leaving a potential classloader regression undetected.

1 open issue

Review effort: Lite

Comment on lines +99 to +106
final Object provider = framework
.loadClass(SharedJsonProviders.class.getName())
.getMethod("jsonProvider")
.invoke(null);
assertNotNull(provider);
// bound to the framework classloader, not to the isolated container one
assertSame(framework, provider.getClass().getClassLoader());
assertSame(isolated, thread.getContextClassLoader());
…s init, TCCL fallback, cached ContainerFinder default, remaining JSON-B call sites

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thboileau

Copy link
Copy Markdown
Contributor Author

Review round 6 — summary

Fixed in ca7ae5649fe.

# Remark Action
1 Framework CL only Fixed: withFrameworkClassLoader falls back to the caller TCCL; original failure rethrown, caller failure suppressed
2 Holder init errors Fixed: static holders replaced by a lazy supplier — failures stay RuntimeException/ServiceConfigurationError, are not cached, next call retries
3 ContainerFinder Fixed: stateless default finder cached; package-private reset() hook
4 Missed call sites TaCoKitGuessSchema (3x) fixed. Out of scope / follow-up (not JSON providers, or cannot depend on impl): Schema.java Json.create* (component-api cannot depend on impl), SchemaConverter ctor / JobImpl GroupKeyProvider / DefaultServiceProvider ProducerFinder / ParameterModelService / ComponentMetadataService / EnrichedPropertyEditorRegistry per-call ServiceLoader.load (different SPIs; caching would share possibly stateful services, needs its own ticket)
5 RecordImpl.toString Fixed: lazy shared Jsonb
6 Shared factories Verified: nothing closes or reconfigures the shared providers/factories (JsonbConfig is created per use)
7 Repeated jsonProvider() Fixed: local/field in SchemaConverter, DiRecordVisitor, RecordJsonMapper
8 Placement/visibility Kept in runtime.record (consumers in impl/manager/di/singer); marked internal in Javadoc
9 Javadoc Corrected (JVM-wide, lazy, fallback)
10 repository-knowledge Sonar/jacoco entry removed
11-13 SharedJsonProvidersTest / ContainerFinderInstanceTest 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.

Signed: Claude Sonnet 5.5

@undx
undx requested a balanced review from Copilot October 29, 2026 17:09

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.

🟡 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.

3 open issues

Review effort: Balanced

…JSON providers, negative ContainerFinder lookup test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

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.

🔵 Needs a closer look

Human review is needed to assess potential retention of isolated-container classloaders and a test that bypasses the modified JSON-B fallback path.

2 open issues
1 resolved since last review

Review effort: Balanced

undx
undx previously approved these changes Oct 30, 2026

@undx undx 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

… 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>
undx
undx previously approved these changes Nov 10, 2026
@sonar-rnd

sonar-rnd Bot commented Nov 13, 2026

Copy link
Copy Markdown

@thboileau
thboileau merged commit f41573c into master Nov 17, 2026
9 checks passed
@thboileau
thboileau deleted the thboileau/QTDI-3029_share_json_providers branch November 17, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants