fix(redshift): discard the final snapshot when DeleteCluster fails (#7072)

* fix(redshift): discard the final snapshot when DeleteCluster fails

DeleteCluster took the final snapshot before tearing the cluster down. When the teardown then failed, the cluster survived but the snapshot stayed behind, so retrying with the same FinalClusterSnapshotIdentifier failed with ClusterSnapshotAlreadyExists. Remove the snapshot when the cluster is still present after a failed removal.

* fix(redshift): keep the final snapshot once container teardown has started

The cleanup added for failed DeleteCluster also ran when containerManager.stop threw. That call removes the container and its volumes before closing the log stream, so a late failure leaves the cluster record behind with the database already gone, and the cleanup then deleted the only remaining copy. Limit the cleanup to the proxy-stop failure, which happens before anything is torn down, and cover both the kept-snapshot and the suppressed-cleanup-failure paths.
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-31 08:45:26 -04:00
1 parent 3ed65caf07
commit 0de2b7fdd8
2 files changed
+72 -4

No files matched your search

@@ -98,6 +98,51 @@ class RedshiftFinalSnapshotStorageTest {
verifyNoInteractions(fixture.proxy());
}
@Test
void deleteClusterRetryAfterProxyStopFailureReusesFinalSnapshotIdentifier() {
Fixture fixture = fixture();
seedCluster(fixture);
doThrow(new IllegalStateException("proxy stop failed")).doNothing()
.when(fixture.proxy()).stopProxy(anyString());
assertThrows(AwsException.class, () -> delete(fixture));
assertEquals("available", fixture.service().describeClusters("final-cluster").getFirst().getClusterStatus());
assertDoesNotThrow(() -> delete(fixture));
assertTrue(fixture.service().describeClusters(null).isEmpty());
}
@Test
void deleteClusterKeepsFinalSnapshotWhenContainerTeardownFails() {
Fixture fixture = fixture();
seedCluster(fixture);
doThrow(new IllegalStateException("container removal failed"))
.when(fixture.manager()).stop(anyString(), anyString());
assertThrows(IllegalStateException.class, () -> delete(fixture));
assertTrue(fixture.service().getSnapshot("final-backup").isPresent());
assertTrue(Files.exists(directory.resolve("redshift-dumps").resolve(ACCOUNT).resolve("final-backup.sql")));
}
@Test
void deleteClusterAttachesFinalSnapshotCleanupFailureToTheProxyStopFailure() {
Fixture fixture = fixture();
seedCluster(fixture);
IllegalStateException proxyFailure = new IllegalStateException("proxy stop failed");
doAnswer(invocation -> {
fixture.service().deleteSnapshot("final-backup");
throw proxyFailure;
}).when(fixture.proxy()).stopProxy(anyString());
AwsException failure = assertThrows(AwsException.class, () -> delete(fixture));
assertEquals("InternalFailure", failure.getErrorCode());
assertEquals(1, failure.getSuppressed().length);
assertInstanceOf(AwsException.class, failure.getSuppressed()[0]);
assertEquals("ClusterSnapshotNotFound", ((AwsException) failure.getSuppressed()[0]).getErrorCode());
}
private Fixture fixture() {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.storage().persistentPath()).thenReturn(directory.toString());