Search in sources :

Example 6 with IndexEntryUpdate

use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatorTest method addUpdates.

@Test
void addUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, schemaDescriptor, "aaa"), add(2, schemaDescriptor, "bbb"), add(3, schemaDescriptor, "ccc"));
    populator.add(updates, NULL);
    index.maybeRefreshBlocking();
    try (var reader = index.getIndexReader();
        NodeValueIterator allEntities = new NodeValueIterator()) {
        reader.query(NULL_CONTEXT, allEntities, unconstrained(), PropertyIndexQuery.exists(1));
        assertArrayEquals(new long[] { 1, 2, 3 }, PrimitiveLongCollections.asArray(allEntities));
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Test(org.junit.jupiter.api.Test)

Example 7 with IndexEntryUpdate

use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.

the class LuceneIndexAccessorIT method populateWithInitialNodes.

private void populateWithInitialNodes(IndexDescriptor indexDescriptor, int nodes, MutableLongSet expectedNodes) throws IndexEntryConflictException, IOException {
    IndexPopulator populator = indexProvider.getPopulator(indexDescriptor, samplingConfig, ByteBufferFactory.heapBufferFactory((int) kibiBytes(100)), INSTANCE, mock(TokenNameLookup.class));
    Collection<IndexEntryUpdate<IndexDescriptor>> initialData = new ArrayList<>();
    populator.create();
    for (long id = 0; id < nodes; id++) {
        Value[] values = values(indexDescriptor, id);
        initialData.add(add(id, indexDescriptor, values));
        expectedNodes.add(id);
        if (initialData.size() >= 100) {
            populator.add(initialData, NULL);
            initialData.clear();
        }
    }
    if (!initialData.isEmpty()) {
        populator.add(initialData, NULL);
    }
    populator.scanCompleted(nullInstance, mock(IndexPopulator.PopulationWorkScheduler.class), NULL);
    populator.close(true, NULL);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue)

Example 8 with IndexEntryUpdate

use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.

the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdatesWithDuplicates.

@Test
void sampleIncludedUpdatesWithDuplicates() {
    populator = newPopulator();
    List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "foo"), add(2, labelSchemaDescriptor, "bar"), add(3, labelSchemaDescriptor, "foo"));
    populator.add(updates, NULL);
    IndexSample sample = populator.sample(NULL);
    assertEquals(new IndexSample(3, 2, 3), sample);
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 9 with IndexEntryUpdate

use of org.neo4j.storageengine.api.IndexEntryUpdate in project neo4j by neo4j.

the class OnlineIndexUpdatesTest method shouldContainFedRelationshipUpdate.

@Test
void shouldContainFedRelationshipUpdate() {
    OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(nodeStore, schemaCache, propertyPhysicalToLogicalConverter, new RecordStorageReader(neoStores), CursorContext.NULL, INSTANCE);
    long relId = 0;
    RelationshipRecord inUse = getRelationship(relId, true, ENTITY_TOKEN);
    Value propertyValue = Values.of("hej");
    long propertyId = createRelationshipProperty(inUse, propertyValue, 1);
    RelationshipRecord notInUse = getRelationship(relId, false, ENTITY_TOKEN);
    relationshipStore.updateRecord(inUse, CursorContext.NULL);
    Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
    PropertyRecord propertyBlocks = new PropertyRecord(propertyId);
    propertyBlocks.setRelId(relId);
    PropertyCommand propertyCommand = new PropertyCommand(recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);
    IndexDescriptor indexDescriptor = IndexPrototype.forSchema(fulltext(RELATIONSHIP, ENTITY_TOKENS, new int[] { 1, 4, 6 })).withName("index").materialise(0);
    createIndexes(indexDescriptor);
    onlineIndexUpdates.feed(nodeGroup(null), relationshipGroup(relationshipCommand, propertyCommand), -1);
    assertTrue(onlineIndexUpdates.hasUpdates());
    Iterator<IndexEntryUpdate<IndexDescriptor>> iterator = onlineIndexUpdates.iterator();
    assertEquals(iterator.next(), IndexEntryUpdate.remove(relId, indexDescriptor, propertyValue, null, null));
    assertFalse(iterator.hasNext());
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Value(org.neo4j.values.storable.Value) Test(org.junit.jupiter.api.Test)

Example 10 with IndexEntryUpdate

use of org.neo4j.storageengine.api.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()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int labelId = ktx.tokenRead().nodeLabel(label.name());
        int propertyKeyId = ktx.tokenRead().propertyKey(key);
        LabelSchemaDescriptor schemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyId);
        for (int number : new int[] { 4, 10 }) {
            Node node = tx.createNode(label);
            node.setProperty(key, number);
            updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, Values.of(number)));
        }
        tx.commit();
        return updates;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) HashSet(java.util.HashSet)

Aggregations

IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)24 Test (org.junit.jupiter.api.Test)18 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 IndexSample (org.neo4j.kernel.api.index.IndexSample)6 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)6 Value (org.neo4j.values.storable.Value)6 ArrayList (java.util.ArrayList)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 ByteBufferFactory (org.neo4j.io.memory.ByteBufferFactory)3 ThreadSafePeakMemoryTracker (org.neo4j.memory.ThreadSafePeakMemoryTracker)3 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)3 PointValue (org.neo4j.values.storable.PointValue)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 TokenNameLookup (org.neo4j.common.TokenNameLookup)2 Transaction (org.neo4j.graphdb.Transaction)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2