Search in sources :

Example 1 with IndexPopulationFailedKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method executorShutdownAfterStoreScanCompletes.

@Test
public void executorShutdownAfterStoreScanCompletes() throws Exception {
    NodeUpdates update = nodeUpdates(1, propertyId, "foo", labelId);
    IndexStoreView storeView = newStoreView(update);
    ExecutorService executor = mock(ExecutorService.class);
    when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
    StoreScan<IndexPopulationFailedKernelException> storeScan = batchingPopulator.indexAllNodes();
    verify(executor, never()).shutdown();
    storeScan.run();
    verify(executor).shutdown();
    verify(executor).awaitTermination(anyLong(), any());
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 2 with IndexPopulationFailedKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method executorForcefullyShutdownIfStoreScanFails.

@Test
@SuppressWarnings("unchecked")
public void executorForcefullyShutdownIfStoreScanFails() throws Exception {
    IndexStoreView storeView = mock(IndexStoreView.class);
    StoreScan<Exception> failingStoreScan = mock(StoreScan.class);
    RuntimeException scanError = new RuntimeException();
    doThrow(scanError).when(failingStoreScan).run();
    when(storeView.visitNodes(any(), any(), any(), any(), anyBoolean())).thenReturn(failingStoreScan);
    ExecutorService executor = mock(ExecutorService.class);
    when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
    StoreScan<IndexPopulationFailedKernelException> storeScan = batchingPopulator.indexAllNodes();
    verify(executor, never()).shutdown();
    try {
        storeScan.run();
        fail("Exception expected");
    } catch (Throwable t) {
        assertSame(scanError, t);
    }
    verify(executor).shutdownNow();
    verify(executor).awaitTermination(anyLong(), any());
}
Also used : NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) ExecutorService(java.util.concurrent.ExecutorService) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) Test(org.junit.Test)

Example 3 with IndexPopulationFailedKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.

@Test
void shouldDropIndexIfPopulationFails() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(indexProxy.getDescriptor()).thenReturn(index);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX, index);
    IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));
    doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
    when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(// first claim it doesn't exist, because it doesn't... so
    Iterators.emptyResourceIterator()).thenReturn(// then after it failed claim it does exist
    Iterators.iterator(index));
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    UniquePropertyValueValidationException exception = assertThrows(UniquePropertyValueValidationException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
    assertEquals("Existing data does not satisfy Constraint( name='constraint', type='UNIQUENESS', schema=(:Label {prop}) ): " + "Both node 2 and node 1 share the property value ( String(\"a\") )", exception.getMessage());
    assertEquals(2, kernel.transactions.size());
    KernelTransactionImplementation tx1 = kernel.transactions.get(0);
    verify(tx1).indexUniqueCreate(prototype);
    verify(schemaRead, times(2)).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
    KernelTransactionImplementation kti2 = kernel.transactions.get(1);
    verify(kti2).addIndexDoDropToTxState(index);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Test(org.junit.jupiter.api.Test)

Example 4 with IndexPopulationFailedKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.

the class MultipleIndexPopulator method indexAllNodes.

public StoreScan<IndexPopulationFailedKernelException> indexAllNodes() {
    int[] labelIds = labelIds();
    int[] propertyKeyIds = propertyKeyIds();
    IntPredicate propertyKeyIdFilter = (propertyKeyId) -> contains(propertyKeyIds, propertyKeyId);
    storeScan = storeView.visitNodes(labelIds, propertyKeyIdFilter, new NodePopulationVisitor(), null, false);
    storeScan.configure(populations);
    return storeScan;
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) Log(org.neo4j.logging.Log) PrimitiveIntCollections.contains(org.neo4j.collection.primitive.PrimitiveIntCollections.contains) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) IntPredicate(java.util.function.IntPredicate) Pair(org.neo4j.helpers.collection.Pair) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Map(java.util.Map) FeatureToggles(org.neo4j.unsafe.impl.internal.dragons.FeatureToggles) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) IndexPopulationFailure.failure(org.neo4j.kernel.impl.api.index.IndexPopulationFailure.failure) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) Collection(java.util.Collection) FlipFailedKernelException(org.neo4j.kernel.api.exceptions.index.FlipFailedKernelException) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IOException(java.io.IOException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) String.format(java.lang.String.format) List(java.util.List) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Descriptor(org.neo4j.kernel.api.index.SchemaIndexProvider.Descriptor) Optional(java.util.Optional) Queue(java.util.Queue) Visitor(org.neo4j.helpers.collection.Visitor) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IntPredicate(java.util.function.IntPredicate)

Example 5 with IndexPopulationFailedKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem.

@Test
public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem() throws IOException, IndexNotFoundKernelException, IndexPopulationFailedKernelException, IndexActivationFailedKernelException {
    // given
    final BatchTransactionApplier applier = newIndexApplier();
    doThrow(new IndexNotFoundKernelException("")).when(indexingService).activateIndex(anyLong());
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final IndexRule rule = constraintIndexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"), 42L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    try {
        apply(applier, command::handle, transactionToApply);
        fail("should have thrown");
    } catch (Exception e) {
        // then
        assertTrue(e.getCause() instanceof IndexNotFoundKernelException);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) IOException(java.io.IOException) IndexActivationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException) Test(org.junit.Test)

Aggregations

IndexPopulationFailedKernelException (org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException)7 Test (org.junit.Test)4 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)3 IOException (java.io.IOException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Visitor (org.neo4j.helpers.collection.Visitor)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1