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, toStringpublic 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
IOExceptionpublic 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
IOExceptionpublic 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
IOExceptionpublic Translog.Location add(BytesReference data) throws IOException
IOExceptionpublic void updateBufferSize(int bufferSize)
throws TranslogException
TranslogExceptionpublic void sync()
throws IOException
IOExceptionpublic boolean syncNeeded()
public int totalOperations()
totalOperations in class TranslogReaderpublic long sizeInBytes()
sizeInBytes in class TranslogReaderprotected void flush()
throws IOException
IOExceptionpublic TranslogReader newReaderFromWriter()
public ImmutableTranslogReader immutableReader() throws TranslogException
TranslogExceptionpublic boolean syncUpTo(long offset)
throws IOException
true if this call caused an actual sync operationIOExceptionprotected void readBytes(ByteBuffer buffer, long position) throws IOException
TranslogReaderreadBytes in class TranslogReaderIOExceptionprotected void checkpoint(long lastSyncPosition,
int operationCounter,
org.elasticsearch.index.translog.ChannelReference channelReference)
throws IOException
IOExceptionprotected final void ensureOpen()
ensureOpen in class TranslogReaderCopyright © 2009–2017. All rights reserved.