Skip to content

Commit

Permalink
Bug hunting
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Sep 25, 2024
1 parent 98ff012 commit 4543777
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.presto.client.StatementStats;
import com.facebook.presto.common.ErrorCode;
import com.facebook.presto.common.Page;
import com.facebook.presto.common.block.Block;
import com.facebook.presto.common.block.BlockEncodingSerde;
import com.facebook.presto.common.transaction.TransactionId;
import com.facebook.presto.common.type.BooleanType;
Expand Down Expand Up @@ -445,6 +446,19 @@ else if (queryManager.getQueryRetryCount(queryId) == 1 && retryQueryWithHistoryB
queryResults.getUpdateCount());
}

private static void validateBlockSizesInPage(Page page)
{
// debugging
for (int channel = 0; channel < page.getChannelCount(); channel++) {
Block block = page.getBlock(channel);
if (block.getPositionCount() != page.getPositionCount()) {
throw new IllegalArgumentException(
format("Wrongly sized block: channel: %d block poition count: %d page position count: %d %s",
channel, block.getPositionCount(), page.getPositionCount(), block.getClass().getCanonicalName()));
}
}
}

private synchronized QueryResults getNextResult(long token, UriInfo uriInfo, String scheme, DataSize targetResultSize, boolean binaryResults)
{
// check if the result for the token have already been created
Expand Down Expand Up @@ -502,6 +516,7 @@ private synchronized QueryResults getNextResult(long token, UriInfo uriInfo, Str
}

Page page = serde.deserialize(serializedPage);
validateBlockSizesInPage(page);
bytes += page.getLogicalSizeInBytes();
rows += page.getPositionCount();
pages.add(new RowIterable(session.toConnectorSession(), types, page));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Iterator;
import java.util.List;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

class RowIterable
Expand All @@ -39,6 +40,8 @@ class RowIterable
this.session = session;
this.types = ImmutableList.copyOf(requireNonNull(types, "types is null"));
this.page = requireNonNull(page, "page is null");

validateBlockSizesInPage(page);
}

@Override
Expand All @@ -60,6 +63,8 @@ private RowIterator(ConnectorSession session, List<Type> types, Page page)
this.session = session;
this.types = types;
this.page = page;

validateBlockSizesInPage(page);
}

@Override
Expand All @@ -74,9 +79,29 @@ protected List<Object> computeNext()
for (int channel = 0; channel < page.getChannelCount(); channel++) {
Type type = types.get(channel);
Block block = page.getBlock(channel);
// Caused by: java.lang.IllegalArgumentException: Invalid position 1 in block with 1 positions
// why does block onlly have one position when we're asking for at least 12?
// It's not an off by one error. It's that there's only one row ID in the block.
// That's why it works with LIMIT 1 and not LIMIT 2
// maybe an issue with compressed dictionary blocks or something like that?
// only some tables/rows use dictionary blocks
// and exception changes from LIMIT 2 to 3
values.add(type.getObjectValue(session.getSqlFunctionProperties(), block, position));
}
return Collections.unmodifiableList(values);
}
}

private static void validateBlockSizesInPage(Page page)
{
// debugging
for (int channel = 0; channel < page.getChannelCount(); channel++) {
Block block = page.getBlock(channel);
if (block.getPositionCount() != page.getPositionCount()) {
throw new IllegalArgumentException(
format("Wrongly sized block: channel: %d block poition count: %d page position count: %d %s",
channel, block.getPositionCount(), page.getPositionCount(), block.getClass().getCanonicalName()));
}
}
}
}

0 comments on commit 4543777

Please sign in to comment.