public class FileMergingCheckpointStateOutputStream extends FsCheckpointStreamFactory.FsCheckpointStateOutputStream
CheckpointStateOutputStream
that writes into a segment of a file and returns a SegmentFileStateHandle
upon closing. Multiple FileMergingCheckpointStateOutputStream
objects can reuse the same underlying file, so that the checkpoint files are merged.
Important: This implementation is NOT thread-safe. Multiple data streams multiplexing the same file should NOT write concurrently. Instead, it is expected that only after one data stream is closed, will other data streams reuse and write to the same underlying file.
Modifier and Type | Class and Description |
---|---|
static interface |
FileMergingCheckpointStateOutputStream.FileMergingSnapshotManagerProxy
A proxy of the
FileMergingSnapshotManager that owns this FileMergingCheckpointStateOutputStream , with the interfaces for dealing with physical files. |
Constructor and Description |
---|
FileMergingCheckpointStateOutputStream(int bufferSize,
FileMergingCheckpointStateOutputStream.FileMergingSnapshotManagerProxy fileMergingSnapshotManagerProxy) |
Modifier and Type | Method and Description |
---|---|
void |
close()
This method throws no exception if the close fails, but only logs the error.
|
SegmentFileStateHandle |
closeAndGetHandle()
Closes the stream and gets a state handle that can create an input stream producing the data
written to this stream.
|
void |
flush()
Flush buffers to file if their size is above
FsCheckpointStreamFactory.FsCheckpointStateOutputStream.localStateThreshold . |
void |
flushToFile() |
Path |
getFilePath() |
long |
getPos()
Gets the position of the stream (non-negative), defined as the number of bytes from the
beginning of the file to the current writing position.
|
void |
sync()
Flushes the data all the way to the persistent non-volatile storage (for example disks).
|
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
isClosed
write
public FileMergingCheckpointStateOutputStream(int bufferSize, FileMergingCheckpointStateOutputStream.FileMergingSnapshotManagerProxy fileMergingSnapshotManagerProxy)
public long getPos() throws IOException
FSDataOutputStream
This method must report accurately report the current position of the stream. Various components of the high-availability and recovery logic rely on the accurate
getPos
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
- Thrown if an I/O error occurs while obtaining the position from the
stream implementation.public void write(int b) throws IOException
write
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
public void flush() throws IOException
FsCheckpointStreamFactory.FsCheckpointStateOutputStream
FsCheckpointStreamFactory.FsCheckpointStateOutputStream.localStateThreshold
.flush
in interface Flushable
flush
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
- Thrown if an I/O error occurs while flushing the stream.public void sync() throws IOException
FSDataOutputStream
sync
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
- Thrown if an I/O error occurs@Nullable public SegmentFileStateHandle closeAndGetHandle() throws IOException
CheckpointStateOutputStream
This closing must be called (also when the caller is not interested in the handle) to
successfully close the stream and retain the produced resource. In contrast, the CheckpointStateOutputStream.close()
method removes the target resource when called.
closeAndGetHandle
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
- Thrown, if the stream cannot be closed.public void close()
FsCheckpointStreamFactory.FsCheckpointStateOutputStream.close()
.close
in interface Closeable
close
in interface AutoCloseable
close
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
public void flushToFile() throws IOException
flushToFile
in class FsCheckpointStreamFactory.FsCheckpointStateOutputStream
IOException
@VisibleForTesting @Nullable public Path getFilePath()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.