Skip to content

Commit 4c7c510

Browse files
authored
Merge pull request #1441 from digital-preservation/increase-window-size
Use larger window size.
2 parents e9c18b5 + 0607e04 commit 4c7c510

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

droid-api/src/main/java/uk/gov/nationalarchives/droid/internal/api/DroidAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public final class DroidAPI implements AutoCloseable {
9191
private static final String OLE2_PUID = "fmt/111";
9292
private static final String S3_SCHEME = "s3";
9393
private static final String GZIP_PUID = "x-fmt/266";
94-
private static final long DEFAULT_MAX_BYTES_TO_SCAN = 65536;
94+
private static final long DEFAULT_MAX_BYTES_TO_SCAN = -1;
9595

9696
private static final AtomicLong ID_GENERATOR = new AtomicLong();
9797

droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/resource/S3WindowReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ public class S3WindowReader extends AbstractReader implements SoftWindowRecovery
4949

5050
private static final int BUFFER_LENGTH = 8192;
5151

52+
private static final int WINDOW_SIZE = 4 * 1024 * 1024;
53+
5254
private final S3Utils.S3ObjectMetadata s3ObjectMetadata;
5355

5456
private final S3Client s3Client;
5557

5658
private final Long length;
5759

5860
public S3WindowReader(WindowCache cache, S3Utils.S3ObjectMetadata s3ObjectMetadata, S3Client s3Client) {
59-
super(cache);
61+
super(WINDOW_SIZE, cache);
6062
this.s3Client = s3Client;
6163
this.length = s3ObjectMetadata.contentLength();
6264
this.s3ObjectMetadata = s3ObjectMetadata;
@@ -81,7 +83,6 @@ private byte[] bytesForRange(long windowStart) throws IOException {
8183
.key(key)
8284
.range("bytes=" + windowStart + "-" + (windowStart + this.windowSize -1))
8385
.build();
84-
8586
try (ResponseInputStream<GetObjectResponse> response = s3Client.getObject(getS3ObjectRequest)) {
8687
return toByteArray(response);
8788
}

droid-core-interfaces/src/test/java/uk/gov/nationalarchives/droid/core/interfaces/resource/S3IdentificationRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testS3IdentificationRequestGetsFirstWindowOnCreation() throws IOExce
6767
verify(mockS3Client, times(1)).getObject(getObjectRequestCaptor.capture());
6868

6969
GetObjectRequest getRequestValue = getObjectRequestCaptor.getValue();
70-
assertEquals(getRequestValue.range(), "bytes=0-4095");
70+
assertEquals(getRequestValue.range(), "bytes=0-4194303");
7171
}
7272

7373
@Test

droid-core-interfaces/src/test/java/uk/gov/nationalarchives/droid/core/interfaces/resource/S3WindowReaderTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
import net.byteseek.io.reader.windows.SoftWindow;
3636
import net.byteseek.io.reader.windows.Window;
3737
import org.junit.jupiter.api.Test;
38+
import org.mockito.Mockito;
39+
import org.mockito.invocation.Invocation;
3840
import software.amazon.awssdk.services.s3.S3Client;
3941
import software.amazon.awssdk.services.s3.S3Uri;
4042
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
41-
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
4243
import software.amazon.awssdk.services.s3.model.S3Exception;
4344

4445
import java.net.URI;
46+
import java.util.Collection;
4547
import java.util.Optional;
4648

4749
import static org.junit.jupiter.api.Assertions.*;
@@ -50,6 +52,7 @@
5052
import static org.mockito.Mockito.when;
5153
import static uk.gov.nationalarchives.droid.core.interfaces.resource.S3TestUtils.mockS3Client;
5254

55+
5356
public class S3WindowReaderTest {
5457

5558
@Test
@@ -70,6 +73,20 @@ public void testWindowReaderReturnsExpectedWindow() throws Exception {
7073
}
7174
}
7275

76+
@Test
77+
public void testWindowReaderReturnsExpectedWindowForLargeFile() throws Exception {
78+
WindowCache windowCache = mock(WindowCache.class);
79+
S3Client s3Client = mockS3Client();
80+
S3Uri s3Uri = S3Uri.builder().uri(URI.create("s3://bucket/key")).build();
81+
S3Utils.S3ObjectMetadata s3ObjectMetadata = new S3Utils.S3ObjectMetadata("bucket", Optional.of("key"), s3Uri, 4L, 1L);
82+
S3WindowReader s3WindowReader = new S3WindowReader(windowCache, s3ObjectMetadata, s3Client);
83+
84+
s3WindowReader.createWindow(0);
85+
Collection<Invocation> invocations = Mockito.mockingDetails(s3Client).getInvocations();
86+
GetObjectRequest getObjectRequest = (GetObjectRequest)invocations.stream().toList().getFirst().getArguments()[0];
87+
assertEquals(getObjectRequest.range(), "bytes=0-" + ((4 * 1024 * 1024) - 1));
88+
}
89+
7390
@Test
7491
public void testWindowReaderReturnsNullIfPositionLessThanZero() throws Exception {
7592
WindowCache windowCache = mock(WindowCache.class);

0 commit comments

Comments
 (0)