Search in sources :

Example 16 with SegmentNodeState

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

the class CheckRepositoryTestBase method addInvalidRevision.

protected void addInvalidRevision() throws InvalidFileStoreVersionException, IOException, CommitFailedException {
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    NodeBuilder builder = nodeStore.getRoot().builder();
    // add a new child "z"
    addChildWithBlobProperties(nodeStore, builder, "z", 5);
    // add a new property value to existing child "a"
    addChildWithBlobProperties(nodeStore, builder, "a", 1);
    NodeState after = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // get record number to corrupt (NODE record for "z")
    SegmentNodeState child = (SegmentNodeState) after.getChildNode("z");
    int zRecordNumber = child.getRecordId().getRecordNumber();
    // get record number to corrupt (NODE record for "a")
    child = (SegmentNodeState) after.getChildNode("a");
    int aRecordNumber = child.getRecordId().getRecordNumber();
    fileStore.close();
    corruptRecord(zRecordNumber);
    corruptRecord(aRecordNumber);
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 17 with SegmentNodeState

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

the class SegmentTarCheckpoints method removeAll.

@Override
public long removeAll() {
    SegmentNodeState head = store.getHead();
    NodeBuilder builder = head.builder();
    NodeBuilder cps = builder.getChildNode("checkpoints");
    long cnt = cps.getChildNodeCount(Integer.MAX_VALUE);
    builder.setChildNode("checkpoints");
    if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
        return cnt;
    } else {
        return -1;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 18 with SegmentNodeState

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

the class SegmentTarCheckpoints method getInfo.

@Override
public Map<String, String> getInfo(String cp) {
    SegmentNodeState head = store.getHead();
    NodeState props = head.getChildNode("checkpoints").getChildNode(cp).getChildNode("properties");
    if (props.exists()) {
        Map<String, String> info = new HashMap<>();
        for (PropertyState p : props.getProperties()) {
            info.put(p.getName(), p.getValue(Type.STRING));
        }
        return info;
    } else {
        return null;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) HashMap(java.util.HashMap) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 19 with SegmentNodeState

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

the class LockBasedScheduler method execute.

private NodeState execute(Commit commit) throws CommitFailedException, InterruptedException {
    // only do the merge if there are some changes to commit
    if (commit.hasChanges()) {
        refreshHead(true);
        SegmentNodeState before = head.get();
        SegmentNodeState after = commit.apply(before);
        if (revisions.setHead(before.getRecordId(), after.getRecordId())) {
            head.set(after);
            contentChanged(after.getChildNode(ROOT), commit.info());
            refreshHead(true);
        }
    }
    return head.get().getChildNode(ROOT);
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 20 with SegmentNodeState

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

the class LockBasedScheduler method schedule.

@Override
public NodeState schedule(@Nonnull Commit commit, SchedulerOption... schedulingOptions) throws CommitFailedException {
    boolean queued = false;
    try {
        long queuedTime = -1;
        if (commitSemaphore.availablePermits() < 1) {
            queuedTime = System.nanoTime();
            stats.onCommitQueued();
            queued = true;
        }
        commitSemaphore.acquire();
        try {
            if (queued) {
                long dequeuedTime = System.nanoTime();
                stats.dequeuedAfter(dequeuedTime - queuedTime);
                stats.onCommitDequeued();
            }
            long beforeCommitTime = System.nanoTime();
            SegmentNodeState merged = (SegmentNodeState) execute(commit);
            commit.applied(merged);
            long afterCommitTime = System.nanoTime();
            stats.committedAfter(afterCommitTime - beforeCommitTime);
            stats.onCommit();
            return merged;
        } finally {
            commitSemaphore.release();
        }
    } catch (InterruptedException e) {
        currentThread().interrupt();
        throw new CommitFailedException("Segment", 2, "Merge interrupted", e);
    } catch (SegmentOverflowException e) {
        throw new CommitFailedException("Segment", 3, "Merge failed", e);
    }
}
Also used : SegmentOverflowException(org.apache.jackrabbit.oak.segment.SegmentOverflowException) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Aggregations

SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)25 RecordId (org.apache.jackrabbit.oak.segment.RecordId)9 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 Test (org.junit.Test)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 IOException (java.io.IOException)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)3 Stopwatch (com.google.common.base.Stopwatch)2 UUID (java.util.UUID)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 Compactor (org.apache.jackrabbit.oak.segment.Compactor)2 SegmentBufferWriter (org.apache.jackrabbit.oak.segment.SegmentBufferWriter)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 WriterCacheManager (org.apache.jackrabbit.oak.segment.WriterCacheManager)2 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)2 Function (com.google.common.base.Function)1 Supplier (com.google.common.base.Supplier)1