Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit a4f3d7a

Browse files
authored
fix: Clean up snapshots when cross region database replication fails (#143)
1 parent 4bf4036 commit a4f3d7a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
group=com.nike
1818
artifactId=cerberus-lifecycle-cli
19-
version=4.12.0
19+
version=4.12.1

src/main/java/com/nike/cerberus/operation/rds/XRegionDatabaseReplicationOperation.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ public void run(XRegionDatabaseReplicationCommand command) {
8484

8585
log.info("Preparing to initiate copy of RDS DB snapshot: {} located in region: {} to region: {}",
8686
sourceSnapshot.getDBClusterSnapshotIdentifier(), sourceRegion.getName(), targetRegion.getName());
87-
DBClusterSnapshot copiedSnapshot = rdsService.copySnapshot(sourceSnapshot, sourceRegion, targetRegion);
88-
rdsService.waitForSnapshotsToBecomeAvailable(copiedSnapshot, targetRegion);
89-
90-
rdsService.deleteSnapshot(sourceSnapshot, sourceRegion);
87+
DBClusterSnapshot copiedSnapshot;
88+
try {
89+
copiedSnapshot = rdsService.copySnapshot(sourceSnapshot, sourceRegion, targetRegion);
90+
rdsService.waitForSnapshotsToBecomeAvailable(copiedSnapshot, targetRegion);
91+
} finally {
92+
rdsService.deleteSnapshot(sourceSnapshot, sourceRegion);
93+
}
9194

9295
String databasePassword = configStore.getCmsDatabasePassword()
9396
.orElseThrow(() -> new RuntimeException("Expected the database password to exist"));
@@ -117,9 +120,9 @@ public void run(XRegionDatabaseReplicationCommand command) {
117120
} else {
118121
throw ase;
119122
}
123+
} finally {
124+
rdsService.deleteSnapshot(copiedSnapshot, targetRegion);
120125
}
121-
122-
rdsService.deleteSnapshot(copiedSnapshot, targetRegion);
123126
}
124127

125128

0 commit comments

Comments
 (0)