Search in sources :

Example 21 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class IndexImporterTest method getFooIndexNodeState.

private NodeState getFooIndexNodeState() throws CommitFailedException {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child("a").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider()));
    NodeState indexed = hook.processCommit(EMPTY_NODE, after, CommitInfo.EMPTY);
    return indexed.getChildNode("oak:index").getChildNode("fooIndex");
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 22 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class PropertyIndexTest method mountWithCommitInWritableMount.

@Test
public void mountWithCommitInWritableMount() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("content").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("foo", "/readOnly").build();
    CompositeHook hook = new CompositeHook(new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))), new EditorHook(new ValidatorProvider() {

        protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
            return new PrivateStoreValidator("/", mip);
        }
    }));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    Mount defMount = mip.getDefaultMount();
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/content", "abc")).exists());
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Mount(org.apache.jackrabbit.oak.spi.mount.Mount) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider) Test(org.junit.Test)

Example 23 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class OrderedPropertyIndexEditorProviderTest method providerShouldBeAvailable.

@Test
public void providerShouldBeAvailable() throws Exception {
    CommitHook hook = new EditorHook(new IndexUpdateProvider(new OrderedPropertyIndexEditorProvider(), null, true));
    NodeBuilder root = EMPTY_NODE.builder();
    createIndexDef(root).setProperty("reindex", false);
    NodeState before = root.getNodeState();
    root.child("foo");
    NodeState after = root.getNodeState();
    hook.processCommit(before, after, CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 24 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class Oak method createNewContentRepository.

private ContentRepository createNewContentRepository() {
    final RepoStateCheckHook repoStateCheckHook = new RepoStateCheckHook();
    final List<Registration> regs = Lists.newArrayList();
    regs.add(whiteboard.register(Executor.class, getExecutor(), Collections.emptyMap()));
    IndexEditorProvider indexEditors = CompositeIndexEditorProvider.compose(indexEditorProviders);
    OakInitializer.initialize(store, new CompositeInitializer(initializers), indexEditors);
    QueryIndexProvider indexProvider = CompositeQueryIndexProvider.compose(queryIndexProviders);
    commitHooks.add(repoStateCheckHook);
    List<CommitHook> initHooks = new ArrayList<CommitHook>(commitHooks);
    initHooks.add(new EditorHook(CompositeEditorProvider.compose(editorProviders)));
    if (asyncTasks != null) {
        IndexMBeanRegistration indexRegistration = new IndexMBeanRegistration(whiteboard);
        regs.add(indexRegistration);
        for (Entry<String, Long> t : asyncTasks.entrySet()) {
            AsyncIndexUpdate task = new AsyncIndexUpdate(t.getKey(), store, indexEditors);
            indexRegistration.registerAsyncIndexer(task, t.getValue());
            closer.register(task);
        }
        PropertyIndexAsyncReindex asyncPI = new PropertyIndexAsyncReindex(new AsyncIndexUpdate(IndexConstants.ASYNC_REINDEX_VALUE, store, indexEditors, true), getExecutor());
        regs.add(registerMBean(whiteboard, PropertyIndexAsyncReindexMBean.class, asyncPI, PropertyIndexAsyncReindexMBean.TYPE, "async"));
    }
    if (NodeCounter.USE_OLD_COUNTER) {
        regs.add(registerMBean(whiteboard, NodeCounterMBean.class, new NodeCounterOld(store), NodeCounterMBean.TYPE, "nodeCounter"));
    } else {
        regs.add(registerMBean(whiteboard, NodeCounterMBean.class, new NodeCounter(store), NodeCounterMBean.TYPE, "nodeCounter"));
    }
    regs.add(registerMBean(whiteboard, QueryEngineSettingsMBean.class, queryEngineSettings, QueryEngineSettingsMBean.TYPE, "settings"));
    regs.add(registerMBean(whiteboard, QueryStatsMBean.class, queryEngineSettings.getQueryStats(), QueryStatsMBean.TYPE, "Oak Query Statistics (Extended)"));
    // FIXME: OAK-810 move to proper workspace initialization
    // initialize default workspace
    Iterable<WorkspaceInitializer> workspaceInitializers = Iterables.transform(securityProvider.getConfigurations(), new Function<SecurityConfiguration, WorkspaceInitializer>() {

        @Override
        public WorkspaceInitializer apply(SecurityConfiguration sc) {
            WorkspaceInitializer wi = sc.getWorkspaceInitializer();
            if (wi instanceof QueryIndexProviderAware) {
                ((QueryIndexProviderAware) wi).setQueryIndexProvider(indexProvider);
            }
            return wi;
        }
    });
    OakInitializer.initialize(workspaceInitializers, store, defaultWorkspaceName, indexEditors);
    // add index hooks later to prevent the OakInitializer to do excessive indexing
    with(new IndexUpdateProvider(indexEditors, failOnMissingIndexProvider));
    withEditorHook();
    // Register observer last to prevent sending events while initialising
    for (Observer observer : observers) {
        regs.add(whiteboard.register(Observer.class, observer, emptyMap()));
    }
    RepositoryManager repositoryManager = new RepositoryManager(whiteboard);
    regs.add(registerMBean(whiteboard, RepositoryManagementMBean.class, repositoryManager, RepositoryManagementMBean.TYPE, repositoryManager.getName()));
    CommitHook composite = CompositeHook.compose(commitHooks);
    regs.add(whiteboard.register(CommitHook.class, composite, Collections.emptyMap()));
    final Tracker<Descriptors> t = whiteboard.track(Descriptors.class);
    return new ContentRepositoryImpl(store, composite, defaultWorkspaceName, queryEngineSettings.unwrap(), indexProvider, securityProvider, new AggregatingDescriptors(t)) {

        @Override
        public void close() throws IOException {
            super.close();
            repoStateCheckHook.close();
            new CompositeRegistration(regs).unregister();
            closer.close();
        }
    };
}
Also used : ContentRepositoryImpl(org.apache.jackrabbit.oak.core.ContentRepositoryImpl) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NodeCounter(org.apache.jackrabbit.oak.plugins.index.counter.jmx.NodeCounter) Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IndexMBeanRegistration(org.apache.jackrabbit.oak.plugins.index.IndexMBeanRegistration) CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration) IndexMBeanRegistration(org.apache.jackrabbit.oak.plugins.index.IndexMBeanRegistration) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) AggregatingDescriptors(org.apache.jackrabbit.oak.spi.descriptors.AggregatingDescriptors) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) OrderedPropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) RepositoryManager(org.apache.jackrabbit.oak.management.RepositoryManager) PropertyIndexAsyncReindex(org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindex) AggregatingDescriptors(org.apache.jackrabbit.oak.spi.descriptors.AggregatingDescriptors) Descriptors(org.apache.jackrabbit.oak.api.Descriptors) QueryIndexProviderAware(org.apache.jackrabbit.oak.spi.query.QueryIndexProviderAware) PropertyIndexAsyncReindexMBean(org.apache.jackrabbit.oak.plugins.index.property.jmx.PropertyIndexAsyncReindexMBean) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) CompositeInitializer(org.apache.jackrabbit.oak.spi.lifecycle.CompositeInitializer) QueryStatsMBean(org.apache.jackrabbit.oak.query.stats.QueryStatsMBean) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) NodeCounterMBean(org.apache.jackrabbit.oak.plugins.index.counter.jmx.NodeCounterMBean) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) CompositeQueryIndexProvider(org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider) QueryEngineSettingsMBean(org.apache.jackrabbit.oak.api.jmx.QueryEngineSettingsMBean) RepositoryManagementMBean(org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean) WorkspaceInitializer(org.apache.jackrabbit.oak.spi.lifecycle.WorkspaceInitializer) NodeCounterOld(org.apache.jackrabbit.oak.plugins.index.counter.jmx.NodeCounterOld) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) CompositeRegistration(org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration)

Aggregations

IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)24 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)14 Test (org.junit.Test)13 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 Before (org.junit.Before)6 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)4 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)3 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)3 LuceneIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider)3 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)2 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)2 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1