Search in sources :

Example 21 with NodeStore

use of org.neo4j.kernel.impl.store.NodeStore in project neo4j by neo4j.

the class PropertyDeleterTest method shouldHandlePropertyChainDeletionOnDynamicRecordCycle.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldHandlePropertyChainDeletionOnDynamicRecordCycle(boolean log) {
    // given
    startStore(log);
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.newRecord();
    node.setId(nodeStore.nextId(NULL));
    List<PropertyBlock> properties = Collections.singletonList(encodedValue(0, random.randomValues().nextAsciiTextValue(1000, 1000)));
    DirectRecordAccessSet initialChanges = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    long firstPropId = propertyCreator.createPropertyChain(node, properties.iterator(), initialChanges.getPropertyRecords());
    node.setNextProp(firstPropId);
    // should update all the changed records directly into the store
    initialChanges.commit();
    // create a cycle in the dynamic record chain cycle
    PropertyRecord firstPropRecord = propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    PropertyBlock dynamicBlock = firstPropRecord.iterator().next();
    createCycleIn(dynamicBlock);
    // when
    DirectRecordAccessSet changes = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    deleter.deletePropertyChain(node, changes.getPropertyRecords());
    changes.commit();
    // then
    assertEquals(Record.NO_NEXT_PROPERTY.longValue(), node.getNextProp());
    assertLogContains("Deleted inconsistent property chain", log);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with NodeStore

use of org.neo4j.kernel.impl.store.NodeStore in project neo4j by neo4j.

the class StoreMigrator method legacyNodesAsInput.

private InputIterable<InputNode> legacyNodesAsInput(NeoStores legacyStore, boolean requiresPropertyMigration, RecordCursors cursors) {
    NodeStore store = legacyStore.getNodeStore();
    final BiConsumer<InputNode, NodeRecord> propertyDecorator = propertyDecorator(requiresPropertyMigration, cursors);
    return new StoreScanAsInputIterable<InputNode, NodeRecord>(store) {

        @Override
        protected InputNode inputEntityOf(NodeRecord record) {
            InputNode node = new InputNode("legacy store", record.getId(), record.getId() * NodeRecordFormat.RECORD_SIZE, record.getId(), InputEntity.NO_PROPERTIES, record.getNextProp(), InputNode.NO_LABELS, record.getLabelField());
            propertyDecorator.accept(node, record);
            return node;
        }
    };
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore)

Example 23 with NodeStore

use of org.neo4j.kernel.impl.store.NodeStore in project neo4j by neo4j.

the class PropertyDeduplicator method deduplicateProperties.

public void deduplicateProperties() throws IOException {
    StoreFactory factory = new StoreFactory(workingDir, pageCache, fileSystem, NullLogProvider.getInstance());
    try (NeoStores neoStores = factory.openNeoStores(StoreType.PROPERTY, StoreType.NODE, StoreType.SCHEMA)) {
        PropertyStore propertyStore = neoStores.getPropertyStore();
        NodeStore nodeStore = neoStores.getNodeStore();
        SchemaStore schemaStore = neoStores.getSchemaStore();
        PrimitiveLongObjectMap<List<DuplicateCluster>> duplicateClusters = collectConflictingProperties(propertyStore);
        resolveConflicts(duplicateClusters, propertyStore, nodeStore, schemaStore, neoStores.getStoreDir());
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ArrayList(java.util.ArrayList) List(java.util.List) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 24 with NodeStore

use of org.neo4j.kernel.impl.store.NodeStore in project neo4j by neo4j.

the class NodeRecordCheckTest method shouldProperlyReportOutOfOrderLabelsThatAreFarAway.

@Test
public void shouldProperlyReportOutOfOrderLabelsThatAreFarAway() throws Exception {
    // given
    final NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
    // We need to do this override so we can put the labels unsorted, since InlineNodeLabels always sorts on insert
    new InlineNodeLabels(node) {

        @Override
        public Collection<DynamicRecord> put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
            return putSorted(node, labelIds, nodeStore, allocator);
        }
    }.put(new long[] { 1, 18, 13, 14, 15, 16, 12 }, null, null);
    LabelTokenRecord label1 = inUse(new LabelTokenRecord(1));
    LabelTokenRecord label12 = inUse(new LabelTokenRecord(12));
    LabelTokenRecord label13 = inUse(new LabelTokenRecord(13));
    LabelTokenRecord label14 = inUse(new LabelTokenRecord(14));
    LabelTokenRecord label15 = inUse(new LabelTokenRecord(15));
    LabelTokenRecord label16 = inUse(new LabelTokenRecord(16));
    LabelTokenRecord label18 = inUse(new LabelTokenRecord(18));
    add(label1);
    add(label12);
    add(label13);
    add(label14);
    add(label15);
    add(label16);
    add(label18);
    add(node);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelsOutOfOrder(18, 13);
    verify(report).labelsOutOfOrder(16, 12);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) Collection(java.util.Collection) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 25 with NodeStore

use of org.neo4j.kernel.impl.store.NodeStore in project neo4j by neo4j.

the class TransactionRecordStateTest method assertRelationshipGroupsInOrder.

private void assertRelationshipGroupsInOrder(NeoStores neoStores, long nodeId, int... types) {
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
    assertTrue("Node should be dense, is " + node, node.isDense());
    long groupId = node.getNextRel();
    int cursor = 0;
    List<RelationshipGroupRecord> seen = new ArrayList<>();
    while (groupId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RecordStore<RelationshipGroupRecord> relationshipGroupStore = neoStores.getRelationshipGroupStore();
        RelationshipGroupRecord group = relationshipGroupStore.getRecord(groupId, relationshipGroupStore.newRecord(), NORMAL);
        seen.add(group);
        assertEquals("Invalid type, seen groups so far " + seen, types[cursor++], group.getType());
        groupId = group.getNext();
    }
    assertEquals("Not enough relationship group records found in chain for " + node, types.length, cursor);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) ArrayList(java.util.ArrayList)

Aggregations

NodeStore (org.neo4j.kernel.impl.store.NodeStore)42 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)28 NeoStores (org.neo4j.kernel.impl.store.NeoStores)12 Test (org.junit.jupiter.api.Test)10 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)10 Test (org.junit.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayList (java.util.ArrayList)7 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 RelationshipGroupStore (org.neo4j.kernel.impl.store.RelationshipGroupStore)6 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)6 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 CountsComputer (org.neo4j.kernel.impl.store.CountsComputer)4 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)4 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)4 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)4 Value (org.neo4j.values.storable.Value)4 BatchingNeoStores (org.neo4j.internal.batchimport.store.BatchingNeoStores)3