Search in sources :

Example 6 with Segment

use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.

the class DefaultStandbySegmentReader method readSegment.

@Override
public byte[] readSegment(String id) {
    UUID uuid = UUID.fromString(id);
    long msb = uuid.getMostSignificantBits();
    long lsb = uuid.getLeastSignificantBits();
    SegmentId segmentId = store.getSegmentIdProvider().newSegmentId(msb, lsb);
    if (store.containsSegment(segmentId)) {
        Segment segment = store.readSegment(segmentId);
        try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
            segment.writeTo(stream);
            return stream.toByteArray();
        } catch (IOException e) {
            log.warn("Error while reading segment content", e);
            return null;
        }
    }
    return null;
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) UUID(java.util.UUID) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 7 with Segment

use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.

the class AbstractFileStore method writeSegment.

private void writeSegment(UUID id, byte[] data, EntryRecovery w) throws IOException {
    long msb = id.getMostSignificantBits();
    long lsb = id.getLeastSignificantBits();
    ByteBuffer buffer = ByteBuffer.wrap(data);
    GCGeneration generation = SegmentId.isDataSegmentId(lsb) ? Segment.getGcGeneration(newSegmentData(buffer), id) : GCGeneration.NULL;
    w.recoverEntry(msb, lsb, data, 0, data.length, generation);
    if (SegmentId.isDataSegmentId(lsb)) {
        Segment segment = new Segment(tracker, segmentReader, tracker.newSegmentId(msb, lsb), buffer);
        populateTarGraph(segment, w);
        populateTarBinaryReferences(segment, w);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 8 with Segment

use of org.apache.jackrabbit.oak.segment.Segment in project jackrabbit-oak by apache.

the class FileStore method writeSegment.

@Override
public void writeSegment(SegmentId id, byte[] buffer, int offset, int length) throws IOException {
    try (ShutDownCloser ignored = shutDown.keepAlive()) {
        Segment segment = null;
        // If the segment is a data segment, create a new instance of Segment to
        // access some internal information stored in the segment and to store
        // in an in-memory cache for later use.
        GCGeneration generation = GCGeneration.NULL;
        Set<UUID> references = null;
        Set<String> binaryReferences = null;
        if (id.isDataSegmentId()) {
            ByteBuffer data;
            if (offset > 4096) {
                data = ByteBuffer.allocate(length);
                data.put(buffer, offset, length);
                data.rewind();
            } else {
                data = ByteBuffer.wrap(buffer, offset, length);
            }
            segment = new Segment(tracker, segmentReader, id, data);
            generation = segment.getGcGeneration();
            references = readReferences(segment);
            binaryReferences = readBinaryReferences(segment);
        }
        tarFiles.writeSegment(id.asUUID(), buffer, offset, length, generation, references, binaryReferences);
        // Keep this data segment in memory as it's likely to be accessed soon.
        if (segment != null) {
            segmentCache.putSegment(segment);
        }
    }
}
Also used : ShutDownCloser(org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer) Segment(org.apache.jackrabbit.oak.segment.Segment) GCGeneration(org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)

Aggregations

Segment (org.apache.jackrabbit.oak.segment.Segment)8 ByteBuffer (java.nio.ByteBuffer)5 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)4 UUID (java.util.UUID)3 IOException (java.io.IOException)2 GCGeneration (org.apache.jackrabbit.oak.segment.file.tar.GCGeneration)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 RecordUsageAnalyser (org.apache.jackrabbit.oak.segment.RecordUsageAnalyser)1 SegmentIdProvider (org.apache.jackrabbit.oak.segment.SegmentIdProvider)1 SegmentReader (org.apache.jackrabbit.oak.segment.SegmentReader)1 SegmentStore (org.apache.jackrabbit.oak.segment.SegmentStore)1 ShutDownCloser (org.apache.jackrabbit.oak.segment.file.ShutDown.ShutDownCloser)1