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