Search in sources :

Example 1 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class PathFilteringDiff method childNodeAdded.

@Override
public boolean childNodeAdded(String name, NodeState after) {
    AbstractDocumentNodeState afterDoc = asDocumentState(after, name);
    String nextPath = afterDoc.getPath();
    PathFilter.Result result = ctx.pathFilter.filter(nextPath);
    if (result == PathFilter.Result.EXCLUDE) {
        return true;
    }
    ctx.traversingNode(nextPath);
    //We avoid this as we need to copy meta properties
    //super.childNodeAdded(name, after);
    NodeBuilder childBuilder = builder.child(name);
    copyMetaProperties(afterDoc, childBuilder, ctx.metaPropNames);
    return after.compareAgainstBaseState(EMPTY_NODE, new PathFilteringDiff(childBuilder, ctx, afterDoc));
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 2 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class SecondaryStoreCache method getDocumentNodeState.

@CheckForNull
@Override
public AbstractDocumentNodeState getDocumentNodeState(String path, RevisionVector rootRevision, RevisionVector lastRev) {
    //TODO We might need skip the calls if they occur due to SecondaryStoreObserver
    //doing the diff or in the startup when we try to sync the state
    PathFilter.Result result = pathFilter.filter(path);
    if (result != PathFilter.Result.INCLUDE) {
        unknownPaths.mark();
        return null;
    }
    if (!DelegatingDocumentNodeState.hasMetaProps(store.getRoot())) {
        return null;
    }
    AbstractDocumentNodeState currentRoot = DelegatingDocumentNodeState.wrap(store.getRoot(), differ);
    //not have the matching result
    if (lastRev.compareTo(currentRoot.getLastRevision()) > 0) {
        return null;
    }
    AbstractDocumentNodeState nodeState = findByMatchingLastRev(currentRoot, path, lastRev);
    if (nodeState != null) {
        headRevMatched.mark();
        return nodeState;
    }
    AbstractDocumentNodeState matchingRoot = findMatchingRoot(rootRevision);
    if (matchingRoot != null) {
        NodeState state = NodeStateUtils.getNode(matchingRoot, path);
        if (state.exists()) {
            AbstractDocumentNodeState docState = asDocState(state);
            prevRevMatched.mark();
            return docState;
        }
    }
    knownMissed.mark();
    return null;
}
Also used : PathFilter(org.apache.jackrabbit.oak.plugins.index.PathFilter) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) CheckForNull(javax.annotation.CheckForNull)

Example 3 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class SecondaryStoreCache method findByMatchingLastRev.

@CheckForNull
private AbstractDocumentNodeState findByMatchingLastRev(AbstractDocumentNodeState root, String path, RevisionVector lastRev) {
    NodeState state = root;
    for (String name : PathUtils.elements(path)) {
        state = state.getChildNode(name);
        if (!state.exists()) {
            return null;
        }
        //requested lastRev is > current node lastRev then no need to check further
        if (lastRev.compareTo(asDocState(state).getLastRevision()) > 0) {
            return null;
        }
    }
    AbstractDocumentNodeState docState = asDocState(state);
    if (lastRev.equals(docState.getLastRevision())) {
        headRevMatched.mark();
        return docState;
    }
    return null;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) CheckForNull(javax.annotation.CheckForNull)

Example 4 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class SecondaryStoreObserver method contentChanged.

@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
    //diffManyChildren might pose problem for e.g. data under uuid index
    if (!firstEventProcessed) {
        log.info("Starting initial sync");
    }
    Stopwatch w = Stopwatch.createStarted();
    AbstractDocumentNodeState target = (AbstractDocumentNodeState) root;
    NodeState secondaryRoot = nodeStore.getRoot();
    NodeState base = DelegatingDocumentNodeState.wrapIfPossible(secondaryRoot, differ);
    NodeBuilder builder = secondaryRoot.builder();
    ApplyDiff diff = new PathFilteringDiff(builder, pathFilter, metaPropNames, target);
    //Copy the root node meta properties
    PathFilteringDiff.copyMetaProperties(target, builder, metaPropNames);
    //Apply the rest of properties
    target.compareAgainstBaseState(base, diff);
    try {
        NodeState updatedSecondaryRoot = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
        secondaryObserver.contentChanged(DelegatingDocumentNodeState.wrap(updatedSecondaryRoot, differ));
        TimerStats timer = info.isExternal() ? external : local;
        timer.update(w.elapsed(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
        if (!firstEventProcessed) {
            log.info("Time taken for initial sync {}", w);
            firstEventProcessed = true;
        }
    } catch (CommitFailedException e) {
        //TODO
        log.warn("Commit to secondary store failed", e);
    }
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Stopwatch(com.google.common.base.Stopwatch) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) TimerStats(org.apache.jackrabbit.oak.stats.TimerStats) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 5 with AbstractDocumentNodeState

use of org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState in project jackrabbit-oak by apache.

the class PathFilteringDiff method childNodeChanged.

@Override
public boolean childNodeChanged(String name, NodeState before, NodeState after) {
    AbstractDocumentNodeState afterDoc = asDocumentState(after, name);
    String nextPath = afterDoc.getPath();
    if (ctx.pathFilter.filter(nextPath) != PathFilter.Result.EXCLUDE) {
        ctx.traversingNode(nextPath);
        NodeBuilder childBuilder = builder.getChildNode(name);
        copyMetaProperties(afterDoc, childBuilder, ctx.metaPropNames);
        return after.compareAgainstBaseState(before, new PathFilteringDiff(builder.getChildNode(name), ctx, afterDoc));
    }
    return true;
}
Also used : AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Aggregations

AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)18 Test (org.junit.Test)9 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 PathFilter (org.apache.jackrabbit.oak.plugins.index.PathFilter)6 CheckForNull (javax.annotation.CheckForNull)3 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)2 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)2 Stopwatch (com.google.common.base.Stopwatch)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)1 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)1 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)1 Counting (org.apache.jackrabbit.oak.stats.Counting)1 TimerStats (org.apache.jackrabbit.oak.stats.TimerStats)1