1996fanrui commented on code in PR #29954:
URL: https://github.com/apache/flink/pull/29954#discussion_r4581708804
##########
flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java:
##########
@@ -1894,7 +1894,18 @@ private void tryShutdownTimerService(long timeoutMs,
TimerService timerService)
public void dispatchOperatorEvent(OperatorID operator,
SerializedValue<OperatorEvent> event)
throws FlinkException {
try {
+ // Operator events must be urgent: the coordinator considers an
event delivered once it
+ // is enqueued here, and it may then take a checkpoint that must
include the event's
+ // effect (e.g. AddSplitEvent). Unaligned checkpoint triggers are
urgent mails (see
+ // triggerCheckpointAsync), so a normal mail could be overtaken by
the trigger. Urgent
+ // mails are executed in FIFO order among themselves
(TaskMailboxImpl keeps them in a
+ // dedicated FIFO urgent queue served before the batch; both mails
are put with the
+ // same priority), which preserves the ordering.
+ // This is also safe for an aligned trigger (a normal mail): the
coordinator's gateway
+ // stays closed from its checkpoint until the task's
AcknowledgeCheckpointEvent, which
+ // is sent after the task-side snapshot, so later events can't
overtake the snapshot.
mainMailboxExecutor.execute(
+ MailboxExecutor.MailOptions.urgent(),
Review Comment:
Valid: the gate mail drains whatever barrier is available when it runs, so a
stale one queued before the `AddSplitEvent` can process the next UC barrier
first. But it needs the stale mail to stay pending for a whole checkpoint
interval, so it's much rarer, and it predates FLINK-35051. Suggest a separate
ticket instead of blocking this PR. WDYT @rkhachatryan?
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java:
##########
@@ -1564,6 +1575,134 @@ void
testTaskAvoidHangingAfterSnapshotStateThrownException() throws Exception {
}
}
+ /** Aligned-checkpoint timeout used by the {@code alignedWithTimeout}
checkpoint options. */
+ private static final long ALIGNED_CHECKPOINT_TIMEOUT_MS = 10_000L;
+
+ /** Upper bound of mailbox steps to wait for the checkpoint trigger to
complete. */
+ private static final int MAX_MAILBOX_STEPS = 100;
+
+ static Stream<Named<CheckpointOptions>>
provideCheckpointOptionsForOperatorEventOrdering() {
+ return Stream.of(
+ Named.of(
+ "alignedNoTimeout",
+ CheckpointOptions.alignedNoTimeout(
+ CheckpointType.CHECKPOINT, getDefault())),
+ Named.of(
+ "alignedWithTimeout",
+ CheckpointOptions.alignedWithTimeout(
+ CheckpointType.CHECKPOINT,
+ getDefault(),
+ ALIGNED_CHECKPOINT_TIMEOUT_MS)),
+ Named.of(
+ "unaligned",
+ CheckpointOptions.unaligned(CheckpointType.CHECKPOINT,
getDefault())));
+ }
+
+ /**
+ * Operator events dispatched before a checkpoint trigger must be applied
before the operator is
+ * snapshotted, including the case of an urgent (unaligned) trigger.
Events are urgent mails too
+ * so that they keep FIFO order with the urgent trigger.
+ */
+ @ParameterizedTest
+ @MethodSource("provideCheckpointOptionsForOperatorEventOrdering")
+ void testOperatorEventsAreAppliedBeforeCheckpointTrigger(CheckpointOptions
checkpointOptions)
Review Comment:
+1, this implicit same-priority assumption is easy to break silently.
--
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]