fix(redshift): raise postgres max_connections to 500 (#6421)

* fix(redshift): raise postgres max_connections to 500

The Postgres container behind a Redshift cluster runs with the default max_connections of 100, and each retained session keeps a connection open. Near 100 sessions, Data API calls and JDBC clients on that cluster encounter 'sorry, too many clients already', well before reaching the 500-session limit. Raising max_connections to 500 in RedshiftContainerManager lets the documented 500-session limit apply.

* fix(redshift): raise default proxy max connections to 500

The PostgreSQL backend limit was raised to 500, but the Redshift auth proxy connection semaphore defaulted to 100 via proxy-max-connections. As a result, client connections above 100 were refused by the proxy before reaching PostgreSQL. Raise the default proxy-max-connections to 500 across config, application YAML, and documentation.

* fix(redshift): follow node type for max_connections and raise proxy default to 2000

* fix(redshift): support rg node types, pass serverless from runtime, and update test stubs

- Include rg.* node types for 2,000 max_connections
- Pass 'serverless' node type from RedshiftServerlessRuntime and drop prefix check
- Update start(...) stubs across integration tests with the six-argument signature
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-24 21:09:27 -04:00
1 parent acb9fd2cd6
commit fac6378abd
17 files changed
+159 -36

No files matched your search

@@ -29,6 +29,6 @@ class RedshiftProxyConfigTest {
void redshiftProxyBoundsHaveDefaults() {
assertEquals(10000, config.services().redshift().proxyHandshakeTimeoutMillis());
assertEquals(5000, config.services().redshift().proxyBackendConnectTimeoutMillis());
assertEquals(100, config.services().redshift().proxyMaxConnections());
assertEquals(2000, config.services().redshift().proxyMaxConnections());
}
}
@@ -53,7 +53,7 @@ class RedshiftSnapshotCfnIntegrationTest {
@BeforeEach
void prepareRuntime() {
when(containers.start(anyString(), anyString(), anyString(), anyString()))
when(containers.start(anyString(), anyString(), anyString(), anyString(), any(), any()))
.thenAnswer(invocation -> new RedshiftContainerHandle("mock-container",
invocation.getArgument(1), "localhost", 5432));
doAnswer(invocation -> {
@@ -19,6 +19,7 @@ import java.net.URI;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@@ -37,7 +38,7 @@ class RedshiftDefaultIamRoleIntegrationTest {
String clusterId = "sdk-default-role";
String first = "arn:aws:iam::000000000000:role/first";
String second = "arn:aws:iam::000000000000:role/second";
when(containerManager.start(anyString(), anyString(), anyString(), anyString()))
when(containerManager.start(anyString(), anyString(), anyString(), anyString(), any(), any()))
.thenReturn(new RedshiftContainerHandle("mock-container", clusterId, "localhost", 5432));
try (RedshiftClient client = RedshiftClient.builder()
.endpointOverride(endpoint)
@@ -47,7 +47,7 @@ class RedshiftFinalSnapshotIntegrationTest {
@BeforeEach
void prepareRuntime() {
when(containerManager.start(anyString(), anyString(), anyString(), anyString()))
when(containerManager.start(anyString(), anyString(), anyString(), anyString(), any(), any()))
.thenReturn(new RedshiftContainerHandle("mock-container", "cluster", "localhost", 5432));
doAnswer(invocation -> {
Files.writeString(invocation.getArgument(3, Path.class), DUMP);
@@ -108,7 +108,7 @@ class RedshiftFinalSnapshotStorageTest {
when(access.storageMode("redshift")).thenReturn("persistent");
StorageFactory factory = new StorageFactory(config, access);
RedshiftContainerManager manager = mock(RedshiftContainerManager.class);
when(manager.start(anyString(), anyString(), anyString(), anyString()))
when(manager.start(anyString(), anyString(), anyString(), anyString(), any(), any()))
.thenReturn(new RedshiftContainerHandle("container", "restored", "localhost", 5432));
doAnswer(invocation -> {
Files.writeString(invocation.getArgument(3, Path.class), "backup contents");
@@ -167,14 +167,14 @@ public class RedshiftOperationsTest {
@Test
@Order(2)
void clusterAndSnapshotLifecycle() {
when(containerManager.start(any(), eq("cluster-src"), any(), any()))
when(containerManager.start(any(), eq("cluster-src"), any(), any(), any(), any()))
.thenReturn(new RedshiftContainerHandle("c1", "cluster-src", "localhost", 5439));
doAnswer(invocation -> {
Path p = invocation.getArgument(3);
Files.writeString(p, "-- dump sql table test_data;");
return null;
}).when(containerManager).takeSnapshot(any(), eq("cluster-src"), eq("admin"), any(Path.class));
when(containerManager.start(any(), eq("cluster-restored"), any(), any()))
when(containerManager.start(any(), eq("cluster-restored"), any(), any(), any(), any()))
.thenReturn(new RedshiftContainerHandle("c2", "cluster-restored", "localhost", 5440));
// 1. CreateCluster
@@ -842,7 +842,7 @@ public class RedshiftOperationsTest {
@Test
@Order(3)
void tagLifecycle() {
when(containerManager.start(any(), eq("cluster-tags"), any(), any()))
when(containerManager.start(any(), eq("cluster-tags"), any(), any(), any(), any()))
.thenReturn(new RedshiftContainerHandle("c3", "cluster-tags", "localhost", 5441));
given()
@@ -1019,7 +1019,7 @@ public class RedshiftOperationsTest {
@Test
@Order(9)
void snapshotCopyLifecycle() {
when(containerManager.start(any(), eq("cluster-copy"), any(), any()))
when(containerManager.start(any(), eq("cluster-copy"), any(), any(), any(), any()))
.thenReturn(new RedshiftContainerHandle("c9", "cluster-copy", "localhost", 5449));
assertEquals(200, redshift("CreateCluster", "ClusterIdentifier", "cluster-copy", "NodeType", "dc2.large",
"MasterUsername", "admin", "MasterUserPassword", "password123").statusCode());
@@ -1098,7 +1098,7 @@ public class RedshiftOperationsTest {
@Test
@Order(10)
void snapshotScheduleLifecycle() {
when(containerManager.start(any(), eq("cluster-sched"), any(), any()))
when(containerManager.start(any(), eq("cluster-sched"), any(), any(), any(), any()))
.thenReturn(new RedshiftContainerHandle("c10", "cluster-sched", "localhost", 5450));
assertEquals(200, redshift("CreateCluster", "ClusterIdentifier", "cluster-sched", "NodeType", "dc2.large",
"MasterUsername", "admin", "MasterUserPassword", "password123").statusCode());
@@ -484,6 +484,15 @@ class RedshiftServiceTest {
verify(clusterBackend, atLeastOnce()).flush();
}
@Test
void createClusterPassesNodeTypeToContainerManager() {
when(cm.start("111111111111", "c-ra3", "admin", "pw"))
.thenReturn(new RedshiftContainerHandle("c-ra3", "c-ra3", "localhost", 5432));
service.createCluster("c-ra3", "ra3.xlplus", "admin", "pw",
null, List.of(), List.of(), null);
verify(cm).start("111111111111", "c-ra3", "admin", "pw", "dev", "ra3.xlplus");
}
private StorageFactory sf;
private AccountAwareStorageBackend<Cluster> clusterBackend;
private AccountAwareStorageBackend<Snapshot> snapshotBackend;
@@ -515,6 +524,10 @@ class RedshiftServiceTest {
snapshotScheduleBackend = mock(AccountAwareStorageBackend.class);
integrationBackend = mock(AccountAwareStorageBackend.class);
cm = mock(RedshiftContainerManager.class);
when(cm.start(any(), any(), any(), any(), any(), any())).thenAnswer(inv ->
cm.start(inv.getArgument(0), inv.getArgument(1), inv.getArgument(2), inv.getArgument(3)));
when(cm.adoptOrStart(any(), any(), any(), any(), any(), any())).thenAnswer(inv ->
cm.adoptOrStart(inv.getArgument(0), inv.getArgument(1), inv.getArgument(2), inv.getArgument(3)));
proxyManager = mock(RedshiftProxyManager.class);
dockerHostResolver = mock(DockerHostResolver.class);
when(dockerHostResolver.resolve()).thenReturn("localhost");
@@ -35,6 +35,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -384,6 +385,61 @@ class RedshiftContainerManagerTest {
verify(lifecycleManager, never()).removeIfExistsStrict("floci-redshift-" + ACCOUNT_ID + "-test-cluster", true);
}
@Test
void startConfiguresMaxConnectionsByNodeTypeAndServerless() {
ContainerBuilder.Builder specBuilder = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
when(containerBuilder.newContainer(anyString())).thenReturn(specBuilder);
ContainerInfo info = new ContainerInfo("cont-123", Map.of(5432, new EndpointInfo("localhost", 5432)));
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(info);
manager.start(ACCOUNT_ID, "test-cluster", "admin", "pass");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=500"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "dc2-cluster", "admin", "pass", "dev", "dc2.large");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=500"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "dc2-8x-cluster", "admin", "pass", "dev", "dc2.8xlarge");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "ra3-cluster", "admin", "pass", "dev", "ra3.xlplus");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "ra3-4x-cluster", "admin", "pass", "dev", "ra3.4xlplus");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "ra3-16x-cluster", "admin", "pass", "dev", "ra3.16xlarge");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "rg-cluster", "admin", "pass", "dev", "rg.xlarge");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
clearInvocations(specBuilder);
manager.start(ACCOUNT_ID, "serverless_us-east-1_analytics-wg", "admin", "pass", "analytics", "serverless");
verify(specBuilder).withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=2000"));
}
@Test
void maxConnectionsResolvesCorrectLimits() {
assertEquals(500, RedshiftContainerManager.maxConnections("my-cluster", null));
assertEquals(500, RedshiftContainerManager.maxConnections("my-cluster", ""));
assertEquals(500, RedshiftContainerManager.maxConnections("my-cluster", "dc2.large"));
assertEquals(500, RedshiftContainerManager.maxConnections("my-cluster", "ds2.xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "dc2.8xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "ra3.xlplus"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "ra3.4xlplus"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "ra3.4xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "ra3.16xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "rg.xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "rg2.xlarge"));
assertEquals(2000, RedshiftContainerManager.maxConnections("my-cluster", "serverless"));
}
@Test
void sameClusterIdentifierAcrossAccountsDoesNotCollide() {
ContainerBuilder.Builder specBuilder = mock(ContainerBuilder.Builder.class, org.mockito.Mockito.RETURNS_SELF);
@@ -15,6 +15,7 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -45,7 +46,7 @@ class RedshiftProxyManagerTest {
EmulatorConfig.RedshiftServiceConfig redshiftConfig = mock(EmulatorConfig.RedshiftServiceConfig.class);
when(redshiftConfig.proxyHandshakeTimeoutMillis()).thenReturn(5000);
when(redshiftConfig.proxyBackendConnectTimeoutMillis()).thenReturn(5000);
when(redshiftConfig.proxyMaxConnections()).thenReturn(100);
when(redshiftConfig.proxyMaxConnections()).thenReturn(2000);
EmulatorConfig.ServicesConfig servicesConfig = mock(EmulatorConfig.ServicesConfig.class);
when(servicesConfig.redshift()).thenReturn(redshiftConfig);
EmulatorConfig config = mock(EmulatorConfig.class);
@@ -71,6 +72,22 @@ class RedshiftProxyManagerTest {
}
}
@Test
void startConfiguresProxyMaxConnections() throws Exception {
RedshiftProxyManager manager = newManager();
int port = FreePorts.anyInterfacePort();
try {
start(manager, KEY, port);
RedshiftAuthProxy proxy = registry(manager).get(KEY);
Field permitsField = RedshiftAuthProxy.class.getDeclaredField("connectionPermits");
permitsField.setAccessible(true);
Semaphore permits = (Semaphore) permitsField.get(proxy);
assertEquals(2000, permits.availablePermits());
} finally {
manager.stopAll();
}
}
@Test
void stopProxyRemovesTheKeyAndReleasesThePort() throws Exception {
RedshiftProxyManager manager = newManager();
@@ -49,7 +49,7 @@ class RedshiftServerlessRuntimeTest {
}
private PasswordValidator startAndCaptureValidator(RedshiftServerlessRuntime.AdminCredentials admin) {
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics")).thenReturn(handle());
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless")).thenReturn(handle());
runtime.start(ACCOUNT, REGION, "my-wg", "root", "Secret123", "analytics", ENDPOINT, false,
() -> Optional.ofNullable(admin));
ArgumentCaptor<PasswordValidator> validator = ArgumentCaptor.forClass(PasswordValidator.class);
@@ -60,17 +60,17 @@ class RedshiftServerlessRuntimeTest {
@Test
void startRunsTheContainerThenFrontsItWithTheProxyOnTheAllocatedEndpoint() {
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics")).thenReturn(handle());
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless")).thenReturn(handle());
RedshiftServerlessRuntime.Backend backend = runtime.start(ACCOUNT, REGION, "my-wg", "root", "Secret123",
"analytics", ENDPOINT, false, Optional::empty);
assertEquals(new RedshiftServerlessRuntime.Backend("172.17.0.5", 5432), backend);
InOrder order = inOrder(containers, proxies);
order.verify(containers).start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics");
order.verify(containers).start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless");
order.verify(proxies).startProxy(eq(RELAY_KEY), eq(7100), eq("172.17.0.5"), eq(5432), eq("localhost"),
eq("root"), eq("Secret123"), eq("analytics"), any(PasswordValidator.class), eq(List.of()));
verify(containers, never()).adoptOrStart(any(), any(), any(), any(), any());
verify(containers, never()).adoptOrStart(any(), any(), any(), any(), any(), any());
}
@Test
@@ -110,7 +110,7 @@ class RedshiftServerlessRuntimeTest {
@Test
void failedAdoptedProxyUsesRecoveryRollback() {
when(containers.adoptOrStart(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics")).thenReturn(handle());
when(containers.adoptOrStart(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless")).thenReturn(handle());
doThrow(new RuntimeException("port in use")).when(proxies).startProxy(any(), anyInt(), any(), anyInt(),
any(), any(), any(), any(), any(PasswordValidator.class), any());
@@ -124,18 +124,18 @@ class RedshiftServerlessRuntimeTest {
@Test
void adoptReattachesToASurvivingContainer() {
when(containers.adoptOrStart(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics")).thenReturn(handle());
when(containers.adoptOrStart(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless")).thenReturn(handle());
runtime.start(ACCOUNT, REGION, "my-wg", "root", "Secret123", "analytics", ENDPOINT, true, Optional::empty);
verify(containers, never()).start(any(), any(), any(), any(), any());
verify(containers, never()).start(any(), any(), any(), any(), any(), any());
verify(proxies).startProxy(eq(RELAY_KEY), eq(7100), any(), anyInt(), any(), any(), any(), any(),
any(PasswordValidator.class), any());
}
@Test
void aProxyThatFailsToStartRollsBackTheContainerAndCredentials() {
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics")).thenReturn(handle());
when(containers.start(ACCOUNT, BACKEND_ID, "root", "Secret123", "analytics", "serverless")).thenReturn(handle());
doThrow(new RuntimeException("port in use")).when(proxies).startProxy(any(), anyInt(), any(), anyInt(),
any(), any(), any(), any(), any(PasswordValidator.class), any());
broker.issue(ACCOUNT, BACKEND_ID, "IAM:alice", List.of(), 900);