use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.
the class AwaitIndexProcedureTest method shouldBlockUntilTheIndexIsOnline.
@Test
void shouldBlockUntilTheIndexIsOnline() throws IndexNotFoundKernelException, InterruptedException {
when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(Iterators.iterator(anyIndex));
when(schemaRead.indexGetForName(anyString())).thenReturn(anyIndex);
AtomicReference<InternalIndexState> state = new AtomicReference<>(POPULATING);
when(schemaRead.indexGetState(any(IndexDescriptor.class))).then(invocationOnMock -> state.get());
AtomicBoolean done = new AtomicBoolean(false);
var thread = new Thread(() -> {
try {
procedure.awaitIndexByName("index", TIMEOUT, TIME_UNIT);
} catch (ProcedureException e) {
throw new RuntimeException(e);
}
done.set(true);
});
thread.start();
assertThat(done.get()).isFalse();
state.set(ONLINE);
thread.join();
assertThat(done.get()).isTrue();
}
use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.
the class IndexingService method init.
/**
* Called while the database starts up, before recovery.
*/
@Override
public void init() throws IOException {
validateDefaultProviderExisting();
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(INIT_TAG))) {
indexMapRef.modify(indexMap -> {
Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
for (IndexDescriptor descriptor : indexDescriptors) {
// No index (except NLI) is allowed to have the name generated for NLI.
if (descriptor.getName().equals(IndexDescriptor.NLI_GENERATED_NAME) && !(descriptor.schema().isAnyTokenSchemaDescriptor() && descriptor.schema().entityType() == NODE)) {
throw new IllegalStateException("Index '" + descriptor.userDescription(tokenNameLookup) + "' is using a reserved name: '" + IndexDescriptor.NLI_GENERATED_NAME + "'. This index must be removed on an earlier version " + "to be able to use binaries for version 4.3 or newer.");
}
IndexProxy indexProxy;
IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
IndexProvider provider = providerMap.lookup(providerDescriptor);
InternalIndexState initialState = provider.getInitialState(descriptor, cursorContext);
indexStates.computeIfAbsent(initialState, internalIndexState -> new ArrayList<>()).add(new IndexLogRecord(descriptor));
internalLog.debug(indexStateInfo("init", initialState, descriptor));
switch(initialState) {
case ONLINE:
monitor.initialState(databaseName, descriptor, ONLINE);
indexProxy = indexProxyCreator.createOnlineIndexProxy(descriptor);
break;
case POPULATING:
// The database was shut down during population, or a crash has occurred, or some other sad thing.
monitor.initialState(databaseName, descriptor, POPULATING);
indexProxy = indexProxyCreator.createRecoveringIndexProxy(descriptor);
break;
case FAILED:
monitor.initialState(databaseName, descriptor, FAILED);
IndexPopulationFailure failure = failure(provider.getPopulationFailure(descriptor, cursorContext));
indexProxy = indexProxyCreator.createFailedIndexProxy(descriptor, failure);
break;
default:
throw new IllegalArgumentException("" + initialState);
}
indexMap.putIndexProxy(indexProxy);
}
logIndexStateSummary("init", indexStates);
return indexMap;
});
}
indexStatisticsStore.init();
}
use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.
the class IndexProviderTests method shouldReportCorrectInitialStateIfIndexDoesntExist.
/* getInitialState */
// pattern: open populator, markAsFailed, close populator, getInitialState, getPopulationFailure
@Test
void shouldReportCorrectInitialStateIfIndexDoesntExist() {
// given
provider = newProvider();
// when
InternalIndexState state = provider.getInitialState(descriptor(), NULL);
// then
assertEquals(InternalIndexState.POPULATING, state);
assertThat(logging).containsMessages("Failed to open index");
}
use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.
the class IndexProviderTests method shouldReportInitialStateAsOnlineIfPopulationCompletedSuccessfully.
@Test
void shouldReportInitialStateAsOnlineIfPopulationCompletedSuccessfully() throws IOException {
// given
provider = newProvider();
IndexPopulator populator = provider.getPopulator(descriptor(), samplingConfig(), heapBufferFactory(1024), INSTANCE, tokenNameLookup);
populator.create();
populator.close(true, NULL);
// when
InternalIndexState state = provider.getInitialState(descriptor(), NULL);
// then
assertEquals(InternalIndexState.ONLINE, state);
}
use of org.neo4j.internal.kernel.api.InternalIndexState in project neo4j by neo4j.
the class SchemaStatementProcedure method includeIndex.
private static boolean includeIndex(SchemaReadCore schemaRead, IndexDescriptor index) {
try {
InternalIndexState indexState = schemaRead.indexGetState(index);
boolean relationshipPropertyIndex = index.getIndexType().equals(IndexType.BTREE) && index.schema().entityType().equals(EntityType.RELATIONSHIP);
return indexState == InternalIndexState.ONLINE && !index.isUnique() && !index.isTokenIndex() && !relationshipPropertyIndex;
} catch (IndexNotFoundKernelException e) {
return false;
}
}
Aggregations