KAFKA-8425: Fix for correctly handling immutable maps (KIP-421 bug)#6795
Conversation
…. The resolveConfigVariable function was modifying the originals map. If this map is immutable it will result in an exception. This fix resolves this issue
| private Map<String, ?> resolveConfigVariables(Map<String, ?> configProviderProps, Map<String, Object> originals) { | ||
| Map<String, String> providerConfigString; | ||
| Map<String, ?> configProperties; | ||
| Map<String, Object> originalsMutable = new HashMap<>(); |
There was a problem hiding this comment.
It's a bit weird to convert an immutable map to mutable and never convert back. Could we refactor the logic to push up the modification logic?
There was a problem hiding this comment.
@tadsul We could perhaps convert this to a immutable map and store in originalslike we do forvalues`.
There was a problem hiding this comment.
I'd suggest naming this variable resolvedOriginals.
rajinisivaram
left a comment
There was a problem hiding this comment.
@tadsul Thanks for the PR. Left a couple of comments. Can we make sure that we have a test that fails without the change?
| private Map<String, ?> resolveConfigVariables(Map<String, ?> configProviderProps, Map<String, Object> originals) { | ||
| Map<String, String> providerConfigString; | ||
| Map<String, ?> configProperties; | ||
| Map<String, Object> originalsMutable = new HashMap<>(); |
There was a problem hiding this comment.
@tadsul We could perhaps convert this to a immutable map and store in originalslike we do forvalues`.
| } | ||
|
|
||
| @Test | ||
| public void testImmutableOriginalsWithConfigProvidersProps() { |
There was a problem hiding this comment.
Does this test fail without the change?
There was a problem hiding this comment.
@tadsul, what is the answer to this question? (Unresolving this conversation.)
There was a problem hiding this comment.
yes the test fails without the comment
There was a problem hiding this comment.
Hmm, I am not sure it would. You should run the test without the changes to AbstractConfig.java to verify. The test invokes new TestIndirectConfigResolution(props, immutableMap) where neither props nor immutableMap is actually immutable. In order fot the test to fail props needs to be unmodifiable since that is the map used as originals. And immutableMap needs to be renamed since it is confusing as it is neither immutable nor the map being tested for immutability.
There was a problem hiding this comment.
oh yes i had to modify the test to make it work .. my yes meant that i could reproduce the issue.. sorry about that i will post the modified test
|
@tadsul There are checkstyle failures in the PR build. Could you please fix those as well? |
|
@tadsul Can we create a JIRA and set 2.3.0 as fix version to make sure it gets merged into 2.3.0 before thre release? |
| private Map<String, ?> resolveConfigVariables(Map<String, ?> configProviderProps, Map<String, Object> originals) { | ||
| Map<String, String> providerConfigString; | ||
| Map<String, ?> configProperties; | ||
| Map<String, Object> originalsMutable = new HashMap<>(); |
There was a problem hiding this comment.
I'd suggest naming this variable resolvedOriginals.
| } | ||
|
|
||
| @Test | ||
| public void testImmutableOriginalsWithConfigProvidersProps() { |
There was a problem hiding this comment.
@tadsul, what is the answer to this question? (Unresolving this conversation.)
|
@tadsul At the moment in This doesn't work as expected for two reasons:
Can't think of a way to fix this behaviour neatly. The only hacky solution I can think of that fixes 1) and 2) would be to check if
|
2. Makes sure RecordMap instance is not overriden
…ap to track all the key access
4fc4c50 to
f89a914
Compare
|
The 'originals' map in AbstractConfig can be mutable or immutable instance. In order to resolve and save the variable configs we have added a new ResolvingMap class. The ResolvingMap class extends from HashMap and keeps a track of original map instance and the resolved configs. It stores the original input map as-is in a separate internal immutable The 'originals' map can also be an instance of RecordingMap. In order to ensure that all the usage are recorded correctly the ResolvingMap overrides get() function to perform the following
|
|
This change will require #6855 to be merged first, which addresses an issue with this PR's builds in which the Kafka Streams tests changed the originals map after instantiating the StreamsConfig class. Once that is merged, this PR's builds should pass. |
|
This will need to be backported to the |
|
#6855 has been merged. Retest this please |
|
retest this please |
…actConfig$ResolvingMap
rajinisivaram
left a comment
There was a problem hiding this comment.
@tadsul Thanks for the updates, LGTM. Merging to trunk and 2.3.
…6795) Since the originals map passed to AbstractConfig constructor may be immutable, avoid updating this map while resolving indirect config variables. Instead a new ResolvingMap instance is now used to store resolved configs. Reviewers: Randall Hauch <rhauch@gmail.com>, Boyang Chen <bchen11@outlook.com>, Rajini Sivaram <rajinisivaram@googlemail.com>
* AK_REPO/2.3: KAFKA-8155: Add 2.2.0 release to system tests (apache#6597) KAFKA-8404: Add HttpHeader to RestClient HTTP Request and Connector REST API (apache#6791) KAFKA-8473: Adjust Connect system tests for incremental cooperative rebalancing (apache#6872) KAFKA-8475: Temporarily restore SslFactory.sslContext() helper KAFKA-8449: Restart tasks on reconfiguration under incremental cooperative rebalancing (apache#6850) KAFKA-8426; Fix for keeping the ConfigProvider configs consistent with KIP-297 (apache#6750) KAFKA-8425: Fix for correctly handling immutable maps (KIP-421 bug) (apache#6795) MINOR: Reordering the props modification with configs construction
…pache#6795) Since the originals map passed to AbstractConfig constructor may be immutable, avoid updating this map while resolving indirect config variables. Instead a new ResolvingMap instance is now used to store resolved configs. Reviewers: Randall Hauch <rhauch@gmail.com>, Boyang Chen <bchen11@outlook.com>, Rajini Sivaram <rajinisivaram@googlemail.com>
The originals map passed to the AbstractConfig class can be immutable. The resolveConfigVariable function was modifying the originals map. If this map is immutable it will result in an exception.
This fix resolves this issue
More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.
Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.
Committer Checklist (excluded from commit message)