mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
fix(redshift): keep a parameter or subnet group deleted during a modify from coming back (#8644)
deleteClusterParameterGroup and deleteClusterSubnetGroup now read and delete the group under the service's lock (mutate), which modifyClusterParameterGroup, resetClusterParameterGroup and modifyClusterSubnetGroup hold from their read to their write. A delete can no longer answer success between a modify's read and its write and have that write put the group back. The parameter group's deletion event is still emitted after the lock.
This commit is contained in:
1 parent
70921dea2c
commit
2ca478b7ba
2 files changed
+56
-13
No files matched your search
@@ -3102,13 +3102,17 @@ public class RedshiftService implements ManagedSecretRotator {
|
||||
}
|
||||
|
||||
public ClusterParameterGroup deleteClusterParameterGroup(String parameterGroupName) {
|
||||
Optional<ClusterParameterGroup> groupOpt = parameterGroups.get(regionalKey(parameterGroupName));
|
||||
if (groupOpt.isEmpty()) {
|
||||
throw new AwsException("ClusterParameterGroupNotFound", "Cluster parameter group " + parameterGroupName + " not found", 404);
|
||||
}
|
||||
ClusterParameterGroup group = groupOpt.get();
|
||||
parameterGroups.delete(regionalKey(parameterGroupName));
|
||||
parameterGroups.flush();
|
||||
// The read and the delete under the service's lock (mutate), which modifyClusterParameterGroup and
|
||||
// resetClusterParameterGroup hold from their read to their write, so a delete can't land in between and be
|
||||
// undone by their write; the event is emitted after it.
|
||||
ClusterParameterGroup group = mutate(() -> {
|
||||
ClusterParameterGroup found = parameterGroups.get(regionalKey(parameterGroupName))
|
||||
.orElseThrow(() -> new AwsException("ClusterParameterGroupNotFound",
|
||||
"Cluster parameter group " + parameterGroupName + " not found", 404));
|
||||
parameterGroups.delete(regionalKey(parameterGroupName));
|
||||
parameterGroups.flush();
|
||||
return found;
|
||||
});
|
||||
emitEvent(RedshiftEventCatalog.PARAMETER_GROUP_DELETED, parameterGroupName,
|
||||
"Cluster parameter group '" + parameterGroupName + "' was deleted at " + eventTime() + ".");
|
||||
return group;
|
||||
@@ -3267,11 +3271,16 @@ public class RedshiftService implements ManagedSecretRotator {
|
||||
}
|
||||
|
||||
public ClusterSubnetGroup deleteClusterSubnetGroup(String name) {
|
||||
ClusterSubnetGroup group = subnetGroups.get(regionalKey(name))
|
||||
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault", "Cluster subnet group " + name + " not found", 400));
|
||||
subnetGroups.delete(regionalKey(name));
|
||||
subnetGroups.flush();
|
||||
return group;
|
||||
// The read and the delete under the service's lock (mutate), which modifyClusterSubnetGroup holds from its
|
||||
// read to its write, so a delete can't land in between and be undone by that write.
|
||||
return mutate(() -> {
|
||||
ClusterSubnetGroup group = subnetGroups.get(regionalKey(name))
|
||||
.orElseThrow(() -> new AwsException("ClusterSubnetGroupNotFoundFault",
|
||||
"Cluster subnet group " + name + " not found", 400));
|
||||
subnetGroups.delete(regionalKey(name));
|
||||
subnetGroups.flush();
|
||||
return group;
|
||||
});
|
||||
}
|
||||
|
||||
// ── Snapshot Copy Grant Operations ───────────────────────────────────────
|
||||
|
||||
@@ -4206,7 +4206,7 @@ class RedshiftServiceTest {
|
||||
assertEquals(Set.of(regionalKey("racy")), groups.keys());
|
||||
}
|
||||
|
||||
/** {@code backend}'s reads and writes, served by a store a test can hold inside its next write. */
|
||||
/** {@code backend}'s reads, writes and deletes, served by a store a test can hold inside its next write. */
|
||||
private static <V> ParkingStore<V> backedByParkingStore(AccountAwareStorageBackend<V> backend) {
|
||||
ParkingStore<V> store = new ParkingStore<>();
|
||||
when(backend.get(anyString())).thenAnswer(call -> store.get(call.getArgument(0)));
|
||||
@@ -4214,9 +4214,43 @@ class RedshiftServiceTest {
|
||||
store.put(call.getArgument(0), call.getArgument(1));
|
||||
return null;
|
||||
}).when(backend).put(anyString(), any());
|
||||
doAnswer(call -> {
|
||||
store.delete(call.getArgument(0));
|
||||
return null;
|
||||
}).when(backend).delete(anyString());
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* A delete of a subnet group that a modify has read and is writing back waits for that write, then deletes it:
|
||||
* the group stays deleted rather than being put back by the modify.
|
||||
*/
|
||||
@Test
|
||||
void aDeleteOfASubnetGroupWaitsForItsModifyAndTheGroupStaysDeleted() throws Exception {
|
||||
ParkingStore<ClusterSubnetGroup> groups = backedByParkingStore(subnetGroupBackend);
|
||||
groups.put(regionalKey("racy"), new ClusterSubnetGroup("racy", "d", "vpc-1", List.of("subnet-1")));
|
||||
groups.parkNextWrite();
|
||||
|
||||
assertOperationWaitsForParkedStore(groups, () -> service.modifyClusterSubnetGroup("racy", "changed", null),
|
||||
() -> service.deleteClusterSubnetGroup("racy"));
|
||||
|
||||
assertEquals(Set.of(), groups.keys());
|
||||
}
|
||||
|
||||
/** As above, for a cluster parameter group. */
|
||||
@Test
|
||||
void aDeleteOfAParameterGroupWaitsForItsModifyAndTheGroupStaysDeleted() throws Exception {
|
||||
ParkingStore<ClusterParameterGroup> groups = backedByParkingStore(parameterGroupBackend);
|
||||
groups.put(regionalKey("racy"), new ClusterParameterGroup("racy", "redshift-1.0", "d"));
|
||||
groups.parkNextWrite();
|
||||
|
||||
assertOperationWaitsForParkedStore(groups, () -> service.modifyClusterParameterGroup("racy",
|
||||
List.of(new Parameter("max_cursor_result_set_size", "1000"))),
|
||||
() -> service.deleteClusterParameterGroup("racy"));
|
||||
|
||||
assertEquals(Set.of(), groups.keys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the first {@code create} inside its write, after its check that the name is free, and runs a second one:
|
||||
* the second must wait for the first, then answer {@code alreadyExists}.
|
||||
|
||||
Reference in new issue
Block a user