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