You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2022/04/04 12:32:14 UTC
[flink] branch master updated (e031f82528b -> caa296b813b)
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
from e031f82528b [hotfix] Modify spelling error in IOUtils.java
new 74ecbd13cf8 [hotfix][runtime] Adds write method for consistency reasons
new 116f297478f [hotfix] Fixes typo in NonClosingOutputStreamDecorator
new 098dc7eca31 [hotfix] Fixes error in JavaDoc
new c50b0706237 [FLINK-26957][runtime] Removes flush in FileSystemJobResultStore
new caa296b813b [FLINK-26957][runtime] Adds invariant to LocalDataOutputStream to verify that no operation is allowed on a closed stream
The 5 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:
.../flink/core/fs/local/LocalDataOutputStream.java | 23 +++++++++++++
.../flink/core/fs/local/LocalFileSystemTest.java | 40 ++++++++++++++++++++++
.../highavailability/FileSystemJobResultStore.java | 8 +++--
.../state/SnappyStreamCompressionDecorator.java | 4 +--
.../runtime/state/StreamCompressionDecorator.java | 6 ++--
.../UncompressedStreamCompressionDecorator.java | 4 +--
.../flink/runtime/util/ForwardingOutputStream.java | 4 +--
...r.java => NonClosingOutputStreamDecorator.java} | 4 +--
8 files changed, 80 insertions(+), 13 deletions(-)
rename flink-runtime/src/main/java/org/apache/flink/runtime/util/{NonClosingOutpusStreamDecorator.java => NonClosingOutputStreamDecorator.java} (90%)
[flink] 01/05: [hotfix][runtime] Adds write method for consistency reasons
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 74ecbd13cf8aab8a88a26e96858ae8a3e6ba30cc
Author: Matthias Pohl <ma...@ververica.com>
AuthorDate: Fri Apr 1 09:49:27 2022 +0200
[hotfix][runtime] Adds write method for consistency reasons
---
.../java/org/apache/flink/core/fs/local/LocalDataOutputStream.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
index 1503b4bc2c9..14eaf70c159 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
@@ -50,6 +50,11 @@ public class LocalDataOutputStream extends FSDataOutputStream {
fos.write(b);
}
+ @Override
+ public void write(@Nonnull final byte[] b) throws IOException {
+ fos.write(b);
+ }
+
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
fos.write(b, off, len);
[flink] 05/05: [FLINK-26957][runtime] Adds invariant to LocalDataOutputStream to verify that no operation is allowed on a closed stream
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit caa296b813b8a719910f4e1337e011c772a12868
Author: Matthias Pohl <ma...@ververica.com>
AuthorDate: Thu Mar 31 14:14:30 2022 +0200
[FLINK-26957][runtime] Adds invariant to LocalDataOutputStream to verify that no operation is allowed on a closed stream
---
.../flink/core/fs/local/LocalDataOutputStream.java | 18 ++++++++++
.../flink/core/fs/local/LocalFileSystemTest.java | 40 ++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
index 14eaf70c159..a4da43416fd 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/local/LocalDataOutputStream.java
@@ -21,9 +21,12 @@ package org.apache.flink.core.fs.local;
import org.apache.flink.annotation.Internal;
import org.apache.flink.core.fs.FSDataOutputStream;
+import javax.annotation.Nonnull;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
/**
* The <code>LocalDataOutputStream</code> class is a wrapper class for a data output stream to the
@@ -35,6 +38,8 @@ public class LocalDataOutputStream extends FSDataOutputStream {
/** The file output stream used to write data. */
private final FileOutputStream fos;
+ private boolean closed = false;
+
/**
* Constructs a new <code>LocalDataOutputStream</code> object from a given {@link File} object.
*
@@ -47,36 +52,49 @@ public class LocalDataOutputStream extends FSDataOutputStream {
@Override
public void write(final int b) throws IOException {
+ checkOpen();
fos.write(b);
}
@Override
public void write(@Nonnull final byte[] b) throws IOException {
+ checkOpen();
fos.write(b);
}
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
+ checkOpen();
fos.write(b, off, len);
}
@Override
public void close() throws IOException {
+ closed = true;
fos.close();
}
@Override
public void flush() throws IOException {
+ checkOpen();
fos.flush();
}
@Override
public void sync() throws IOException {
+ checkOpen();
fos.getFD().sync();
}
@Override
public long getPos() throws IOException {
+ checkOpen();
return fos.getChannel().position();
}
+
+ private void checkOpen() throws IOException {
+ if (closed) {
+ throw new ClosedChannelException();
+ }
+ }
}
diff --git a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
index f985d5aca46..ca7cd5ce7bb 100644
--- a/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
+++ b/flink-core/src/test/java/org/apache/flink/core/fs/local/LocalFileSystemTest.java
@@ -27,6 +27,7 @@ import org.apache.flink.core.fs.FileSystemKind;
import org.apache.flink.core.fs.Path;
import org.apache.flink.util.ExecutorUtils;
import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.function.ThrowingConsumer;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assume;
@@ -38,6 +39,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -349,6 +351,44 @@ public class LocalFileSystemTest extends TestLogger {
}
}
+ @Test(expected = ClosedChannelException.class)
+ public void testFlushMethodFailsOnClosedOutputStream() throws IOException {
+ testMethodCallFailureOnClosedStream(FSDataOutputStream::flush);
+ }
+
+ @Test(expected = ClosedChannelException.class)
+ public void testWriteIntegerMethodFailsOnClosedOutputStream() throws IOException {
+ testMethodCallFailureOnClosedStream(os -> os.write(0));
+ }
+
+ @Test(expected = ClosedChannelException.class)
+ public void testWriteBytesMethodFailsOnClosedOutputStream() throws IOException {
+ testMethodCallFailureOnClosedStream(os -> os.write(new byte[0]));
+ }
+
+ @Test(expected = ClosedChannelException.class)
+ public void testWriteBytesSubArrayMethodFailsOnClosedOutputStream() throws IOException {
+ testMethodCallFailureOnClosedStream(os -> os.write(new byte[0], 0, 0));
+ }
+
+ @Test(expected = ClosedChannelException.class)
+ public void testGetPosMethodFailsOnClosedOutputStream() throws IOException {
+ testMethodCallFailureOnClosedStream(FSDataOutputStream::getPos);
+ }
+
+ private void testMethodCallFailureOnClosedStream(
+ ThrowingConsumer<FSDataOutputStream, IOException> callback) throws IOException {
+ final FileSystem fs = FileSystem.getLocalFileSystem();
+ final FSDataOutputStream outputStream =
+ fs.create(
+ new Path(
+ temporaryFolder.getRoot().toString(),
+ "close_fs_test_" + UUID.randomUUID()),
+ WriteMode.OVERWRITE);
+ outputStream.close();
+ callback.accept(outputStream);
+ }
+
private Collection<File> createTargetDirectories(
File root, int directoryDepth, int numberDirectories) {
final StringBuilder stringBuilder = new StringBuilder();
[flink] 02/05: [hotfix] Fixes typo in NonClosingOutputStreamDecorator
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 116f297478f2d443178510565b1cd5a2f387e241
Author: Matthias Pohl <ma...@ververica.com>
AuthorDate: Fri Apr 1 18:09:45 2022 +0200
[hotfix] Fixes typo in NonClosingOutputStreamDecorator
---
.../flink/runtime/state/SnappyStreamCompressionDecorator.java | 4 ++--
.../org/apache/flink/runtime/state/StreamCompressionDecorator.java | 6 +++---
.../flink/runtime/state/UncompressedStreamCompressionDecorator.java | 4 ++--
...pusStreamDecorator.java => NonClosingOutputStreamDecorator.java} | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/state/SnappyStreamCompressionDecorator.java b/flink-runtime/src/main/java/org/apache/flink/runtime/state/SnappyStreamCompressionDecorator.java
index 5b024149d1f..ff3318b55cb 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/state/SnappyStreamCompressionDecorator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/state/SnappyStreamCompressionDecorator.java
@@ -20,7 +20,7 @@ package org.apache.flink.runtime.state;
import org.apache.flink.annotation.Internal;
import org.apache.flink.runtime.util.NonClosingInputStreamDecorator;
-import org.apache.flink.runtime.util.NonClosingOutpusStreamDecorator;
+import org.apache.flink.runtime.util.NonClosingOutputStreamDecorator;
import org.xerial.snappy.SnappyFramedInputStream;
import org.xerial.snappy.SnappyFramedOutputStream;
@@ -42,7 +42,7 @@ public class SnappyStreamCompressionDecorator extends StreamCompressionDecorator
private static final double MIN_COMPRESSION_RATIO = 0.85d;
@Override
- protected OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream)
+ protected OutputStream decorateWithCompression(NonClosingOutputStreamDecorator stream)
throws IOException {
return new SnappyFramedOutputStream(stream, COMPRESSION_BLOCK_SIZE, MIN_COMPRESSION_RATIO);
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/state/StreamCompressionDecorator.java b/flink-runtime/src/main/java/org/apache/flink/runtime/state/StreamCompressionDecorator.java
index ad9e52c64e2..e32a51b97bb 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/state/StreamCompressionDecorator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/state/StreamCompressionDecorator.java
@@ -20,7 +20,7 @@ package org.apache.flink.runtime.state;
import org.apache.flink.annotation.Internal;
import org.apache.flink.runtime.util.NonClosingInputStreamDecorator;
-import org.apache.flink.runtime.util.NonClosingOutpusStreamDecorator;
+import org.apache.flink.runtime.util.NonClosingOutputStreamDecorator;
import java.io.IOException;
import java.io.InputStream;
@@ -46,7 +46,7 @@ public abstract class StreamCompressionDecorator implements Serializable {
* @return an output stream that is decorated by the compression scheme.
*/
public final OutputStream decorateWithCompression(OutputStream stream) throws IOException {
- return decorateWithCompression(new NonClosingOutpusStreamDecorator(stream));
+ return decorateWithCompression(new NonClosingOutputStreamDecorator(stream));
}
/**
@@ -64,7 +64,7 @@ public abstract class StreamCompressionDecorator implements Serializable {
* @param stream the stream to decorate
* @return an output stream that is decorated by the compression scheme.
*/
- protected abstract OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream)
+ protected abstract OutputStream decorateWithCompression(NonClosingOutputStreamDecorator stream)
throws IOException;
/**
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/state/UncompressedStreamCompressionDecorator.java b/flink-runtime/src/main/java/org/apache/flink/runtime/state/UncompressedStreamCompressionDecorator.java
index 05ac250ea38..7fa053e069b 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/state/UncompressedStreamCompressionDecorator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/state/UncompressedStreamCompressionDecorator.java
@@ -20,7 +20,7 @@ package org.apache.flink.runtime.state;
import org.apache.flink.annotation.Internal;
import org.apache.flink.runtime.util.NonClosingInputStreamDecorator;
-import org.apache.flink.runtime.util.NonClosingOutpusStreamDecorator;
+import org.apache.flink.runtime.util.NonClosingOutputStreamDecorator;
import java.io.IOException;
import java.io.InputStream;
@@ -36,7 +36,7 @@ public class UncompressedStreamCompressionDecorator extends StreamCompressionDec
private static final long serialVersionUID = 1L;
@Override
- protected OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream)
+ protected OutputStream decorateWithCompression(NonClosingOutputStreamDecorator stream)
throws IOException {
return stream;
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutpusStreamDecorator.java b/flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutputStreamDecorator.java
similarity index 90%
rename from flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutpusStreamDecorator.java
rename to flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutputStreamDecorator.java
index dee7d7d0057..c4057737525 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutpusStreamDecorator.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/util/NonClosingOutputStreamDecorator.java
@@ -25,9 +25,9 @@ import java.io.OutputStream;
/** Decorator for input streams that ignores calls to {@link OutputStream#close()}. */
@Internal
-public class NonClosingOutpusStreamDecorator extends ForwardingOutputStream {
+public class NonClosingOutputStreamDecorator extends ForwardingOutputStream {
- public NonClosingOutpusStreamDecorator(OutputStream delegate) {
+ public NonClosingOutputStreamDecorator(OutputStream delegate) {
super(delegate);
}
[flink] 03/05: [hotfix] Fixes error in JavaDoc
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 098dc7eca315370d2f53be3318461476f0efeac4
Author: Matthias Pohl <ma...@ververica.com>
AuthorDate: Fri Apr 1 18:10:59 2022 +0200
[hotfix] Fixes error in JavaDoc
---
.../java/org/apache/flink/runtime/util/ForwardingOutputStream.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/util/ForwardingOutputStream.java b/flink-runtime/src/main/java/org/apache/flink/runtime/util/ForwardingOutputStream.java
index d2c4b396086..b2bbb7ef756 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/util/ForwardingOutputStream.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/util/ForwardingOutputStream.java
@@ -25,8 +25,8 @@ import java.io.IOException;
import java.io.OutputStream;
/**
- * Output stream, that wraps another input stream and forwards all method calls to the wrapped
- * stream.
+ * {@code OutputStream}, that wraps another {@code OutputStream} and forwards all method calls to
+ * the wrapped stream.
*/
@Internal
public class ForwardingOutputStream extends OutputStream {
[flink] 04/05: [FLINK-26957][runtime] Removes flush in FileSystemJobResultStore
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit c50b0706237114adec195b84202b969a148ccece
Author: Matthias Pohl <ma...@ververica.com>
AuthorDate: Thu Mar 31 13:49:24 2022 +0200
[FLINK-26957][runtime] Removes flush in FileSystemJobResultStore
The writeValue calls close by default internally. Calling flush afterwards
could cause errors. It's also not really necessary. OutputStream.flush does
not guarantee persistence according to its JavaDoc. In contrast, calling
close does guarantee it.
---
.../flink/runtime/highavailability/FileSystemJobResultStore.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/FileSystemJobResultStore.java b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/FileSystemJobResultStore.java
index 5f05180c05c..010ce77e74c 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/FileSystemJobResultStore.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/FileSystemJobResultStore.java
@@ -28,6 +28,7 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.runtime.jobmaster.JobResult;
import org.apache.flink.runtime.rest.messages.json.JobResultDeserializer;
import org.apache.flink.runtime.rest.messages.json.JobResultSerializer;
+import org.apache.flink.runtime.util.NonClosingOutputStreamDecorator;
import org.apache.flink.util.Preconditions;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
@@ -137,8 +138,11 @@ public class FileSystemJobResultStore extends AbstractThreadsafeJobResultStore {
public void createDirtyResultInternal(JobResultEntry jobResultEntry) throws IOException {
final Path path = constructDirtyPath(jobResultEntry.getJobId());
try (OutputStream os = fileSystem.create(path, FileSystem.WriteMode.NO_OVERWRITE)) {
- mapper.writeValue(os, new JsonJobResultEntry(jobResultEntry));
- os.flush();
+ mapper.writeValue(
+ // working around the internally used _writeAndClose method to ensure that close
+ // is only called once
+ new NonClosingOutputStreamDecorator(os),
+ new JsonJobResultEntry(jobResultEntry));
}
}