Class SegmentBufferWriter
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.SegmentBufferWriter
-
public class SegmentBufferWriter extends Object
This class encapsulates the state of a segment being written. It provides methods for writing primitive data types and for pre-allocating buffer space in the current segment. Should the current segment not have enough space left the current segment is flushed and a fresh one is allocated.The common usage pattern is:
SegmentBufferWriter writer = ... writer.prepare(...) // allocate buffer writer.writeXYZ(...)The behaviour of this class is undefined should the pre-allocated buffer be overrun be calling any of the write methods.Instances of this class are not thread safe
-
-
Constructor Summary
Constructors Constructor Description SegmentBufferWriter(@NotNull SegmentIdProvider idProvider, @Nullable String wid, @NotNull GCGeneration gcGeneration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull RecordIdexecute(@NotNull GCGeneration gcGeneration, @NotNull org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation writeOperation)voidflush(@NotNull SegmentStore store)Adds a segment header to the buffer and writes a segment to the segment store.@NotNull GCGenerationgetGCGeneration()RecordIdprepare(RecordType type, int size, Collection<RecordId> ids, SegmentStore store)Before writing a record (which are written backwards, from the end of the file to the beginning), this method is called, to ensure there is enough space.voidwriteByte(byte value)voidwriteBytes(byte[] data, int offset, int length)voidwriteInt(int value)voidwriteLong(long value)voidwriteRecordId(RecordId recordId)Write a record ID.voidwriteShort(short value)
-
-
-
Constructor Detail
-
SegmentBufferWriter
public SegmentBufferWriter(@NotNull @NotNull SegmentIdProvider idProvider, @Nullable @Nullable String wid, @NotNull @NotNull GCGeneration gcGeneration)
-
-
Method Detail
-
execute
@NotNull public @NotNull RecordId execute(@NotNull @NotNull GCGeneration gcGeneration, @NotNull @NotNull org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation writeOperation) throws IOException
- Throws:
IOException
-
getGCGeneration
@NotNull public @NotNull GCGeneration getGCGeneration()
-
writeByte
public void writeByte(byte value)
-
writeShort
public void writeShort(short value)
-
writeInt
public void writeInt(int value)
-
writeLong
public void writeLong(long value)
-
writeRecordId
public void writeRecordId(RecordId recordId)
Write a record ID.- Parameters:
recordId- the record ID.
-
writeBytes
public void writeBytes(byte[] data, int offset, int length)
-
flush
public void flush(@NotNull @NotNull SegmentStore store) throws IOExceptionAdds a segment header to the buffer and writes a segment to the segment store. This is done automatically (called from prepare) when there is not enough space for a record. It can also be called explicitly.- Throws:
IOException
-
prepare
public RecordId prepare(RecordType type, int size, Collection<RecordId> ids, SegmentStore store) throws IOException
Before writing a record (which are written backwards, from the end of the file to the beginning), this method is called, to ensure there is enough space. A new segment is also created if there is not enough space in the segment lookup table or elsewhere.This method does not actually write into the segment, just allocates the space (flushing the segment if needed and starting a new one), and sets the write position (records are written from the end to the beginning, but within a record from left to right).
- Parameters:
type- the record type (only used for root records)size- the size of the record, excluding the size used for the record idsids- the record idsstore- theSegmentStoreinstance to write full segments to- Returns:
- a new record id
- Throws:
IOException
-
-