Skip to content

Commit

Permalink
JS API should error if it receives a smaller snapshot than expected
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 authored and nbauernfeind committed Jan 9, 2024
1 parent c52a739 commit 100e24b
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageMessageWrapper;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageSnapshotOptions;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageSnapshotRequest;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageSubscriptionRequest;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.BarrageUpdateMetadata;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.barrage.flatbuf.barrage_generated.io.deephaven.barrage.flatbuf.ColumnConversionMode;
import io.deephaven.web.client.api.Callbacks;
Expand All @@ -36,6 +35,7 @@
import io.deephaven.web.client.api.barrage.stream.BiDiStream;
import io.deephaven.web.client.fu.JsLog;
import io.deephaven.web.client.state.ClientTableState;
import io.deephaven.web.shared.data.Range;
import io.deephaven.web.shared.data.TableSnapshot;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsNullable;
Expand All @@ -45,6 +45,7 @@
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Iterator;

import static io.deephaven.web.client.api.barrage.WebBarrageUtils.makeUint8ArrayFromBitset;
import static io.deephaven.web.client.api.barrage.WebBarrageUtils.serializeRanges;
Expand Down Expand Up @@ -320,14 +321,14 @@ public Promise<TableData> snapshot(JsRangeSet rows, Column[] columns) {
new FlightData());

Builder doGetRequest = new Builder(1024);
double columnsOffset = BarrageSubscriptionRequest.createColumnsVector(doGetRequest,
double columnsOffset = BarrageSnapshotRequest.createColumnsVector(doGetRequest,
makeUint8ArrayFromBitset(columnBitset));
double viewportOffset = BarrageSubscriptionRequest.createViewportVector(doGetRequest, serializeRanges(
double viewportOffset = BarrageSnapshotRequest.createViewportVector(doGetRequest, serializeRanges(
Collections.singleton(rows.getRange())));
double serializationOptionsOffset = BarrageSnapshotOptions
.createBarrageSnapshotOptions(doGetRequest, ColumnConversionMode.Stringify, true, 0, 0);
double tableTicketOffset =
BarrageSubscriptionRequest.createTicketVector(doGetRequest, state.getHandle().getTicket());
BarrageSnapshotRequest.createTicketVector(doGetRequest, state.getHandle().getTicket());
BarrageSnapshotRequest.startBarrageSnapshotRequest(doGetRequest);
BarrageSnapshotRequest.addTicket(doGetRequest, tableTicketOffset);
BarrageSnapshotRequest.addColumns(doGetRequest, columnsOffset);
Expand Down Expand Up @@ -365,7 +366,24 @@ public Promise<TableData> snapshot(JsRangeSet rows, Column[] columns) {
WebBarrageUtils.typedArrayToLittleEndianByteBuffer(flightData.getDataBody_asU8()), update,
true,
columnTypes);
callback.onSuccess(snapshot);

// TODO deephaven-core(#188) this check no longer makes sense
Iterator<Range> rangeIterator = rows.getRange().rangeIterator();
long expectedCount = 0;
while (rangeIterator.hasNext()) {
Range range = rangeIterator.next();
if (range.getFirst() >= snapshot.getTableSize()) {
break;
}
long end = Math.min(range.getLast(), snapshot.getTableSize());
expectedCount += end - range.getFirst() + 1;
}
if (expectedCount != snapshot.getIncludedRows().size()) {
callback.onFailure("Server did not send expected number of rows, expected " + expectedCount
+ ", actual " + snapshot.getIncludedRows().size());
} else {
callback.onSuccess(snapshot);
}
});
stream.onStatus(status -> {
if (!status.isOk()) {
Expand Down

0 comments on commit 100e24b

Please sign in to comment.