skdfeitian commented on code in PR #4614:
URL: https://github.com/apache/paimon/pull/4614#discussion_r2057299025
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/BucketUnawareCompactSource.java:
##########
@@ -74,76 +72,66 @@ public BucketUnawareCompactSource(
this.filter = filter;
}
- /**
- * Do not annotate with <code>@override</code> here to maintain
compatibility with Flink 1.18-.
- */
- public void open(OpenContext openContext) throws Exception {
- open(new Configuration());
+ @Override
+ public Boundedness getBoundedness() {
+ return streaming ? Boundedness.CONTINUOUS_UNBOUNDED :
Boundedness.BOUNDED;
}
- /**
- * Do not annotate with <code>@override</code> here to maintain
compatibility with Flink 2.0+.
- */
- public void open(Configuration parameters) throws Exception {
- compactionCoordinator =
- new UnawareAppendTableCompactionCoordinator(table, streaming,
filter);
+ @Override
+ public SourceReader<UnawareAppendCompactionTask, SimpleSourceSplit>
createReader(
+ SourceReaderContext readerContext) throws Exception {
Preconditions.checkArgument(
-
RuntimeContextUtils.getNumberOfParallelSubtasks(getRuntimeContext()) == 1,
+ readerContext.currentParallelism() == 1,
"Compaction Operator parallelism in paimon MUST be one.");
+ return new BucketUnawareCompactSourceReader(table, streaming, filter,
scanInterval);
}
- @Override
- public void run(SourceContext<UnawareAppendCompactionTask> sourceContext)
throws Exception {
- this.ctx = sourceContext;
- while (isRunning) {
- boolean isEmpty;
- synchronized (ctx.getCheckpointLock()) {
- if (!isRunning) {
- return;
- }
- try {
- // do scan and plan action, emit append-only compaction
tasks.
- List<UnawareAppendCompactionTask> tasks =
compactionCoordinator.run();
- isEmpty = tasks.isEmpty();
- tasks.forEach(ctx::collect);
- } catch (EndOfScanException esf) {
- LOG.info("Catching EndOfStreamException, the stream is
finished.");
- return;
- }
- }
+ /** BucketUnawareCompactSourceReader. */
+ public static class BucketUnawareCompactSourceReader
+ extends
AbstractNonCoordinatedSourceReader<UnawareAppendCompactionTask> {
+ private final UnawareAppendTableCompactionCoordinator
compactionCoordinator;
+ private final long scanInterval;
+ private long lastFetchTimeMillis = 0L;
- if (isEmpty) {
- Thread.sleep(scanInterval);
- }
+ public BucketUnawareCompactSourceReader(
+ FileStoreTable table, boolean streaming, Predicate filter,
long scanInterval) {
+ this.scanInterval = scanInterval;
+ compactionCoordinator =
+ new UnawareAppendTableCompactionCoordinator(table,
streaming, filter);
}
- }
- @Override
- public void cancel() {
- if (ctx != null) {
- synchronized (ctx.getCheckpointLock()) {
- isRunning = false;
+ @Override
+ public InputStatus pollNext(ReaderOutput<UnawareAppendCompactionTask>
readerOutput)
+ throws Exception {
+ long sleepTimeMillis = scanInterval - System.currentTimeMillis() +
lastFetchTimeMillis;
+ if (sleepTimeMillis > 0) {
+ Thread.sleep(sleepTimeMillis);
+ }
Review Comment:
Will this modification cause the source to be busy max 100% in the flink UI?
Please help me check this issue :
https://github.com/apache/paimon/issues/5463
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]