Search in sources :

Example 6 with SegmentNodeState

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

the class FileStoreIT method testRecovery.

@Test
public void testRecovery() throws Exception {
    FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    store.flush();
    RandomAccessFile data0 = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "r");
    long pos0 = data0.length();
    SegmentNodeState base = store.getHead();
    SegmentNodeBuilder builder = base.builder();
    builder.setProperty("step", "a");
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.flush();
    long pos1 = data0.length();
    data0.close();
    base = store.getHead();
    builder = base.builder();
    builder.setProperty("step", "b");
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertEquals("b", store.getHead().getString("step"));
    store.close();
    RandomAccessFile file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
    file.setLength(pos1);
    file.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertEquals("a", store.getHead().getString("step"));
    store.close();
    file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
    file.setLength(pos0);
    file.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
    assertFalse(store.getHead().hasProperty("step"));
    store.close();
}
Also used : RandomAccessFile(java.io.RandomAccessFile) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 7 with SegmentNodeState

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

the class SegmentTarCheckpoints method removeUnreferenced.

@Override
public long removeUnreferenced() {
    SegmentNodeState head = store.getHead();
    Set<String> refs = getReferencedCheckpoints(head.getChildNode("root"));
    NodeBuilder builder = head.builder();
    NodeBuilder cps = builder.getChildNode("checkpoints");
    long cnt = 0;
    for (String c : cps.getChildNodeNames()) {
        if (refs.contains(c)) {
            continue;
        }
        cps.getChildNode(c).remove();
        cnt++;
    }
    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 8 with SegmentNodeState

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

the class SegmentTarCheckpoints method setInfoProperty.

@Override
public int setInfoProperty(String cp, String name, String value) {
    SegmentNodeState head = store.getHead();
    NodeBuilder builder = head.builder();
    NodeBuilder props = builder.getChildNode("checkpoints").getChildNode(cp).getChildNode("properties");
    if (props.exists()) {
        if (value == null) {
            props.removeProperty(name);
        } else {
            props.setProperty(name, value, Type.STRING);
        }
        if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return 0;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 9 with SegmentNodeState

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

the class SegmentTarCheckpoints method remove.

@Override
public int remove(String cp) {
    SegmentNodeState head = store.getHead();
    NodeBuilder builder = head.builder();
    NodeBuilder cpn = builder.getChildNode("checkpoints").getChildNode(cp);
    if (cpn.exists()) {
        cpn.remove();
        if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return 0;
    }
}
Also used : SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 10 with SegmentNodeState

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

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