Skip to content

Commit ae6c57b

Browse files
committed
Increase S3 delete batch size to 1000
Matches batch size used in legacy FS io.trino.hdfs.s3.TrinoS3FileSystem#DELETE_BATCH_SIZE 1000 is the maximum batch size supported by S3 client Reduces potential of getting throttled by S3
1 parent 890bfa0 commit ae6c57b

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
final class S3FileSystem
7070
implements TrinoFileSystem
7171
{
72+
static final int DELETE_BATCH_SIZE = 1000;
73+
7274
private final Executor uploadExecutor;
7375
private final S3Client client;
7476
private final S3Presigner preSigner;
@@ -188,7 +190,7 @@ private void deleteObjects(Collection<Location> locations)
188190
String bucket = entry.getKey();
189191
Collection<String> allKeys = entry.getValue();
190192

191-
for (List<String> keys : partition(allKeys, 250)) {
193+
for (List<String> keys : partition(allKeys, DELETE_BATCH_SIZE)) {
192194
List<ObjectIdentifier> objects = keys.stream()
193195
.map(key -> ObjectIdentifier.builder().key(key).build())
194196
.toList();

lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemMinIo.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
*/
1414
package io.trino.filesystem.s3;
1515

16+
import com.google.common.io.Closer;
1617
import io.airlift.units.DataSize;
1718
import io.opentelemetry.api.OpenTelemetry;
19+
import io.trino.filesystem.Location;
1820
import io.trino.testing.containers.Minio;
1921
import org.junit.jupiter.api.AfterAll;
2022
import org.junit.jupiter.api.Test;
@@ -25,7 +27,10 @@
2527

2628
import java.io.IOException;
2729
import java.net.URI;
30+
import java.util.List;
2831

32+
import static io.trino.filesystem.s3.S3FileSystem.DELETE_BATCH_SIZE;
33+
import static org.assertj.core.api.Assertions.assertThat;
2934
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3035

3136
public class TestS3FileSystemMinIo
@@ -119,4 +124,23 @@ public void testListDirectories()
119124
// MinIO is not hierarchical but has hierarchical naming constraints. For example it's not possible to have two blobs "level0" and "level0/level1".
120125
testListDirectories(true);
121126
}
127+
128+
@Test
129+
void testDeleteManyFiles()
130+
throws IOException
131+
{
132+
try (Closer closer = Closer.create()) {
133+
// create a large number of files to test batch deletion over multiple batches
134+
// we run this test only on MinIO to avoid API costs and long execution time on AWS S3
135+
List<TempBlob> blobs = randomBlobs(closer, DELETE_BATCH_SIZE + 100);
136+
List<Location> locations = blobs.stream()
137+
.map(TempBlob::location)
138+
.toList();
139+
140+
getFileSystem().deleteFiles(locations);
141+
for (Location location : locations) {
142+
assertThat(getFileSystem().newInputFile(location).exists()).isFalse();
143+
}
144+
}
145+
}
122146
}

lib/trino-filesystem/src/test/java/io/trino/filesystem/AbstractTestTrinoFileSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ public void testListLexicographicalOrder()
12141214
throws IOException
12151215
{
12161216
try (Closer closer = Closer.create()) {
1217-
List<TempBlob> blobs = randomBlobs(closer);
1217+
List<TempBlob> blobs = randomBlobs(closer, 100);
12181218

12191219
List<Location> sortedLocations = blobs.stream()
12201220
.map(TempBlob::location)
@@ -1538,11 +1538,11 @@ protected TempBlob randomBlobLocation(String nameHint)
15381538
return tempBlob;
15391539
}
15401540

1541-
private List<TempBlob> randomBlobs(Closer closer)
1541+
protected List<TempBlob> randomBlobs(Closer closer, int count)
15421542
{
15431543
char[] chars = new char[] {'a', 'b', 'c', 'd', 'A', 'B', 'C', 'D'};
15441544
ImmutableList.Builder<TempBlob> names = ImmutableList.builder();
1545-
for (int i = 0; i < 100; i++) {
1545+
for (int i = 0; i < count; i++) {
15461546
StringBuilder name = new StringBuilder();
15471547
for (int j = 0; j < 10; j++) {
15481548
name.append(chars[ThreadLocalRandom.current().nextInt(chars.length)]);

0 commit comments

Comments
 (0)