This is an automated email from the ASF dual-hosted git repository.

mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 6f8268412e3c5f6e5391c777be8d0b9438921a2a
Author: Hussain Towaileb <[email protected]>
AuthorDate: Fri Aug 2 17:52:23 2024 +0300

    [NO ISSUE]: Handle unexpected EOF when reading from cloud storage
    
    Ext-ref: MB-62987
    Change-Id: I3a71d2b93e9e31ce38b345044624c987c77c5d37
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18586
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Hussain Towaileb <[email protected]>
    Reviewed-by: Michael Blow <[email protected]>
---
 .../org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
index 24d5fa9a3d..319b71318f 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
@@ -129,17 +129,22 @@ public final class S3CloudClient implements ICloudClient {
     public int read(String bucket, String path, long offset, ByteBuffer 
buffer) throws HyracksDataException {
         guardian.checkReadAccess(bucket, path);
         profiler.objectGet();
+        long bytesToRead = buffer.remaining();
         long readTo = offset + buffer.remaining() - 1;
         GetObjectRequest rangeGetObjectRequest = 
GetObjectRequest.builder().range("bytes=" + offset + "-" + readTo)
                 .bucket(bucket).key(config.getPrefix() + path).build();
 
         int totalRead = 0;
-        int read = 0;
+        int read;
 
         // TODO(htowaileb): add retry logic here
         try (ResponseInputStream<GetObjectResponse> response = 
s3Client.getObject(rangeGetObjectRequest)) {
             while (buffer.remaining() > 0) {
                 read = response.read(buffer.array(), buffer.position(), 
buffer.remaining());
+                if (read == -1) {
+                    throw new IllegalStateException("Unexpected EOF 
encountered. File: " + path + ", expected bytes: "
+                            + bytesToRead + ", bytes read: " + totalRead);
+                }
                 buffer.position(buffer.position() + read);
                 totalRead += read;
             }

Reply via email to