Repository navigation
Fix: Prevent static cache pollution affecting decimal.format across concurrent connectors - #309
Open
kotapullarao wants to merge 2 commits into
Open
kotapullarao wants to merge 2 commits into
kotapullarao wants to merge 2 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes converter cache sharing between HTTP sink connector instances running in the same Kafka Connect worker.
RecordValueConverterpreviously used a static cache keyed only by the runtime record value class. This could allow one connector instance to reuse a converter initialized by another connector instance with a differentdecimal.formatconfiguration.This PR changes the converter cache to be instance-scoped, so each
RecordValueConverterkeeps converters created from its own connector configuration.Fixes #308.
Problem
decimal.formatis a connector-level configuration. A connector configured with:decimal.format=NUMERICshould serialize Avro decimal logical types as JSON numbers in the HTTP request body.
However, when multiple HTTP sink connector instances run in the same Kafka Connect worker with different
decimal.formatvalues, the configured behavior can leak between connector instances.Example:
decimal.format=BASE64decimal.format=NUMERICStructBecause the converter cache was static and keyed only by runtime value class, a converter cached for
Struct.classby one connector could be reused by the other connector, regardless of its owndecimal.format.Root Cause
In
RecordValueConverter, converters were cached in a static map:The cache key was only:
This means connector-specific conversion settings, such as
decimal.format, were not part of the cache identity.The
clear()call increate()reduced stale state after task restarts, but it did not provide proper isolation between concurrently running connector instances in the same worker JVM.Solution
Changed the converter cache from static/global to instance-level:
Each
RecordValueConverterinstance now maintains its own cache, using converters created from its ownHttpSinkConfig.Changes Made
RUNTIME_CLASS_TO_CONVERTER_CACHEfrom a static field to an instance field.runtimeClassToConverterCacheto follow instance field naming conventions.clear()call fromcreate(), since each converter instance now starts with its own empty cache.Impact
decimal.formatconfiguration consistently.RecordValueConverterinstance.Testing
RecordValueConverterTest:RecordValueConverterwithdecimal.format=BASE64RecordValueConverterwithdecimal.format=NUMERICStructvalue with both convertersBASE64converter cached theStructconverter first../gradlew test --tests io.aiven.kafka.connect.http.converter.RecordValueConverterTestResult:
Related Issues/PRs