Repository navigation
Conversation
| .get(0); | ||
| assert!(terminated > 0, "found no backend to terminate"); | ||
| .unwrap(); | ||
| assert_eq!(terminated.len(), 1); |
There was a problem hiding this comment.
pitfall (medium): possible flakiness. The old check was count > 0. This one needs exactly one matching backend, and the termination of that backend must return true. These tests are serial, but a backend from the previous test's endpoint (or from a dropped pg_client()) can still appear in pg_stat_activity for a short time after its client is dropped, and its last query can name TEST_TABLE too. If that backend is in the list, len() is 2. If it has already exited, pg_terminate_backend returns false for it. It passed 8 of 8 runs for me locally, but it is still a race. Suggest asserting that at least one backend was terminated, e.g. assert!(terminated.iter().any(|r| r.get::<_, bool>(0))), or filtering on application_name / the worker's pid.
There was a problem hiding this comment.
Fixed in 3fc5077: the case now asserts that at least one backend was terminated.
| && let Some(controller) = self.controller.upgrade() | ||
| && !controller.shutdown_token().is_cancelled() | ||
| { | ||
| controller.encode_error( |
There was a problem hiding this comment.
missing (medium): no test covers this new error path. Encode failures used to come back to the controller from Encoder::encode. Now the worker reports them itself, and no test checks the encoder_error tag (grep finds none). Each worker also reports separately and does not say which writer thread failed, while the old message said "N of the connector's writer threads failed". Please add a case where a part fails to serialize or its cursor fails, and assert that (a) the controller gets one encoder_error, and (b) batch_end still returns. In the cursor-failure case, pending is dropped before it is stored, so write_batch returns Ok((0, 0)) for that part. That behaviour should be checked on purpose too.
There was a problem hiding this comment.
Added worker_reports_cursor_error_and_other_worker_commits in 3fc5077: one part's cursor does not open. It checks one encoder_error, no transport error, batch_end returns, and the other part is in the table. The Ok((0, 0)) for that part is intended and has a comment: the encode error is its report. Without the worker's report the case gets 0 encode errors.
| fn start_batch(&mut self) -> Option<anyhow::Error> { | ||
| let error = self.batch_start_inner().err()?; | ||
| /// the start when the batch ends, within its limit of attempts. | ||
| fn start_batch(&mut self) { |
There was a problem hiding this comment.
observation (medium): error volume. pg_batch_start is now reported once per worker per batch instead of once per batch. During a server outage with threads: N, the endpoint error count and logs grow N times faster than before. Is that intended? If not, consider rate-limiting the report or tagging it with worker-thread-{idx} so the repeats can be told apart.
There was a problem hiding this comment.
Not intended to grow silently: the message now names worker-thread-N (3fc5077), so the repeats can be told apart. I did not rate-limit it: pg_conn_retry is already reported for each worker in the same way.
|
What I ran
I checked that the controller calls Test cases not covered
Gates: one flakiness risk in |
|
Thanks. All points are addressed in 3fc5077 (see the inline replies). For problem A: the test proxy can now model a pool of one server connection in transaction mode (a |
|
What I ran (debug, local PostgreSQL 16)
I reviewed the new protocol for hangs.
Otherwise LGTM. |
… transaction The endpoint of the Postgres output connector ran each batch in three rounds (start, encode, end) and waited for every worker at the end of each round. A worker that finished a round kept its transaction open, and with it a server connection of a pool and its row locks, until the slowest worker finished the round. This caused two problems: - Behind a pooler in transaction mode with a pool smaller than the number of writer threads, each batch stopped until the pooler timed out the threads that waited for a connection. - When a trigger, a foreign key or a second unique index made two workers lock the same row, the second worker waited for the lock of the first, and the first waited at the endpoint for the second. PostgreSQL does not see this as a deadlock, so the batch hung. The endpoint now waits only once for each batch, at its end: - batch_start and encode only queue commands and return. encode reads the extra column values one time and gives them to all workers, so that a later set_extra_columns does not change a batch that encode already took. encode sends the part of each worker, also after a worker that has ended, and then returns one error that names the workers that ended. - A worker opens its transaction when it gets a part with rows, and writes it. A worker with no rows opens no transaction. - batch_end sends BatchEnd and collects one reply from each worker. - A worker reports a failed start (pg_batch_start, not fatal, with its number) and an encode failure (with its number and the full chain of causes) itself, as it already did for its statements. A fast worker now commits before a slow one, so a reader can see a part of a batch for longer. A batch was never atomic across workers. Tests that read the database or the live count after encode now wait for the condition. The proxy fault for an idle session that is lost is removed: a worker with no rows no longer opens a session for the batch. New cases: - A trigger that updates one row for each insert, two workers and one statement per row: hangs on the old code. - The test proxy as a pool of one server connection, two workers: runs into its time limit on the old code. - A worker with no rows starts no transaction. - A batch keeps the extra column values of the time when encode took it. - A part whose cursor does not open gives one encoder_error, the batch ends, and the other worker commits. - A worker that has ended does not keep the parts of the other workers from being sent. Docs: the pool and lock notes of the sink page, the extra columns snapshot, and the PgBouncer setting for named prepared statements. Fixes: #8096 Signed-off-by: Xavier Bestel <xavier.bestel@feldera.com>
|
Status of the review point: the two review commits are squashed into the main commit (ec6b6fb). The tree is the same. |
Linked Issue
Fixes #8096. Found during the work on #8017 and #8026 (related to #8014).
What changes
The endpoint of the Postgres output connector waited for every writer thread three times for each batch (start, encode, end). A thread that finished a round kept its transaction open, with a server connection of the pool and its row locks, until the slowest thread finished the round.
query_wait_timeout(120 s by default in PgBouncer), then the threads wrote their part againBEGINto its own commitNew protocol:
batch_startencodeEncodefor each part, returnsbatch_endBatchEnd, waits for one reply from each workerOther points:
BEGINand an encode failure are reported by the worker itself (pg_batch_startnot fatal,encoder_error), as it already did for its statements, and not when the pipeline is stopping.encodetakes the extra column values one time for all workers, so aset_extra_columnsafterencodereturned does not change the batch.Behavior change, in the docs and the changelog: a fast thread commits before a slow one, so a reader can see a part of a batch for longer. A batch was never atomic across threads.
This PR conflicts with #8020, #8021, #8027 and #8098, which change the same file. I will rebase the ones that merge after it.
Describe Manual Test Plan
workers_commit_with_a_shared_row_lock: anAFTER INSERTtrigger updates one counter row, 2 threads, one statement per row, 20 rowsthe batch did not finish(it waits until the 30 slock_timeoutof the trigger)idle_worker_opens_no_transaction: 2 threads, 1 row, through the proxySTART TRANSACTIONqueued_batch_keeps_extra_columnsencodeencodereturned after the flushes)postgres_outputbenchmarkChecklist
Breaking Changes?
None in the configuration. Behavior change: see above.