Search in sources :

Example 1 with RecordId

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

the class StandbyClientSyncExecution method execute.

void execute() throws Exception {
    RecordId remoteHead = getHead();
    if (remoteHead == null) {
        throw new IllegalStateException("Unable to fetch remote head");
    }
    if (remoteHead.equals(store.getHead().getRecordId())) {
        return;
    }
    long t = System.currentTimeMillis();
    SegmentNodeState before = store.getHead();
    SegmentNodeBuilder builder = before.builder();
    SegmentNodeState current = newSegmentNodeState(remoteHead);
    compareAgainstBaseState(current, before, builder);
    boolean ok = store.getRevisions().setHead(before.getRecordId(), remoteHead);
    store.flush();
    log.debug("updated head state successfully: {} in {}ms.", ok, System.currentTimeMillis() - t);
}
Also used : SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 2 with RecordId

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

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

the class ReadOnlyRevisions method setHead.

@Override
public boolean setHead(@Nonnull RecordId expected, @Nonnull RecordId head, @Nonnull Option... options) {
    checkBound();
    RecordId id = this.head.get();
    return id.equals(expected) && this.head.compareAndSet(id, head);
}
Also used : FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId) RecordId(org.apache.jackrabbit.oak.segment.RecordId)

Example 4 with RecordId

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

the class FileStoreUtil method findPersistedRecordId.

/**
     * Traverse the journal until a record ID is found that exists in the
     * provided segment store.
     *
     * @param store   An instance of {@link SegmentStore}.
     * @param idProvider  The {@code SegmentIdProvider} of the {@code store}
     * @param journal Path to the journal file.
     * @return An instance of {@link RecordId}, or {@code null} if none could be
     * found.
     * @throws IOException If an I/O error occurs.
     */
static RecordId findPersistedRecordId(SegmentStore store, SegmentIdProvider idProvider, File journal) throws IOException {
    try (JournalReader journalReader = new JournalReader(journal)) {
        while (journalReader.hasNext()) {
            JournalEntry entry = journalReader.next();
            try {
                RecordId id = RecordId.fromString(idProvider, entry.getRevision());
                if (store.containsSegment(id.getSegmentId())) {
                    return id;
                }
                log.warn("Unable to access revision {}, rewinding...", id);
            } catch (IllegalArgumentException ignore) {
                log.warn("Skipping invalid record id {}", entry);
            }
        }
    }
    return null;
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId)

Example 5 with RecordId

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

the class FileStoreIT method setRevisionTest.

@Test
public void setRevisionTest() throws Exception {
    try (FileStore store = fileStoreBuilder(getFileStoreFolder()).build()) {
        RecordId id1 = store.getRevisions().getHead();
        SegmentNodeState base = store.getHead();
        SegmentNodeBuilder builder = base.builder();
        builder.setProperty("step", "a");
        store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
        RecordId id2 = store.getRevisions().getHead();
        store.flush();
        try (ReadOnlyFileStore roStore = fileStoreBuilder(getFileStoreFolder()).buildReadOnly()) {
            assertEquals(id2, roStore.getRevisions().getHead());
            roStore.setRevision(id1.toString());
            assertEquals(id1, roStore.getRevisions().getHead());
            roStore.setRevision(id2.toString());
            assertEquals(id2, roStore.getRevisions().getHead());
        }
    }
}
Also used : SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Aggregations

RecordId (org.apache.jackrabbit.oak.segment.RecordId)28 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)14 Test (org.junit.Test)9 FileStoreUtil.findPersistedRecordId (org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)7 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Stopwatch (com.google.common.base.Stopwatch)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 PrintWriter (java.io.PrintWriter)1 Random (java.util.Random)1