java.io.Closeable, java.lang.AutoCloseable, java.lang.Comparable<BaseTranslogReader>public class TranslogWriter extends BaseTranslogReader implements java.io.Closeable
| Modifier and Type | Field | Description |
|---|---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
closed |
channel, generation, header, path| Modifier and Type | Method | Description |
|---|---|---|
Translog.Location |
add(BytesReference data,
long seqNo) |
Add the given bytes to the translog with the specified sequence number; returns the location the bytes were written to.
|
void |
close() |
|
TranslogReader |
closeIntoReader() |
Closes this writer and transfers its underlying file channel to a new immutable
TranslogReader |
static TranslogWriter |
create(ShardId shardId,
java.lang.String translogUUID,
long fileGeneration,
java.nio.file.Path file,
ChannelFactory channelFactory,
ByteSizeValue bufferSize,
long initialMinTranslogGen,
long initialGlobalCheckpoint,
java.util.function.LongSupplier globalCheckpointSupplier,
java.util.function.LongSupplier minTranslogGenerationSupplier,
long primaryTerm) |
|
protected void |
ensureOpen() |
|
java.lang.Exception |
getTragicException() |
If this
TranslogWriter was closed as a side-effect of a tragic exception,
e.g. |
protected boolean |
isClosed() |
|
org.elasticsearch.index.translog.TranslogSnapshot |
newSnapshot() |
|
protected void |
readBytes(java.nio.ByteBuffer targetBuffer,
long position) |
reads bytes at position into the given buffer, filling it.
|
long |
sizeInBytes() |
|
void |
sync() |
write all buffered ops to disk and fsync file.
|
boolean |
syncNeeded() |
Returns
true if there are buffered operations that have not been flushed and fsynced to disk or if the latest global
checkpoint has not yet been fsynced |
boolean |
syncUpTo(long offset) |
Syncs the translog up to at least the given offset unless already synced
|
int |
totalOperations() |
checksummedStream, compareTo, getFirstOperationOffset, getGeneration, getLastModifiedTime, getPrimaryTerm, path, read, readSize, toStringpublic static TranslogWriter create(ShardId shardId, java.lang.String translogUUID, long fileGeneration, java.nio.file.Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize, long initialMinTranslogGen, long initialGlobalCheckpoint, java.util.function.LongSupplier globalCheckpointSupplier, java.util.function.LongSupplier minTranslogGenerationSupplier, long primaryTerm) throws java.io.IOException
java.io.IOExceptionpublic java.lang.Exception getTragicException()
TranslogWriter was closed as a side-effect of a tragic exception,
e.g. disk full while flushing a new segment, this returns the root cause exception.
Otherwise (no tragic exception has occurred) it returns null.public Translog.Location add(BytesReference data, long seqNo) throws java.io.IOException
data - the bytes to writeseqNo - the sequence number associated with the operationjava.io.IOException - if writing to the translog resulted in an I/O exceptionpublic void sync()
throws java.io.IOException
java.io.IOExceptionpublic boolean syncNeeded()
true if there are buffered operations that have not been flushed and fsynced to disk or if the latest global
checkpoint has not yet been fsyncedpublic int totalOperations()
totalOperations in class BaseTranslogReaderpublic long sizeInBytes()
sizeInBytes in class BaseTranslogReaderpublic TranslogReader closeIntoReader() throws java.io.IOException
TranslogReaderTranslogReaderjava.io.IOException - if any of the file operations resulted in an I/O exceptionpublic org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()
newSnapshot in class BaseTranslogReaderpublic boolean syncUpTo(long offset)
throws java.io.IOException
true if this call caused an actual sync operationjava.io.IOExceptionprotected void readBytes(java.nio.ByteBuffer targetBuffer,
long position)
throws java.io.IOException
BaseTranslogReaderreadBytes in class BaseTranslogReaderjava.io.IOExceptionprotected final void ensureOpen()
public final void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionprotected final boolean isClosed()