Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-10477: Enabling the same behavior of NULL JsonNodeType to MISSI… #9306

Merged
merged 2 commits into from
Oct 2, 2020

Conversation

shaikzakiriitm
Copy link
Contributor

…NG JsonNodeType in JsonConverter.

From v2.10.0 onwards, in jackson lib, ObjectMapper.readTree(input) started to return JsonNode of type MISSING for empty input, as mentioned in the issue: FasterXML/jackson-databind#2211.

This caused to throw a DataException["Unknown schema type: null"] when an empty message key was parsed to be converted to Connect format via JsonConverter. The schemaType for MISSING type of JsonNode was returned as null, which resulted in this exception.

As part of this PR, made changes in JsonParser to incorporate the Jackson's ObjectMapper treatment of empty input from v2.10.0 onwards. Treating MISSING JsonNodeType in a similar fashion as that of NULL JsonNodeType.
Added a unit test for this.

Related Jira ticket captures further details: https://issues.apache.org/jira/browse/KAFKA-10477
All unit tests passed locally.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

…NG JsonNodeType in JsonConverter.

From 2.10.0 onwards, in jackson lib, ObjectMapper.readTree(input) started to return JsonNode of type MISSING for empty input, as mentioned in the issue: FasterXML/jackson-databind#2211.
Made changes in JsonParser to incorporate this, and treat MISSING JsonNodeType in a similar fashion as that of NULL JsonNodeType.
Added a unit test for this.
@shaikzakiriitm
Copy link
Contributor Author

@kkonstantine @rhauch Kindly take a look at the changes. Thanks!

@shaikzakiriitm
Copy link
Contributor Author

Failures are in ConnectionQuotasTest, and ConsumerBounceTest test classes, and appear unrelated to the change in this PR.

@rhauch rhauch added the connect label Sep 21, 2020
@rhauch
Copy link
Contributor

rhauch commented Sep 28, 2020

@shaikzakiriitm, you mentioned above:

From v2.10.0 onwards, in jackson lib, ObjectMapper.readTree(input) started to return JsonNode of type MISSING for empty input, as mentioned in the issue: FasterXML/jackson-databind#2211.

However, the FasterXML/jackson-databind#2211 you mention above talks about this behavior changing in 2.9 relative to 2.8. This seems to not align with the your assertion in the KAFKA-10477 that:

Things were working fine when the dependency on jackson lib was of version v2.9.10.3

Can you clarify?

@shaikzakiriitm
Copy link
Contributor Author

shaikzakiriitm commented Oct 1, 2020

Following are the version dependencies of Apache Kafka (ak) on com.fasterxml.jackson.core:jackson-databind (j)

  • ak v2.1.0 -> j v2.9.7
  • ak v2.1.1 -> j v2.9.8
  • ak v2.2.0 -> j v2.9.8
  • ak v2.2.1 -> j v2.9.8
  • ak v2.2.2 -> j v2.10.0
  • ak v2.3.0 -> j v2.9.9 [Looks like an outlier, where ak version increased with a decrease in jackson-databind version]
  • ak v2.3.1 -> j v2.10.0
  • ak v2.4.0 -> j v2.10.0
  • ak v2.4.1 -> j v2.10.0
  • ak v2.5.1 -> j v2.10.2
  • ak v2.6 -> j v2.10.2

The behavior of the Jackson ObjectMapper#readTree() method when called with a blank string/empty-input changed as follows (based on the information from FasterXML/jackson-databind#2211) :

  • For Jackson v2.x-2.8.x, return NullNode
  • For Jackson v2.9.x return null
  • For Jackson v2.10.0 and beyond return MissingNode

However, in all AK versions JsonConverter throws an error when it gets a MissingNode. This is only a problem for AK versions (v2.2.2, v2.3.1, v2.4.0, v2.4.1, v2.5.1, v2.6) that were released with Jackson 2.10.0 or later:

  • All versions of AK 2.1.x-2.2.1, ObjectMapper.readTree() returns null on empty input, which AK populates in an envelope, and the payload in the envelope which is null is treated as json node of JsonNodeType NULL. And this NULL case is handled in JsonConverter#convertToConnect().
  • AK version 2.2.2, ObjectMapper.readTree() returns MissingNode on empty input, which AK populates as payload in envelope; this payload is a jsonNode of JsonNodeType MISSING. And JsonConverter#convertToConnect() considers schemaType to be null for MISSING case, which results in DataException.
  • AK 2.3.0, (uses jackson-databind version 2.9.9), ObjectMapper.readTree() returns null on empty input, which AK populates as payload in envelope; this payload when retrieved in to be used in JsonConverter.convertToConnect(), is treated as NullNode, of JsonNodeType NULL. (as in the case of AK 2.1.x-2.2.1).
  • AK 2.3.1-2.6, ObjectMapper.readTree() returns MissingNode on empty input, which AK populates as payload in envelope; this payload is a jsonNode of type MISSING which causes the DataException.

