Search in sources :

Example 6 with SegmentNodeBuilder

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

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

the class TarRevisionsTest method addChild.

@Nonnull
private static SegmentNodeState addChild(SegmentNodeState node, String name) {
    SegmentNodeBuilder builder = node.builder();
    builder.setChildNode(name);
    return builder.getNodeState();
}
Also used : SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) Nonnull(javax.annotation.Nonnull)

Example 8 with SegmentNodeBuilder

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

the class FileStoreIT method testRestartAndGC.

public void testRestartAndGC(boolean memoryMapping) throws Exception {
    FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    SegmentNodeState base = store.getHead();
    SegmentNodeBuilder builder = base.builder();
    byte[] data = new byte[10 * 1024 * 1024];
    new Random().nextBytes(data);
    Blob blob = builder.createBlob(new ByteArrayInputStream(data));
    builder.setProperty("foo", blob);
    store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
    store.flush();
    store.getRevisions().setHead(store.getRevisions().getHead(), base.getRecordId());
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.gc();
    store.flush();
    store.close();
    store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(memoryMapping).build();
    store.close();
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Aggregations

SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)8 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)7 Test (org.junit.Test)3 RecordId (org.apache.jackrabbit.oak.segment.RecordId)2 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 ConflictAnnotatingRebaseDiff (org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1