Search in sources :

Example 1 with SegmentNodeState

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

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

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

the class TarRevisionsTest method setHead.

@Test
public void setHead() throws IOException {
    RecordId headId = revisions.getHead();
    SegmentNodeState newRoot = addChild(reader.readNode(headId), "a");
    assertTrue(revisions.setHead(headId, newRoot.getRecordId()));
    store.flush();
    try (JournalReader reader = createJournalReader()) {
        assertTrue(reader.hasNext());
        assertEquals(newRoot.getRecordId().toString10(), reader.next().getRevision());
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Example 4 with SegmentNodeState

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

the class TarRevisionsTest method concurrentSetHead.

@Test
public void concurrentSetHead() {
    RecordId headId = revisions.getHead();
    SegmentNodeState rootA = addChild(reader.readNode(headId), "a");
    SegmentNodeState rootB = addChild(reader.readNode(headId), "a");
    assertTrue(revisions.setHead(headId, rootA.getRecordId()));
    assertFalse(revisions.setHead(headId, rootB.getRecordId()));
    assertEquals(rootA, reader.readHeadState(revisions));
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Example 5 with SegmentNodeState

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

the class TarRevisionsTest method concurrentSetHeadFromFunction.

@Test
public void concurrentSetHeadFromFunction() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    ListeningExecutorService executor = listeningDecorator(newFixedThreadPool(2));
    try {
        ListenableFuture<Boolean> t1 = executor.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return null != revisions.setHead(new Function<RecordId, RecordId>() {

                    @Nullable
                    @Override
                    public RecordId apply(RecordId headId) {
                        return addChild(reader.readNode(headId), "a").getRecordId();
                    }
                });
            }
        });
        ListenableFuture<Boolean> t2 = executor.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return null != revisions.setHead(new Function<RecordId, RecordId>() {

                    @Nullable
                    @Override
                    public RecordId apply(RecordId headId) {
                        return addChild(reader.readNode(headId), "b").getRecordId();
                    }
                });
            }
        });
        assertTrue(t1.get(500, MILLISECONDS));
        assertTrue(t2.get(500, MILLISECONDS));
        SegmentNodeState root = reader.readNode(revisions.getHead());
        assertTrue(root.hasChildNode("a"));
        assertTrue(root.hasChildNode("b"));
    } finally {
        executor.shutdown();
    }
}
Also used : ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

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