public class TranslogWriter extends BaseTranslogReader implements java.io.Closeable
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
closed |
static java.lang.String |
TRANSLOG_CODEC |
static int |
VERSION |
static int |
VERSION_CHECKPOINTS |
static int |
VERSION_CHECKSUMS |
channel, firstOperationOffset, generation, path| Modifier and Type | Method and 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,
java.util.function.LongSupplier globalCheckpointSupplier,
long initialMinTranslogGen,
java.util.function.LongSupplier minTranslogGenerationSupplier) |
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, path, read, readSize, toStringpublic static final java.lang.String TRANSLOG_CODEC
public static final int VERSION_CHECKSUMS
public static final int VERSION_CHECKPOINTS
public static final int VERSION
protected final java.util.concurrent.atomic.AtomicBoolean closed
public static TranslogWriter create(ShardId shardId, java.lang.String translogUUID, long fileGeneration, java.nio.file.Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize, java.util.function.LongSupplier globalCheckpointSupplier, long initialMinTranslogGen, java.util.function.LongSupplier minTranslogGenerationSupplier) 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.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionprotected final boolean isClosed()