Class AbstractRemoteSegmentArchiveWriter
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.remote.AbstractRemoteSegmentArchiveWriter
-
- All Implemented Interfaces:
SegmentArchiveWriter
- Direct Known Subclasses:
AwsSegmentArchiveWriter
,AzureSegmentArchiveWriter
public abstract class AbstractRemoteSegmentArchiveWriter extends Object implements SegmentArchiveWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
created
protected int
entries
protected Map<UUID,RemoteSegmentArchiveEntry>
index
protected IOMonitor
ioMonitor
protected FileStoreMonitor
monitor
protected Optional<SegmentWriteQueue>
queue
protected long
totalLength
protected WriteAccessController
writeAccessController
-
Constructor Summary
Constructors Constructor Description AbstractRemoteSegmentArchiveWriter(IOMonitor ioMonitor, FileStoreMonitor monitor)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
afterQueueClosed()
Hook for executing additional actions after the segment write queue is closed.protected abstract void
afterQueueFlushed()
Hook for executing additional actions after the segment write queue is flushed.void
close()
Close the archive.boolean
containsSegment(long msb, long lsb)
Check if the segment exists.protected abstract Buffer
doReadArchiveEntry(RemoteSegmentArchiveEntry indexEntry)
Reads a segment from remote storage into a buffer.protected abstract void
doWriteArchiveEntry(RemoteSegmentArchiveEntry indexEntry, byte[] data, int offset, int size)
Writes a segment to the remote storage.protected abstract void
doWriteDataFile(byte[] data, String extension)
Writes a data file inside the archive.void
flush()
Flush all the data to the storage.int
getEntryCount()
Get the number of entries currently contained in the archive.long
getLength()
Get the current length of the archive.boolean
isCreated()
Check if the archive has been created (eg.boolean
isRemote()
This method returnstrue
if the storage is accessed via a network protocol, not tight to the traditional storage technology, for example, HTTP.Buffer
readSegment(long msb, long lsb)
Read the segment.void
writeBinaryReferences(@org.jetbrains.annotations.NotNull byte[] data)
Write the binary references data.void
writeDataFile(byte[] data, String extension)
void
writeGraph(@org.jetbrains.annotations.NotNull byte[] data)
Write the graph data.void
writeSegment(long msb, long lsb, @org.jetbrains.annotations.NotNull byte[] data, int offset, int size, int generation, int fullGeneration, boolean compacted)
Write the new segment to the archive.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveWriter
getName
-
-
-
-
Field Detail
-
ioMonitor
protected final IOMonitor ioMonitor
-
monitor
protected final FileStoreMonitor monitor
-
queue
protected final Optional<SegmentWriteQueue> queue
-
index
protected Map<UUID,RemoteSegmentArchiveEntry> index
-
entries
protected int entries
-
totalLength
protected long totalLength
-
created
protected volatile boolean created
-
writeAccessController
protected WriteAccessController writeAccessController
-
-
Constructor Detail
-
AbstractRemoteSegmentArchiveWriter
public AbstractRemoteSegmentArchiveWriter(IOMonitor ioMonitor, FileStoreMonitor monitor)
-
-
Method Detail
-
writeSegment
public void writeSegment(long msb, long lsb, @NotNull @org.jetbrains.annotations.NotNull byte[] data, int offset, int size, int generation, int fullGeneration, boolean compacted) throws IOException
Description copied from interface:SegmentArchiveWriter
Write the new segment to the archive.- Specified by:
writeSegment
in interfaceSegmentArchiveWriter
- Parameters:
msb
- the most significant bits of the identifier of the segmentlsb
- the least significant bits of the identifier of the segmentdata
- the data.offset
- the start offset in the data.size
- the number of bytes to write.generation
- the segment generation, seeSegmentArchiveEntry.getGeneration()
fullGeneration
- the segment full generation, seeSegmentArchiveEntry.getFullGeneration()
compacted
- the segment compaction property, seeSegmentArchiveEntry.isCompacted()
- Throws:
IOException
-
readSegment
public Buffer readSegment(long msb, long lsb) throws IOException
Description copied from interface:SegmentArchiveWriter
Read the segment.- Specified by:
readSegment
in interfaceSegmentArchiveWriter
- Parameters:
msb
- the most significant bits of the identifier of the segmentlsb
- the least significant bits of the identifier of the segment- Returns:
- byte buffer containing the segment data or null if segment doesn't exist
- Throws:
IOException
-
containsSegment
public boolean containsSegment(long msb, long lsb)
Description copied from interface:SegmentArchiveWriter
Check if the segment exists.- Specified by:
containsSegment
in interfaceSegmentArchiveWriter
- Parameters:
msb
- the most significant bits of the identifier of the segmentlsb
- the least significant bits of the identifier of the segment- Returns:
- true if the segment exists
-
writeGraph
public void writeGraph(@NotNull @org.jetbrains.annotations.NotNull byte[] data) throws IOException
Description copied from interface:SegmentArchiveWriter
Write the graph data.- Specified by:
writeGraph
in interfaceSegmentArchiveWriter
- Parameters:
data
- serialized segment graph data- Throws:
IOException
-
writeBinaryReferences
public void writeBinaryReferences(@NotNull @org.jetbrains.annotations.NotNull byte[] data) throws IOException
Description copied from interface:SegmentArchiveWriter
Write the binary references data.- Specified by:
writeBinaryReferences
in interfaceSegmentArchiveWriter
- Parameters:
data
- serialized binary references data- Throws:
IOException
-
writeDataFile
public void writeDataFile(byte[] data, String extension) throws IOException
- Throws:
IOException
-
getLength
public long getLength()
Description copied from interface:SegmentArchiveWriter
Get the current length of the archive.- Specified by:
getLength
in interfaceSegmentArchiveWriter
- Returns:
- length of the archive, in bytes
-
getEntryCount
public int getEntryCount()
Description copied from interface:SegmentArchiveWriter
Get the number of entries currently contained in the archive.- Specified by:
getEntryCount
in interfaceSegmentArchiveWriter
- Returns:
- number of entries
-
close
public void close() throws IOException
Description copied from interface:SegmentArchiveWriter
Close the archive.- Specified by:
close
in interfaceSegmentArchiveWriter
- Throws:
IOException
-
isCreated
public boolean isCreated()
Description copied from interface:SegmentArchiveWriter
Check if the archive has been created (eg. something has been written).- Specified by:
isCreated
in interfaceSegmentArchiveWriter
- Returns:
- true if the archive has been created, false otherwise
-
flush
public void flush() throws IOException
Description copied from interface:SegmentArchiveWriter
Flush all the data to the storage. After returning from this method successfully, all the segments written with theSegmentArchiveWriter.writeSegment(long, long, byte[], int, int, int, int, boolean)
should be actually saved to the storage.- Specified by:
flush
in interfaceSegmentArchiveWriter
- Throws:
IOException
-
isRemote
public boolean isRemote()
Description copied from interface:SegmentArchiveWriter
This method returnstrue
if the storage is accessed via a network protocol, not tight to the traditional storage technology, for example, HTTP. Based on that info, for instance, calling classes can decide to update archive metadata (graph, binary references, index) more frequently, and not only when the archive is being closed. With that multiple Oak processes can access the storage simultaneously, with one process in read-write mode and one or more processes in read-only mode.- Specified by:
isRemote
in interfaceSegmentArchiveWriter
- Returns:
-
doWriteArchiveEntry
protected abstract void doWriteArchiveEntry(RemoteSegmentArchiveEntry indexEntry, byte[] data, int offset, int size) throws IOException
Writes a segment to the remote storage.- Parameters:
indexEntry
- , the archive index entry to writedata
- , the actual bytes in the entryoffset
- , the start offset in the data.size
- , the number of bytes to write.- Throws:
IOException
-
doReadArchiveEntry
protected abstract Buffer doReadArchiveEntry(RemoteSegmentArchiveEntry indexEntry) throws IOException
Reads a segment from remote storage into a buffer.- Parameters:
indexEntry
- , the archive index entry to read- Returns:
- th buffer containing the segment bytes
- Throws:
IOException
-
doWriteDataFile
protected abstract void doWriteDataFile(byte[] data, String extension) throws IOException
Writes a data file inside the archive. This entry is not a segment. Its full name is given by archive name + extension.- Parameters:
data
- , bytes to writeextension
- , the extension of the data file- Throws:
IOException
-
afterQueueClosed
protected abstract void afterQueueClosed() throws IOException
Hook for executing additional actions after the segment write queue is closed.- Throws:
IOException
-
afterQueueFlushed
protected abstract void afterQueueFlushed() throws IOException
Hook for executing additional actions after the segment write queue is flushed.- Throws:
IOException
-
-