[Bigtable] Fix Bigtable segment truncation when open end key is startKey + null byte (#39842) - #39843
Conversation
…Key + null byte (apache#39842) When truncateRequest splits an open end-key range where endKey == lastKey + "\0", Bigtable server rejects the next request with INVALID_ARGUMENT (start_key must be less than end_key) because start_key_open is normalized to lastKey + "\0". Skip such exhausted open ranges during segment truncation. Fixes apache#39842
c9c3f55 to
c582a81
Compare
| segment.addRowRanges(newRange.build()); | ||
| } else { | ||
| // Row is split, remove all read rowKeys and split RowSet at last buffered Row | ||
| if (rowRange.getEndKeyCase() == RowRange.EndKeyCase.END_KEY_OPEN |
There was a problem hiding this comment.
I noticed and fixed a similar issue with reconstructing row key ranges before in the reading large rows logic https://screenshot-v2.corp.google.com/7dli6t427bceg. Maybe it's worth using RowSetUtil.erase to handle this here. But this fix in beam looks correct.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39843 +/- ##
=========================================
Coverage 57.09% 57.10%
- Complexity 3639 3654 +15
=========================================
Files 1191 1191
Lines 192556 192587 +31
Branches 3816 3831 +15
=========================================
+ Hits 109946 109980 +34
+ Misses 79042 79035 -7
- Partials 3568 3572 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @Abacn for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #39842
Problem
When reading from Cloud Bigtable using Apache Beam, reads are processed in buffered segments. When a segment hits buffer memory limits or row limits during a read, Beam pauses the stream and calls
truncateRequestto construct a newReadRowsRequestfor the remainder of the key range starting from(start_key_open: lastKey).For key ranges where the open end key is the start key with an appended null byte (e.g.,
[K, K\0), common in single-row scans, prefix scans, or dynamic work rebalancing splits),EndPoint.compareTocompares"K\0"to"K", evaluating toendCmp > 0. BecauseendCmp > 0,truncateRequestdid not skip the range after reading keyK, and generated a request with(start_key_open: K, end_key_open: K\0).Cloud Bigtable server validates
start_key_openasK\0and strictly enforcesstart_key < end_key. BecauseK\0 < K\0is false, Bigtable server rejects the request with:io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Error in field 'row_ranges' : Error in element #0 : start_key must be less than end_key
Solution
In
BigtableServiceImpl.BigtableSegmentReaderImpl.truncateRequest, check ifrowRange.getEndKeyCase() == END_KEY_OPENand skip the range iflastKey + "\0" >= rowRange.getEndKeyOpen().Tests
testReadRangeWithNullByteEndKeyAtByteLimitinBigtableServiceImplTest.javaverifying that ranges with an open null-byte suffix end key are properly recognized as exhausted during truncation without generating invalid requests.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.