Search in sources :

Example 6 with IndexNotFoundKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException in project neo4j by neo4j.

the class LookupAccessorsFromRunningDb method apply.

@Override
public IndexAccessor apply(IndexDescriptor indexDescriptor) {
    try {
        IndexProxy proxy = indexingService.getIndexProxy(indexDescriptor);
        while (proxy instanceof AbstractDelegatingIndexProxy) {
            proxy = ((AbstractDelegatingIndexProxy) proxy).getDelegate();
        }
        assertEquals(InternalIndexState.ONLINE, proxy.getState());
        return ((OnlineIndexProxy) proxy).accessor();
    } catch (IndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : OnlineIndexProxy(org.neo4j.kernel.impl.api.index.OnlineIndexProxy) AbstractDelegatingIndexProxy(org.neo4j.kernel.impl.api.index.AbstractDelegatingIndexProxy) AbstractDelegatingIndexProxy(org.neo4j.kernel.impl.api.index.AbstractDelegatingIndexProxy) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) OnlineIndexProxy(org.neo4j.kernel.impl.api.index.OnlineIndexProxy) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)

Example 7 with IndexNotFoundKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException in project neo4j by neo4j.

the class CheckerTestBase method labelIndexWriter.

IndexUpdater labelIndexWriter() {
    IndexingService indexingService = db.getDependencyResolver().resolveDependency(IndexingService.class);
    final IndexDescriptor[] indexDescriptors = schemaStorage.indexGetForSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE), CursorContext.NULL);
    // The Node Label Index should exist and be unique.
    assertThat(indexDescriptors.length).isEqualTo(1);
    IndexDescriptor nli = indexDescriptors[0];
    IndexProxy indexProxy;
    try {
        indexProxy = indexingService.getIndexProxy(nli);
    } catch (IndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
    return indexProxy.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 8 with IndexNotFoundKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    // when
    var indexReader = accessor.newValueReader();
    BinaryLatch dropLatch = new BinaryLatch();
    BinaryLatch sampleLatch = new BinaryLatch();
    LuceneIndexSampler indexSampler = spy((LuceneIndexSampler) indexReader.createSampler());
    doAnswer(inv -> {
        var obj = inv.callRealMethod();
        // We have now started the sampling, let the index try to drop
        dropLatch.release();
        // Wait for the drop to be blocked
        sampleLatch.await();
        return obj;
    }).when(indexSampler).newTask();
    List<Future<?>> futures = new ArrayList<>();
    try (var reader = indexReader;
        /* do not inline! */
        IndexSampler sampler = indexSampler) /* do not inline! */
    {
        futures.add(threading.execute((IOFunction<Void, Void>) nothing -> {
            try {
                indexSampler.sampleIndex(NULL);
                fail("expected exception");
            } catch (IndexNotFoundKernelException e) {
                assertEquals("Index dropped while sampling.", e.getMessage());
            } finally {
                dropLatch.release();
            }
            return nothing;
        }, null));
        futures.add(threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
            dropLatch.await();
            accessor.drop();
            return nothing;
        }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 10, MINUTES));
    } finally {
        // drop is blocked, okay to finish sampling (will fail since index is dropped)
        sampleLatch.release();
        for (Future<?> future : futures) {
            future.get();
        }
    }
}
Also used : IOFunction(org.neo4j.function.IOFunction) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) Test(org.junit.Test)

Example 9 with IndexNotFoundKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException in project neo4j by neo4j.

the class UniqueDatabaseIndexSamplerTest method uniqueSamplingCancel.

@Test
void uniqueSamplingCancel() {
    when(indexSearcher.getIndexReader().numDocs()).thenAnswer(invocation -> {
        taskControl.cancel();
        return 17;
    });
    UniqueLuceneIndexSampler sampler = new UniqueLuceneIndexSampler(indexSearcher, taskControl);
    IndexNotFoundKernelException notFoundKernelException = assertThrows(IndexNotFoundKernelException.class, () -> sampler.sampleIndex(NULL));
    assertEquals("Index dropped while sampling.", notFoundKernelException.getMessage());
}
Also used : IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Test(org.junit.jupiter.api.Test)

Example 10 with IndexNotFoundKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException in project neo4j by neo4j.

the class SchemaImpl method awaitIndexesOnline.

private boolean awaitIndexesOnline(Iterable<IndexDescriptor> indexes, Function<IndexDescriptor, String> describe, long duration, TimeUnit unit, boolean bubbleNotFound) {
    Stopwatch startTime = Stopwatch.start();
    do {
        boolean allOnline = true;
        SchemaRead schemaRead = transaction.schemaRead();
        for (IndexDescriptor index : indexes) {
            if (index == IndexDescriptor.NO_INDEX) {
                allOnline = false;
                break;
            }
            try {
                InternalIndexState indexState = schemaRead.indexGetState(index);
                if (indexState == InternalIndexState.POPULATING) {
                    allOnline = false;
                    break;
                }
                if (indexState == InternalIndexState.FAILED) {
                    String cause = schemaRead.indexGetFailure(index);
                    String message = "Index " + describe.apply(index) + " entered a " + indexState + " state. Please see database logs.";
                    message = IndexPopulationFailure.appendCauseOfFailure(message, cause);
                    throw new IllegalStateException(message);
                }
            } catch (IndexNotFoundKernelException e) {
                if (bubbleNotFound) {
                    throw newIndexNotFoundException(descriptorToDefinition(transaction.tokenRead(), index), e);
                }
                // Weird that the index vanished, but we'll just wait and see if it comes back until we time out.
                allOnline = false;
                break;
            }
        }
        if (allOnline) {
            return false;
        }
        sleepIgnoreInterrupt();
    } while (!startTime.hasTimedOut(duration, unit));
    return true;
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stopwatch(org.neo4j.time.Stopwatch) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Aggregations

IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)21 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)13 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)5 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 CursorContext (org.neo4j.io.pagecache.context.CursorContext)4 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)4 IOException (java.io.IOException)3 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 UncheckedIOException (java.io.UncheckedIOException)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 EntityType (org.neo4j.common.EntityType)2 Iterators (org.neo4j.internal.helpers.collection.Iterators)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2