So, this PR aims to resolve the DataException that gets thrown when jackson-databind's ObjectMapper.readTree() returns MissingNode upon encountering an empty input, so that JsonConverter treats MissingNode in a similar behavior as that of null.

@shaikzakiriitm
Copy link
Contributor Author

@shaikzakiriitm, you mentioned above:

From v2.10.0 onwards, in jackson lib, ObjectMapper.readTree(input) started to return JsonNode of type MISSING for empty input, as mentioned in the issue: FasterXML/jackson-databind#2211.

However, the FasterXML/jackson-databind#2211 you mention above talks about this behavior changing in 2.9 relative to 2.8. This seems to not align with the your assertion in the KAFKA-10477 that:

Things were working fine when the dependency on jackson lib was of version v2.9.10.3

Can you clarify?

Hi, I have shared more details in the comment #9306 (comment) . Kindly let me know if any further details are needed. Thanks!

@rhauch
Copy link
Contributor

rhauch commented Oct 1, 2020

Thanks for putting together this comprehensive list of AK versions, Jackson versions, and behavior.

  • ak v2.3.0 -> j v2.9.9 [Looks like an outlier, where ak version increased with a decrease in jackson-databind version]
    I don't think this was an outlier. If you sort them by release dates, things look a bit more logical and you can see how the Jackson versions only continually increase over time:

ak v2.1.0 (2018-11-20)-> j v2.9.7
ak v2.1.1 (2019-02-15) -> j v2.9.8
ak v2.2.0 (2019-03-22) -> j v2.9.8
ak v2.2.1 (2019-06-01) -> j v2.9.8
ak v2.3.0 (2019-06-24) -> j v2.9.9
ak v2.3.1 (2019-10-24) -> j v2.10.0
ak v2.2.2 (2019-12-01) -> j v2.10.0
ak v2.4.0 (2019-12-13) -> j v2.10.0
ak v2.4.1 (2020-03-10)-> j v2.10.0
ak v2.5.0 (2020-04-14) -> j v2.10.2
ak v2.6.0 (2020-08-03) -> j v2.10.2
ak v2.5.1 (2020-08-10) -> j v2.10.2

IOW, the following versions are all affected since they use Jackson 2.10.x:

  • 2.3.1
  • 2.2.2
  • 2.4.0
  • 2.4.1
  • 2.5.0
  • 2.5.1
  • 2.6.0

and thus the following branches are affected since they now use Jackson 2.10.x:

  • 2.2
  • 2.3
  • 2.4
  • 2.5
  • 2.6

I've also gone through a number of versions of the https://github.com/FasterXML/jackson-databind code, looking for how MissingNode is used. It's obvious that MissingNode is used a lot more prevalently in 2.10.0. But the documentation for MissingNode is as follows:

In most respects this placeholder node will act as {@link NullNode};
for example, for purposes of value conversions, value is considered
to be null and represented as value zero when used for numeric
conversions.

So I think it's pretty clear that we should treat JsonNodeType.MISSING as null. This is what this PR tries to do, and I'm now less concerned about unexpected behavioral changes after having read and verified this analysis.

Once this PR is merged to trunk, this fix will need to be backported to the following branches that are all affected because they use Jackson 2.10.x:

  • 2.2
  • 2.3
  • 2.4
  • 2.5
  • 2.6

@rhauch
Copy link
Contributor

rhauch commented Oct 1, 2020

@shaikzakiriitm I added another test to verify that having a null within a JSON field is not a problem. It builds for me locally, and the new test passes when I've tested it against 2.3.1, 2.2.2, 2.4.0, 2.4.1, 2.5.0, 2.5.1, 2.6.0. However, even though it doesn't fail with these versions like your other test, it is still useful to at least verify that such behavior is unchanged.

If we get a green build, I'll merge as discussed above.

Copy link
Contributor

@rhauch rhauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @shaikzakiriitm!

@rhauch
Copy link
Contributor

rhauch commented Oct 2, 2020

No green jobs, but all of the Connect and MirrorMaker2 tests in all of the jobs passed. All of the failures in the tests were (flaky) client, broker, or streams tests.

