Skip to content

Commit 605e3ef

Browse files
authored
[Issue #1273] fix readFully in S3 storage (#1274)
The new AWS SDK returns ReadOnlyByteBuffer, which can not be copied using the backing array.
1 parent c4edfb0 commit 605e3ef

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pixels-storage/pixels-storage-s3/src/main/java/io/pixelsdb/pixels/storage/s3/AbstractS3Reader.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public abstract class AbstractS3Reader implements PhysicalReader
5151
* The implementations of most methods in this class are from its subclass PhysicalS3Reader.
5252
*/
5353

54-
protected boolean enableAsync = false;
55-
protected boolean useAsyncClient = false;
54+
protected boolean enableAsync;
55+
protected boolean useAsyncClient;
5656
protected static final ExecutorService clientService;
5757

5858
static
@@ -125,7 +125,7 @@ protected String toRange(long start, int length)
125125
}
126126

127127
@Override
128-
public long getFileLength() throws IOException
128+
public long getFileLength()
129129
{
130130
return length;
131131
}
@@ -159,7 +159,8 @@ public ByteBuffer readFully(int len) throws IOException
159159
this.numRequests++;
160160
this.position += len;
161161
return response.asByteBuffer();
162-
} catch (Exception e)
162+
}
163+
catch (Exception e)
163164
{
164165
throw new IOException("Failed to read object.", e);
165166
}
@@ -175,8 +176,16 @@ public void readFully(byte[] buffer) throws IOException
175176
public void readFully(byte[] buffer, int off, int len) throws IOException
176177
{
177178
ByteBuffer byteBuffer = readFully(len);
178-
// This is more efficient than byteBuffer.put(buffer, off, len).
179-
System.arraycopy(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), buffer, off, len);
179+
if (byteBuffer.hasArray())
180+
{
181+
// This is more efficient than byteBuffer.get(buffer, off, len).
182+
System.arraycopy(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
183+
buffer, off, len);
184+
}
185+
else
186+
{
187+
byteBuffer.get(buffer, off, len);
188+
}
180189
}
181190

182191
/**

0 commit comments

Comments
 (0)