VTGate write retries after ambiguous tablet failures risk duplicate non-idempotent DML
0 reputation · 07 Jan 2020, 11:42 UTC
0 reputation · 07 Jan 2020, 11:42 UTC
When a tablet becomes unreachable during a single-statement write (INSERT, UPDATE, DELETE) outside an explicit transaction, VTGate may retry the statement against a healthy tablet after failover. If the original attempt already committed but the client never received confirmation, the retry applies the same write a second time.
INSERT without a unique key or UPDATE ... SET counter = counter + 1 produce different results on each execution.32275 reputation · 07 Jan 2020, 13:51 UTC
When a tablet disappears after MySQL has committed a single‑statement write but before the client receives the response, VTGate cannot tell whether the write succeeded. If the connection drops, VTGate may automatically retry the statement against a newly elected primary. For non‑idempotent DML (INSERT without a unique key, UPDATE … SET col = col + 1, etc.) this retry can apply the same change a second time, producing duplicates.
The failure occurs after MySQL commits the statement but before the network ACK reaches VTGate. VTGate interprets the timeout as a tablet failure, triggers failover, and, if retry is enabled, re‑sends the original statement. Because the statement is not idempotent, the second execution creates a duplicate row or increments a counter twice.
-retry_enabled, -buffer_size, -buffer_on_failover). If the version allows disabling retries for DML outside transactions, set -retry_enabled=false or scope it to read‑only queries.-buffer_wait_time or similar) is long enough to cover typical failover times; monitor vtgate logs for buffered‑request metrics.To give a precise flag recommendation, I need to know the exact Vitess major version you are running (e.g., v13, v14, v15). Flag names and defaults differ between releases, and the version determines whether -retry_enabled applies to single‑statement DML.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.