Class FileStateHandle
- java.lang.Object
-
- org.apache.flink.runtime.state.filesystem.FileStateHandle
-
- All Implemented Interfaces:
Serializable
,StateObject
,StreamStateHandle
- Direct Known Subclasses:
RelativeFileStateHandle
public class FileStateHandle extends Object implements StreamStateHandle
StreamStateHandle
for state that was written to a file stream. The written data is identified by the file path. The state can be read again by callingopenInputStream()
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.StateObject
StateObject.StateObjectLocation, StateObject.StateObjectSizeStatsCollector
-
-
Constructor Summary
Constructors Constructor Description FileStateHandle(Path filePath, long stateSize)
Creates a new file state for the given file path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<byte[]>
asBytesIfInMemory()
void
collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
Collects statistics about state size and location from the state object.void
discardState()
Discard the state by deleting the file that stores the state.boolean
equals(Object o)
Path
getFilePath()
Gets the path where this handle's state is stored.long
getStateSize()
Returns the file size in bytes.PhysicalStateHandleID
getStreamStateHandleID()
int
hashCode()
Optional<Path>
maybeGetPath()
FSDataInputStream
openInputStream()
Returns anFSDataInputStream
that can be used to read back the data that was previously written to the stream.String
toString()
-
-
-
Constructor Detail
-
FileStateHandle
public FileStateHandle(Path filePath, long stateSize)
Creates a new file state for the given file path.- Parameters:
filePath
- The path to the file that stores the state.
-
-
Method Detail
-
maybeGetPath
public Optional<Path> maybeGetPath()
- Specified by:
maybeGetPath
in interfaceStreamStateHandle
- Returns:
- Path to an underlying file represented by this
StreamStateHandle
orOptional.empty()
if there is no such file.
-
getFilePath
public Path getFilePath()
Gets the path where this handle's state is stored.- Returns:
- The path where this handle's state is stored.
-
openInputStream
public FSDataInputStream openInputStream() throws IOException
Description copied from interface:StreamStateHandle
Returns anFSDataInputStream
that can be used to read back the data that was previously written to the stream.- Specified by:
openInputStream
in interfaceStreamStateHandle
- Throws:
IOException
-
asBytesIfInMemory
public Optional<byte[]> asBytesIfInMemory()
- Specified by:
asBytesIfInMemory
in interfaceStreamStateHandle
- Returns:
- Content of this handle as bytes array if it is already in memory.
-
getStreamStateHandleID
public PhysicalStateHandleID getStreamStateHandleID()
- Specified by:
getStreamStateHandleID
in interfaceStreamStateHandle
- Returns:
- a unique identifier of this handle.
-
discardState
public void discardState() throws Exception
Discard the state by deleting the file that stores the state. If the parent directory of the state is empty after deleting the state file, it is also deleted.- Specified by:
discardState
in interfaceStateObject
- Throws:
Exception
- Thrown, if the file deletion (not the directory deletion) fails.
-
getStateSize
public long getStateSize()
Returns the file size in bytes.- Specified by:
getStateSize
in interfaceStateObject
- Returns:
- The file size in bytes.
-
collectSizeStats
public void collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
Description copied from interface:StateObject
Collects statistics about state size and location from the state object.- Specified by:
collectSizeStats
in interfaceStateObject
- Parameters:
collector
- the statistics collector.
-
-