Skip to content

Commit

Permalink
Fix multi-page delete for S3 platform storage (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Traverse authored Aug 10, 2023
1 parent a30942d commit 269d918
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,39 +370,49 @@ protected CompletionStage<Void> fsDeleteFile(String objectKey, IExecutionContext
@Override
protected CompletionStage<Void> fsDeleteDir(String directoryKey, IExecutionContext ctx) {

return fsDeleteDir(directoryKey, true, ctx);
return fsDeleteDirPage(directoryKey, null, ctx);
}

protected CompletionStage<Void> fsDeleteDir(String directoryKey, boolean firstPass, IExecutionContext ctx) {
protected CompletionStage<Void> fsDeleteDirPage(String directoryKey, String continuation, IExecutionContext ctx) {

var absoluteDir = usePrefix(directoryKey);

// Using default page size of 1000 keys
var listRequest = ListObjectsV2Request.builder()
.bucket(bucket)
.prefix(absoluteDir)
.continuationToken(continuation)
.build();

// Send request and get response onto the EL for execContext
var listResponse = toContext(ctx, client.listObjectsV2(listRequest));

// TODO: Handle contents more than one page, use list objects iterator, or post back to event loop
return listResponse.thenCompose(contents -> {

return listResponse.thenCompose(list -> {

if (!list.hasContents()) {
if (firstPass)
if (!contents.hasContents()) {
if (continuation == null)
throw errors.explicitError("RMDIR", directoryKey, OBJECT_NOT_FOUND);
else
return CompletableFuture.completedFuture(0).thenApply(x -> null);
throw errors.explicitError("RMDIR", directoryKey, IO_ERROR, "Expected more objects during delete");
}

return fsDeleteDirContents(list, ctx);
var delete = fsDeleteDirContents(contents, ctx);
var nextPage = contents.nextContinuationToken();

if (nextPage == null)
return delete;

else
return delete.thenCompose(x -> fsDeleteDirPage(directoryKey, nextPage, ctx));
});
}

private CompletionStage<Void>
fsDeleteDirContents(ListObjectsV2Response contents, IExecutionContext ctx) {

if (!contents.hasContents())
return CompletableFuture.completedFuture(null);

var objIds = contents.contents()
.stream()
.map(obj -> ObjectIdentifier.builder().key(obj.key()).build())
Expand Down

0 comments on commit 269d918

Please sign in to comment.