fix(redshift): preserve frontend state after an error Sync (#9401)

A query pipelined after Sync but before the previous ReadyForQuery could lose its prepared statement and portal during error recovery. The next frontend cycle now starts once Sync is registered or already queued, while its pending response stays the backend ownership barrier. A failed backend cycle is tracked apart from frontend discard mode, so a failed owned COPY transaction still rolls back at Sync, and the SQL needed for user-change audit events is kept.
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-11-24 22:02:22 -04:00
1 parent 0e32c55191
commit 8216c2b382
5 files changed
+210 -3

No files matched your search

@@ -18,6 +18,7 @@ final class BackendResponseCoordinator {
private final Map<Long, GateResult> resolvedGates = new HashMap<>();
private long nextSequence = 1;
private boolean discardingUntilSync;
private boolean extendedCycleFailed;
private boolean closed;
private char lastReadyStatus = 'I';
@@ -42,6 +43,9 @@ final class BackendResponseCoordinator {
}
} else {
pending.addLast(new PendingOperation(ticket, mutation, response));
if (operation == Operation.SYNC) {
discardingUntilSync = false;
}
}
changed.signalAll();
return ticket;
@@ -157,7 +161,6 @@ final class BackendResponseCoordinator {
pending.removeFirst();
reject(head);
resolveSkippedGate(head);
discardingUntilSync = true;
discardQueuedOperationsBeforeSync();
}
changed.signalAll();
@@ -169,6 +172,7 @@ final class BackendResponseCoordinator {
confirm(head);
if (operation == Operation.SYNC) {
discardingUntilSync = false;
extendedCycleFailed = false;
}
changed.signalAll();
}
@@ -193,7 +197,6 @@ final class BackendResponseCoordinator {
pending.remove(owned);
confirm(owned);
if (failed) {
discardingUntilSync = true;
discardQueuedOperationsBeforeSync();
}
changed.signalAll();
@@ -222,6 +225,15 @@ final class BackendResponseCoordinator {
}
}
boolean extendedCycleFailed() {
lock.lock();
try {
return extendedCycleFailed;
} finally {
lock.unlock();
}
}
char lastReadyStatus() {
lock.lock();
try {
@@ -256,11 +268,14 @@ final class BackendResponseCoordinator {
}
private void discardQueuedOperationsBeforeSync() {
extendedCycleFailed = true;
while (!pending.isEmpty() && pending.peekFirst().ticket().operation() != Operation.SYNC) {
PendingOperation skipped = pending.removeFirst();
reject(skipped);
resolveSkippedGate(skipped);
}
// Sync starts the next frontend cycle; its queued response still prevents early backend ownership.
discardingUntilSync = pending.isEmpty();
}
private void resolveSkippedGate(PendingOperation operation) {
@@ -881,7 +881,7 @@ public class RedshiftInterceptingBridge {
}
try {
backend.setSoTimeout(EXCHANGE_READ_TIMEOUT_MS);
boolean failed = coordinator.isDiscardingUntilSync();
boolean failed = coordinator.extendedCycleFailed();
try {
copyBackend.finish(failed);
} catch (S3TransferException e) {