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);
}
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));
}
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);
}
}
}
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);
}
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());
}
Aggregations