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, toString
public 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.IOException
public 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.IOException
public 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 BaseTranslogReader
public long sizeInBytes()
sizeInBytes
in class BaseTranslogReader
public TranslogReader closeIntoReader() throws java.io.IOException
TranslogReader
TranslogReader
java.io.IOException
- if any of the file operations resulted in an I/O exceptionpublic org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()
newSnapshot
in class BaseTranslogReader
public boolean syncUpTo(long offset) throws java.io.IOException
true
if this call caused an actual sync operationjava.io.IOException
protected void readBytes(java.nio.ByteBuffer targetBuffer, long position) throws java.io.IOException
BaseTranslogReader
readBytes
in class BaseTranslogReader
java.io.IOException
protected final void ensureOpen()
public final void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
protected final boolean isClosed()