Search in sources :

Example 1 with SegmentId

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

the class DebugStore method getReferencedSegmentIds.

private static List<SegmentId> getReferencedSegmentIds(ReadOnlyFileStore store, Segment segment) {
    List<SegmentId> result = new ArrayList<>();
    for (int i = 0; i < segment.getReferencedSegmentIdCount(); i++) {
        UUID uuid = segment.getReferencedSegmentId(i);
        long msb = uuid.getMostSignificantBits();
        long lsb = uuid.getLeastSignificantBits();
        result.add(store.getSegmentIdProvider().newSegmentId(msb, lsb));
    }
    return result;
}
Also used : SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) UUID(java.util.UUID)

Example 2 with SegmentId

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

the class DebugTars method filterNodeStates.

private void filterNodeStates(Set<UUID> uuids, List<String> paths, SegmentNodeState state, String path) {
    Set<String> localPaths = newTreeSet();
    for (PropertyState ps : state.getProperties()) {
        if (ps instanceof SegmentPropertyState) {
            SegmentPropertyState sps = (SegmentPropertyState) ps;
            RecordId recordId = sps.getRecordId();
            UUID id = recordId.getSegmentId().asUUID();
            if (uuids.contains(id)) {
                if (ps.getType().tag() == PropertyType.STRING) {
                    String val = "";
                    if (ps.count() > 0) {
                        // only shows the first value, do we need more?
                        val = displayString(ps.getValue(Type.STRING, 0));
                    }
                    localPaths.add(getLocalPath(path, ps, val, recordId));
                } else {
                    localPaths.add(getLocalPath(path, ps, recordId));
                }
            }
            if (ps.getType().tag() == PropertyType.BINARY) {
                // look for extra segment references
                for (int i = 0; i < ps.count(); i++) {
                    Blob b = ps.getValue(Type.BINARY, i);
                    for (SegmentId sbid : SegmentBlob.getBulkSegmentIds(b)) {
                        UUID bid = sbid.asUUID();
                        if (!bid.equals(id) && uuids.contains(bid)) {
                            localPaths.add(getLocalPath(path, ps, recordId));
                        }
                    }
                }
            }
        }
    }
    RecordId stateId = state.getRecordId();
    if (uuids.contains(stateId.getSegmentId().asUUID())) {
        localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
    }
    RecordId templateId = getTemplateId(state);
    if (uuids.contains(templateId.getSegmentId().asUUID())) {
        localPaths.add(path + "[Template@" + templateId + "]");
    }
    paths.addAll(localPaths);
    for (ChildNodeEntry ce : state.getChildNodeEntries()) {
        NodeState c = ce.getNodeState();
        if (c instanceof SegmentNodeState) {
            filterNodeStates(uuids, paths, (SegmentNodeState) c, path + ce.getName() + "/");
        }
    }
}
Also used : SegmentBlob(org.apache.jackrabbit.oak.segment.SegmentBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) RecordId(org.apache.jackrabbit.oak.segment.RecordId) UUID(java.util.UUID) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 3 with SegmentId

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

the class StandbyClientSyncExecution method copySegmentFromPrimary.

private void copySegmentFromPrimary(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)

Example 4 with SegmentId

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

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

the class SegmentTarFactory method hasExternalBlobReferences.

@Override
public boolean hasExternalBlobReferences() throws IOException {
    final FileStoreBuilder builder = fileStoreBuilder(new File(dir, "segmentstore"));
    builder.withMaxFileSize(256);
    builder.withMemoryMapping(false);
    ReadOnlyFileStore fs;
    try {
        fs = builder.buildReadOnly();
    } catch (InvalidFileStoreVersionException e) {
        throw new IOException(e);
    }
    try {
        for (SegmentId id : fs.getSegmentIds()) {
            if (!id.isDataSegmentId()) {
                continue;
            }
            id.getSegment().forEachRecord(new Segment.RecordConsumer() {

                @Override
                public void consume(int number, RecordType type, int offset) {
                    // see java.nio.file.FileVisitor
                    if (type == RecordType.BLOB_ID) {
                        throw new ExternalBlobFound();
                    }
                }
            });
        }
        return false;
    } catch (ExternalBlobFound e) {
        return true;
    } finally {
        fs.close();
    }
}
Also used : FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) RecordType(org.apache.jackrabbit.oak.segment.RecordType) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ReadOnlyFileStore(org.apache.jackrabbit.oak.segment.file.ReadOnlyFileStore) IOException(java.io.IOException) File(java.io.File) Segment(org.apache.jackrabbit.oak.segment.Segment)

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