Search in sources :

Example 16 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method clusterWithClockDifferences2.

// OAK-3388
@Test
public void clusterWithClockDifferences2() throws Exception {
    MemoryDocumentStore store = new MemoryDocumentStore();
    long now = System.currentTimeMillis();
    Clock c1 = new Clock.Virtual();
    c1.waitUntil(now);
    Revision.setClock(c1);
    DocumentNodeStore ns1 = builderProvider.newBuilder().clock(c1).setDocumentStore(store).setAsyncDelay(0).setClusterId(1).getNodeStore();
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("node").setProperty("p", 1);
    merge(ns1, b1);
    // make /node visible
    ns1.runBackgroundOperations();
    Revision.resetClockToDefault();
    Clock c2 = new Clock.Virtual();
    // c2 is five seconds ahead
    c2.waitUntil(now + 5000);
    Revision.setClock(c2);
    DocumentNodeStore ns2 = builderProvider.newBuilder().clock(c2).setDocumentStore(store).setAsyncDelay(0).setClusterId(2).getNodeStore();
    // ns2 sees /node
    assertTrue(ns2.getRoot().hasChildNode("node"));
    assertEquals(1, ns2.getRoot().getChildNode("node").getProperty("p").getValue(Type.LONG).longValue());
    // increment /node/p ns2
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("node").setProperty("p", 2);
    merge(ns2, b2);
    ns2.runBackgroundOperations();
    // increment /node/p2 on ns1
    Revision.resetClockToDefault();
    Revision.setClock(c1);
    ns1.runBackgroundOperations();
    b1 = ns1.getRoot().builder();
    assertEquals(2, b1.getChildNode("node").getProperty("p").getValue(Type.LONG).longValue());
    b1.child("node").setProperty("p", 3);
    merge(ns1, b1);
    ns1.runBackgroundOperations();
    // check if /node/p=3 is visible on ns2
    Revision.resetClockToDefault();
    Revision.setClock(c2);
    ns2.runBackgroundOperations();
    b2 = ns2.getRoot().builder();
    assertEquals(3, b2.getChildNode("node").getProperty("p").getValue(Type.LONG).longValue());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 17 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method diffExternalChanges.

// OAK-2232
@Test
public void diffExternalChanges() throws Exception {
    long modifiedResMillis = SECONDS.toMillis(MODIFIED_IN_SECS_RESOLUTION);
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    DocumentStore docStore = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(docStore).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(docStore).setClusterId(2).getNodeStore();
    NodeBuilder builder = ns1.getRoot().builder();
    NodeBuilder test = builder.child("test");
    for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
        test.child("node-" + i);
    }
    ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    // make sure next change has a different _modified value
    clock.waitUntil(clock.getTime() + modifiedResMillis * 2);
    builder = ns2.getRoot().builder();
    builder.child("test").child("foo");
    ns2.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // 'wait' again for a different _modified value
    clock.waitUntil(clock.getTime() + modifiedResMillis * 2);
    builder = ns1.getRoot().builder();
    builder.child("test").child("bar");
    ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // remember current root for diff
    NodeState r1 = ns1.getRoot();
    ns2.runBackgroundOperations();
    ns1.runBackgroundOperations();
    NodeState r2 = ns1.getRoot();
    // are we able to see foo?
    boolean found = false;
    for (ChildNodeEntry entry : r2.getChildNode("test").getChildNodeEntries()) {
        if (entry.getName().equals("foo")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    // diff must report '/test' modified and '/test/foo' added
    TrackingDiff diff = new TrackingDiff();
    r2.compareAgainstBaseState(r1, diff);
    assertEquals(1, diff.modified.size());
    assertTrue(diff.modified.contains("/test"));
    assertEquals(1, diff.added.size());
    assertTrue(diff.added.contains("/test/foo"));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 18 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method docChildCacheWithIncompatiblDocStoreSort.

@Test
public void docChildCacheWithIncompatiblDocStoreSort() throws CommitFailedException {
    final Set<String> reads = Sets.newHashSet();
    final ConcurrentSkipListMap<String, NodeDocument> nodes = new ConcurrentSkipListMap<String, NodeDocument>(new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            int ret = o1.compareTo(o2);
            if (o1.indexOf("child") > 0 && o2.indexOf("child") > 0) {
                ret = (-ret);
            }
            return ret;
        }
    });
    MemoryDocumentStore docStore = new MemoryDocumentStore() {

        @Override
        @SuppressWarnings("unchecked")
        protected <T extends Document> ConcurrentSkipListMap<String, T> getMap(Collection<T> collection) {
            if (collection == Collection.NODES) {
                return (ConcurrentSkipListMap<String, T>) nodes;
            } else {
                return super.getMap(collection);
            }
        }

        @Override
        public <T extends Document> T find(Collection<T> collection, String key) {
            reads.add(key);
            return super.find(collection, key);
        }
    };
    DocumentNodeStore store = builderProvider.newBuilder().setUseSimpleRevision(true).setClusterId(1).setAsyncDelay(0).setDocumentStore(docStore).getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    //create < INITIAL_FETCH_SIZE children to have complete child cache entries
    NodeBuilder parentBuilder = builder.child("parent");
    int numChildren = DocumentNodeState.INITIAL_FETCH_SIZE - 2;
    for (int i = 0; i < numChildren; i++) {
        parentBuilder.child("child" + (i + 1));
    }
    merge(store, builder);
    store.invalidateNodeChildrenCache();
    //Force fill child node cache
    NodeState parentNodeState = store.getRoot().getChildNode("parent");
    Iterables.size(parentNodeState.getChildNodeEntries());
    reads.clear();
    NodeState nonExistingChild = parentNodeState.getChildNode("child501-non-existing-child");
    assertEquals("Fully cached entry in doc child cache should be able to find non existing children" + " even if doc store sort order is incompatible to that of Java", 0, reads.size());
    assertFalse("Non existing children should be reported as such", nonExistingChild.exists());
    store.invalidateNodeCache("/parent/child25", store.getHeadRevision());
    reads.clear();
    NodeState existingChild = parentNodeState.getChildNode("child25");
    assertTrue("Fully cached entry in doc child cache should be able to find existing children" + " even if doc store sort order is incompatible to that of Java", reads.size() > 0);
    assertTrue("Existing children should be reported as such", existingChild.exists());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) Test(org.junit.Test)

Example 19 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentSplitTest method splitDocWithHasBinary.

@Test
public void splitDocWithHasBinary() throws Exception {
    DocumentStore store = mk.getDocumentStore();
    DocumentNodeStore ns = mk.getNodeStore();
    NodeBuilder b1 = ns.getRoot().builder();
    b1.child("test").child("foo").setProperty("binaryProp", ns.createBlob(randomStream(1, 4096)));
    ns.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // is parent
    for (int i = 0; i < NodeDocument.NUM_REVS_THRESHOLD; i++) {
        b1 = ns.getRoot().builder();
        b1.child("test").child("foo").setProperty("prop", i);
        ns.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    ns.runBackgroundOperations();
    NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/test/foo"));
    List<NodeDocument> prevDocs = ImmutableList.copyOf(doc.getAllPreviousDocs());
    assertEquals(1, prevDocs.size());
    //Check for hasBinary
    assertTrue(doc.hasBinary());
    assertTrue(prevDocs.get(0).hasBinary());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 20 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class DocumentNodeStoreTest method getNewestRevision.

// OAK-1662
@Test
public void getNewestRevision() throws Exception {
    DocumentStore docStore = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setDocumentStore(docStore).setAsyncDelay(0).setClusterId(1).getNodeStore();
    ns1.getRoot();
    ns1.runBackgroundOperations();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setDocumentStore(docStore).setAsyncDelay(0).setClusterId(2).getNodeStore();
    ns2.getRoot();
    NodeBuilder b1 = ns1.getRoot().builder();
    for (int i = 0; i < NodeDocument.NUM_REVS_THRESHOLD; i++) {
        b1.setProperty("p", String.valueOf(i));
        ns1.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    ns1.runBackgroundOperations();
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.setProperty("q", "value");
    ns2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20