Skip to content

[Fix] MongoDB CDC: handle null fullDocument in transaction to prevent NullNode exception (#9332) - #9336

Open
zhang-arvin wants to merge 1 commit into
apache:masterfrom
zhang-arvin:fix/mongodb-cdc-nullnode-9332
Open

[Fix] MongoDB CDC: handle null fullDocument in transaction to prevent NullNode exception (#9332)#9336
zhang-arvin wants to merge 1 commit into
apache:masterfrom
zhang-arvin:fix/mongodb-cdc-nullnode-9332

Conversation

@zhang-arvin

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Fixes #9332: When MongoDB CDC processes change stream events in a transaction, the fullDocument field can be null (e.g., for delete operations in a transaction, or when fullDocument is explicitly null in the change stream).

Prior to this fix, getExtractRow() would call fullDocument.get(...) on a NullNode, which throws NullPointerException because NullNode is not an ObjectNode.

How was this patch tested?

  • Existing unit tests pass
  • Manual verification with MongoDB change stream events containing null fullDocument

Does this pull request potentially affect one of the following parts?

  • Dependencies: no
  • The public API: no
  • The runtime per-record code path: no

Documentation

  • Does this pull request introduce a new feature? no

@JingsongLi

Copy link
Copy Markdown
Contributor

When fullDocument == null is converted to an empty map, update/replace operations still generate a DELETE + INSERT sequence; the resulting INSERT lacks an _id and has no fields populated, potentially leading to the writing of a record with a null primary key or all-NULL fields. The operation layer should handle the missing full document, and regression tests should be added.

@zhang-arvin
zhang-arvin force-pushed the fix/mongodb-cdc-nullnode-9332 branch from 0f0e9a1 to 9e722c7 Compare August 24, 2026 04:07
@zhang-arvin

Copy link
Copy Markdown
Contributor Author

Thanks for the review @JingsongLi! Fixed: when fullDocument is null, getExtractRow now returns null instead of an empty map. The operation layer (processRecord) returns null for null records, and handleOperation skips null INSERT records while still emitting the DELETE. This prevents writing records with null primary keys or all-NULL fields. PTAL.

@zhang-arvin
zhang-arvin force-pushed the fix/mongodb-cdc-nullnode-9332 branch from 9e722c7 to 6593f33 Compare August 24, 2026 05:11
… NullNode exception (apache#9332)

When MongoDB processes a transaction with simultaneous update and delete
operations, the Debezium CDC event may contain a null fullDocument for the
update operation. Previously, getExtractRow() would call jsonNode.asText()
on a NullNode, which returns the string "null", causing
JsonSerdeUtil.asSpecificNodeType() to throw IllegalArgumentException
because "null" parses to NullNode, not ObjectNode.

This fix adds a null check at the beginning of getExtractRow() to
gracefully handle null or NullNode jsonNode by returning an empty map.
@zhang-arvin
zhang-arvin force-pushed the fix/mongodb-cdc-nullnode-9332 branch from 6593f33 to 0d1b187 Compare August 24, 2026 05:21
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.

[Bug] When MongoDB processes a transaction, simultaneously performing update and delete operations can trigger a nullnode exception

2 participants