Search in sources :

Example 21 with NodeStore

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

the class ManyChildNodesTest method manyChildNodes.

@Test
public void manyChildNodes() throws Exception {
    TestStore store = new TestStore();
    DocumentMK mk = new DocumentMK.Builder().setDocumentStore(store).open();
    NodeStore ns = mk.getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    for (int i = 0; i < DocumentNodeState.MAX_FETCH_SIZE * 2; i++) {
        builder.child("c-" + i);
    }
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    store.queries.clear();
    // must fetch in batches
    for (ChildNodeEntry entry : ns.getRoot().getChildNodeEntries()) {
        entry.getName();
    }
    // maximum fetch size is MAX_FETCH_SIZE plus one because
    // DocumentNodeStore will use this value to find out if there
    // are more child nodes than requested
    int maxFetchSize = DocumentNodeState.MAX_FETCH_SIZE + 1;
    for (Map.Entry<String, Integer> e : store.queries.entrySet()) {
        assertTrue(e.getValue() + " > " + maxFetchSize, e.getValue() <= maxFetchSize);
    }
    mk.dispose();
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Map(java.util.Map) Test(org.junit.Test)

Example 22 with NodeStore

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

the class IndexUpdateTest method testReindexAsync.

/**
     * Async Reindex Test (OAK-2174)
     * <ul>
     * <li>Add some content</li>
     * <li>Add an index definition with the reindex flag and the reindex-async flag set</li>
     * <li>Run the background async job manually</li>
     * <li>Search & verify</li>
     * </ul>
     */
@Test
public void testReindexAsync() throws Exception {
    IndexEditorProvider provider = new PropertyIndexEditorProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
    NodeStore store = new MemoryNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
    builder.child("testRoot").setProperty("foo", "abc");
    // merge it back in
    store.merge(builder, hook, CommitInfo.EMPTY);
    // first check that the async flag exist
    NodeState ns1 = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    assertTrue(ns1.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertTrue(ns1.getProperty(REINDEX_ASYNC_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertEquals(ASYNC_REINDEX_VALUE, ns1.getString(ASYNC_PROPERTY_NAME));
    AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
    int max = 5;
    // same behaviour as PropertyIndexAsyncReindex mbean
    boolean done = false;
    int count = 0;
    while (!done || count >= max) {
        async.run();
        done = async.isFinished();
        count++;
    }
    // first check that the index content nodes exist
    NodeState ns = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
    checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
    assertFalse(ns.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
    assertNull(ns.getProperty(ASYNC_PROPERTY_NAME));
    // next, lookup
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 23 with NodeStore

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

the class InitialContent method initialize.

@Override
public void initialize(@Nonnull NodeBuilder builder) {
    builder.setProperty(JCR_PRIMARYTYPE, NT_REP_ROOT, Type.NAME);
    if (!builder.hasChildNode(JCR_SYSTEM)) {
        NodeBuilder system = builder.child(JCR_SYSTEM);
        system.setProperty(JCR_PRIMARYTYPE, NT_REP_SYSTEM, Type.NAME);
        system.child(JCR_VERSIONSTORAGE).setProperty(JCR_PRIMARYTYPE, REP_VERSIONSTORAGE, Type.NAME);
        system.child(JCR_NODE_TYPES).setProperty(JCR_PRIMARYTYPE, NT_REP_NODE_TYPES, Type.NAME);
        system.child(VersionConstants.JCR_ACTIVITIES).setProperty(JCR_PRIMARYTYPE, VersionConstants.REP_ACTIVITIES, Type.NAME);
        Namespaces.setupNamespaces(system);
    }
    BundlingConfigInitializer.INSTANCE.initialize(builder);
    NodeBuilder versionStorage = builder.child(JCR_SYSTEM).child(JCR_VERSIONSTORAGE);
    if (prePopulateVS && !isInitialized(versionStorage)) {
        createIntermediateNodes(versionStorage);
    }
    if (!builder.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
        NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
        NodeBuilder uuid = IndexUtils.createIndexDefinition(index, "uuid", true, true, ImmutableList.<String>of(JCR_UUID), null);
        uuid.setProperty("info", "Oak index for UUID lookup (direct lookup of nodes with the mixin 'mix:referenceable').");
        NodeBuilder nodetype = IndexUtils.createIndexDefinition(index, "nodetype", true, false, ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES), null);
        nodetype.setProperty("info", "Oak index for queries with node type, and possibly path restrictions, " + "for example \"/jcr:root/content//element(*, mix:language)\".");
        IndexUtils.createReferenceIndex(index);
        index.child("counter").setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME).setProperty(TYPE_PROPERTY_NAME, NodeCounterEditorProvider.TYPE).setProperty(IndexConstants.ASYNC_PROPERTY_NAME, IndexConstants.ASYNC_PROPERTY_NAME).setProperty("info", "Oak index that allows to estimate " + "how many nodes are stored below a given path, " + "to decide whether traversing or using an index is faster.");
    }
    // squeeze node state before it is passed to store (OAK-2411)
    NodeState base = squeeze(builder.getNodeState());
    NodeStore store = new MemoryNodeStore(base);
    registerBuiltIn(RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null, null));
    NodeState target = store.getRoot();
    target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 24 with NodeStore

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

the class DocumentSplitTest method keepRevisionsForMostRecentChanges.

// OAK-1794
@Test
public void keepRevisionsForMostRecentChanges() throws Exception {
    DocumentStore store = mk.getDocumentStore();
    NodeStore ns = mk.getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    builder.setProperty("foo", -1);
    builder.setProperty("bar", -1);
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    for (int i = 0; i < NUM_REVS_THRESHOLD; i++) {
        builder = ns.getRoot().builder();
        builder.setProperty("foo", i);
        ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    mk.runBackgroundOperations();
    NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/"));
    assertNotNull(doc);
    // the local _revisions map must still contain the entry for
    // the initial 'bar' property
    Map<Revision, String> valueMap = doc.getValueMap("bar");
    assertFalse(valueMap.isEmpty());
    Revision r = valueMap.keySet().iterator().next();
    assertTrue(doc.getLocalRevisions().containsKey(r));
    // but also the previous document must contain the revision
    List<NodeDocument> prevDocs = Lists.newArrayList(doc.getAllPreviousDocs());
    assertEquals(1, prevDocs.size());
    NodeDocument prev = prevDocs.get(0);
    assertTrue(prev.getLocalRevisions().containsKey(r));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 25 with NodeStore

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

the class DocumentSplitTest method keepCommitRootForMostRecentChanges.

// OAK-1794
@Test
public void keepCommitRootForMostRecentChanges() throws Exception {
    DocumentStore store = mk.getDocumentStore();
    NodeStore ns = mk.getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    builder.setProperty("p", -1);
    NodeBuilder test = builder.child("test");
    test.setProperty("foo", -1);
    test.setProperty("bar", -1);
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    for (int i = 0; i < NUM_REVS_THRESHOLD; i++) {
        builder = ns.getRoot().builder();
        builder.setProperty("p", i);
        test = builder.child("test");
        test.setProperty("foo", i);
        ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    mk.runBackgroundOperations();
    NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/test"));
    assertNotNull(doc);
    // the local _commitRoot map must still contain the entry for
    // the initial 'bar' property
    Map<Revision, String> valueMap = doc.getValueMap("bar");
    assertFalse(valueMap.isEmpty());
    Revision r = valueMap.keySet().iterator().next();
    assertTrue(doc.getLocalCommitRoot().containsKey(r));
    // but also the previous document must contain the commitRoot entry
    List<NodeDocument> prevDocs = Lists.newArrayList(doc.getAllPreviousDocs());
    assertEquals(1, prevDocs.size());
    NodeDocument prev = prevDocs.get(0);
    assertTrue(prev.getLocalCommitRoot().containsKey(r));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)141 Test (org.junit.Test)81 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)52 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29 Blob (org.apache.jackrabbit.oak.api.Blob)24 Before (org.junit.Before)18 FileInputStream (java.io.FileInputStream)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)16 File (java.io.File)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)13 Oak (org.apache.jackrabbit.oak.Oak)10 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)10 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)10 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)10 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)9 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)9 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)9