Package org.apache.flink.runtime.state
Class SnapshotDirectory
java.lang.Object
org.apache.flink.runtime.state.SnapshotDirectory
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 a
DirectoryStateHandle 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, calling
cleanup() will delete the underlying directory resource.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PathThis path describes the underlying directory for the snapshot.protected AtomicReference<org.apache.flink.runtime.state.SnapshotDirectory.State>This reference tracks the lifecycle state of the snapshot directory. -
Method Summary
Modifier and TypeMethodDescriptionbooleancleanup()Calling this method will attempt delete the underlying snapshot directory recursively, if the state is "ongoing".abstract DirectoryStateHandleCalling this method completes the snapshot for this snapshot directory, if possible, and creates a correspondingDirectoryStateHandlethat points to the snapshot directory.booleanbooleanexists()inthashCode()booleanReturnstrueif the snapshot is marked as completed.Path[]List the files in the snapshot directory.booleanmkdirs()static SnapshotDirectoryCreates a permanent snapshot directory for the given path, which will not delete the underlying directory incleanup()aftercompleteSnapshotAndGetHandle()was called.static SnapshotDirectoryCreates a local temporary snapshot directory for the given path.toString()
-
Field Details
-
directory
This path describes the underlying directory for the snapshot. -
state
This reference tracks the lifecycle state of the snapshot directory.
-
-
Method Details
-
getDirectory
-
mkdirs
- Throws:
IOException
-
exists
- Throws:
IOException
-
listDirectory
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
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:
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
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".
-
equals
-
hashCode
public int hashCode() -
toString
-
temporary
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
Creates a permanent snapshot directory for the given path, which will not delete the underlying directory incleanup()aftercompleteSnapshotAndGetHandle()was called.- Throws:
IOException
-