mirror of
https://github.com/floci-io/floci.git
synced 2026-12-06 03:28:18 -05:00
fix(neptune): reserve cluster identity while provisioning (#7851)
Claim the account, region and cluster identifier before starting the backend. Concurrent retries receive the modeled duplicate-cluster fault before they can start or roll back the owning request's container. Release the claim on every exit so a failed create can be retried. Port the Neptune commit 1c24af0a250c from AndreKurait/floci#473. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
d1205c34a2
commit
9a01e92ab7
3 files changed
+131
-2
No files matched your search
@@ -46,6 +46,7 @@ public class NeptuneService {
|
||||
private final NeptuneContainerManager containerManager;
|
||||
private final NeptuneProxyManager proxyManager;
|
||||
private final Set<Integer> usedPorts = ConcurrentHashMap.newKeySet();
|
||||
private final Set<String> provisioningClusterNames = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Inject
|
||||
public NeptuneService(EmulatorConfig config,
|
||||
@@ -72,9 +73,26 @@ public class NeptuneService {
|
||||
public NeptuneCluster createDbCluster(String id, String engineVersion, boolean iamEnabled,
|
||||
NeptuneClusterSettings settings, Map<String, String> tags) {
|
||||
settings.validate();
|
||||
String identity = resourceIdentity(currentAccount(), currentRegion(), id);
|
||||
if (!provisioningClusterNames.add(identity)) {
|
||||
throw clusterAlreadyExists(id);
|
||||
}
|
||||
try {
|
||||
return provisionDbCluster(id, engineVersion, iamEnabled, settings, tags);
|
||||
} finally {
|
||||
provisioningClusterNames.remove(identity);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException clusterAlreadyExists(String id) {
|
||||
return new AwsException("DBClusterAlreadyExistsFault",
|
||||
"Neptune cluster " + id + " already exists.", 400);
|
||||
}
|
||||
|
||||
private NeptuneCluster provisionDbCluster(String id, String engineVersion, boolean iamEnabled,
|
||||
NeptuneClusterSettings settings, Map<String, String> tags) {
|
||||
if (getStoredCluster(id).isPresent()) {
|
||||
throw new AwsException("DBClusterAlreadyExistsFault",
|
||||
"Neptune cluster " + id + " already exists.", 400);
|
||||
throw clusterAlreadyExists(id);
|
||||
}
|
||||
|
||||
// Open the try immediately after reserving the port so config reads below can't leak it.
|
||||
|
||||
Reference in new issue
Block a user