Skip to content

draft: fix split overflow #34961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release-2.61.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,9 @@ protected List<BigtableSource> reduceSplits(
long size = 0;
for (BigtableSource source : splits) {
if (counter == numberToCombine
|| !checkRangeAdjacency(previousSourceRanges, source.getRanges())) {
|| !checkRangeAdjacency(previousSourceRanges, source.getRanges())
// Protect against overflows
|| Long.MAX_VALUE - size <= source.getEstimatedSizeBytes(options)) {
reducedSplits.add(
new BigtableSource(
factory,
Expand Down Expand Up @@ -1807,7 +1809,11 @@ private List<BigtableSource> splitRangeBasedOnSamples(
// 2. we want to scan to the end (endKey is empty) or farther (lastEndKey < endKey).
if (!lastEndKey.isEmpty()
&& (range.getEndKey().isEmpty() || lastEndKey.compareTo(range.getEndKey()) < 0)) {
splits.add(this.withSingleRange(ByteKeyRange.of(lastEndKey, range.getEndKey())));
long responseOffset = sampleRowKeys.get(sampleRowKeys.size() - 1).getOffsetBytes();
long sampleSizeBytes = responseOffset - lastOffset;
splits.add(this
.withSingleRange(ByteKeyRange.of(lastEndKey, range.getEndKey()))
.withEstimatedSizeBytes(sampleSizeBytes));
}

List<BigtableSource> ret = splits.build();
Expand Down Expand Up @@ -1904,7 +1910,8 @@ private List<BigtableSource> splitKeyRangeIntoBundleSizedSubranges(
desiredBundleSizeBytes);
if (sampleSizeBytes <= desiredBundleSizeBytes) {
return Collections.singletonList(
this.withSingleRange(ByteKeyRange.of(range.getStartKey(), range.getEndKey())));
this.withSingleRange(ByteKeyRange.of(range.getStartKey(), range.getEndKey()))
.withEstimatedSizeBytes(sampleSizeBytes));
}

checkArgument(
Expand Down Expand Up @@ -2050,8 +2057,12 @@ public final long getSplitPointsConsumed() {
BigtableSource primary;
BigtableSource residual;
try {
primary = source.withSingleRange(ByteKeyRange.of(range.getStartKey(), splitKey));
residual = source.withSingleRange(ByteKeyRange.of(splitKey, range.getEndKey()));
primary = source
.withSingleRange(ByteKeyRange.of(range.getStartKey(), splitKey))
.withEstimatedSizeBytes((long)(source.estimatedSizeBytes * fraction));
residual = source
.withSingleRange(ByteKeyRange.of(splitKey, range.getEndKey()))
.withEstimatedSizeBytes((long)(source.estimatedSizeBytes * (1 - fraction)));
} catch (RuntimeException e) {
LOG.info(
"{}: Interpolating for fraction {} yielded invalid split key {}.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,35 @@ public void testReadingWithSplits() throws Exception {
assertSourcesEqualReferenceSource(source, splits, null /* options */);
}

@Test
public void testSplitDoesNotOverflow() throws Exception {
final String table = "TEST-SPLIT-OVERFLOW-TABLE";
final int numRows = 300000;
final int numSamples = 300000;
final long bytesPerRow = 15000L;

// Set up test table data and sample row keys for size estimation and splitting.
makeTableData(table, numRows);
service.setupSampleRowKeys(table, numSamples, bytesPerRow);

// Generate source and split it.
BigtableSource source =
new BigtableSource(
factory,
configId,
config,
BigtableReadOptions.builder()
.setTableId(StaticValueProvider.of(table))
.setKeyRanges(ALL_KEY_RANGE)
.build(),
null /*size*/);
List<BigtableSource> splits = source.split(500000000000L, null /* options */);

for(BigtableSource split : splits) {
assertTrue(split.getEstimatedSizeBytes(null) > 0);
}
}

/**
* Regression test for <a href="https://github.com/apache/beam/issues/28793">[Bug]: BigtableSource
* "Desired bundle size 0 bytes must be greater than 0" #28793</a>.
Expand Down
Loading