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 2022/07/19 07:08:45 UTC

[GitHub] [flink] masteryhx opened a new pull request, #20306: [FLINK-28581][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

masteryhx opened a new pull request, #20306:
URL: https://github.com/apache/flink/pull/20306

   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   This pull request makes output stream of StateChangeFsUploader could be closed normally while enbaling compression.
   
   ## Brief change log
   
    - Always call close in StateChangeFsUploader#upload while enabling compression
   
   ## Verifying this change
   
   - Added StateChangeFsUploaderTest#testCompress
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no)
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? no
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #20306: [FLINK-28581][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20306:
URL: https://github.com/apache/flink/pull/20306#issuecomment-1188686281

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "11d60649fee22de40a46d359644fe413267726d4",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "11d60649fee22de40a46d359644fe413267726d4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 11d60649fee22de40a46d359644fe413267726d4 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] rkhachatryan commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
rkhachatryan commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r925596963


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   The logic becomes a bit tricky IMO.
   I think we can simplify it by:
   1. wrapping the stream we want to close 
   2. in wrapper, making sure it is closed at most once
   3. close the wrapper using `try-finally`
   
   And we also get rid of `wrappedStreamClosed`.
   
   Something like this:
   
   ```
   try (FSDataOutputStream fsStream =
       wrapWithCloseOnce(fileSystem.create(path, NO_OVERWRITE))) {
       try (OutputStreamWithPos stream = wrap(fsStream)) {
           ...
       }
   }
   
   ```
   ```
   private static FSDataOutputStream wrapWithCloseOnce(FSDataOutputStream stream) {
       return new FSDataOutputStream() {
           private boolean closed;
   
           @Override
           public void close() throws IOException {
               if (!closed) {
                   closed = true;
                   stream.close();
               }
           }
   
           ...
       };
   }
   ```
   WDYT?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] masteryhx commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
masteryhx commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r930578280


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   I have tried to remove and rerun it, it also cannot work. It's not the reason.
   Actually, I found the the case will always fail whether enabling compression or not.
   What confused me is that the case will always fail only if I warp the stream even if there is no other logic.
   And It just keep running until timeout and don't thrown an exception.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] reswqa commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r925236630


##########
flink-dstl/flink-dstl-dfs/src/test/java/org/apache/flink/changelog/fs/StateChangeFsUploaderTest.java:
##########
@@ -19,18 +19,32 @@
 package org.apache.flink.changelog.fs;
 
 import org.apache.flink.api.common.JobID;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.local.LocalDataOutputStream;
+import org.apache.flink.core.fs.local.LocalFileSystem;
 
+import org.junit.Rule;
 import org.junit.jupiter.api.Test;
+import org.junit.rules.TemporaryFolder;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup;
+import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /** {@link StateChangeFsUploader} test. */
 class StateChangeFsUploaderTest {

Review Comment:
   For assertion, I suggest using AssertJ instead of Junit's, and you can find the reason here: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   and
   https://docs.google.com/document/d/1514Wa_aNB9bJUen4xm5uiuXOooOJTtXqS_Jqk9KJitU/edit#heading=h.dson7yjrbvvx



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] rkhachatryan merged pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
rkhachatryan merged PR #20306:
URL: https://github.com/apache/flink/pull/20306


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] masteryhx commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
masteryhx commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r931875189


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   I think your analysis is right.
   I have modified it and found it works.
   Thanks a lot!



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] masteryhx commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
masteryhx commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r926363765


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   Nice suggestion.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] reswqa commented on a diff in pull request #20306: [FLINK-28581][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r925151253


##########
flink-dstl/flink-dstl-dfs/src/test/java/org/apache/flink/changelog/fs/StateChangeFsUploaderTest.java:
##########
@@ -19,18 +19,32 @@
 package org.apache.flink.changelog.fs;
 
 import org.apache.flink.api.common.JobID;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.local.LocalDataOutputStream;
+import org.apache.flink.core.fs.local.LocalFileSystem;
 
+import org.junit.Rule;
 import org.junit.jupiter.api.Test;
