Search in sources :

Example 1 with SegmentNodeBuilder

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

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

the class LockBasedScheduler method removeCheckpoint.

@Override
public boolean removeCheckpoint(String name) {
    checkNotNull(name);
    // try 5 times
    for (int i = 0; i < 5; i++) {
        if (commitSemaphore.tryAcquire()) {
            try {
                refreshHead(true);
                SegmentNodeState state = head.get();
                SegmentNodeBuilder builder = state.builder();
                NodeBuilder cp = builder.child("checkpoints").child(name);
                if (cp.exists()) {
                    cp.remove();
                    SegmentNodeState newState = builder.getNodeState();
                    if (revisions.setHead(state.getRecordId(), newState.getRecordId())) {
                        refreshHead(false);
                        return true;
                    }
                }
            } finally {
                commitSemaphore.release();
            }
        }
    }
    return false;
}
Also used : SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 3 with SegmentNodeBuilder

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

the class FileStoreIT method nonBlockingROStore.

@Test
public void nonBlockingROStore() throws Exception {
    FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    // first 1kB
    store.flush();
    SegmentNodeState base = store.getHead();
    SegmentNodeBuilder builder = base.builder();
    builder.setProperty("step", "a");
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    // second 1kB
    store.flush();
    ReadOnlyFileStore ro = null;
    try {
        ro = fileStoreBuilder(getFileStoreFolder()).buildReadOnly();
        assertEquals(store.getRevisions().getHead(), ro.getRevisions().getHead());
    } finally {
        if (ro != null) {
            ro.close();
        }
        store.close();
    }
}
Also used : SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Example 4 with SegmentNodeBuilder

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

Example 5 with SegmentNodeBuilder

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

the class StandbyClientSyncExecution method execute.

void execute(StandbyClient client) throws Exception {
    RecordId remoteHead = getHead(client);
    if (remoteHead == null) {
        log.error("Unable to fetch remote head");
        return;
    }
    if (remoteHead.equals(store.getHead().getRecordId())) {
        return;
    }
    Stopwatch stopwatch = Stopwatch.createStarted();
    SegmentNodeState before = store.getHead();
    SegmentNodeBuilder builder = before.builder();
    SegmentNodeState current = newSegmentNodeState(remoteHead);
    compareAgainstBaseState(client, current, before, builder);
    store.getRevisions().setHead(before.getRecordId(), remoteHead);
    log.info("Updated head state in {}", stopwatch);
}
Also used : Stopwatch(com.google.common.base.Stopwatch) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Aggregations

SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)10 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)9 RecordId (org.apache.jackrabbit.oak.segment.RecordId)3 Test (org.junit.Test)3 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Stopwatch (com.google.common.base.Stopwatch)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)1 ConflictAnnotatingRebaseDiff (org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 Before (org.junit.Before)1