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);
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations