feat(redshift): intercept Extended Query protocol (#3474)

* feat(redshift): decode Extended Query wire messages

* feat(redshift): track Extended Query statements and portals

* feat(redshift): coordinate Extended Query backend responses

* refactor(redshift): share S3 COPY and UNLOAD transfers

* feat(redshift): execute S3 transfers through Extended Query

* fix(redshift): retain next-cycle pipelined portals

* feat(redshift): intercept Extended Query statements

* test(redshift): cover Extended Query JDBC compatibility

* test(redshift): cover Extended Query SDK compatibility

* docs(redshift): document Extended Query interception

* feat(redshift): implement extended query execution handling in BackendResponseCoordinator and update related classes

* feat(redshift): enhance ExtendedS3Exchange with client synchronization handling

* fix(redshift): synchronize extended COPY failures

* fix(redshift): tolerate backend ownership fragmentation

* fix(redshift): forward extended query flush frames

* fix(redshift): abort backend copy on unload failure

* fix(redshift): preserve later extended query mutations

* fix(redshift): return ready state after copy failure

* test(redshift): cover later sync cycle rollback

* fix(redshift): preserve independent mutations when rejecting a pipelined mutation

ExtendedQuerySession.rejectFrom() restored the whole statements/portals
map back to the rejected mutation's "before" snapshot and truncated the
journal to the end, discarding any later, independent mutation that
happened to run first. The coordinator already rejects one pipelined
mutation at a time in journal order, so this only ever needs to undo
that one mutation's own effect.

Each journal entry now also records its own "after" snapshot at
creation time, since reconstructing it later from the next entry's
"before" or from the live maps goes stale once an earlier reject's
cascading portal cleanup has already touched a key this mutation never
itself changed.

* fix(redshift): forward the real ReadyForQuery after a COPY/UNLOAD failure

readClientSync(client) called the two-argument overload without its
Flush-forwarding OutputStream, which did not compile.

Every error branch in the Extended Query COPY/UNLOAD path sent CopyFail
and Sync to the backend but never drained or forwarded the backend's
resulting ReadyForQuery: the client waited on a frame nobody ever read
off the wire. drainReadyForQuery already existed for exactly this but
was never called. Wire it into every COPY and UNLOAD error branch.
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-13 08:54:52 -04:00
1 parent 04f0c3b7fd
commit e9454af855
15 files changed
+2717 -381

No files matched your search

@@ -6,6 +6,7 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.redshift.RedshiftClient;
import software.amazon.awssdk.services.redshift.model.Cluster;
import software.amazon.awssdk.services.redshift.model.CreateClusterRequest;
@@ -21,11 +22,14 @@ import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import java.net.ConnectException;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.Duration;
@@ -121,19 +125,33 @@ public class RedshiftTest {
.clusterIdentifier("test-cluster")
.build()).clusters().get(0);
String jdbcUrl = "jdbc:postgresql://" + cluster.endpoint().address() + ":"
+ cluster.endpoint().port() + "/dev?preferQueryMode=simple";
+ cluster.endpoint().port() + "/dev";
S3Client s3 = TestFixtures.s3Client();
String bucket = "redshift-unload-compat";
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
s3.putObject(PutObjectRequest.builder().bucket(bucket).key("in/data.txt").contentType("text/plain").build(),
RequestBody.fromString("1|alice\n2|bob\n"));
try (Connection conn = DriverManager.getConnection(jdbcUrl, "admin", "Password123");
Statement st = conn.createStatement()) {
st.execute("DROP TABLE IF EXISTS unload_src");
st.execute("CREATE TABLE unload_src (id int, name text)");
st.execute("INSERT INTO unload_src VALUES (1, 'alice'), (2, 'bob')");
st.execute("UNLOAD ('select id, name from unload_src order by id') "
+ "TO 's3://redshift-unload-compat/out/'");
try (PreparedStatement ddl = conn.prepareStatement("CREATE TABLE unload_src (id int, name text)")) {
ddl.execute();
}
try (PreparedStatement copy = conn.prepareStatement(
"COPY unload_src FROM 's3://redshift-unload-compat/in/data.txt'")) {
copy.execute();
}
try (PreparedStatement unload = conn.prepareStatement(
"UNLOAD ('select id, name from unload_src order by id') "
+ "TO 's3://redshift-unload-compat/out/' ALLOWOVERWRITE")) {
unload.execute();
}
try (ResultSet rows = st.executeQuery("SELECT count(*) FROM unload_src")) {
assertTrue(rows.next());
assertEquals(2, rows.getInt(1));
}
}
ListObjectsV2Response listing = s3.listObjectsV2(ListObjectsV2Request.builder()