wwj6591812 commented on code in PR #4039:
URL: https://github.com/apache/paimon/pull/4039#discussion_r1727394744
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/AppendBypassCoordinateOperator.java:
##########
@@ -57,27 +76,49 @@ public void open() throws Exception {
checkArgument(
getRuntimeContext().getNumberOfParallelSubtasks() == 1,
"Compaction Coordinator parallelism in paimon MUST be one.");
- this.coordinator = new UnawareAppendTableCompactionCoordinator(table,
true, null);
long intervalMs =
table.coreOptions().continuousDiscoveryInterval().toMillis();
- getProcessingTimeService().scheduleWithFixedDelay(this, 0, intervalMs);
+ this.compactTasks = new LinkedBlockingQueue<>();
+ UnawareAppendTableCompactionCoordinator coordinator =
+ new UnawareAppendTableCompactionCoordinator(table, true, null);
+ this.executorService =
+ Executors.newSingleThreadScheduledExecutor(
+ newDaemonThreadFactory("Compaction Coordinator"));
+ this.executorService.scheduleWithFixedDelay(
+ () -> asyncPlan(coordinator), 0, intervalMs,
TimeUnit.MILLISECONDS);
+ this.getProcessingTimeService().scheduleWithFixedDelay(this, 0,
intervalMs);
}
- @Override
- public void onProcessingTime(long time) {
- while (true) {
+ public void asyncPlan(UnawareAppendTableCompactionCoordinator coordinator)
{
+ while (compactTasks.size() < MAX_PENDING_TASKS) {
List<UnawareAppendCompactionTask> tasks = coordinator.run();
- for (UnawareAppendCompactionTask task : tasks) {
- output.collect(new StreamRecord<>(Either.Right(task)));
- }
-
+ compactTasks.addAll(tasks);
if (tasks.isEmpty()) {
break;
}
}
}
+ @Override
+ public void onProcessingTime(long time) {
+ while (mailbox.isIdle()) {
+ for (int i = 0; i < EMIT_PER_BATCH; i++) {
+ UnawareAppendCompactionTask task = compactTasks.poll();
+ if (task == null) {
+ return;
+ }
+ output.collect(new StreamRecord<>(Either.Right(task)));
+ }
+ }
Review Comment:
add a log after for?
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/AppendBypassCoordinateOperator.java:
##########
@@ -57,27 +76,49 @@ public void open() throws Exception {
checkArgument(
getRuntimeContext().getNumberOfParallelSubtasks() == 1,
"Compaction Coordinator parallelism in paimon MUST be one.");
- this.coordinator = new UnawareAppendTableCompactionCoordinator(table,
true, null);
long intervalMs =
table.coreOptions().continuousDiscoveryInterval().toMillis();
- getProcessingTimeService().scheduleWithFixedDelay(this, 0, intervalMs);
+ this.compactTasks = new LinkedBlockingQueue<>();
+ UnawareAppendTableCompactionCoordinator coordinator =
+ new UnawareAppendTableCompactionCoordinator(table, true, null);
+ this.executorService =
+ Executors.newSingleThreadScheduledExecutor(
+ newDaemonThreadFactory("Compaction Coordinator"));
+ this.executorService.scheduleWithFixedDelay(
+ () -> asyncPlan(coordinator), 0, intervalMs,
TimeUnit.MILLISECONDS);
+ this.getProcessingTimeService().scheduleWithFixedDelay(this, 0,
intervalMs);
}
- @Override
- public void onProcessingTime(long time) {
- while (true) {
+ public void asyncPlan(UnawareAppendTableCompactionCoordinator coordinator)
{
+ while (compactTasks.size() < MAX_PENDING_TASKS) {
List<UnawareAppendCompactionTask> tasks = coordinator.run();
- for (UnawareAppendCompactionTask task : tasks) {
- output.collect(new StreamRecord<>(Either.Right(task)));
- }
-
+ compactTasks.addAll(tasks);
Review Comment:
> Why?
Because if tasks.isEmpty(), then there is no need to execute
compactTasks.addAll (tasks);
##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/AppendBypassCoordinateOperator.java:
##########
@@ -57,27 +76,49 @@ public void open() throws Exception {
checkArgument(
getRuntimeContext().getNumberOfParallelSubtasks() == 1,
"Compaction Coordinator parallelism in paimon MUST be one.");
- this.coordinator = new UnawareAppendTableCompactionCoordinator(table,
true, null);
long intervalMs =
table.coreOptions().continuousDiscoveryInterval().toMillis();
- getProcessingTimeService().scheduleWithFixedDelay(this, 0, intervalMs);
+ this.compactTasks = new LinkedBlockingQueue<>();
+ UnawareAppendTableCompactionCoordinator coordinator =
+ new UnawareAppendTableCompactionCoordinator(table, true, null);
+ this.executorService =
+ Executors.newSingleThreadScheduledExecutor(
+ newDaemonThreadFactory("Compaction Coordinator"));
+ this.executorService.scheduleWithFixedDelay(
+ () -> asyncPlan(coordinator), 0, intervalMs,
TimeUnit.MILLISECONDS);
+ this.getProcessingTimeService().scheduleWithFixedDelay(this, 0,
intervalMs);
}
- @Override
- public void onProcessingTime(long time) {
- while (true) {
+ public void asyncPlan(UnawareAppendTableCompactionCoordinator coordinator)
{
+ while (compactTasks.size() < MAX_PENDING_TASKS) {
List<UnawareAppendCompactionTask> tasks = coordinator.run();
- for (UnawareAppendCompactionTask task : tasks) {
- output.collect(new StreamRecord<>(Either.Right(task)));
- }
-
+ compactTasks.addAll(tasks);
if (tasks.isEmpty()) {
break;
}
}
}
+ @Override
+ public void onProcessingTime(long time) {
+ while (mailbox.isIdle()) {
+ for (int i = 0; i < EMIT_PER_BATCH; i++) {
+ UnawareAppendCompactionTask task = compactTasks.poll();
+ if (task == null) {
+ return;
+ }
+ output.collect(new StreamRecord<>(Either.Right(task)));
+ }
+ }
+ }
+
@Override
public void processElement(StreamRecord<CommitT> record) throws Exception {
output.collect(new StreamRecord<>(Either.Left(record.getValue())));
}
+
+ @Override
+ public void close() throws Exception {
+ ExecutorUtils.gracefulShutdown(1, TimeUnit.MINUTES, executorService);
Review Comment:
Should we wait compactTasks to be empty or check it is empty here?
--
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]