Search in sources :

Example 1 with ApplyDiff

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));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 2 with ApplyDiff

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);
    }
}
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 3 with ApplyDiff

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;
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff)

Example 4 with ApplyDiff

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);
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) FilteringNodeState(org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ReportingNodeState(org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 5 with ApplyDiff

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));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) ModifiedNodeState(org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Root(org.apache.jackrabbit.oak.api.Root) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook)

Aggregations

ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)11 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)10 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)6 Root (org.apache.jackrabbit.oak.api.Root)5 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)5 NamespaceEditorProvider (org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Nonnull (javax.annotation.Nonnull)2 RepositoryException (javax.jcr.RepositoryException)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2 Oak (org.apache.jackrabbit.oak.Oak)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 FilteringNodeState (org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState)2 ReportingNodeState (org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState)2 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)2