masteryhx commented on code in PR #24513:
URL: https://github.com/apache/flink/pull/24513#discussion_r1533335369


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/OperatorStateBackendTest.java:
##########
@@ -418,6 +430,62 @@ void testSnapshotEmpty() throws Exception {
         assertThat(stateHandle).isNull();
     }
 
+    @Test
+    void testFileMergingSnapshotEmpty(@TempDir File tmpFolder) throws 
Exception {

Review Comment:
   Could we also test the registery of the new handle ?
   Or test that the subsumed checkpoint will discard correctly.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/filemerging/DirectoryStreamStateHandle.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.runtime.state.filemerging;
+
+import org.apache.flink.core.fs.FSDataInputStream;
+import org.apache.flink.runtime.state.DirectoryStateHandle;
+import org.apache.flink.runtime.state.PhysicalStateHandleID;
+import org.apache.flink.runtime.state.SharedStateRegistryKey;
+import org.apache.flink.runtime.state.StreamStateHandle;
+import org.apache.flink.util.FileUtils;
+
+import javax.annotation.Nonnull;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Optional;
+
+/** Wrap {@link DirectoryStateHandle} to a {@link StreamStateHandle}. */
+public class DirectoryStreamStateHandle extends DirectoryStateHandle 
implements StreamStateHandle {
+
+    private static final long serialVersionUID = -6453596108675892492L;
+
+    public DirectoryStreamStateHandle(@Nonnull Path directory, long 
directorySize) {
+        super(directory, directorySize);
+    }
+
+    @Override
+    public FSDataInputStream openInputStream() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Optional<byte[]> asBytesIfInMemory() {
+        return Optional.empty();
+    }
+
+    @Override
+    public PhysicalStateHandleID getStreamStateHandleID() {
+        return new PhysicalStateHandleID(getDirectory().toString());
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        DirectoryStreamStateHandle that = (DirectoryStreamStateHandle) o;
+
+        return getDirectory().equals(that.getDirectory());
+    }
+
+    @Override
+    public String toString() {
+        return "DirectoryStreamStateHandle{" + "directory=" + getDirectory() + 
'}';
+    }
+
+    public static DirectoryStreamStateHandle forPathWithSize(@Nonnull Path 
directory) {
+        long size;
+        try {
+            size = FileUtils.getDirectoryFilesSize(directory);
+        } catch (IOException e) {
+            size = 0L;
+        }
+        return new DirectoryStreamStateHandle(directory, size);
+    }
+
+    public static SharedStateRegistryKey createStateRegistryKey(

Review Comment:
   Could this be a member function ?



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/filemerging/SegmentFileStateHandle.java:
##########
@@ -62,19 +77,58 @@ public class SegmentFileStateHandle implements 
StreamStateHandle {
      * @param scope The state's scope, whether it is exclusive or shared.
      */
     public SegmentFileStateHandle(
-            Path filePath, long startPos, long stateSize, 
CheckpointedStateScope scope) {
+            Path directoryPath,
+            Path filePath,
+            long startPos,
+            long stateSize,
+            CheckpointedStateScope scope) {
         this.filePath = filePath;
         this.stateSize = stateSize;
         this.startPos = startPos;
         this.scope = scope;
+        this.directoryStateHandle =
+                DirectoryStreamStateHandle.forPathWithSize(
+                        new File(directoryPath.getPath()).toPath());

Review Comment:
   +1, At least we should not calculate for every SegmentFileStateHandle in the 
same directory.



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