Skip to content

Commit

Permalink
Change unexpected read from exception to warn
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunjeet committed Jun 22, 2023
1 parent 8770271 commit ab45e0d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void applyDeltaOnlyPlan(HollowUpdatePlan updatePlan, HollowConsumer.Refr
private void applyDeltaTransition(HollowConsumer.Blob blob, boolean isSnapshotPlan, HollowConsumer.RefreshListener[] refreshListeners) throws Throwable {
LOG.info("Attempting delta transition ...");
if (!memoryMode.equals(MemoryMode.ON_HEAP)) {
LOG.info("SNAP: Attempting delta transition in shared-memory mode ...");
LOG.info(String.format("SNAP: Attempting delta transition to %s in shared-memory mode ...", blob.getToVersion()));
}

try (HollowBlobInput in = HollowBlobInput.modeBasedSelector(memoryMode, blob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public void destroy() throws IOException {

@Override
public byte get(long index) {
if (index >= this.size) {
throw new IllegalStateException();
if (index >= this.size) { // SNAP: TODO: realized in transformer
if (index >= this.size + Long.BYTES) {
LOG.warning(String.format("SNAP: unexpected get from EncodedByteBuffer: index=%s, size=%s", index, size));
}
}

byte retVal = this.bufferView.getByte(this.bufferView.position() + index);
return retVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,28 @@ public byte getByte(long index) throws BufferUnderflowException {

// advances pos in backing buf
public int getBytes(long index, long len, byte[] bytes, boolean restorePos) {
if (index < capacity) {
int spineIndex = (int)(index >>> (shift));
ByteBuffer buf = spine[spineIndex];
int indexIntoBuf = (int)(index & mask);
int toCopy = (int) Math.min(len, buf.capacity() - indexIntoBuf);
int savePos = buf.position();
try {
buf.position(indexIntoBuf);
buf.get(bytes, 0, toCopy);
if (restorePos) {
buf.position(savePos);
}
} catch (BufferUnderflowException e) {
throw e;
}
return toCopy;
} else {
assert(index < capacity + Long.BYTES);
if (index >= capacity) {
// this situation occurs when read for bits near the end of the buffer requires reading a long value that
// extends past the buffer capacity by upto Long.BYTES bytes. To handle this case,
// return 0 for (index >= capacity - Long.BYTES && index < capacity )
// these zero bytes will be discarded anyway when the returned long value is shifted to get the queried bits
throw new UnsupportedOperationException(String.format("Unexpected read past the end, index=%s, capacity=%s", index, capacity));
LOG.warning(String.format("Unexpected read past the end, index=%s, capacity=%s", index, capacity));
}
int spineIndex = (int)(index >>> (shift));
ByteBuffer buf = spine[spineIndex];
int indexIntoBuf = (int)(index & mask);
int toCopy = (int) Math.min(len, buf.capacity() - indexIntoBuf);
int savePos = buf.position();
try {
buf.position(indexIntoBuf);
buf.get(bytes, 0, toCopy);
if (restorePos) {
buf.position(savePos);
}
} catch (BufferUnderflowException e) {
throw e;
}
return toCopy;
}

public int putBytes(long index, long len, byte[] bytes, boolean restorePos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ private void readUsingVariableLengthDataModes(File testFile, int padding) throws
assertEquals(testByteArray.get(13 + padding), testByteBuffer.get(13 + padding));
assertEquals(testByteArray.get(127 + padding), testByteBuffer.get(127 + padding));

// out of bounds read
try {
testByteBuffer.get(testFile.length());
Assert.fail();
} catch (IllegalStateException e) {
// this is expected
} catch (Exception e) {
Assert.fail();
}
// SNAP: TODO: // out of bounds read
// try {
// testByteBuffer.get(testFile.length());
// Assert.fail();
// } catch (IllegalStateException e) {
// // this is expected
// } catch (Exception e) {
// Assert.fail();
// }
}

// write a File of TEST_SINGLE_BUFFER_CAPACITY_BYTES*4 size, assuming TEST_SINGLE_BUFFER_CAPACITY_BYTES is 32
Expand Down

0 comments on commit ab45e0d

Please sign in to comment.