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 aDirectoryStateHandle
when 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 Path
directory
This path describes the underlying directory for the snapshot.protected AtomicReference<org.apache.flink.runtime.state.SnapshotDirectory.State>
state
This 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 boolean
cleanup()
Calling this method will attempt delete the underlying snapshot directory recursively, if the state is "ongoing".abstract DirectoryStateHandle
completeSnapshotAndGetHandle()
Calling this method completes the snapshot for this snapshot directory, if possible, and creates a correspondingDirectoryStateHandle
that points to the snapshot directory.boolean
equals(Object o)
boolean
exists()
Path
getDirectory()
int
hashCode()
boolean
isSnapshotCompleted()
Returnstrue
if the snapshot is marked as completed.Path[]
listDirectory()
List the files in the snapshot directory.boolean
mkdirs()
static SnapshotDirectory
permanent(Path directory)
Creates a permanent snapshot directory for the given path, which will not delete the underlying directory incleanup()
aftercompleteSnapshotAndGetHandle()
was called.static SnapshotDirectory
temporary(File directory)
Creates a local temporary snapshot directory for the given path.String
toString()
-
-
-
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 IOException
Calling 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:
true
if delete is successful,false
otherwise.- Throws:
IOException
- if an exception happens during the delete.
-
isSnapshotCompleted
public boolean isSnapshotCompleted()
Returnstrue
if 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 correspondingDirectoryStateHandle
that 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 returntrue
if 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
true
if 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
-
-