[ASTERIXDB-2712][EXT] Fix ByteBuffer limit when read more data
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- When reading more data, ensure the limit is
set to capacity.
- Log RuntimeExceptions in SocketServerInputStream
Change-Id: I7ed572ce90c64b145abef6eb0e4dc0e788f2667e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/5724
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/AsterixInputStreamReader.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/AsterixInputStreamReader.java
index 8e166c0..d35ad26 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/AsterixInputStreamReader.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/AsterixInputStreamReader.java
@@ -68,7 +68,7 @@
}
@Override
- public int read(char cbuf[], int offset, int length) throws IOException {
+ public int read(char[] cbuf, int offset, int length) throws IOException {
if (done) {
return -1;
}
@@ -84,7 +84,9 @@
} else {
// need to read more data
System.arraycopy(bytes, byteBuffer.position(), bytes, 0, byteBuffer.remaining());
+ len = 0; // reset to read more bytes
byteBuffer.position(byteBuffer.remaining());
+ byteBuffer.limit(byteBuffer.capacity()); //set limit to capacity for the new bytes
while (len == 0) {
len = in.read(bytes, byteBuffer.position(), bytes.length - byteBuffer.position());
}
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/SocketServerInputStream.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/SocketServerInputStream.java
index fb9a4a6..0fe81cd 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/SocketServerInputStream.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/input/stream/SocketServerInputStream.java
@@ -137,6 +137,11 @@
@Override
public boolean handleException(Throwable th) {
+ if (th instanceof RuntimeException) {
+ //Log runtime exception
+ //TODO Should we continue anyway?
+ LOGGER.error("Encountered an unexpected error", th);
+ }
try {
return accept();
} catch (IOException e) {