Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public GcpObjectStoreFileStorage(Map<String, Object> credentials) {
protected Storage createObjectStoreStorage(Map<String, Object> credentials) {
return StorageOptions.http()
.setCredentials(getGcpCredentialsSupplier(credentials))
.setStorageRetryStrategy(StorageRetryStrategy.getDefaultStorageRetryStrategy())
.setStorageRetryStrategy(StorageRetryStrategy.getUniformStorageRetryStrategy())
.setRetrySettings(
RetrySettings.newBuilder()
.setMaxAttempts(OBJECT_STORE_MAX_ATTEMPTS_CONFIG)
Expand Down Expand Up @@ -110,7 +110,19 @@ public List<FileEntry> getFileEntriesWithoutContent(List<FileEntry> fileEntries)

@Override
public void deleteFile(String id, String space) {
storage.delete(bucketName, id);
deleteFileWithGeneration(id);
}

private boolean deleteFileWithGeneration(String id) {
Blob blob = storage.get(bucketName, id);
if (blob == null) {
return false;
}
if (blob.getGeneration() == null) {
return storage.delete(bucketName, id);
}
//Without generationMatch the delete requests are not retried because a retry can "accidentally delete a newer object version"
return storage.delete(bucketName, id, Storage.BlobSourceOption.generationMatch(blob.getGeneration()));
}

@Override
Expand Down Expand Up @@ -212,8 +224,10 @@ private int removeBlobsByFilter(Predicate<? super Blob> filter) {
return deletedBlobsResults.size();
}

protected List<Boolean> deleteBlobs(List<BlobId> blobIds) {
return storage.delete(blobIds);
private List<Boolean> deleteBlobs(List<BlobId> blobIds) {
return blobIds.stream()
.map(blobId -> deleteFileWithGeneration(blobId.getName()))
.toList();
}

protected Set<String> getEntryNames(Predicate<? super Blob> filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
Expand All @@ -16,6 +15,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.http.MediaType;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand All @@ -34,15 +34,6 @@ public void setUp() {
protected Storage createObjectStoreStorage(Map<String, Object> credentials) {
return storage;
}

@Override
protected List<Boolean> deleteBlobs(List<BlobId> blobIds) {
List<Boolean> deletedBlobsResults = new ArrayList<>();
for (BlobId blobId : blobIds) {
deletedBlobsResults.add(storage.delete(blobId));
}
return List.copyOf(deletedBlobsResults);
}
};
spaceId = UUID.randomUUID()
.toString();
Expand Down
Loading