CDC Captured the DELETE. Why Is the Row Still in the Target?
A source-level walkthrough of delete propagation in Apache SeaTunnel 3.0.0's JDBC sink.
An order disappears from the application database. The CDC reader records the delete. The pipeline remains running. Yet the order still appears in the reporting database.
At that point, “CDC is working” is too broad a diagnosis. It tells us something about capture, but not whether the destination applied the intended change.
Disclosure: I am an Apache SeaTunnel PMC member. The article was checked against the linked released documentation and source. The illustrative SQL and configuration have not been executed for this article; no benchmark or production-test result is claimed.
To investigate this properly, follow one deleted key through the pipeline:
Source DELETE
→ change event with row identity
→ transformations that preserve the change
→ sink statement selection
→ successful target commit
→ the table or view used by the report
Each arrow is a place where the meaning of the event can be lost, delayed, or applied somewhere other than expected.
Start with the target's contract
Consider a current-state table in the reporting PostgreSQL database:
CREATE TABLE public.orders_current (
order_id BIGINT PRIMARY KEY,
status VARCHAR(32) NOT NULL
);
For one stable key, the intended behavior is straightforward:
- Insert
(42, 'created'): row 42 exists withcreated. - Update row 42 to
paid: row 42 exists withpaid. - Delete row 42: row 42 is absent.
These are expected outcomes for this example, not results from a benchmark or a test run performed for this article.
An audit table has a different contract. It may retain a delete event permanently. That can be correct too. The problem is treating an append-only event history as though it were a current-state replica. Before inspecting connector settings, decide which of these two tables you are building.
The sink needs identity as well as an operation
A delete needs a way to identify the target row. For this example, that identity is order_id.
If a transformation drops that field, renames it without updating the sink configuration, or changes its value inconsistently, the source can capture the right event while the destination cannot address the right row.
The expected target operation is conceptually:
DELETE FROM public.orders_current WHERE order_id = ?;
The placeholder must be bound to the deleted row's identity. A key in configuration is therefore part of the data contract, not just a performance hint.
Composite identities need the same attention. If uniqueness is defined by (tenant_id, order_id), deleting by order_id alone is not an equivalent operation.
What SeaTunnel 3.0.0 actually selects
I use its JDBC implementation here because the statement-selection boundary is explicit in the released source.
In JdbcOutputFormatBuilder, the ordinary path with configured keys builds separate upsert and delete executors. The delete statement comes from the database dialect and the key columns. A custom SQL statement takes a different branch. A path without usable keys uses a simple generated insert executor instead.
This distinction is visible in the SeaTunnel 3.0.0 executor builder.
For the current-state example, this PostgreSQL sink fragment makes the intended mode explicit:
# Sink fragment only, not a complete runnable job.
# The source must emit changelog rows with order_id and status.
sink {
Jdbc {
url = "jdbc:postgresql://db-host:5432/reporting"
driver = "org.postgresql.Driver"
username = "sync_user"
password = "<replace-with-your-secret>"
generate_sink_sql = true
database = "reporting"
table = "public.orders_current"
primary_keys = ["order_id"]
schema_save_mode = "ERROR_WHEN_SCHEMA_NOT_EXIST"
data_save_mode = "APPEND_DATA"
is_exactly_once = false
}
}
The URL and database refer to the same PostgreSQL database. The schema belongs in the dotted table value: public.orders_current, not database = "public". The factory resolves these into database, schema, and table components. See the 3.0.0 sink factory.
This fragment assumes a pre-created target table, a compatible PostgreSQL JDBC driver, and a user permitted to read metadata and apply the required writes. Replace the host and credentials for your environment; the password string is only a placeholder, not an environment-variable expression. The versioned JDBC documentation documents driver installation and schema-qualified PostgreSQL table names.
The fragment leaves enable_upsert at its default of true and use_copy_statement at its default of false. It supplies no custom query. The defaults are defined in JdbcSinkOptions. APPEND_DATA controls treatment of existing target data when the job starts; it does not convert every CDC event into an INSERT. The save-mode handler retains existing schema and data for that mode. The example makes no exactly-once claim.
How a DELETE reaches its executor
The keyed buffered path uses BufferReducedBatchStatementExecutor.
Its addToBatch method skips UPDATE_BEFORE, extracts the key, and stores the change in a key-indexed buffer. INSERT and UPDATE_AFTER select the upsert side; DELETE selects the delete side. At execution, the delete executor receives the key row.
The buffer also replaces an earlier entry for the same key. Consequently, the implementation can coalesce changes within a batch rather than execute a separate database statement for every incoming event. That suits current-state materialization; it is not an event-by-event audit record.
These details are specific to this released buffered executor. They should not be generalized to every sink or every database-specific execution path. This article also assumes a stable key rather than attempting to cover primary-key changes.
Why a custom INSERT does not acquire delete semantics
Now consider a separate configuration that uses custom SQL instead of generated SQL:
generate_sink_sql = false
query = "INSERT INTO public.orders_current(order_id, status) VALUES (?, ?)"
This is an alternative write-mode excerpt, not two lines to add to the preceding generated-SQL example.
The simple statement executor converts each supplied row into parameters and adds it to the prepared statement. It does not inspect RowKind and rewrite an INSERT into a DELETE. See SimpleBatchStatementExecutor in 3.0.0.
Depending on the incoming values and target constraints, the insert may succeed or fail. Neither outcome establishes correct delete propagation. Custom SQL is useful when you need control over the write operation. That control also makes its semantics your responsibility.
Diagnose one key, not the whole pipeline
For a missing delete, I would gather these observations in order:
- Capture: Is there an actual delete event for the key, rather than an assumption based on the source table's current contents?
- Transformation: Does the row reaching the sink still carry the delete operation and the correct key?
- Execution path: Is this the keyed generated-SQL path, custom SQL, COPY, or another database-specific mode?
- Database application: Did the write flush and commit successfully? Inspect errors and the actual destination table.
- Consumer visibility: Does the reporting query read that table directly, or a cache, replica, materialized view, or another schema?
The JDBC output format buffers records and executes batches during flushing, so receiving an event is not itself evidence that the target has already applied it. Its 3.0.0 implementation provides a concrete starting point for following that boundary.
There is one further recovery question: could an older update arrive after the delete and recreate the row? A design that permits out-of-order replay needs an explicit ordering or version policy. Successful execution of a delete alone cannot settle that question.
The useful success criterion is precise: for this key, the intended operation reached the correct sink path, committed at the destination, and produced the state the consumer is supposed to see.
Comments
Post a Comment