You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ar...@apache.org on 2021/01/15 12:57:01 UTC
[flink] branch master updated (78b4e60 -> 2790db1)
This is an automated email from the ASF dual-hosted git repository.
arvid pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git.
from 78b4e60 [FLINK-20981][coordination] Allow initializing jobs to be suspended
new 5e4c1fa [FLINK-20309][network] Add NetworkActionsLogger for easier debugging
new 2790db1 [FLINK-20309][tests] Make source split assignment in UnalignedCheckpointITCase stable.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../channel/ChannelStateWriteRequest.java | 2 +
.../channel/RecoveredChannelStateHandler.java | 3 +
.../io/network/logger/NetworkActionsLogger.java | 68 ++++++++++++++++++++++
.../partition/consumer/RemoteInputChannel.java | 2 +
.../partition/consumer/SingleInputGate.java | 3 +
.../checkpointing/UnalignedCheckpointITCase.java | 5 +-
.../checkpointing/UnalignedCheckpointTestBase.java | 15 +++--
7 files changed, 89 insertions(+), 9 deletions(-)
create mode 100644 flink-runtime/src/main/java/org/apache/flink/runtime/io/network/logger/NetworkActionsLogger.java
[flink] 01/02: [FLINK-20309][network] Add NetworkActionsLogger for
easier debugging
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
arvid pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 5e4c1fa63186675431b28b1b7ff09a17a5c0e2c2
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed Jan 13 11:42:39 2021 +0100
[FLINK-20309][network] Add NetworkActionsLogger for easier debugging
---
.../channel/ChannelStateWriteRequest.java | 2 +
.../channel/RecoveredChannelStateHandler.java | 3 +
.../io/network/logger/NetworkActionsLogger.java | 68 ++++++++++++++++++++++
.../partition/consumer/RemoteInputChannel.java | 2 +
.../partition/consumer/SingleInputGate.java | 3 +
5 files changed, 78 insertions(+)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequest.java b/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequest.java
index 17be93b..0d347ab 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequest.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequest.java
@@ -19,6 +19,7 @@ package org.apache.flink.runtime.checkpoint.channel;
import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult;
import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.runtime.io.network.logger.NetworkActionsLogger;
import org.apache.flink.runtime.state.CheckpointStorageLocationReference;
import org.apache.flink.util.CloseableIterator;
import org.apache.flink.util.Preconditions;
@@ -84,6 +85,7 @@ interface ChannelStateWriteRequest {
writer -> {
while (iterator.hasNext()) {
Buffer buffer = iterator.next();
+ NetworkActionsLogger.log(ChannelStateWriteRequest.class, name, buffer);
try {
checkArgument(buffer.isBuffer());
} catch (Exception e) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/RecoveredChannelStateHandler.java b/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/RecoveredChannelStateHandler.java
index 8906c58..f2ccfb6 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/RecoveredChannelStateHandler.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/RecoveredChannelStateHandler.java
@@ -22,6 +22,7 @@ import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
import org.apache.flink.runtime.io.network.buffer.Buffer;
import org.apache.flink.runtime.io.network.buffer.BufferBuilder;
import org.apache.flink.runtime.io.network.buffer.BufferConsumer;
+import org.apache.flink.runtime.io.network.logger.NetworkActionsLogger;
import org.apache.flink.runtime.io.network.partition.CheckpointedResultPartition;
import org.apache.flink.runtime.io.network.partition.CheckpointedResultSubpartition;
import org.apache.flink.runtime.io.network.partition.consumer.InputGate;
@@ -66,6 +67,7 @@ class InputChannelRecoveredStateHandler
@Override
public void recover(InputChannelInfo channelInfo, Buffer buffer) {
if (buffer.readableBytes() > 0) {
+ NetworkActionsLogger.log(getClass(), "recover", buffer);
getChannel(channelInfo).onRecoveredStateBuffer(buffer);
} else {
buffer.recycleBuffer();
@@ -116,6 +118,7 @@ class ResultSubpartitionRecoveredStateHandler
throws IOException {
bufferBuilderAndConsumer.f0.finish();
if (bufferBuilderAndConsumer.f1.isDataAvailable()) {
+ NetworkActionsLogger.log(getClass(), "recover", bufferBuilderAndConsumer.f1);
boolean added =
getSubpartition(subpartitionInfo)
.add(bufferBuilderAndConsumer.f1, Integer.MIN_VALUE);
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/logger/NetworkActionsLogger.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/logger/NetworkActionsLogger.java
new file mode 100644
index 0000000..0aed4d6
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/logger/NetworkActionsLogger.java
@@ -0,0 +1,68 @@
+/*
+ * 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.runtime.io.network.logger;
+
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.runtime.io.network.buffer.BufferConsumer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/** Utility class for logging actions that happened in the network stack for debugging purposes. */
+public class NetworkActionsLogger {
+ private static final Logger LOG = LoggerFactory.getLogger(NetworkActionsLogger.class);
+
+ private static final boolean ENABLED = LOG.isTraceEnabled();
+ private static final boolean INCLUDE_HASH = true;
+
+ public static void log(Class<?> clazz, String action, Buffer buffer) {
+ if (ENABLED) {
+ LOG.trace("{}#{} buffer = [{}]", clazz.getSimpleName(), action, toPrettyString(buffer));
+ }
+ }
+
+ public static void log(Class<?> clazz, String action, BufferConsumer bufferConsumer) {
+ if (ENABLED) {
+ Buffer buffer = null;
+ try (BufferConsumer copiedBufferConsumer = bufferConsumer.copy()) {
+ buffer = copiedBufferConsumer.build();
+ log(clazz, action, buffer);
+ checkState(copiedBufferConsumer.isFinished());
+ } finally {
+ if (buffer != null) {
+ buffer.recycleBuffer();
+ }
+ }
+ }
+ }
+
+ private static String toPrettyString(Buffer buffer) {
+ StringBuilder prettyString = new StringBuilder("size=").append(buffer.getSize());
+ if (INCLUDE_HASH) {
+ byte[] bytes = new byte[buffer.getSize()];
+ buffer.readOnlySlice().asByteBuf().readBytes(bytes);
+ prettyString.append(", hash=").append(Arrays.hashCode(bytes));
+ }
+ return prettyString.toString();
+ }
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
index a9e5ffd..be8afe6 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannel.java
@@ -35,6 +35,7 @@ import org.apache.flink.runtime.io.network.api.serialization.EventSerializer;
import org.apache.flink.runtime.io.network.buffer.Buffer;
import org.apache.flink.runtime.io.network.buffer.Buffer.DataType;
import org.apache.flink.runtime.io.network.buffer.BufferProvider;
+import org.apache.flink.runtime.io.network.logger.NetworkActionsLogger;
import org.apache.flink.runtime.io.network.partition.PartitionNotFoundException;
import org.apache.flink.runtime.io.network.partition.PrioritizedDeque;
import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
@@ -444,6 +445,7 @@ public class RemoteInputChannel extends InputChannel {
final boolean wasEmpty;
boolean firstPriorityEvent = false;
synchronized (receivedBuffers) {
+ NetworkActionsLogger.log(getClass(), "onBuffer", buffer);
// Similar to notifyBufferAvailable(), make sure that we never add a buffer
// after releaseAllResources() released all buffers from receivedBuffers
// (see above for details).
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
index 5cdc368..3181b63 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java
@@ -33,6 +33,7 @@ import org.apache.flink.runtime.io.network.buffer.Buffer;
import org.apache.flink.runtime.io.network.buffer.BufferDecompressor;
import org.apache.flink.runtime.io.network.buffer.BufferPool;
import org.apache.flink.runtime.io.network.buffer.BufferProvider;
+import org.apache.flink.runtime.io.network.logger.NetworkActionsLogger;
import org.apache.flink.runtime.io.network.partition.PartitionProducerStateProvider;
import org.apache.flink.runtime.io.network.partition.PrioritizedDeque;
import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
@@ -652,6 +653,8 @@ public class SingleInputGate extends IndexedInputGate {
checkUnavailability();
continue;
}
+ NetworkActionsLogger.log(
+ getClass(), "waitAndGetNextData", bufferAndAvailabilityOpt.get().buffer());
final BufferAndAvailability bufferAndAvailability = bufferAndAvailabilityOpt.get();
if (bufferAndAvailability.moreAvailable()) {
[flink] 02/02: [FLINK-20309][tests] Make source split assignment in
UnalignedCheckpointITCase stable.
Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
arvid pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 2790db14e7e5fb119f5471c42cd41e547d184f48
Author: Arvid Heise <ar...@ververica.com>
AuthorDate: Thu Jan 14 20:05:05 2021 +0100
[FLINK-20309][tests] Make source split assignment in UnalignedCheckpointITCase stable.
Currently, the assignment is only stable if all splits are assigned at once. For any unexpected failure, the split assignment becomes more dynamic and the previously employed hash map made the assignment non-deterministic. The fix is to always assign a split to the same source instance, such that the base number (nextNumber % increment) is equal to the reader index.
---
.../test/checkpointing/UnalignedCheckpointITCase.java | 5 ++++-
.../test/checkpointing/UnalignedCheckpointTestBase.java | 15 +++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointITCase.java b/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointITCase.java
index b7be1e1..6445750 100644
--- a/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointITCase.java
+++ b/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointITCase.java
@@ -26,6 +26,7 @@ import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.java.typeutils.GenericTypeInfo;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.state.FunctionInitializationContext;
import org.apache.flink.runtime.state.FunctionSnapshotContext;
@@ -505,7 +506,9 @@ public class UnalignedCheckpointITCase extends UnalignedCheckpointTestBase {
public void initializeState(FunctionInitializationContext context) throws Exception {
stateList =
context.getOperatorStateStore()
- .getListState(new ListStateDescriptor<>("state", BitSet.class));
+ .getListState(
+ new ListStateDescriptor<>(
+ "state", new GenericTypeInfo<>(BitSet.class)));
this.seenRecords = getOnlyElement(stateList.get(), new BitSet());
}
}
diff --git a/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointTestBase.java b/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointTestBase.java
index 352a530..9e82110 100644
--- a/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointTestBase.java
+++ b/flink-tests/src/test/java/org/apache/flink/test/checkpointing/UnalignedCheckpointTestBase.java
@@ -73,7 +73,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@@ -325,6 +324,10 @@ public abstract class UnalignedCheckpointTestBase extends TestLogger {
this.numCompletedCheckpoints = numCompletedCheckpoints;
}
+ public int getBaseNumber() {
+ return (int) (nextNumber % increment);
+ }
+
@Override
public String splitId() {
return String.valueOf(increment);
@@ -379,13 +382,9 @@ public abstract class UnalignedCheckpointTestBase extends TestLogger {
public void addReader(int subtaskId) {
if (context.registeredReaders().size() == context.currentParallelism()
&& !state.unassignedSplits.isEmpty()) {
- int numReaders = context.registeredReaders().size();
- Map<Integer, List<LongSplit>> assignment = new HashMap<>();
- for (int i = 0; i < state.unassignedSplits.size(); i++) {
- assignment
- .computeIfAbsent(i % numReaders, t -> new ArrayList<>())
- .add(state.unassignedSplits.get(i));
- }
+ Map<Integer, List<LongSplit>> assignment =
+ state.unassignedSplits.stream()
+ .collect(Collectors.groupingBy(LongSplit::getBaseNumber));
LOG.info("Assigning splits {}", assignment);
context.assignSplits(new SplitsAssignment<>(assignment));
state.unassignedSplits.clear();