Search in sources :

Example 1 with AsyncIndexUpdate

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

the class AsyncPropertyIndexTest method testAsyncPropertyNoChanges.

@Test
public void testAsyncPropertyNoChanges() throws Exception {
    NodeStore store = new MemoryNodeStore();
    assertTrue(Iterables.isEmpty(store.checkpoints()));
    AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
    async.run();
    async.run();
    async.close();
    assertTrue(Iterables.isEmpty(store.checkpoints()));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) Test(org.junit.Test)

Example 2 with AsyncIndexUpdate

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

the class OakTest method closeAsyncIndexers.

@Test
public void closeAsyncIndexers() throws Exception {
    final AtomicReference<AsyncIndexUpdate> async = new AtomicReference<AsyncIndexUpdate>();
    Whiteboard wb = new DefaultWhiteboard() {

        @Override
        public <T> Registration register(Class<T> type, T service, Map<?, ?> properties) {
            if (service instanceof AsyncIndexUpdate) {
                async.set((AsyncIndexUpdate) service);
            }
            return super.register(type, service, properties);
        }
    };
    Oak oak = new Oak().with(new OpenSecurityProvider()).with(wb).withAsyncIndexing("foo-async", 5);
    ContentRepository repo = oak.createContentRepository();
    ((Closeable) repo).close();
    assertNotNull(async.get());
    assertTrue(async.get().isClosed());
    assertNull(WhiteboardUtils.getService(wb, AsyncIndexUpdate.class));
}
Also used : DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Map(java.util.Map) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Example 3 with AsyncIndexUpdate

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

the class IndexImporterTest method laneUnlockedInCaseOfFailure.

@Test
public void laneUnlockedInCaseOfFailure() 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();
    IndexImporterProvider importerProvider = new IndexImporterProvider() {

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

        @Override
        public String getType() {
            return "property";
        }
    };
    final String exceptionMessage = "TEST MESSAGE";
    ClusterNodeStoreLock lock = new ClusterNodeStoreLock(store);
    provider = new PropertyIndexEditorProvider() {

        @Override
        public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) {
            throw new RuntimeException(exceptionMessage);
        }
    };
    IndexImporter importer = new IndexImporter(store, temporaryFolder.getRoot(), provider, lock);
    importer.addImporterProvider(importerProvider);
    try {
        importer.importIndex();
        fail();
    } catch (RuntimeException ignore) {
    }
    assertFalse(lock.isLocked("async"));
    AsyncIndexerLock lock2 = new AsyncIndexerLock() {

        @Override
        public LockToken lock(String asyncIndexerLane) throws CommitFailedException {
            return mock(LockToken.class);
        }

        @Override
        public void unlock(LockToken token) throws CommitFailedException {
            throw new IllegalStateException("Exception in unlock");
        }
    };
    IndexImporter importer2 = new IndexImporter(store, temporaryFolder.getRoot(), provider, lock2);
    importer2.addImporterProvider(importerProvider);
    try {
        importer2.importIndex();
        fail();
    } catch (RuntimeException ignore) {
        assertEquals(exceptionMessage, ignore.getMessage());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) File(java.io.File) Test(org.junit.Test)

Example 4 with AsyncIndexUpdate

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

the class ActiveDeletedBlobCollectionIT method createRepository.

@Override
protected ContentRepository createRepository() {
    adbc = new ActiveDeletedBlobCollectorImpl(clock, new File(blobCollectionRoot.getRoot(), "deleted-blobs"), executorService);
    IndexCopier copier = createIndexCopier();
    editorProvider = new LuceneIndexEditorProvider(copier, null, new ExtractedTextCache(10 * FileUtils.ONE_MB, 100), null, Mounts.defaultMountInfoProvider(), adbc);
    provider = new LuceneIndexProvider(copier);
    mongoConnection = connectionFactory.getConnection();
    MongoUtils.dropCollections(mongoConnection.getDatabase());
    if (dataStoreType == DataStoreType.WITHOUT_FDS) {
        MongoBlobStore blobStore = new MongoBlobStore(mongoConnection.getDatabase());
        blobStore.setBlockSize(128);
        blobStore.setBlockSizeMin(48);
        this.blobStore = new CountingBlobStore(blobStore);
    } else {
        FileDataStore fds = new FileDataStore();
        fds.init(fileDataStoreRoot.getRoot().getAbsolutePath());
        DataStoreBlobStore dsbs = new DataStoreBlobStore(fds);
        dsbs.setBlockSize(128);
        this.blobStore = new CountingBlobStore(dsbs);
    }
    nodeStore = new DocumentMK.Builder().setMongoDB(mongoConnection.getMongoClient(), mongoConnection.getDBName()).setBlobStore(this.blobStore).getNodeStore();
    asyncIndexUpdate = new AsyncIndexUpdate("async", nodeStore, editorProvider);
    return new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(editorProvider).createContentRepository();
}
Also used : MongoBlobStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore) ActiveDeletedBlobCollectorImpl(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollectorImpl) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) IndexCopier(org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider) ExtractedTextCache(org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCache) InitialContent(org.apache.jackrabbit.oak.InitialContent) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) Oak(org.apache.jackrabbit.oak.Oak) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) File(java.io.File) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

Example 5 with AsyncIndexUpdate

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

the class ActiveDeletedBlobSyncTrackerTest method createRepository.

@Override
protected ContentRepository createRepository() {
    try {
        File blobCollectorDeleted = new File(blobCollectionRoot.getRoot(), "deleted-blobs");
        blobCollectorDeleted.mkdirs();
        adbc = new ActiveDeletedBlobCollectorImpl(clock, new File(blobCollectionRoot.getRoot(), "deleted-blobs"), executorService);
        IndexCopier copier = createIndexCopier();
        editorProvider = new LuceneIndexEditorProvider(copier, null, new ExtractedTextCache(10 * FileUtils.ONE_MB, 100), null, Mounts.defaultMountInfoProvider(), adbc);
        provider = new LuceneIndexProvider(copier);
        OakFileDataStore ds = new OakFileDataStore();
        ds.setMinRecordLength(10);
        ds.init(fileDataStoreRoot.getRoot().getAbsolutePath());
        DataStoreBlobStore dsbs = new DataStoreBlobStore(ds);
        this.blobStore = new AbstractActiveDeletedBlobTest.CountingBlobStore(dsbs);
        FileStore store = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMemoryMapping(false).withBlobStore(blobStore).build();
        nodeStore = SegmentNodeStoreBuilders.builder(store).build();
        BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore;
        trackingStore.addTracker(new BlobIdTracker(blobTrackerRoot.getRoot().getAbsolutePath(), getOrCreateId(nodeStore), 600, dsbs));
        // set the blob store to skip writing blobs through the node store
        editorProvider.setBlobStore(blobStore);
        asyncIndexUpdate = new AsyncIndexUpdate("async", nodeStore, editorProvider);
        return new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(editorProvider).createContentRepository();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) ActiveDeletedBlobCollectorImpl(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollectorImpl) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) IndexCopier(org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier) IOException(java.io.IOException) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider) ExtractedTextCache(org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCache) InitialContent(org.apache.jackrabbit.oak.InitialContent) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) BlobIdTracker(org.apache.jackrabbit.oak.plugins.blob.datastore.BlobIdTracker) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) BlobTrackingStore(org.apache.jackrabbit.oak.plugins.blob.BlobTrackingStore) Oak(org.apache.jackrabbit.oak.Oak) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) File(java.io.File) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore)

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