Search in sources :

Example 36 with NodeStore

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

the class RelationshipGroupGetterTest method openStore.

@BeforeEach
void openStore() {
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, logProvider, PageCacheTracer.NULL, writable());
    stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP, StoreType.NODE, StoreType.NODE_LABEL);
    groupStore = spy(stores.getRelationshipGroupStore());
    NodeStore nodeStore = stores.getNodeStore();
    groupRecords = new DirectRecordAccess<>(groupStore, Loaders.relationshipGroupLoader(groupStore, NULL));
    nodeRecords = new DirectRecordAccess<>(nodeStore, Loaders.nodeLoader(nodeStore, NULL));
    groupGetter = new RelationshipGroupGetter(groupStore, NULL);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) NodeStore(org.neo4j.kernel.impl.store.NodeStore) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 37 with NodeStore

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

the class OnlineIndexUpdatesTest method setUp.

@BeforeEach
void setUp() throws IOException {
    life = new LifeSupport();
    Config config = Config.defaults();
    NullLogProvider nullLogProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName()), pageCache, fileSystem, nullLogProvider, NULL, writable());
    neoStores = storeFactory.openAllNeoStores(true);
    GBPTreeCountsStore counts = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, immediate(), new CountsComputer(neoStores, pageCache, NULL, databaseLayout, INSTANCE, NullLog.getInstance()), writable(), NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1_000);
    life.add(wrapInLifecycle(counts));
    nodeStore = neoStores.getNodeStore();
    relationshipStore = neoStores.getRelationshipStore();
    PropertyStore propertyStore = neoStores.getPropertyStore();
    schemaCache = new SchemaCache(new StandardConstraintRuleAccessor(), index -> index);
    propertyPhysicalToLogicalConverter = new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore(), CursorContext.NULL);
    life.start();
    propertyCreator = new PropertyCreator(neoStores.getPropertyStore(), new PropertyTraverser(CursorContext.NULL), CursorContext.NULL, INSTANCE);
    recordAccess = new DirectRecordAccess<>(neoStores.getPropertyStore(), Loaders.propertyLoader(propertyStore, CursorContext.NULL));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) NO_NEXT_RELATIONSHIP(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Collections.singletonList(java.util.Collections.singletonList) NO_LABELS_FIELD(org.neo4j.kernel.impl.store.record.Record.NO_LABELS_FIELD) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NullLog(org.neo4j.logging.NullLog) PageCache(org.neo4j.io.pagecache.PageCache) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NODE(org.neo4j.common.EntityType.NODE) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) CountsStore(org.neo4j.counts.CountsStore) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) Values(org.neo4j.values.storable.Values) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) NO_NEXT_PROPERTY(org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Iterator(java.util.Iterator) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) IOException(java.io.IOException) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.configuration.Config) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) NullLogProvider(org.neo4j.logging.NullLogProvider) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with NodeStore

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

the class PropertyDeleterTest method shouldHandlePropertyChainDeletionOnCycle.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldHandlePropertyChainDeletionOnCycle(boolean log) {
    // given
    startStore(log);
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.newRecord();
    node.setId(nodeStore.nextId(NULL));
    List<PropertyBlock> properties = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        properties.add(encodedValue(i, random.nextValue()));
    }
    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 property chain A -> B
    // ^---v
    List<Value> valuesInTheFirstTwoRecords = new ArrayList<>();
    PropertyRecord firstPropRecord = propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(firstPropRecord, valuesInTheFirstTwoRecords);
    long secondPropId = firstPropRecord.getNextProp();
    PropertyRecord secondPropRecord = propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(secondPropRecord, valuesInTheFirstTwoRecords);
    secondPropRecord.setNextProp(firstPropId);
    propertyStore.updateRecord(secondPropRecord, NULL);
    // when
    DirectRecordAccessSet changes = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    deleter.deletePropertyChain(node, changes.getPropertyRecords());
    changes.commit();
    // then
    assertEquals(Record.NO_NEXT_PROPERTY.longValue(), node.getNextProp());
    assertFalse(propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertFalse(propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertLogContains("Deleted inconsistent property chain with cycle", log);
    if (log) {
        for (Value value : valuesInTheFirstTwoRecords) {
            assertLogContains(value.toString(), true);
        }
    }
}
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) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with NodeStore

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

the class PropertyDeleterTest method shouldHandlePropertyChainDeletionOnUnusedDynamicRecord.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldHandlePropertyChainDeletionOnUnusedDynamicRecord(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();
    PropertyRecord firstPropRecord = propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    PropertyBlock dynamicBlock = firstPropRecord.iterator().next();
    makeSomeUnusedIn(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 with unused record", 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 40 with NodeStore

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

the class RecordNodeCursorTest method shouldChooseFastTotalDegreeLookupWhenPossible.

@Test
void shouldChooseFastTotalDegreeLookupWhenPossible() {
    // given
    NodeStore nodeStore = mock(NodeStore.class);
    long relationshipId = 99;
    long nextRelationshipId = relationshipId + 1;
    long nodeId = 5;
    int degree = 123;
    when(nodeStore.getHighestPossibleIdInUse(NULL)).thenReturn(nodeId + 1);
    doAnswer(invocationOnMock -> {
        long id = invocationOnMock.getArgument(0);
        NodeRecord record = invocationOnMock.getArgument(1);
        record.setId(id);
        record.initialize(true, NULL_REFERENCE.longValue(), false, relationshipId, NO_LABELS_FIELD.longValue());
        return null;
    }).when(nodeStore).getRecordByCursor(eq(nodeId), any(), any(), any());
    RelationshipStore relationshipStore = mock(RelationshipStore.class);
    doAnswer(invocationOnMock -> {
        long id = invocationOnMock.getArgument(0);
        RelationshipRecord record = invocationOnMock.getArgument(1);
        record.setId(id);
        record.initialize(true, NULL_REFERENCE.longValue(), nodeId, nodeId + 10, 1, degree, nextRelationshipId, 33, 44, true, false);
        return null;
    }).when(relationshipStore).getRecordByCursor(eq(relationshipId), any(), any(), any());
    RelationshipGroupStore groupStore = mock(RelationshipGroupStore.class);
    RelationshipGroupDegreesStore groupDegreesStore = mock(RelationshipGroupDegreesStore.class);
    RecordNodeCursor nodeCursor = new RecordNodeCursor(nodeStore, relationshipStore, groupStore, groupDegreesStore, NULL);
    // when
    nodeCursor.single(nodeId);
    assertThat(nodeCursor.next()).isTrue();
    SingleDegree mutator = new SingleDegree();
    nodeCursor.degrees(RelationshipSelection.ALL_RELATIONSHIPS, mutator, true);
    // then
    assertThat(mutator.getTotal()).isEqualTo(degree);
    verifyNoInteractions(groupStore);
    verify(relationshipStore).getRecordByCursor(eq(relationshipId), any(), any(), any());
    verify(relationshipStore, never()).getRecordByCursor(eq(nextRelationshipId), any(), any(), any());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) SingleDegree(org.neo4j.storageengine.util.SingleDegree) Test(org.junit.jupiter.api.Test)

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