@rhauch rhauch merged commit ca559a2 into apache:trunk Oct 2, 2020
rhauch pushed a commit that referenced this pull request Oct 2, 2020
…ULL nodes (#9306)

Fixes a regression introduced in `JsonConverter` with previous upgrades from Jackson Databind 2.9.x to 2.10.x. Jackson Databind version 2.10.0 included a backward-incompatible behavioral change to use `JsonNodeType.MISSING` (and `MissingNode`, the subclass of `JsonNode` that has a type of `MISSING`) instead of `JsonNodeType.NULL` / `NullNode`. See FasterXML/jackson-databind#2211 for details of this change.

This change makes recovers the older `JsonConverter` behavior of returning null on empty input.

Added two unit tests for this change. Both unit tests were independently tested with earlier released versions and passed on all versions that used Jackson 2.9.x and earlier, and failed on all versions that used 2.10.x and that did not have the fixed included in the PR. Both of the new unit tests pass with this fix to `JsonConverter`.

Author: Shaik Zakir Hussain <[email protected]>
Reviewer: Randall Hauch <[email protected]>
rhauch pushed a commit that referenced this pull request Oct 2, 2020
…ULL nodes (#9306)

Fixes a regression introduced in `JsonConverter` with previous upgrades from Jackson Databind 2.9.x to 2.10.x. Jackson Databind version 2.10.0 included a backward-incompatible behavioral change to use `JsonNodeType.MISSING` (and `MissingNode`, the subclass of `JsonNode` that has a type of `MISSING`) instead of `JsonNodeType.NULL` / `NullNode`. See FasterXML/jackson-databind#2211 for details of this change.

This change makes recovers the older `JsonConverter` behavior of returning null on empty input.

Added two unit tests for this change. Both unit tests were independently tested with earlier released versions and passed on all versions that used Jackson 2.9.x and earlier, and failed on all versions that used 2.10.x and that did not have the fixed included in the PR. Both of the new unit tests pass with this fix to `JsonConverter`.

Author: Shaik Zakir Hussain <[email protected]>
Reviewer: Randall Hauch <[email protected]>
rhauch pushed a commit that referenced this pull request Oct 2, 2020
…ULL nodes (#9306)

Fixes a regression introduced in `JsonConverter` with previous upgrades from Jackson Databind 2.9.x to 2.10.x. Jackson Databind version 2.10.0 included a backward-incompatible behavioral change to use `JsonNodeType.MISSING` (and `MissingNode`, the subclass of `JsonNode` that has a type of `MISSING`) instead of `JsonNodeType.NULL` / `NullNode`. See FasterXML/jackson-databind#2211 for details of this change.

This change makes recovers the older `JsonConverter` behavior of returning null on empty input.

Added two unit tests for this change. Both unit tests were independently tested with earlier released versions and passed on all versions that used Jackson 2.9.x and earlier, and failed on all versions that used 2.10.x and that did not have the fixed included in the PR. Both of the new unit tests pass with this fix to `JsonConverter`.

Author: Shaik Zakir Hussain <[email protected]>
Reviewer: Randall Hauch <[email protected]>
rhauch pushed a commit that referenced this pull request Oct 2, 2020
…ULL nodes (#9306)

Fixes a regression introduced in `JsonConverter` with previous upgrades from Jackson Databind 2.9.x to 2.10.x. Jackson Databind version 2.10.0 included a backward-incompatible behavioral change to use `JsonNodeType.MISSING` (and `MissingNode`, the subclass of `JsonNode` that has a type of `MISSING`) instead of `JsonNodeType.NULL` / `NullNode`. See FasterXML/jackson-databind#2211 for details of this change.

This change makes recovers the older `JsonConverter` behavior of returning null on empty input.

Added two unit tests for this change. Both unit tests were independently tested with earlier released versions and passed on all versions that used Jackson 2.9.x and earlier, and failed on all versions that used 2.10.x and that did not have the fixed included in the PR. Both of the new unit tests pass with this fix to `JsonConverter`.

Author: Shaik Zakir Hussain <[email protected]>
Reviewer: Randall Hauch <[email protected]>
rhauch pushed a commit that referenced this pull request Oct 2, 2020
…ULL nodes (#9306)

Fixes a regression introduced in `JsonConverter` with previous upgrades from Jackson Databind 2.9.x to 2.10.x. Jackson Databind version 2.10.0 included a backward-incompatible behavioral change to use `JsonNodeType.MISSING` (and `MissingNode`, the subclass of `JsonNode` that has a type of `MISSING`) instead of `JsonNodeType.NULL` / `NullNode`. See FasterXML/jackson-databind#2211 for details of this change.

This change makes recovers the older `JsonConverter` behavior of returning null on empty input.

Added two unit tests for this change. Both unit tests were independently tested with earlier released versions and passed on all versions that used Jackson 2.9.x and earlier, and failed on all versions that used 2.10.x and that did not have the fixed included in the PR. Both of the new unit tests pass with this fix to `JsonConverter`.

Author: Shaik Zakir Hussain <[email protected]>
Reviewer: Randall Hauch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants