Repository navigation
[flink] Read absent parser paths as NULL in MongoDB specified mode - #11440
LuciferYang wants to merge 4 commits into
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
The three local parser tests and the eleven MongoDB table-action integration tests in CI passed. I reproduced a silent stale-row result for a partitioned target by committing the records emitted by the updated parser.
| } catch (PathNotFoundException e) { | ||
| // A delete or update event carries only the _id of the document, and a document | ||
| // does not have to contain every configured field. | ||
| parsedRow.put(columnNames[i], null); |
There was a problem hiding this comment.
[P1] Reject retractions without the target partition value
The new NULL handling also accepts an absent routing field. I reproduced this with schema.start.mode=specified, field.name=_id,region, parser.path=$._id,$.region, and a target with PRIMARY KEY (_id), PARTITIONED BY (region), bucket=1. Insert {_id: "1", region: "east"} and then deliver a delete with documentKey={_id: "1"}. On the base the parser fails with PathNotFoundException. With this change the parser emits -D {region=null, _id=1}, the write commits, and the target still contains 1:east. An update that moves the document can likewise leave an extra row.
The documentation describes this outcome, but an existing specified-mode job can now resume and checkpoint past changes that did not take effect. Could we keep NULL handling for payload fields and fail explicitly when the target partition cannot be derived for a retraction?
There was a problem hiding this comment.
Payload fields still read NULL. In specified mode, a retraction built from documentKey (a delete, or the first half of an update or replace) now fails the job when the table needs a field the action writes but the key does not carry. Besides a partition key, that means a primary key field, a sequence.field, aggregation without aggregation.remove-record-on-delete, and partial-update with a sequence group. From the key, the retraction reads plain property paths such as $.region; computed columns of those and constants also count as known. The key stores a nested shard key under its dotted name, so a table partitioned by $.location.region fails too. With ignore-delete = true the job runs on with stale rows, unless the writer's NOT NULL check fails. Under aggregation that would count old and new values, so the error omits it. Dynamic mode is unchanged. Your repro now fails at the delete (MongoDBSyncTableActionITCase#testSpecifiedModeRejectsDeleteWithoutPartitionValue).
JingsongLi
left a comment
There was a problem hiding this comment.
The 35 focused local Flink cases passed. Exact-head CDC CI passed 12 MongoDB sync integration cases, including the partition retraction regression. I reproduced a checkpointed delete that the guard still accepts on the default partial-update configuration.
| + "table created with '%s' = 'true' removes the row instead", | ||
| CoreOptions.AGGREGATION_REMOVE_RECORD_ON_DELETE.key()); | ||
| } | ||
| if (options.mergeEngine() == CoreOptions.MergeEngine.PARTIAL_UPDATE |
There was a problem hiding this comment.
[P1] Reject a key-only Mongo retraction when partial-update has no delete policy. I fed an actual specified-mode insert and a delete carrying only _id through CdcRecordStoreWriteOperator, with merge-engine=partial-update, no sequence group, and default delete settings. Each event was flushed and committed in its own checkpoint. This head accepts the retraction and publishes snapshot 2; reading that snapshot then throws 'Partial update can not accept delete records' when the two files merge. The old parser stopped at the missing region before the delete reached the sink. With this change the job can checkpoint past an unreadable snapshot. When ignore-delete is off, reject this configuration before writing the partial retraction unless whole-row deletion is enabled.
There was a problem hiding this comment.
Fixed in c0dbdca.
A key-only retraction is now rejected before it is written when the table has no delete policy: ignore-delete off, partial-update.remove-record-on-delete off, and no sequence group. Your configuration — partial-update, no sequence group, default delete settings — is rejected at CdcRecordStoreWriteOperator, and the error names partial-update.remove-record-on-delete. CdcRecordStoreWriteOperatorTest#testRejectPartialRetractionThatCannotBeApplied covers it. A sequence group keeps the previous rejection, and ignore-delete still drops the retraction before the merge engine sees it.
Purpose
close #11439
In MongoDB CDC
schema.start.mode=specified, an update, replace or delete failed the job withPathNotFoundExceptionwhen a configured path was outsidedocumentKey, which holds only_idand the shard key. An absent path now reads NULL, as indynamicmode.A DELETE built from
documentKeynow records the fields it read from the key (CdcRecord.withKnownFields). The CDC write operators fail it when the table needs another field to apply it: a partition key, a primary key field, asequence.field,aggregationwithoutaggregation.remove-record-on-delete, orpartial-updatewith a sequence group. Written anyway, such a DELETE would not remove the stored row.ignore-delete = trueskips the check. Only plain property paths such as$.regionare read from the key, so nested shard keys read NULL. Dynamic mode is unchanged.A misspelled path for a non-key field now gives a NULL column instead of failing on the first record.
Tests
Mongo4VersionStrategyTest: absent fields read NULL on deletes, updates and inserts. A retraction knows_id, computed columns of it and constants, but notnow(), non-property paths, or a computed column of a field the key lacks, even one replacing a key field. Key fields, JSON null included, read as in the document, and nested shard keys read NULL. Dynamic mode does not mark retractions.CdcRecordStoreWriteOperatorTest: each rule rejects a key-only DELETE. Fields the record does not carry,ignore-retractaggregation andignore-deleteare accepted. The error suggestsignore-deleteonly when the writer would then accept the DELETE, and never for aggregation. The dynamic-bucket writer runs the same check, andCdcRecordStoreMultiWriteOperatorTestcovers the database sink.CdcRecordUtilsTest,CdcRecordSerializeITCase: the known fields survive case conversion and Java and Kryo serialization.MongoDBSyncTableActionITCase:testSpecifiedModeCDCOperationsapplies update, replace and delete events;testSpecifiedModeRejectsDeleteWithoutPartitionValuefails the job at a delete on a table partitioned byname.