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
Constructor and Description |
---|
TranslogWriter(org.elasticsearch.index.translog.ChannelFactory channelFactory,
ShardId shardId,
long generation,
java.nio.channels.FileChannel channel,
java.nio.file.Path path,
ByteSizeValue bufferSize) |
Modifier and Type | Method and Description |
---|---|
Translog.Location |
add(BytesReference data)
add the given bytes to the translog and return the location they were written at
|
void |
close() |
TranslogReader |
closeIntoReader()
closes this writer and transfers it's underlying file channel to a new immutable reader
|
static TranslogWriter |
create(ShardId shardId,
java.lang.String translogUUID,
long fileGeneration,
java.nio.file.Path file,
org.elasticsearch.index.translog.ChannelFactory channelFactory,
ByteSizeValue bufferSize) |
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() |
Translog.Snapshot |
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 ops
|
boolean |
syncUpTo(long offset)
Syncs the translog up to at least the given offset unless already synced
|
int |
totalOperations() |
checksummedStream, compareTo, getFirstOperationOffset, getGeneration, path, read, readSize, toString
public 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 TranslogWriter(org.elasticsearch.index.translog.ChannelFactory channelFactory, ShardId shardId, long generation, java.nio.channels.FileChannel channel, java.nio.file.Path path, ByteSizeValue bufferSize) throws java.io.IOException
java.io.IOException
public static TranslogWriter create(ShardId shardId, java.lang.String translogUUID, long fileGeneration, java.nio.file.Path file, org.elasticsearch.index.translog.ChannelFactory channelFactory, ByteSizeValue bufferSize) 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) throws java.io.IOException
java.io.IOException
public void sync() throws java.io.IOException
java.io.IOException
public boolean syncNeeded()
public int totalOperations()
totalOperations
in class BaseTranslogReader
public long sizeInBytes()
sizeInBytes
in class BaseTranslogReader
public TranslogReader closeIntoReader() throws java.io.IOException
java.io.IOException
public Translog.Snapshot 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.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
protected final boolean isClosed()