Search in sources :

Example 46 with ChildNodeEntry

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

the class PropertyIndexInfoProvider method computeCountEstimate.

private void computeCountEstimate(PropertyIndexInfo info, NodeState idxState) {
    long count = -1;
    for (ChildNodeEntry cne : idxState.getChildNodeEntries()) {
        //In multiplexing setups there can be multiple index nodes
        if (NodeStateUtils.isHidden(cne.getName())) {
            NodeState indexData = cne.getNodeState();
            long estimate = ApproximateCounter.getCountSync(indexData);
            if (estimate > 0) {
                if (count < 0) {
                    count = 0;
                }
                count += estimate;
            } else if (count < 0 && indexData.getChildNodeCount(1) == 0) {
                //If we cannot get estimate then at least try to see if any index data is there or not
                count = 0;
            }
        }
    }
    info.estimatedCount = count;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 47 with ChildNodeEntry

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

the class PropertyIndexStats method getStatsForAllIndexes.

@Override
public TabularData getStatsForAllIndexes(String path, int maxValueCount, int maxDepth, int maxPathCount) throws OpenDataException {
    String indexRootPath = concat(path, "oak:index");
    NodeState idxRoot = NodeStateUtils.getNode(store.getRoot(), indexRootPath);
    TabularType tt = new TabularType(PropertyIndexStats.class.getName(), "Property Index Stats", getType(), new String[] { "path" });
    TabularDataSupport tds = new TabularDataSupport(tt);
    for (ChildNodeEntry cne : idxRoot.getChildNodeEntries()) {
        if ("property".equals(cne.getNodeState().getString("type"))) {
            CompositeData stats = getStatsForIndex(concat(indexRootPath, cne.getName()), cne.getNodeState(), maxValueCount, maxDepth, maxPathCount);
            tds.put(stats);
        }
    }
    return tds;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) CompositeData(javax.management.openmbean.CompositeData)

Example 48 with ChildNodeEntry

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

the class ConcurrentReadAndAddTest method readNodes.

private void readNodes() {
    delayQuery = true;
    NodeState test = ns.getRoot().getChildNode("test");
    for (ChildNodeEntry entry : test.getChildNodeEntries()) {
        entry.getNodeState();
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 49 with ChildNodeEntry

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

the class DocumentNodeStoreTest method concurrentChildOperations.

// OAK-3646
@Test
public void concurrentChildOperations() throws Exception {
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    MemoryDocumentStore store = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(store).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0).clock(clock).setDocumentStore(store).setClusterId(2).getNodeStore();
    // create some children under /foo/bar
    NodeBuilder b1 = ns1.getRoot().builder();
    NodeBuilder node = b1.child("foo").child("bar");
    node.child("child-0");
    node.child("child-1");
    node.child("child-2");
    merge(ns1, b1);
    // make changes visible on both cluster nodes
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    // remove child-0 on cluster node 1
    b1 = ns1.getRoot().builder();
    b1.child("foo").child("bar").getChildNode("child-0").remove();
    merge(ns1, b1);
    // push _lastRev updates to DocumentStore
    ns1.runBackgroundOperations();
    // remove child-1 on cluster node 2
    NodeBuilder b2 = ns2.getRoot().builder();
    b2.child("foo").child("bar").getChildNode("child-1").remove();
    merge(ns2, b2);
    // on cluster node 2, remove of child-0 is not yet visible
    DocumentNodeState bar = asDocumentNodeState(ns2.getRoot().getChildNode("foo").getChildNode("bar"));
    List<ChildNodeEntry> children = Lists.newArrayList(bar.getChildNodeEntries());
    assertEquals(2, Iterables.size(children));
    RevisionVector invalidate = bar.getLastRevision();
    assertNotNull(invalidate);
    // this will make changes from cluster node 1 visible
    ns2.runBackgroundOperations();
    // wait two hours
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(2));
    // collect everything older than one hour
    // this will remove child-0 and child-1 doc
    ns1.getVersionGarbageCollector().gc(1, TimeUnit.HOURS);
    // forget cache entry for deleted node
    ns2.invalidateNodeCache("/foo/bar/child-0", invalidate);
    children = Lists.newArrayList(ns2.getRoot().getChildNode("foo").getChildNode("bar").getChildNodeEntries());
    assertEquals(1, Iterables.size(children));
}
Also used : 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 50 with ChildNodeEntry

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

the class DocumentNodeStoreTest method readChildrenWithDeletedSiblings.

// OAK-1861
@Test
public void readChildrenWithDeletedSiblings() throws Exception {
    final AtomicInteger maxLimit = new AtomicInteger(0);
    DocumentStore docStore = new MemoryDocumentStore() {

        @Nonnull
        @Override
        public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
            if (collection == NODES) {
                maxLimit.set(Math.max(limit, maxLimit.get()));
            }
            return super.query(collection, fromKey, toKey, limit);
        }
    };
    DocumentNodeStore ns = builderProvider.newBuilder().setDocumentStore(docStore).setAsyncDelay(0).getNodeStore();
    NodeBuilder builder = ns.getRoot().builder();
    for (int i = 0; i < 1000; i++) {
        builder.child("node-" + i);
    }
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // now remove all except the last one
    for (int i = 0; i < 999; i++) {
        builder = ns.getRoot().builder();
        builder.getChildNode("node-" + i).remove();
        ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    for (ChildNodeEntry entry : ns.getRoot().getChildNodeEntries()) {
        entry.getName();
    }
    // must not read more than DocumentNodeState.INITIAL_FETCH_SIZE + 1
    assertTrue(maxLimit.get() + " > " + (DocumentNodeState.INITIAL_FETCH_SIZE + 1), maxLimit.get() <= DocumentNodeState.INITIAL_FETCH_SIZE + 1);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)58 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)43 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)2 JsopBuilder.prettyPrint (org.apache.jackrabbit.oak.commons.json.JsopBuilder.prettyPrint)2 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)2