You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/03/29 12:54:26 UTC
[GitHub] [flink] AHeise commented on a change in pull request #15313: [FLINK-19682] Actively timeout checkpoint barriers on the inputs
AHeise commented on a change in pull request #15313:
URL: https://github.com/apache/flink/pull/15313#discussion_r603229559
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AlternatingController.java
##########
@@ -22,6 +22,7 @@
import org.apache.flink.runtime.checkpoint.CheckpointException;
import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+import org.apache.flink.util.clock.Clock;
Review comment:
commit message should include component.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AbstractAlignedBarrierHandlerAction.java
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
Review comment:
Again component in commit message is missing.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AbstractAlternatingAlignedBarrierHandlerAction.java
##########
@@ -74,9 +58,10 @@ public final BarrierHandlerAction barrierReceived(
context.triggerGlobalCheckpoint(checkpointBarrier);
state.unblockAllChannels();
return new AlternatingWaitingForFirstBarrier(state.getInputs());
- } else if (context.isTimedOut(checkpointBarrier)
- || checkpointBarrier.getCheckpointOptions().isUnalignedCheckpoint()) {
- return alignmentTimeout(context, checkpointBarrier);
+ } else if (context.isTimedOut(checkpointBarrier)) {
+ state.removeFromBlocked(channelInfo);
Review comment:
Why is it necessary to unblock that single channel?
##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/io/checkpointing/TestBarrierHandlerBuilder.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
+import org.apache.flink.streaming.runtime.tasks.TestSubtaskCheckpointCoordinator;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.SystemClock;
+
+/** A builder for creating instances of {@link SingleCheckpointBarrierHandler} for tests. */
+public class TestBarrierHandlerBuilder {
+ private final AbstractInvokable target;
+ private Clock clock = SystemClock.getInstance();
+
+ private TestBarrierHandlerBuilder(AbstractInvokable target) {
+ this.target = target;
+ }
+
+ public static TestBarrierHandlerBuilder builder(AbstractInvokable target) {
Review comment:
It's quite unusual to see the `builder` factory method on the `Builder` class. For any class A with class ABuilder, I know the two variations:
```
class A {
static ABuilder builder(...) { // or `newBuilder` etc.
}
}
```
and having a public ctor on Builder.
##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/TestCheckpointedInputGateBuilder.java
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.util;
+
+import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter;
+import org.apache.flink.runtime.io.network.buffer.NetworkBufferPool;
+import org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder;
+import org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder;
+import org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel;
+import org.apache.flink.streaming.api.operators.MailboxExecutor;
+import org.apache.flink.streaming.api.operators.SyncMailboxExecutor;
+import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointBarrierHandler;
+import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate;
+import org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor;
+import org.apache.flink.util.function.SupplierWithException;
+
+import java.io.IOException;
+import java.util.function.BiFunction;
+
+/** A builder for creating instances of {@link CheckpointedInputGate} for tests. */
+public class TestCheckpointedInputGateBuilder {
+ private final int numChannels;
+ private final BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler>
+ barrierHandlerFactory;
+
+ private ChannelStateWriter channelStateWriter = new RecordingChannelStateWriter();
+ private SupplierWithException<SingleInputGate, IOException> gateBuilder = this::buildTestGate;
+ private MailboxExecutor mailboxExecutor;
+
+ private TestCheckpointedInputGateBuilder(
+ int numChannels,
+ BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler>
+ barrierHandler) {
+ this.numChannels = numChannels;
+ this.barrierHandlerFactory = barrierHandler;
+
+ this.mailboxExecutor = new SyncMailboxExecutor();
+ }
+
+ public static TestCheckpointedInputGateBuilder builder(
+ int numChannels,
+ BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler>
+ barrierHandlerFactory) {
+ return new TestCheckpointedInputGateBuilder(numChannels, barrierHandlerFactory);
+ }
+
+ /**
+ * Uses {@link RemoteInputChannel RemoteInputChannels} and enables {@link
+ * #withMailboxExecutor()} by default.
+ */
+ public TestCheckpointedInputGateBuilder withRemoteChannels() {
+ this.gateBuilder = this::buildRemoteGate;
+ return withMailboxExecutor();
Review comment:
I wouldn't implicitly enable mailbox executor. Is it completely unusable without executor?
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AlternatingController.java
##########
@@ -35,15 +36,19 @@
public class AlternatingController implements CheckpointBarrierBehaviourController {
private final AlignedController alignedController;
private final UnalignedController unalignedController;
+ private final Clock clock;
Review comment:
👍 awesome change
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AbstractAlignedBarrierHandlerAction.java
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+
+import java.io.IOException;
+
+/** Actions to be taken when processing aligned checkpoints. */
+abstract class AbstractAlignedBarrierHandlerAction implements BarrierHandlerAction {
+
+ private final AlignedCheckpointState state;
Review comment:
I like the idea with state object. We were floating that around before.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AlignedCheckpointState.java
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+import org.apache.flink.runtime.io.network.partition.consumer.CheckpointableInput;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/** A state pojo for {@link AbstractAlignedBarrierHandlerAction}. */
Review comment:
Not a POJO at all (I guess you started at this point).
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AbstractAlignedBarrierHandlerAction.java
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+
+import java.io.IOException;
+
+/** Actions to be taken when processing aligned checkpoints. */
+abstract class AbstractAlignedBarrierHandlerAction implements BarrierHandlerAction {
+
+ private final AlignedCheckpointState state;
+
+ protected AbstractAlignedBarrierHandlerAction(AlignedCheckpointState state) {
+ this.state = state;
+ }
+
+ @Override
+ public final BarrierHandlerAction alignmentTimeout(
+ Context context, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException {
+ throw new IllegalStateException(
+ "Alignment should not be timed out if we are not alternating.");
+ }
+
+ @Override
+ public final BarrierHandlerAction announcementReceived(
+ Context context, InputChannelInfo channelInfo, int sequenceNumber) {
+ return this;
+ }
+
+ @Override
+ public final BarrierHandlerAction barrierReceived(
+ Context context, InputChannelInfo channelInfo, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException {
+ assert !checkpointBarrier.getCheckpointOptions().isUnalignedCheckpoint();
Review comment:
I'd rather go for `checkState`. Barriers are rare enough that we don't need to go for max performance.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AbstractAlternatingAlignedBarrierHandlerAction.java
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+import org.apache.flink.runtime.io.network.partition.consumer.CheckpointableInput;
+
+import java.io.IOException;
+
+/**
+ * Actions to be taken when processing aligned checkpoints and possibly switching to unaligned
+ * checkpoints.
+ */
+abstract class AbstractAlternatingAlignedBarrierHandlerAction implements BarrierHandlerAction {
+
+ private final AlignedCheckpointState state;
+
+ protected AbstractAlternatingAlignedBarrierHandlerAction(AlignedCheckpointState state) {
+ this.state = state;
+ }
+
+ @Override
+ public final BarrierHandlerAction alignmentTimeout(
+ Context context, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException {
+ state.prioritizeAllAnnouncements();
+ CheckpointBarrier unalignedBarrier = checkpointBarrier.asUnaligned();
+ context.triggerTaskCheckpoint(unalignedBarrier);
+ for (CheckpointableInput input : state.getInputs()) {
+ input.checkpointStarted(checkpointBarrier);
+ }
+ context.triggerGlobalCheckpoint(unalignedBarrier);
+ return new CollectingBarriersUnaligned(true, state.getInputs());
+ }
+
+ @Override
+ public final BarrierHandlerAction announcementReceived(
+ Context context, InputChannelInfo channelInfo, int sequenceNumber) {
+ state.addSeenAnnouncement(channelInfo, sequenceNumber);
+ return this;
+ }
+
+ @Override
+ public final BarrierHandlerAction barrierReceived(
+ Context context, InputChannelInfo channelInfo, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException {
+ if (checkpointBarrier.getCheckpointOptions().isUnalignedCheckpoint()) {
+ BarrierHandlerAction unalignedState = alignmentTimeout(context, checkpointBarrier);
+ return unalignedState.barrierReceived(context, channelInfo, checkpointBarrier);
+ }
+
+ state.removeSeenAnnouncement(channelInfo);
+ state.blockChannel(channelInfo);
+ if (context.allBarriersReceived()) {
+ context.triggerGlobalCheckpoint(checkpointBarrier);
+ state.unblockAllChannels();
+ return new AlternatingWaitingForFirstBarrier(state.getInputs());
+ } else if (context.isTimedOut(checkpointBarrier)
+ || checkpointBarrier.getCheckpointOptions().isUnalignedCheckpoint()) {
+ return alignmentTimeout(context, checkpointBarrier);
+ }
+
+ return transitionAfterBarrierReceived(state);
+ }
+
+ protected abstract BarrierHandlerAction transitionAfterBarrierReceived(
Review comment:
It feels a bit odd that you pass state as a parameter here. I guess it's needed to convert to a different action? How about adding some protected methods here like `toAlternating`, `toAligned`, etc. and instead of passing the state just call these methods in `transitionAfterBarrierReceived` implementations.
Btw I'd call this method `convertAfter...`. Transition makes sense in a state machine, which is hardly recognizable here.
##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/TestCheckpointedInputGateBuilder.java
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.util;
+
+import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter;
+import org.apache.flink.runtime.io.network.buffer.NetworkBufferPool;
+import org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder;
+import org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate;
+import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder;
+import org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel;
+import org.apache.flink.streaming.api.operators.MailboxExecutor;
+import org.apache.flink.streaming.api.operators.SyncMailboxExecutor;
+import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointBarrierHandler;
+import org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate;
+import org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor;
+import org.apache.flink.util.function.SupplierWithException;
+
+import java.io.IOException;
+import java.util.function.BiFunction;
+
+/** A builder for creating instances of {@link CheckpointedInputGate} for tests. */
+public class TestCheckpointedInputGateBuilder {
+ private final int numChannels;
+ private final BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler>
+ barrierHandlerFactory;
+
+ private ChannelStateWriter channelStateWriter = new RecordingChannelStateWriter();
+ private SupplierWithException<SingleInputGate, IOException> gateBuilder = this::buildTestGate;
+ private MailboxExecutor mailboxExecutor;
+
+ private TestCheckpointedInputGateBuilder(
+ int numChannels,
+ BiFunction<SingleInputGate, ChannelStateWriter, CheckpointBarrierHandler>
Review comment:
How about passing the `TestBarrierHandlerBuilder` directly? There is no usage that requires the lambda and would make the usage more crisp.
Btw strictly speaking `TestBarrierHandlerBuilder` should be a factory.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/AlignedCheckpointState.java
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+import org.apache.flink.runtime.io.network.partition.consumer.CheckpointableInput;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/** A state pojo for {@link AbstractAlignedBarrierHandlerAction}. */
+final class AlignedCheckpointState {
+ private final Map<InputChannelInfo, Integer> sequenceNumberInAnnouncedChannels =
+ new HashMap<>();
+
+ /**
+ * {@link #blockedChannels} are the ones for which we have already processed {@link
+ * CheckpointBarrier}. {@link #sequenceNumberInAnnouncedChannels} on the other hand, are the
+ * ones that we have processed announcement but not yet a barrier.
+ */
+ private final Set<InputChannelInfo> blockedChannels = new HashSet<>();
+
+ private final CheckpointableInput[] inputs;
+
+ public AlignedCheckpointState(CheckpointableInput[] inputs) {
+ this.inputs = inputs;
+ }
+
+ public void blockChannel(InputChannelInfo channelInfo) {
+ inputs[channelInfo.getGateIdx()].blockConsumption(channelInfo);
+ blockedChannels.add(channelInfo);
+ }
+
+ public void prioritizeAllAnnouncements() throws IOException {
+ for (Map.Entry<InputChannelInfo, Integer> announcedNumberInChannel :
+ sequenceNumberInAnnouncedChannels.entrySet()) {
+ InputChannelInfo channelInfo = announcedNumberInChannel.getKey();
+ inputs[channelInfo.getGateIdx()].convertToPriorityEvent(
+ channelInfo.getInputChannelIdx(), announcedNumberInChannel.getValue());
+ }
+ sequenceNumberInAnnouncedChannels.clear();
+ }
+
+ public void unblockAllChannels() throws IOException {
Review comment:
This doesn't sound like a state-ish operation. We should probably not have any access to `CheckpointableInput` for a pure state class. If it's not a state object and you like the cut as is, I'd find a better name for the class like `ChannelController` or so.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/SingleCheckpointBarrierHandler.java
##########
@@ -226,15 +226,19 @@ public void processBarrier(CheckpointBarrier barrier, InputChannelInfo channelIn
currentState = currentState.barrierReceived(context, channelInfo, barrier);
} catch (CheckpointException e) {
abortInternal(barrier.getId(), e);
+ } catch (RuntimeException | IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e);
}
Review comment:
`ExceptionUtil#rethrowIOException`
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/BarrierHandlerAction.java
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+
+import java.io.IOException;
+
+/**
+ * Represents a state in a state machine of processing a checkpoint. There are 4 base states:
+ *
+ * <ul>
+ * <li>Waiting for an aligned barrier
+ * <li>Collecting aligned barriers
+ * <li>Waiting for an unaligned barrier
+ * <li>Collecting unaligned barriers
+ * </ul>
+ *
+ * <p>Additionally depending on the configuration we can switch between aligned and unaligned
+ * actions.
+ */
+interface BarrierHandlerAction {
Review comment:
If you really want to do the state machine route (which is probably a good idea), how about actually calling it `BarrierHandlerState`. I had a hard time initially to recognize the state machine.
I'd name the internal state then `ChannelState`.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/WaitingForFirstBarrierUnaligned.java
##########
@@ -63,14 +63,18 @@ public BarrierHandlerAction barrierReceived(
CheckpointBarrier unalignedBarrier = checkpointBarrier.asUnaligned();
context.triggerTaskCheckpoint(unalignedBarrier);
for (CheckpointableInput input : inputs) {
- input.checkpointStarted(checkpointBarrier);
+ input.checkpointStarted(unalignedBarrier);
}
context.triggerGlobalCheckpoint(unalignedBarrier);
if (context.allBarriersReceived()) {
for (CheckpointableInput input : inputs) {
- input.checkpointStopped(checkpointBarrier.getId());
+ input.checkpointStopped(unalignedBarrier.getId());
+ }
+ if (alternating) {
+ return new AlternatingWaitingForFirstBarrier(inputs);
+ } else {
+ return this;
Review comment:
When would we not be alternating?
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/BarrierHandlerAction.java
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.io.checkpointing;
+
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.channel.InputChannelInfo;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+
+import java.io.IOException;
+
+/**
+ * Represents a state in a state machine of processing a checkpoint. There are 4 base states:
+ *
+ * <ul>
+ * <li>Waiting for an aligned barrier
+ * <li>Collecting aligned barriers
+ * <li>Waiting for an unaligned barrier
+ * <li>Collecting unaligned barriers
+ * </ul>
+ *
+ * <p>Additionally depending on the configuration we can switch between aligned and unaligned
+ * actions.
+ */
+interface BarrierHandlerAction {
+ BarrierHandlerAction alignmentTimeout(Context context, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException;
+
+ BarrierHandlerAction announcementReceived(
+ Context context, InputChannelInfo channelInfo, int sequenceNumber) throws IOException;
+
+ BarrierHandlerAction barrierReceived(
+ Context context, InputChannelInfo channelInfo, CheckpointBarrier checkpointBarrier)
+ throws IOException, CheckpointException;
+
+ BarrierHandlerAction abort(long cancelledId) throws IOException;
+
+ /**
+ * An entry point for communication between {@link BarrierHandlerAction} and {@link
+ * SingleCheckpointBarrierHandler}.
+ */
+ interface Context {
Review comment:
`Controller` to keep in sync with Mailbox?
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/InputProcessorUtil.java
##########
@@ -147,15 +156,44 @@ public static CheckpointBarrierHandler createCheckpointBarrierHandler(
Arrays.stream(inputs)
.mapToLong(gate -> gate.getChannelInfos().size())
.sum();
- CheckpointBarrierBehaviourController controller =
- config.isUnalignedCheckpointsEnabled()
- ? new AlternatingController(
- new AlignedController(inputs),
- new UnalignedController(checkpointCoordinator, inputs),
- clock)
- : new AlignedController(inputs);
- return new SingleCheckpointBarrierHandler(
- taskName, toNotifyOnCheckpoint, clock, numberOfChannels, controller);
+ if (config.isUnalignedCheckpointsEnabled()) {
+ return SingleCheckpointBarrierHandler.alternating(
+ taskName,
+ toNotifyOnCheckpoint,
+ checkpointCoordinator,
+ clock,
+ numberOfChannels,
+ (callable, delay) -> {
+ ScheduledFuture<?> scheduledFuture =
+ timerService.registerTimer(
+ timerService.getCurrentProcessingTime()
+ + delay.toMillis(),
+ timestamp ->
+ mailboxExecutor.submit(
+ callable,
+ "Execute checkpoint barrier handler delayed action"));
+ return () -> scheduledFuture.cancel(false);
+ },
Review comment:
Extract that.
##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/checkpointing/SingleCheckpointBarrierHandler.java
##########
@@ -126,69 +202,38 @@ public void processBarrier(CheckpointBarrier barrier, InputChannelInfo channelIn
if (currentCheckpointId > barrierId
|| (currentCheckpointId == barrierId && !isCheckpointPending())) {
- controller.obsoleteBarrierReceived(channelInfo, barrier);
return;
}
- checkSubsumedCheckpoint(barrier);
+ checkNewCheckpoint(barrier);
- if (numBarriersReceived == 0) {
+ if (numBarriersReceived++ == 0) {
if (getNumOpenChannels() == 1) {
markAlignmentStartAndEnd(barrier.getTimestamp());
} else {
markAlignmentStart(barrier.getTimestamp());
}
allBarriersReceivedFuture = new CompletableFuture<>();
-
- if (!handleBarrier(barrier, channelInfo, controller::preProcessFirstBarrier)) {
- return;
- }
- }
-
- if (!handleBarrier(barrier, channelInfo, controller::barrierReceived)) {
- return;
}
- if (currentCheckpointId == barrierId) {
Review comment:
Maybe translate it into a checkState then?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org