Search in sources :

Example 11 with InternalIndexState

use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationFailingWithFileNotFoundException.

@Test
void shouldRequestIndexPopulationFailingWithFileNotFoundException() {
    // Given
    long faultyIndexId = 1;
    NoSuchFileException error = new NoSuchFileException("/some/path/somewhere");
    LuceneIndexProvider provider = newFaultyIndexProvider(faultyIndexId, error);
    // When
    IndexDescriptor descriptor = forSchema(forLabel(1, 1), provider.getProviderDescriptor()).withName("index_" + faultyIndexId).materialise(faultyIndexId);
    InternalIndexState initialState = provider.getInitialState(descriptor, NULL);
    // Then
    assertThat(initialState).isEqualTo(InternalIndexState.POPULATING);
    assertThat(logProvider).containsException(error);
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) NoSuchFileException(java.nio.file.NoSuchFileException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with InternalIndexState

use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationIfTheIndexIsCorrupt.

@Test
void shouldRequestIndexPopulationIfTheIndexIsCorrupt() {
    // Given
    long faultyIndexId = 1;
    CorruptIndexException error = new CorruptIndexException("It's broken.", "");
    LuceneIndexProvider provider = newFaultyIndexProvider(faultyIndexId, error);
    // When
    IndexDescriptor descriptor = forSchema(forLabel(1, 1), provider.getProviderDescriptor()).withName("index_" + faultyIndexId).materialise(faultyIndexId);
    InternalIndexState initialState = provider.getInitialState(descriptor, NULL);
    // Then
    assertThat(initialState).isEqualTo(InternalIndexState.POPULATING);
    assertThat(logProvider).containsException(error);
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 13 with InternalIndexState

use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationWhenFailingWithEOFException.

@Test
void shouldRequestIndexPopulationWhenFailingWithEOFException() {
    // Given
    long faultyIndexId = 1;
    EOFException error = new EOFException("/some/path/somewhere");
    LuceneIndexProvider provider = newFaultyIndexProvider(faultyIndexId, error);
    // When
    IndexDescriptor descriptor = forSchema(forLabel(1, 1), provider.getProviderDescriptor()).withName("index_" + faultyIndexId).materialise(faultyIndexId);
    InternalIndexState initialState = provider.getInitialState(descriptor, NULL);
    // Then
    assertThat(initialState).isEqualTo(InternalIndexState.POPULATING);
    assertThat(logProvider).containsException(error);
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) EOFException(java.io.EOFException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 14 with InternalIndexState

use of org.neo4j.internal.kernel.api.InternalIndexState 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)

Example 15 with InternalIndexState

use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.

the class SchemaImpl method getIndexState.

@Override
public IndexState getIndexState(final IndexDefinition index) {
    try {
        transaction.assertOpen();
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor reference = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
        InternalIndexState indexState = schemaRead.indexGetState(reference);
        switch(indexState) {
            case POPULATING:
                return POPULATING;
            case ONLINE:
                return ONLINE;
            case FAILED:
                return FAILED;
            default:
                throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
        }
    } catch (KernelException e) {
        throw newIndexNotFoundException(index, e);
    }
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)25 Test (org.junit.jupiter.api.Test)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)16 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)7 TokenRead (org.neo4j.internal.kernel.api.TokenRead)7 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)7 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)5 ArrayList (java.util.ArrayList)3 EnumMap (java.util.EnumMap)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 MutableLongObjectMap (org.eclipse.collections.api.map.primitive.MutableLongObjectMap)3 LongObjectHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)3 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 String.format (java.lang.String.format)2 Path (java.nio.file.Path)2 Arrays (java.util.Arrays)2