Package org.elasticsearch.index.translog
Class TranslogWriter
java.lang.Object
org.elasticsearch.index.translog.BaseTranslogReader
org.elasticsearch.index.translog.TranslogWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Comparable<BaseTranslogReader>
-
Field Summary
Fields inherited from class org.elasticsearch.index.translog.BaseTranslogReader
channel, generation, header, path
-
Method Summary
Modifier and TypeMethodDescriptionadd(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()
Closes this writer and transfers its underlying file channel to a new immutableTranslogReader
static TranslogWriter
create(ShardId shardId, String translogUUID, long fileGeneration, Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize, long initialMinTranslogGen, long initialGlobalCheckpoint, LongSupplier globalCheckpointSupplier, LongSupplier minTranslogGenerationSupplier, long primaryTerm, TragicExceptionHolder tragedy, LongConsumer persistedSequenceNumberConsumer, BigArrays bigArrays)
protected void
protected boolean
isClosed()
org.elasticsearch.index.translog.TranslogSnapshot
protected void
readBytes(ByteBuffer targetBuffer, long position)
reads bytes at position into the given buffer, filling it.long
void
sync()
write all buffered ops to disk and fsync file.boolean
Returnstrue
if there are buffered operations that have not been flushed and fsynced to disk or if the latest global checkpoint has not yet been fsyncedint
Methods inherited from class org.elasticsearch.index.translog.BaseTranslogReader
checksummedStream, compareTo, getFirstOperationOffset, getGeneration, getLastModifiedTime, getPrimaryTerm, path, read, readSize, toString
-
Field Details
-
closed
-
-
Method Details
-
create
public static TranslogWriter create(ShardId shardId, String translogUUID, long fileGeneration, Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize, long initialMinTranslogGen, long initialGlobalCheckpoint, LongSupplier globalCheckpointSupplier, LongSupplier minTranslogGenerationSupplier, long primaryTerm, TragicExceptionHolder tragedy, LongConsumer persistedSequenceNumberConsumer, BigArrays bigArrays) throws IOException- Throws:
IOException
-
add
Add the given bytes to the translog with the specified sequence number; returns the location the bytes were written to.- Parameters:
data
- the bytes to writeseqNo
- the sequence number associated with the operation- Returns:
- the location the bytes were written to
- Throws:
IOException
- if writing to the translog resulted in an I/O exception
-
sync
write all buffered ops to disk and fsync file. Note: any exception during the sync process will be interpreted as a tragic exception and the writer will be closed before raising the exception.- Throws:
IOException
-
syncNeeded
public boolean syncNeeded()Returnstrue
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 -
totalOperations
public int totalOperations()- Specified by:
totalOperations
in classBaseTranslogReader
-
sizeInBytes
public long sizeInBytes()- Specified by:
sizeInBytes
in classBaseTranslogReader
-
closeIntoReader
Closes this writer and transfers its underlying file channel to a new immutableTranslogReader
- Returns:
- a new
TranslogReader
- Throws:
IOException
- if any of the file operations resulted in an I/O exception
-
newSnapshot
public org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()- Overrides:
newSnapshot
in classBaseTranslogReader
-
readBytes
Description copied from class:BaseTranslogReader
reads bytes at position into the given buffer, filling it.- Specified by:
readBytes
in classBaseTranslogReader
- Throws:
IOException
-
ensureOpen
protected final void ensureOpen() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isClosed
protected final boolean isClosed()
-