use of org.apache.jackrabbit.oak.spi.state.ApplyDiff 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);
}
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));
NodeState target = store.getRoot();
target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
use of org.apache.jackrabbit.oak.spi.state.ApplyDiff 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.spi.state.ApplyDiff in project jackrabbit-oak by apache.
the class CommitHookEnhancer method toComposite.
private CompositeNodeBuilder toComposite(NodeState nodeState, CompositeNodeState compositeRoot) {
CompositeNodeBuilder builder = compositeRoot.builder();
nodeState.compareAgainstBaseState(compositeRoot, new ApplyDiff(builder));
return builder;
}
use of org.apache.jackrabbit.oak.spi.state.ApplyDiff in project jackrabbit-oak by apache.
the class InitialContentMigrator method copyDiffToTarget.
private NodeState copyDiffToTarget(NodeState before, NodeState after, NodeState targetRoot, boolean tracePaths) throws IOException, CommitFailedException {
NodeBuilder targetBuilder = targetRoot.builder();
NodeState currentRoot = wrapNodeState(after);
NodeState baseRoot = wrapNodeState(before);
currentRoot.compareAgainstBaseState(baseRoot, new ApplyDiff(targetBuilder));
return targetNodeStore.merge(targetBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.state.ApplyDiff in project jackrabbit-oak by apache.
the class TestUtil method registerNodeType.
public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn) {
// Taken from org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent
NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
NodeStore store = new MemoryNodeStore(base);
Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null);
NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types");
NodeState target = store.getRoot();
target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Aggregations