public class TranslogWriter extends TranslogReader
Modifier and Type | Class and Description |
---|---|
static class |
TranslogWriter.Type |
Modifier and Type | Field and Description |
---|---|
protected long |
lastSyncedOffset |
protected int |
operationCounter |
protected ReleasableLock |
readLock |
protected ShardId |
shardId |
static String |
TRANSLOG_CODEC |
static int |
VERSION |
static int |
VERSION_CHECKPOINTS |
static int |
VERSION_CHECKSUMS |
protected ReleasableLock |
writeLock |
protected long |
writtenOffset |
channel, channelReference, closed, firstOperationOffset, generation, UNKNOWN_OP_COUNT
Constructor and Description |
---|
TranslogWriter(ShardId shardId,
long generation,
org.elasticsearch.index.translog.ChannelReference channelReference) |
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
|
protected void |
checkpoint(long lastSyncPosition,
int operationCounter,
org.elasticsearch.index.translog.ChannelReference channelReference) |
protected void |
closeWithTragicEvent(Throwable throwable) |
static TranslogWriter |
create(TranslogWriter.Type type,
ShardId shardId,
String translogUUID,
long fileGeneration,
Path file,
Callback<org.elasticsearch.index.translog.ChannelReference> onClose,
int bufferSize,
org.elasticsearch.index.translog.TranslogWriter.ChannelFactory channelFactory) |
protected void |
ensureOpen() |
protected void |
flush()
Flushes the buffer if the translog is buffered.
|
Throwable |
getTragicException()
If this
TranslogWriter was closed as a side-effect of a tragic exception,
e.g. |
ImmutableTranslogReader |
immutableReader()
returns a new immutable reader which only exposes the current written operation *
|
TranslogReader |
newReaderFromWriter()
returns a new reader that follows the current writes (most importantly allows making
repeated snapshots that includes new content)
|
protected void |
readBytes(ByteBuffer buffer,
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() |
void |
updateBufferSize(int bufferSize)
change the size of the internal buffer if relevant
|
close, compareTo, getFirstOperationOffset, getGeneration, isClosed, newReaderSnapshot, newSnapshot, open, path, read, read, toString
public static final String TRANSLOG_CODEC
public static final int VERSION_CHECKSUMS
public static final int VERSION_CHECKPOINTS
public static final int VERSION
protected final ShardId shardId
protected final ReleasableLock readLock
protected final ReleasableLock writeLock
protected volatile long lastSyncedOffset
protected volatile int operationCounter
protected volatile long writtenOffset
public TranslogWriter(ShardId shardId, long generation, org.elasticsearch.index.translog.ChannelReference channelReference) throws IOException
IOException
public static TranslogWriter create(TranslogWriter.Type type, ShardId shardId, String translogUUID, long fileGeneration, Path file, Callback<org.elasticsearch.index.translog.ChannelReference> onClose, int bufferSize, org.elasticsearch.index.translog.TranslogWriter.ChannelFactory channelFactory) throws IOException
IOException
public Throwable 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.protected final void closeWithTragicEvent(Throwable throwable) throws IOException
IOException
public Translog.Location add(BytesReference data) throws IOException
IOException
public void updateBufferSize(int bufferSize) throws TranslogException
TranslogException
public void sync() throws IOException
IOException
public boolean syncNeeded()
public int totalOperations()
totalOperations
in class TranslogReader
public long sizeInBytes()
sizeInBytes
in class TranslogReader
protected void flush() throws IOException
IOException
public TranslogReader newReaderFromWriter()
public ImmutableTranslogReader immutableReader() throws TranslogException
TranslogException
public boolean syncUpTo(long offset) throws IOException
true
if this call caused an actual sync operationIOException
protected void readBytes(ByteBuffer buffer, long position) throws IOException
TranslogReader
readBytes
in class TranslogReader
IOException
protected void checkpoint(long lastSyncPosition, int operationCounter, org.elasticsearch.index.translog.ChannelReference channelReference) throws IOException
IOException
protected final void ensureOpen()
ensureOpen
in class TranslogReader
Copyright © 2009–2016. All rights reserved.