Samrat002 commented on code in PR #28268:
URL: https://github.com/apache/flink/pull/28268#discussion_r3356334359


##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/writer/NativeS3RecoverableWriterRecoveryTest.java:
##########
@@ -0,0 +1,288 @@
+/*
+ * 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.fs.s3native.writer;
+
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.core.fs.RecoverableFsDataOutputStream;
+import org.apache.flink.core.fs.RecoverableWriter;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link NativeS3RecoverableWriter#recover}. */
+class NativeS3RecoverableWriterRecoveryTest {
+
+    private static final String BUCKET = 
InMemoryNativeS3Operations.DEFAULT_BUCKET;
+    private static final String KEY = "out.txt";
+    private static final long MIN_PART_SIZE = 10L;
+
+    @TempDir java.nio.file.Path tmp;
+
+    @Test
+    void persistThenRecoverPreservesTailBytes() throws Exception {
+        InMemoryNativeS3Operations s3 = new InMemoryNativeS3Operations();
+        NativeS3RecoverableWriter writer1 =
+                NativeS3RecoverableWriter.writer(
+                        s3, tmp.toString(), MIN_PART_SIZE, /* maxConcurrent */ 
1);

Review Comment:
    - Flink's RecoverableWriter contract gives a single writer instance 
ownership of a single open stream per file path. There is no concurrent writer 
for the same path.        
    - Each persist() call uploads a fresh side object under 
<key>/.incomplete/<UUID> (unique per call, see 
NativeS3RecoverableFsDataOutputStream). So back-to-back persist()s do not race. 
they produce distinct objects.                                                  
                                                                                
  
    - At any point in time, the number of live side objects for a given path 
equals the number of un-retired checkpoints that carried tail bytes for that 
file. When Flink retires a checkpoint it calls cleanupRecoverableState(), which 
deletes the corresponding side object 
`NativeS3RecoverableWriter#cleanupRecoverableState`.
    - On recovery, only the side object referenced by the restored 
ResumeRecoverable is consulted. Older side objects from earlier checkpoints are 
independent. Flink's retention policy governs their lifetime, not the recover 
path. 
   
   
   So there's no concurrency on the side object itself. It's written once 
during persist(), read at most once during recover(), and deleted once during 
checkpoint retirement.



-- 
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]

Reply via email to