Package org.apache.flink.runtime.state
Class SnapshotDirectory
- java.lang.Object
-
- org.apache.flink.runtime.state.SnapshotDirectory
-
public abstract class SnapshotDirectory extends Object
This class represents a directory that is the target for a state snapshot. This class provides some method that simplify resource management when dealing with such directories, e.g. it can produce aDirectoryStateHandlewhen the snapshot is completed and disposal considers whether or not a snapshot was already completed. For a completed snapshot, the ownership for cleanup is transferred to the created directory state handle. For incomplete snapshots, callingcleanup()will delete the underlying directory resource.
-
-
Field Summary
Fields Modifier and Type Field Description protected PathdirectoryThis path describes the underlying directory for the snapshot.protected AtomicReference<org.apache.flink.runtime.state.SnapshotDirectory.State>stateThis reference tracks the lifecycle state of the snapshot directory.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancleanup()Calling this method will attempt delete the underlying snapshot directory recursively, if the state is "ongoing".abstract DirectoryStateHandlecompleteSnapshotAndGetHandle()Calling this method completes the snapshot for this snapshot directory, if possible, and creates a correspondingDirectoryStateHandlethat points to the snapshot directory.booleanequals(Object o)booleanexists()PathgetDirectory()inthashCode()booleanisSnapshotCompleted()Returnstrueif the snapshot is marked as completed.Path[]listDirectory()List the files in the snapshot directory.booleanmkdirs()static SnapshotDirectorypermanent(Path directory)Creates a permanent snapshot directory for the given path, which will not delete the underlying directory incleanup()aftercompleteSnapshotAndGetHandle()was called.static SnapshotDirectorytemporary(File directory)Creates a local temporary snapshot directory for the given path.StringtoString()
-
-
-
Field Detail
-
directory
@Nonnull protected final Path directory
This path describes the underlying directory for the snapshot.
-
state
@Nonnull protected AtomicReference<org.apache.flink.runtime.state.SnapshotDirectory.State> state
This reference tracks the lifecycle state of the snapshot directory.
-
-
Method Detail
-
getDirectory
@Nonnull public Path getDirectory()
-
mkdirs
public boolean mkdirs() throws IOException- Throws:
IOException
-
exists
public boolean exists() throws IOException- Throws:
IOException
-
listDirectory
public Path[] listDirectory() throws IOException
List the files in the snapshot directory.- Returns:
- the files in the snapshot directory.
- Throws:
IOException- if there is a problem creating the file statuses.
-
cleanup
public boolean cleanup() throws IOExceptionCalling this method will attempt delete the underlying snapshot directory recursively, if the state is "ongoing". In this case, the state will be set to "deleted" as a result of this call.- Returns:
trueif delete is successful,falseotherwise.- Throws:
IOException- if an exception happens during the delete.
-
isSnapshotCompleted
public boolean isSnapshotCompleted()
Returnstrueif the snapshot is marked as completed.
-
completeSnapshotAndGetHandle
@Nullable public abstract DirectoryStateHandle completeSnapshotAndGetHandle() throws IOException
Calling this method completes the snapshot for this snapshot directory, if possible, and creates a correspondingDirectoryStateHandlethat points to the snapshot directory. Calling this method can change the lifecycle state from ONGOING to COMPLETED if the directory should no longer deleted incleanup(). This method can return Can returntrueif the directory is temporary and should therefore not be referenced in a handle.- Returns:
- A directory state handle that points to the snapshot directory. Can return
trueif the directory is temporary and should therefore not be referenced in a handle. - Throws:
IOException- if the state of this snapshot directory object is different from "ongoing".
-
temporary
public static SnapshotDirectory temporary(@Nonnull File directory) throws IOException
Creates a local temporary snapshot directory for the given path. This will always return "null" as result ofcompleteSnapshotAndGetHandle()and always attempt to delete the underlying directory incleanup().- Throws:
IOException
-
permanent
public static SnapshotDirectory permanent(@Nonnull Path directory) throws IOException
Creates a permanent snapshot directory for the given path, which will not delete the underlying directory incleanup()aftercompleteSnapshotAndGetHandle()was called.- Throws:
IOException
-
-