Search in sources :

Example 6 with SegmentId

use of org.apache.jackrabbit.oak.segment.SegmentId 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 7 with SegmentId

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

the class DebugSegments method debugSegment.

private static void debugSegment(ReadOnlyFileStore store, String segment) {
    Matcher matcher = SEGMENT_REGEX.matcher(segment);
    if (!matcher.matches()) {
        System.err.println("Unknown argument: " + segment);
        return;
    }
    if (matcher.group(1) != null) {
        UUID uuid = UUID.fromString(matcher.group(1));
        SegmentId id = store.getSegmentIdProvider().newSegmentId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
        System.out.println(id.getSegment());
        return;
    }
    RecordId id1 = store.getRevisions().getHead();
    RecordId id2 = null;
    if (matcher.group(2) != null) {
        id1 = fromString(store.getSegmentIdProvider(), matcher.group(3));
        if (matcher.group(4) != null) {
            id2 = fromString(store.getSegmentIdProvider(), matcher.group(5));
        }
    }
    String path = "/";
    if (matcher.group(6) != null) {
        path = matcher.group(6);
    }
    if (id2 == null) {
        NodeState node = store.getReader().readNode(id1);
        System.out.println("/ (" + id1 + ") -> " + node);
        for (String name : PathUtils.elements(path)) {
            node = node.getChildNode(name);
            RecordId nid = null;
            if (node instanceof SegmentNodeState) {
                nid = ((SegmentNodeState) node).getRecordId();
            }
            System.out.println("  " + name + " (" + nid + ") -> " + node);
        }
        return;
    }
    NodeState node1 = store.getReader().readNode(id1);
    NodeState node2 = store.getReader().readNode(id2);
    for (String name : PathUtils.elements(path)) {
        node1 = node1.getChildNode(name);
        node2 = node2.getChildNode(name);
    }
    System.out.println(JsopBuilder.prettyPrint(JsopDiff.diffToJsop(node1, node2)));
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Matcher(java.util.regex.Matcher) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) RecordId(org.apache.jackrabbit.oak.segment.RecordId) RecordId.fromString(org.apache.jackrabbit.oak.segment.RecordId.fromString) UUID(java.util.UUID) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 8 with SegmentId

use of org.apache.jackrabbit.oak.segment.SegmentId 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 9 with SegmentId

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

the class ReadOnlyFileStore method getSegmentIds.

public Iterable<SegmentId> getSegmentIds() {
    List<SegmentId> ids = new ArrayList<>();
    for (UUID id : tarFiles.getSegmentIds()) {
        long msb = id.getMostSignificantBits();
        long lsb = id.getLeastSignificantBits();
        ids.add(tracker.newSegmentId(msb, lsb));
    }
    return ids;
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 10 with SegmentId

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

the class StandbyClientSyncExecution method copySegmentFromPrimary.

private void copySegmentFromPrimary(StandbyClient client, UUID uuid) throws Exception {
    byte[] data = client.getSegment(uuid.toString());
    if (data == null) {
        throw new IllegalStateException("Unable to read segment " + uuid);
    }
    long msb = uuid.getMostSignificantBits();
    long lsb = uuid.getLeastSignificantBits();
    SegmentId segmentId = idProvider.newSegmentId(msb, lsb);
    store.writeSegment(segmentId, data, 0, data.length);
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId)

Aggregations

SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)11 UUID (java.util.UUID)6 Segment (org.apache.jackrabbit.oak.segment.Segment)5 ArrayList (java.util.ArrayList)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 IOException (java.io.IOException)2 RecordId (org.apache.jackrabbit.oak.segment.RecordId)2 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)1 RecordType (org.apache.jackrabbit.oak.segment.RecordType)1 RecordUsageAnalyser (org.apache.jackrabbit.oak.segment.RecordUsageAnalyser)1 SegmentBlob (org.apache.jackrabbit.oak.segment.SegmentBlob)1