Search in sources :

Example 11 with AsyncIndexUpdate

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

the class IndexImporterTest method importData_IncrementalUpdate.

@Test
public void importData_IncrementalUpdate() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    new AsyncIndexUpdate("async", store, provider).run();
    String checkpoint = createIndexDirs("/oak:index/fooIndex");
    builder = store.getRoot().builder();
    builder.child("c").setProperty("foo", "abc");
    builder.child("d").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    new AsyncIndexUpdate("async", store, provider).run();
    FilterImpl f = createFilter(store.getRoot(), NT_BASE);
    PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
    assertEquals(of("a", "b", "c", "d"), find(lookup, "foo", "abc", f));
    IndexImporterProvider importerProvider = new IndexImporterProvider() {

        @Override
        public void importIndex(NodeState root, NodeBuilder defn, File indexDir) {
            assertEquals("fooIndex", indexDir.getName());
            assertEquals(2, defn.getProperty(REINDEX_COUNT).getValue(Type.LONG).longValue());
            defn.getChildNode(IndexConstants.INDEX_CONTENT_NODE_NAME).remove();
            NodeState cpState = store.retrieve(checkpoint);
            NodeState indexData = NodeStateUtils.getNode(cpState, "/oak:index/fooIndex/:index");
            defn.setChildNode(IndexConstants.INDEX_CONTENT_NODE_NAME, indexData);
        }

        @Override
        public String getType() {
            return "property";
        }
    };
    builder = store.getRoot().builder();
    builder.child("e").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    IndexImporter importer = new IndexImporter(store, temporaryFolder.getRoot(), provider, NOOP_LOCK);
    importer.addImporterProvider(importerProvider);
    importer.addImporterProvider(importerProvider);
    importer.importIndex();
    NodeState idx = store.getRoot().getChildNode("oak:index").getChildNode("fooIndex");
    assertEquals("async", idx.getString("async"));
    lookup = new PropertyIndexLookup(store.getRoot());
    // It would not pickup /e as thats not yet indexed as part of last checkpoint
    assertEquals(of("a", "b", "c", "d"), find(lookup, "foo", "abc", f));
    assertNull(store.retrieve(checkpoint));
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) PropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Example 12 with AsyncIndexUpdate

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

the class IndexImporterTest method importData_DisabledIndexes.

@Test
public void importData_DisabledIndexes() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder idxa = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null);
    idxa.setProperty(ASYNC_PROPERTY_NAME, "async");
    idxa.setProperty(IndexConstants.SUPERSEDED_INDEX_PATHS, asList("/oak:index/barIndex"), Type.STRINGS);
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    new AsyncIndexUpdate("async", store, provider).run();
    String checkpoint = createIndexDirs("/oak:index/fooIndex");
    builder = store.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "barIndex", true, false, ImmutableSet.of("foo"), null);
    builder.child("c").setProperty("foo", "abc");
    builder.child("d").setProperty("foo", "abc");
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    new AsyncIndexUpdate("async", store, provider).run();
    IndexImporterProvider importerProvider = new IndexImporterProvider() {

        @Override
        public void importIndex(NodeState root, NodeBuilder defn, File indexDir) {
        }

        @Override
        public String getType() {
            return "property";
        }
    };
    IndexImporter importer = new IndexImporter(store, temporaryFolder.getRoot(), provider, NOOP_LOCK);
    importer.addImporterProvider(importerProvider);
    importer.importIndex();
    NodeState idx = store.getRoot().getChildNode("oak:index").getChildNode("barIndex");
    assertEquals(TYPE_DISABLED, idx.getString(TYPE_PROPERTY_NAME));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Example 13 with AsyncIndexUpdate

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

the class AsyncPropertyIndexTest method testAsyncPropertyLookup.

@Test
public void testAsyncPropertyLookup() throws Exception {
    NodeStore store = new MemoryNodeStore();
    assertTrue(Iterables.isEmpty(store.checkpoints()));
    NodeBuilder builder = store.getRoot().builder();
    // add a property index on 'foo'
    NodeBuilder def = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, of("foo"), null);
    def.setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
    // add some content
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), STRINGS);
    NodeState head = store.merge(builder, hook, EMPTY);
    // query the index, check it doesn't get indexed by the normal PI
    FilterImpl f = createFilter(head, NT_BASE);
    PropertyIndexLookup lookup = new PropertyIndexLookup(head);
    try {
        assertEquals(of(), find(lookup, "foo", "abc", f));
        fail();
    } catch (IllegalArgumentException e) {
    // expected: no index for "foo"
    }
    // run async first time, there are some changes
    AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
    async.run();
    assertEquals(ASYNC_REINDEX_VALUE, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
    // run async second time, there are no changes, should switch to sync
    async.run();
    async.close();
    assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME).getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
    assertTrue(Iterables.isEmpty(store.checkpoints()));
    // add content, it should be indexed synchronously
    builder = store.getRoot().builder();
    builder.child("c").setProperty("foo", "def");
    head = store.merge(builder, hook, EMPTY);
    f = createFilter(head, NT_BASE);
    lookup = new PropertyIndexLookup(head);
    assertEquals(ImmutableSet.of("b", "c"), find(lookup, "foo", "def", f));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with AsyncIndexUpdate

use of org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate 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

AsyncIndexUpdate (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate)14 Test (org.junit.Test)9 File (java.io.File)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)6 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)6 QueryIndexProvider (org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)4 InitialContent (org.apache.jackrabbit.oak.InitialContent)3 Oak (org.apache.jackrabbit.oak.Oak)3 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)3 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)3 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)3 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)2 DataStoreBlobStore (org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)2 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)2 ExtractedTextCache (org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCache)2 IndexCopier (org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier)2