Search in sources :

Example 26 with NodeStore

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

the class BatchInsertTest method shouldSortLabelIdsWhenGetOrCreate.

@Test
public void shouldSortLabelIdsWhenGetOrCreate() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    // WHEN
    long nodeId = inserter.createNode(map("Item", 123456789123L), label("AA"), label("BB"), label("CC"), label("DD"));
    inserter.setNodeLabels(nodeId, label("CC"), label("AA"), label("DD"), label("EE"), label("FF"));
    // THEN
    NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), RecordLoad.NORMAL);
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] labelIds = labels.get(nodeStore);
    long[] sortedLabelIds = labelIds.clone();
    Arrays.sort(sortedLabelIds);
    assertArrayEquals(sortedLabelIds, labelIds);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Example 27 with NodeStore

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

the class BatchInsertTest method shouldNotCreateSameLabelTwiceOnSameNode.

@Test
public void shouldNotCreateSameLabelTwiceOnSameNode() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    // WHEN
    long nodeId = inserter.createNode(map("itemId", 1000L), label("Item"), label("Item"));
    // THEN
    NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL);
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] labelIds = labels.get(nodeStore);
    assertEquals(1, labelIds.length);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Example 28 with NodeStore

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

the class ReadRecordsStepTest method shouldContinueThroughBigIdHoles.

@Test
public void shouldContinueThroughBigIdHoles() throws Exception {
    // GIVEN
    NodeStore store = mock(NodeStore.class);
    long highId = 100L;
    when(store.getHighId()).thenReturn(highId);
    when(store.newRecord()).thenReturn(new NodeRecord(-1));
    org.neo4j.unsafe.impl.batchimport.Configuration config = withBatchSize(DEFAULT, 10);
    when(store.newRecordCursor(any(NodeRecord.class))).thenAnswer(invocation -> {
        return new ControlledRecordCursor<>((NodeRecord) invocation.getArguments()[0], record -> {
            record.setInUse(record.getId() < config.batchSize() || record.getId() >= highId - config.batchSize() / 2);
            return record.inUse() && record.getId() < highId;
        });
    });
    ReadRecordsStep<NodeRecord> step = new ReadRecordsStep<>(mock(StageControl.class), config, store, allIn(store, config));
    step.start(0);
    // WHEN
    NodeRecord[] first = (NodeRecord[]) step.nextBatchOrNull(0, config.batchSize());
    NodeRecord[] second = (NodeRecord[]) step.nextBatchOrNull(1, config.batchSize());
    NodeRecord[] third = (NodeRecord[]) step.nextBatchOrNull(2, config.batchSize());
    // THEN
    assertEquals(config.batchSize(), first.length);
    assertEquals(0L, first[0].getId());
    assertEquals(first[0].getId() + config.batchSize() - 1, first[first.length - 1].getId());
    assertEquals(config.batchSize() / 2, second.length);
    assertEquals(highId - 1, second[second.length - 1].getId());
    assertNull(third);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) Test(org.junit.Test)

Example 29 with NodeStore

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

the class MultipleIndexPopulatorUpdatesTest method updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan.

@Test
public void updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan() throws IndexPopulationFailedKernelException, IOException, IndexEntryConflictException {
    NeoStores neoStores = Mockito.mock(NeoStores.class);
    CountsTracker countsTracker = mock(CountsTracker.class);
    NodeStore nodeStore = mock(NodeStore.class);
    PropertyStore propertyStore = mock(PropertyStore.class);
    NodeRecord nodeRecord = getNodeRecord();
    PropertyRecord propertyRecord = getPropertyRecord();
    when(neoStores.getCounts()).thenReturn(countsTracker);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getPropertyRecordChain(anyInt())).thenReturn(Collections.singletonList(propertyRecord));
    when(countsTracker.nodeCount(anyInt(), any(Register.DoubleLongRegister.class))).thenReturn(Registers.newDoubleLongRegister(3, 3));
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(20L);
    when(nodeStore.newRecord()).thenReturn(nodeRecord);
    when(nodeStore.getRecord(anyInt(), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 1));
    when(nodeStore.getRecord(eq(7L), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 7));
    ProcessListenableNeoStoreIndexView storeView = new ProcessListenableNeoStoreIndexView(LockService.NO_LOCK_SERVICE, neoStores);
    MultipleIndexPopulator indexPopulator = new MultipleIndexPopulator(storeView, logProvider);
    storeView.setProcessListener(new NodeUpdateProcessListener(indexPopulator));
    IndexPopulator populator = createIndexPopulator();
    IndexUpdater indexUpdater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(storeView)).thenReturn(indexUpdater);
    addPopulator(indexPopulator, populator, 1, NewIndexDescriptorFactory.forLabel(1, 1));
    indexPopulator.create();
    StoreScan<IndexPopulationFailedKernelException> storeScan = indexPopulator.indexAllNodes();
    storeScan.run();
    Mockito.verify(indexUpdater, times(0)).process(any(IndexEntryUpdate.class));
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 30 with NodeStore

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

the class CountsComputerTest method rebuildCounts.

private void rebuildCounts(long lastCommittedTransactionId) throws IOException {
    cleanupCountsForRebuilding();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache, fs, NullLogProvider.getInstance());
    try (Lifespan life = new Lifespan();
        NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
        int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
        CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
        CountsTracker countsTracker = createCountsTracker();
        life.add(countsTracker.setInitializer(countsComputer));
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

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