+import org.junit.rules.TemporaryFolder;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup;
+import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /** {@link StateChangeFsUploader} test. */
 class StateChangeFsUploaderTest {

Review Comment:
   @masteryhx Thanks for contribution, would you want to migrate this test class to Junit5 and AssertJ, and rewrite testCompress in that way.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] reswqa commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r925236630


##########
flink-dstl/flink-dstl-dfs/src/test/java/org/apache/flink/changelog/fs/StateChangeFsUploaderTest.java:
##########
@@ -19,18 +19,32 @@
 package org.apache.flink.changelog.fs;
 
 import org.apache.flink.api.common.JobID;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.local.LocalDataOutputStream;
+import org.apache.flink.core.fs.local.LocalFileSystem;
 
+import org.junit.Rule;
 import org.junit.jupiter.api.Test;
+import org.junit.rules.TemporaryFolder;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup;
+import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /** {@link StateChangeFsUploader} test. */
 class StateChangeFsUploaderTest {

Review Comment:
   For assertion, I suggest using AssertJ instead of Junit's, and you can find the reason here: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] rkhachatryan commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
rkhachatryan commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r930864433


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   
   I mean that with [this change](https://github.com/apache/flink/pull/20306#discussion_r930161714), neither wrapping, nor additional flag check (`wrappedStreamClosed`) would be required.
   
   Currently, the composition of streams looks like this:
   1. `OutputStreamWithPos` <-- closed by the inner `try` block
   1. `BufferedOutputStream`
   1. `SnappyFramedOutputStream` or `UncompressedStreamCompressionDecorator`
   1. maybe `NonClosingOutputStreamDecorator` <- doesn't proxy `close()`
   1. `FSDataOutputStream` <-- closed by the outer `try` block
   
   Where (4) `NonClosingOutputStreamDecorator` is conditional in `wrap()`.
   But that condition is unnecessary because `StreamCompressionDecorator` instance is already choosen in (3).
   
   So if `decorateWithCompression` would **always** add `NonClosingOutputStreamDecorator` then it should solve the problem.
   
   WDYT?
   



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] rkhachatryan commented on a diff in pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
rkhachatryan commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r930161714


##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   An alternative could be to remove
   ```
   OutputStream compressed =
           compression ? instance.decorateWithCompression(fsStream) : fsStream;
   ```
   
   Could you check if that causes the build to fail?



##########
flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/StateChangeFsUploader.java:
##########
@@ -168,7 +168,7 @@ private UploadTasksResult upload(Path path, Collection<UploadTask> tasks) throws
                 wrappedStreamClosed = true;
             }
         } finally {
-            if (!wrappedStreamClosed) {
+            if (!wrappedStreamClosed || compression) {
                 fsStream.close();
             }

Review Comment:
   An alternative could be to remove
   ```
   OutputStream compressed =
           compression ? instance.decorateWithCompression(fsStream) : fsStream;
   ```
   
   Could you check if that causes the build to fail?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] masteryhx commented on a diff in pull request #20306: [FLINK-28581][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
masteryhx commented on code in PR #20306:
URL: https://github.com/apache/flink/pull/20306#discussion_r925231850


##########
flink-dstl/flink-dstl-dfs/src/test/java/org/apache/flink/changelog/fs/StateChangeFsUploaderTest.java:
##########
@@ -19,18 +19,32 @@
 package org.apache.flink.changelog.fs;
 
 import org.apache.flink.api.common.JobID;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.local.LocalDataOutputStream;
+import org.apache.flink.core.fs.local.LocalFileSystem;
 
+import org.junit.Rule;
 import org.junit.jupiter.api.Test;
+import org.junit.rules.TemporaryFolder;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups.createUnregisteredTaskManagerJobMetricGroup;
+import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /** {@link StateChangeFsUploader} test. */
 class StateChangeFsUploaderTest {

Review Comment:
   Thanks for the suggestion. Modified.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] rkhachatryan commented on pull request #20306: [FLINK-28602][state/changelog] Close stream of StateChangeFsUploader normally while enabling compression

Posted by GitBox <gi...@apache.org>.
rkhachatryan commented on PR #20306:
URL: https://github.com/apache/flink/pull/20306#issuecomment-1191538555

   Build failure might be related to this change, could you please double check @masteryhx ?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org