Search in sources :

Example 1 with IndexEntryUpdate

use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.

the class NodeStoreScanTest method shouldGiveBackCompletionPercentage.

@Test
public void shouldGiveBackCompletionPercentage() throws Throwable {
    // given
    final int total = 10;
    when(nodeStore.getHighId()).thenReturn((long) total);
    NodeRecord inUseRecord = new NodeRecord(42);
    inUseRecord.setInUse(true);
    when(nodeStore.getRecord(anyLong(), any(NodeRecord.class), any(RecordLoad.class))).thenReturn(inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord);
    final PercentageSupplier percentageSupplier = new PercentageSupplier();
    final NodeStoreScan scan = new NodeStoreScan(nodeStore, locks, total) {

        private int read = 0;

        @Override
        public void acceptUpdate(MultipleIndexPopulator.MultipleIndexUpdater updater, IndexEntryUpdate update, long currentlyIndexedNodeId) {
        // no-op
        }

        @Override
        public void configure(List list) {
        // no-op
        }

        @Override
        public void process(NodeRecord node) {
            // then
            read++;
            float expected = (float) read / total;
            float actual = percentageSupplier.get();
            assertEquals(String.format("%f==%f", expected, actual), expected, actual, 0.0);
        }
    };
    percentageSupplier.setStoreScan(scan);
    // when
    scan.run();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStoreScan(org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) List(java.util.List) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) Test(org.junit.Test)

Example 2 with IndexEntryUpdate

use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.

the class IndexingServiceTest method shouldDeliverUpdatesThatOccurDuringPopulationToPopulator.

@SuppressWarnings("unchecked")
@Test
public void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Exception {
    // given
    when(populator.newPopulatingUpdater(storeView)).thenReturn(updater);
    CountDownLatch latch = new CountDownLatch(1);
    doAnswer(afterAwaiting(latch)).when(populator).add(anyList());
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(1, "value1")));
    life.start();
    // when
    indexingService.createIndexes(IndexRule.indexRule(0, index, PROVIDER_DESCRIPTOR));
    IndexProxy proxy = indexingService.getIndexProxy(0);
    assertEquals(InternalIndexState.POPULATING, proxy.getState());
    IndexEntryUpdate value2 = add(2, "value2");
    try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE)) {
        updater.process(value2);
    }
    latch.countDown();
    waitForIndexesToComeOnline(indexingService, 0);
    verify(populator, timeout(1000)).close(true);
    // then
    assertEquals(InternalIndexState.ONLINE, proxy.getState());
    InOrder order = inOrder(populator, accessor, updater);
    order.verify(populator).create();
    order.verify(populator).includeSample(add(1, "value1"));
    order.verify(populator).add(Mockito.anyListOf(IndexEntryUpdate.class));
    // invoked from indexAllNodes(), empty because the id we added (2) is bigger than the one we indexed (1)
    //
    // (We don't get an update for value2 here because we mock a fake store that doesn't contain it
    //  just for the purpose of testing this behavior)
    order.verify(populator).newPopulatingUpdater(storeView);
    order.verify(updater).close();
    order.verify(populator).sampleResult();
    order.verify(populator).close(true);
    verifyNoMoreInteractions(updater);
    verifyNoMoreInteractions(populator);
    verifyZeroInteractions(accessor);
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) InOrder(org.mockito.InOrder) CountDownLatch(java.util.concurrent.CountDownLatch) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 3 with IndexEntryUpdate

use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.

the class IndexRecoveryIT method createSomeBananas.

private Set<IndexEntryUpdate> createSomeBananas(Label label) {
    Set<IndexEntryUpdate> updates = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctxSupplier = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = ctxSupplier.get()) {
            int labelId = statement.readOperations().labelGetForName(label.name());
            int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
            LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
            for (int number : new int[] { 4, 10 }) {
                Node node = db.createNode(label);
                node.setProperty(key, number);
                updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, number));
            }
        }
        tx.success();
        return updates;
    }
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) HashSet(java.util.HashSet)

Example 4 with IndexEntryUpdate

use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldPopulateIndexWithASmallDataset.

@Test
public void shouldPopulateIndexWithASmallDataset() throws Exception {
    // GIVEN
    String value = "Mattias";
    long node1 = createNode(map(name, value), FIRST);
    createNode(map(name, value), SECOND);
    createNode(map(age, 31), FIRST);
    long node4 = createNode(map(age, 35, name, value), FIRST);
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), false);
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
    // WHEN
    job.run();
    // THEN
    IndexEntryUpdate update1 = IndexEntryUpdate.add(node1, descriptor, value);
    IndexEntryUpdate update2 = add(node4, descriptor, value);
    verify(populator).create();
    verify(populator).configureSampling(true);
    verify(populator).includeSample(update1);
    verify(populator).includeSample(update2);
    verify(populator, times(2)).add(anyListOf(IndexEntryUpdate.class));
    verify(populator).sampleResult();
    verify(populator).close(true);
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 5 with IndexEntryUpdate

use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.

the class MultipleIndexPopulatorTest method testMultiplePopulatorUpdater.

@Test
public void testMultiplePopulatorUpdater() throws IOException, IndexEntryConflictException {
    IndexUpdater indexUpdater1 = mock(IndexUpdater.class);
    IndexPopulator indexPopulator1 = createIndexPopulator(indexUpdater1);
    IndexPopulator indexPopulator2 = createIndexPopulator();
    addPopulator(indexPopulator1, 1);
    addPopulator(indexPopulator2, 2);
    doThrow(getPopulatorException()).when(indexPopulator2).newPopulatingUpdater(any(PropertyAccessor.class));
    IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(mock(PropertyAccessor.class));
    IndexEntryUpdate propertyUpdate = createIndexEntryUpdate(index1);
    multipleIndexUpdater.process(propertyUpdate);
    checkPopulatorFailure(indexPopulator2);
    verify(indexUpdater1).process(propertyUpdate);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Aggregations

IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)20 Test (org.junit.Test)16 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)7 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)4 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)4 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)3 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 ArrayList (java.util.ArrayList)1