Class SegmentBufferWriter
java.lang.Object
org.apache.jackrabbit.oak.segment.SegmentBufferWriter
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
ConstructorsConstructorDescriptionSegmentBufferWriter
(@NotNull SegmentIdProvider idProvider, @Nullable String wid, @NotNull GCGeneration gcGeneration) -
Method Summary
Modifier and TypeMethodDescription@NotNull RecordId
execute
(@NotNull GCGeneration gcGeneration, @NotNull org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation writeOperation) void
flush
(@NotNull SegmentStore store) Adds a segment header to the buffer and writes a segment to the segment store.@NotNull GCGeneration
prepare
(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.void
writeByte
(byte value) void
writeBytes
(byte[] data, int offset, int length) void
writeInt
(int value) void
writeLong
(long value) void
writeRecordId
(RecordId recordId) Write a record ID.void
writeShort
(short value)
-
Constructor Details
-
SegmentBufferWriter
public SegmentBufferWriter(@NotNull @NotNull SegmentIdProvider idProvider, @Nullable @Nullable String wid, @NotNull @NotNull GCGeneration gcGeneration)
-
-
Method Details
-
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
-
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
Write a record ID.- Parameters:
recordId
- the record ID.
-
writeBytes
public void writeBytes(byte[] data, int offset, int length) -
flush
Adds 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
- theSegmentStore
instance to write full segments to- Returns:
- a new record id
- Throws:
IOException
-