Search in sources :

Example 1 with Segment

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

the class StandbyTestUtils method mockSegment.

public static Segment mockSegment(UUID uuid, byte[] buffer) {
    SegmentStore store = mock(SegmentStore.class);
    SegmentIdProvider idProvider = mock(SegmentIdProvider.class);
    SegmentReader reader = mock(SegmentReader.class);
    long msb = uuid.getMostSignificantBits();
    long lsb = uuid.getLeastSignificantBits();
    SegmentId id = new SegmentId(store, msb, lsb);
    ByteBuffer data = ByteBuffer.wrap(buffer);
    return new Segment(idProvider, reader, id, data);
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) SegmentIdProvider(org.apache.jackrabbit.oak.segment.SegmentIdProvider) ByteBuffer(java.nio.ByteBuffer) SegmentReader(org.apache.jackrabbit.oak.segment.SegmentReader) Segment(org.apache.jackrabbit.oak.segment.Segment) SegmentStore(org.apache.jackrabbit.oak.segment.SegmentStore)

Example 2 with Segment

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

the class DefaultStandbyReferencesReader method readReferences.

@Override
public Iterable<String> readReferences(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);
        List<String> references = newArrayList();
        for (int i = 0; i < segment.getReferencedSegmentIdCount(); i++) {
            references.add(segment.getReferencedSegmentId(i).toString());
        }
        return references;
    }
    return null;
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) UUID(java.util.UUID) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 3 with Segment

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

the class DebugStore method debugFileStore.

private static void debugFileStore(ReadOnlyFileStore store) {
    Map<SegmentId, List<SegmentId>> idmap = Maps.newHashMap();
    int dataCount = 0;
    long dataSize = 0;
    int bulkCount = 0;
    long bulkSize = 0;
    RecordUsageAnalyser analyser = new RecordUsageAnalyser(store.getReader());
    for (SegmentId id : store.getSegmentIds()) {
        if (id.isDataSegmentId()) {
            Segment segment = id.getSegment();
            dataCount++;
            dataSize += segment.size();
            idmap.put(id, getReferencedSegmentIds(store, segment));
            analyseSegment(segment, analyser);
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
            idmap.put(id, Collections.<SegmentId>emptyList());
        }
    }
    System.out.println("Total size:");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
    System.out.println(analyser.toString());
    Set<SegmentId> garbage = newHashSet(idmap.keySet());
    Queue<SegmentId> queue = Queues.newArrayDeque();
    queue.add(store.getRevisions().getHead().getSegmentId());
    while (!queue.isEmpty()) {
        SegmentId id = queue.remove();
        if (garbage.remove(id)) {
            queue.addAll(idmap.get(id));
        }
    }
    dataCount = 0;
    dataSize = 0;
    bulkCount = 0;
    bulkSize = 0;
    for (SegmentId id : garbage) {
        if (id.isDataSegmentId()) {
            dataCount++;
            dataSize += id.getSegment().size();
        } else if (id.isBulkSegmentId()) {
            bulkCount++;
            bulkSize += id.getSegment().size();
        }
    }
    System.out.format("%nAvailable for garbage collection:%n");
    System.out.format("%s in %6d data segments%n", byteCountToDisplaySize(dataSize), dataCount);
    System.out.format("%s in %6d bulk segments%n", byteCountToDisplaySize(bulkSize), bulkCount);
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) RecordUsageAnalyser(org.apache.jackrabbit.oak.segment.RecordUsageAnalyser) ArrayList(java.util.ArrayList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 4 with Segment

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

the class MemoryStore method writeSegment.

@Override
public void writeSegment(SegmentId id, byte[] data, int offset, int length) throws IOException {
    ByteBuffer buffer = ByteBuffer.allocate(length);
    buffer.put(data, offset, length);
    buffer.rewind();
    Segment segment = new Segment(tracker, segmentReader, id, buffer);
    if (segments.putIfAbsent(id, segment) != null) {
        throw new IOException("Segment override: " + id);
    }
}
Also used : IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Segment(org.apache.jackrabbit.oak.segment.Segment)

Example 5 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, TarWriter w) throws IOException {
    long msb = id.getMostSignificantBits();
    long lsb = id.getLeastSignificantBits();
    ByteBuffer buffer = ByteBuffer.wrap(data);
    int generation = Segment.getGcGeneration(buffer, id);
    w.writeEntry(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) Segment(org.apache.jackrabbit.oak.segment.Segment)

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