Skip to content

Commit

Permalink
fix: consider Storage#delete(BlobId) idempotent when id has generation (
Browse files Browse the repository at this point in the history
#2222)

Update logic to consider an object delete request to be idempotent if the objects generation is specified in the BlobId.
  • Loading branch information
BenWhitehead authored Sep 25, 2023
1 parent f092c4e commit 453dd63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public ResultRetryAlgorithm<?> getFor(DeleteNotificationConfigRequest req) {
}

public ResultRetryAlgorithm<?> getFor(DeleteObjectRequest req) {
if (req.getGeneration() > 0 || req.hasIfGenerationMatch()) {
return retryStrategy.getIdempotentHandler();
}
return retryStrategy.getNonidempotentHandler();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public ResultRetryAlgorithm<?> getForObjectsCreate(
public ResultRetryAlgorithm<?> getForObjectsDelete(
StorageObject pb, Map<StorageRpc.Option, ?> optionsMap) {
return optionsMap.containsKey(StorageRpc.Option.IF_GENERATION_MATCH)
|| (pb.getGeneration() != null && pb.getGeneration() > 0)
? retryStrategy.getIdempotentHandler()
: retryStrategy.getNonidempotentHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,9 @@ private static void delete(ArrayList<RpcMethodMapping> a) {
(ctx, c) ->
ctx.map(
state -> {
boolean success =
ctx.getStorage().delete(state.getBlob().getBlobId());
BlobId id = state.getBlob().getBlobId();
BlobId idWithoutGeneration = BlobId.of(id.getBucket(), id.getName());
boolean success = ctx.getStorage().delete(idWithoutGeneration);
assertTrue(success);
return state.with(success);
}))
Expand Down Expand Up @@ -1169,7 +1170,17 @@ private static void delete(ArrayList<RpcMethodMapping> a) {
a.add(
RpcMethodMapping.newBuilder(67, objects.delete)
.withApplicable(not(TestRetryConformance::isPreconditionsProvided))
.withTest((ctx, c) -> ctx.peek(state -> state.getBlob().delete()))
.withTest(
(ctx, c) ->
ctx.peek(
state -> {
Blob blob = state.getBlob();
Blob blobWithoutGeneration =
blob.toBuilder()
.setBlobId(BlobId.of(blob.getBucket(), blob.getName()))
.build();
blobWithoutGeneration.delete();
}))
.build());
a.add(
RpcMethodMapping.newBuilder(68, objects.delete)
Expand Down

0 comments on commit 453dd63

Please sign in to comment.