diff --git a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java index 25ea43a741e..9bcd65df59f 100644 --- a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java +++ b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java @@ -1376,7 +1376,7 @@ public KeyRenameThread(String oldKey) { /** * Enum to indicate remote storage mode */ - private enum RemoteStorageMode { + enum RemoteStorageMode { S3, GCP } diff --git a/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreUtils.java b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreUtils.java index 750afc6e8d9..7b4a9afa1c2 100644 --- a/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreUtils.java +++ b/oak-blob-cloud/src/test/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3DataStoreUtils.java @@ -47,9 +47,12 @@ import org.apache.jackrabbit.core.data.DataStore; import org.apache.jackrabbit.oak.commons.PropertiesUtil; import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.jackrabbit.oak.blob.cloud.s3.S3Backend.RemoteStorageMode; + /** * Extension to {@link DataStoreUtils} to enable S3 extensions for cleaning and initialization. */ @@ -155,13 +158,20 @@ public static void deleteBucket(String bucket, Date date) throws Exception { ObjectListing prevObjectListing = s3service.listObjects(bucket); while (prevObjectListing != null) { List deleteList = new ArrayList(); + List keysToDelete = new ArrayList<>(); for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) { deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey())); + keysToDelete.add(s3ObjSumm.getKey()); } - if (deleteList.size() > 0) { - DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket); - delObjsReq.setKeys(deleteList); - s3service.deleteObjects(delObjsReq); + if (!deleteList.isEmpty()) { + RemoteStorageMode mode = getMode(props); + if (mode == RemoteStorageMode.S3) { + DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket); + delObjsReq.setKeys(deleteList); + s3service.deleteObjects(delObjsReq); + } else { + keysToDelete.forEach(key -> s3service.deleteObject(bucket, key)); + } } if (!prevObjectListing.isTruncated()) break; @@ -177,6 +187,12 @@ public static void deleteBucket(String bucket, Date date) throws Exception { s3service.shutdown(); } + @NotNull + private static RemoteStorageMode getMode(@NotNull Properties props) { + return props.getProperty(S3Constants.S3_END_POINT, "").contains("googleapis") ? + RemoteStorageMode.GCP : RemoteStorageMode.S3; + } + protected static HttpsURLConnection getHttpsConnection(long length, URI uri) throws IOException { HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection(); conn.setDoOutput(true);