-
Notifications
You must be signed in to change notification settings - Fork 608
[flink] Fix batch log scan with empty buckets #4007
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
Changes from all commits
4d8ab14
68bf13e
2aa3799
8595ec2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,7 +178,9 @@ public RecordsWithSplitIds<RecordAndPos> fetch() throws IOException { | |
| return FlinkRecordsWithSplitIds.emptyRecords(); | ||
| } | ||
| ScanRecords scanRecords = logScanner.poll(POLL_TIMEOUT); | ||
| return forLogRecords(scanRecords); | ||
| FlinkRecordsWithSplitIds records = forLogRecords(scanRecords); | ||
| removeFinishedSplits(records.finishedSplits()); | ||
| return records; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -258,7 +260,7 @@ private void subscribeLog(SourceSplitBase split, long startingOffset) { | |
| Optional<Long> stoppingOffsetOpt = logSplit.getStoppingOffset(); | ||
| if (stoppingOffsetOpt.isPresent()) { | ||
| Long stoppingOffset = stoppingOffsetOpt.get(); | ||
| if (startingOffset >= stoppingOffset) { | ||
| if (startingOffset >= stoppingOffset || stoppingOffset == 0) { | ||
| // is empty log splits as no log record can be fetched | ||
| emptyLogSplits.add(split.splitId()); | ||
| isEmptyLogSplit = true; | ||
|
|
@@ -468,6 +470,11 @@ private FlinkRecordsWithSplitIds forLogRecords(ScanRecords scanRecords) { | |
| splitIdByTableBucket.put(scanBucket, splitId); | ||
| tableScanBuckets.add(scanBucket); | ||
| List<ScanRecord> bucketScanRecords = scanRecords.records(scanBucket); | ||
| Long consumedUpToOffset = scanRecords.consumedUpToOffset(scanBucket); | ||
| if (consumedUpToOffset != null && consumedUpToOffset >= stoppingOffset) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can unsubscribe each finished
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I kept the unsubscribe logic in |
||
| stoppingOffsets.put(scanBucket, stoppingOffset); | ||
| finishedSplits.add(splitId); | ||
| } | ||
| if (!bucketScanRecords.isEmpty()) { | ||
| final ScanRecord lastRecord = bucketScanRecords.get(bucketScanRecords.size() - 1); | ||
| // We keep the maximum message timestamp in the fetch for calculating lags | ||
|
|
@@ -514,6 +521,28 @@ public String next() { | |
| return recordsWithSplitIds; | ||
| } | ||
|
|
||
| /** | ||
| * Retire log buckets after building the corresponding finished result. | ||
| * | ||
| * @param finishedSplitIds split IDs that were reported as finished | ||
| */ | ||
| private void removeFinishedSplits(Set<String> finishedSplitIds) { | ||
| Iterator<Map.Entry<TableBucket, String>> iterator = subscribedBuckets.entrySet().iterator(); | ||
| while (iterator.hasNext()) { | ||
| Map.Entry<TableBucket, String> entry = iterator.next(); | ||
| if (finishedSplitIds.contains(entry.getValue())) { | ||
| TableBucket tableBucket = entry.getKey(); | ||
| if (tableBucket.getPartitionId() == null) { | ||
| logScanner.unsubscribe(tableBucket.getBucket()); | ||
| } else { | ||
| logScanner.unsubscribe(tableBucket.getPartitionId(), tableBucket.getBucket()); | ||
| } | ||
| stoppingOffsets.remove(tableBucket); | ||
| iterator.remove(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private CloseableIterator<RecordAndPos> toRecordAndPos( | ||
| Iterator<ScanRecord> recordAndPosIterator) { | ||
| return new CloseableIterator<RecordAndPos>() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which situation, stoppingOffset == 0?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This covers a newly created table or partition with no data, where the latest offset is
0. SinceEARLIEST_OFFSETis the sentinel value-2,startingOffset >= stoppingOffsetevaluates tofalseeven though there are no records to read. Therefore, we need to handlestoppingOffset == 0explicitly.