Repository navigation
Conversation
| | The same batch fails in 10 attempts, the first one included, for one of the causes above. | Reports an error and drops the batch. | | ||
| | The server rejects the credentials, or the database does not exist. | Reports an error and drops the batch. | | ||
| | The server rejects a statement, for example because of a constraint. | Reports an error and drops the batch. A new connection cannot correct this failure. | | ||
| | The connector cannot encode a row of the batch. | Reports an error and drops the batch. It rolls back the rows of the batch that it wrote before the failure. | |
There was a problem hiding this comment.
pitfall (medium): This row says the connector "drops the batch", but with threads > 1 only the thread whose encode failed rolls back. The other threads still commit their parts (the PR description says so too). The changelog entry has the same problem. Please name the per-thread scope, for example:
| | The connector cannot encode a row of the batch. | Reports an error and drops the batch. It rolls back the rows of the batch that it wrote before the failure. | | |
| | The connector cannot encode a row of the batch. | Reports an error. The writer thread that had the row rolls back its part of the batch. With `threads` > 1, the other threads still commit their parts. | |
There was a problem hiding this comment.
Done in 9f8c6ad, with your wording, and the changelog says the same.
|
Review of the Postgres output encode-failure fix The fix looks correct to me.
missing (medium): cases the new tests do not cover
Gates: tests pass (integration cases plus revert checks), docs and changelog are updated (see the inline comment on the multi-thread wording), there is no new |
|
Thanks. In 9f8c6ad:
Without the fix, the two new cases and |
…code failed When the encode of a batch failed after some rows, the Postgres output connector could write a part of that batch: - The first encode failed. The worker left its transaction open, and the end of the batch flushed the buffers and committed. The rows before the failed row were in the table, and the rows after it were not. - The encode failed when the worker wrote the batch again after a lost transaction. The rows that it had put in the buffers stayed there, and the next batch wrote them and counted them as its own. Give an encode failure a transaction state of its own, EncodeFailed. At the end of the batch the worker rolls the transaction back and reports that it wrote none of its rows, as it does for a statement that the server rejected. The controller reports the encode error itself, as before. Clear the buffers of the worker when a batch ends, so that no exit path of a batch leaves rows for the next batch. With more than one thread, each worker has its own transaction: the worker whose encode failed writes nothing, and the other workers commit their parts. This rule is not new. The two new suite cases use a wrapper around a batch that makes the serializer fail at a chosen row of a chosen cursor. Fixes: #8020 Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
… failure With more than one writer thread, only the thread whose encode failed drops its part of the batch. The other threads commit their parts. Say so in the docs and the changelog. Add suite cases for this rule with two threads, and for an encode failure in cdc mode. Both fail without the fix. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
After an encode failure, the worker kept its transaction open until the end of the batch. The endpoint waits for every worker to finish its encode before it ends the batch. If the failed worker had already written a row that another worker needs to lock (a trigger, a foreign key, a second unique index), that worker could not finish its encode, and the batch hung. Roll back the transaction and clear the buffers before the reply to the endpoint. The end of the batch then reports the dropped part as before, with the rollback failure if there was one. The new suite case gives the failing worker a lock that the other worker needs. It ends in time with the fix, and runs into its time limit without it. The changelog now limits the promise to the transaction whose encode failed: a commit whose reply was lost can already have written rows. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
| - Connectors: when the PostgreSQL output connector cannot encode a row, it | ||
| now drops the batch. Before, it could write a part of that batch, or write | ||
| rows of that batch together with the next batch. | ||
|
|
There was a problem hiding this comment.
bug (docs, medium): This entry and the next one describe the same change, and they disagree. This one says the connector "drops the batch". The next one (and postgresql.md) says only the thread whose encode failed drops its part, and the other threads commit theirs. It looks like a leftover from the first commit. Delete this entry and keep the per-thread one.
There was a problem hiding this comment.
Fixed in c4cfc55: the first entry is removed. It was a duplicate from a rebase.
|
What I ran (local PostgreSQL 16,
Review. The fix is correct. One Coverage gaps (medium):
Apart from the duplicate changelog entry (inline), this looks good. |
swanandx
left a comment
There was a problem hiding this comment.
The fix is correct. Please make these changes:
changelog.mdhas two entries for this change. Remove the first one ("it now drops the batch"), because with more than one thread the other threads still commit.- If #8205 merges first, remove the third commit, because #8205 removes the wait that it works around.
- If #8205 merges first, reset the
EncodeFailedstate at batch end. In #8205, a worker with no rows returns beforestart_batch(), so the state from the last batch stays.
The tests of an encode failure used only an insert whose value did not serialize. Add cases for the other paths that reach the same handling: - a delete in materialized mode, whose key does not serialize: all the rows stay in the table; - an upsert: the rows keep their old values; - a cursor that does not open: nothing is written, and the next batch is written; - an encode failure after a statement of the same batch lost its transaction to a lock timeout: the part is dropped with no new attempt. All four fail when an encode failure does not roll the transaction back. Remove a duplicate changelog entry that a rebase left. Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
|
Status of the review points, as of c4cfc55:
The four new cases fail when an encode failure does not roll the transaction back. Local PostgreSQL 15: the 9 cases of the module pass. |
Linked Issue
Fixes #8020. Found during the review of #8017 (related to #8014).
What changes
When the encode of a batch failed after some rows, the Postgres output connector could write a part of that batch. An encode failure is rare: it needs a value that the serializer rejects, or a failure to read the batch.
How:
EncodeFailed. The end of the batch handles it as it handlesRejected(a statement that the server rejected): rollback, and apg_batch_enderror. The controller still reports the encode error itself.write_batchleaves rows for the next batch.Not changed: with more than one thread, each worker has its own transaction. The worker whose encode failed writes nothing, and the other workers commit their parts.
This PR touches the same functions as #8098. The one that merges second needs a rebase.
Describe Manual Test Plan
first_encode_rolls_back_partial_batch: 3 rows, one statement for each row, the encode fails at row 3. Then a normal batchretry_encode_discards_buffered_rows: 2 rows, the session is ended before the commit, the encode fails at row 2 when the worker writes the batch again. Then a normal batch of 1 rowwal_level = replica) and the 2 TLS casesdbsp_connectorsandstatic-connectorsChecklist
Breaking Changes?
None. Behavior change, in the changelog: a batch whose encode fails is now dropped as a whole by the thread that had it.