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();
}
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"));
}
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));
}
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));
}
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));
}
Aggregations