use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.
the class RelationshipGroupChecker method checkToRelationship.
/**
* Check relationship groups to first in chain relationship. Run only on first node-range
*/
private void checkToRelationship(long fromGroupId, long toGroupId, PageCacheTracer pageCacheTracer) {
try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(RELATIONSHIP_GROUPS_CHECKER_TAG));
RecordReader<RelationshipGroupRecord> groupReader = new RecordReader<>(neoStores.getRelationshipGroupStore(), true, cursorContext);
RecordReader<RelationshipGroupRecord> comparativeReader = new RecordReader<>(neoStores.getRelationshipGroupStore(), false, cursorContext);
RecordStorageReader reader = new RecordStorageReader(neoStores);
RecordRelationshipScanCursor relationshipCursor = reader.allocateRelationshipScanCursor(cursorContext)) {
for (long id = fromGroupId; id < toGroupId && !context.isCancelled(); id++) {
RelationshipGroupRecord record = groupReader.read(id);
if (!record.inUse()) {
continue;
}
long owningNode = record.getOwningNode();
if (owningNode < 0) {
reporter.forRelationshipGroup(record).illegalOwner();
}
checkValidToken(record, record.getType(), context.tokenHolders.relationshipTypeTokens(), neoStores.getRelationshipTypeTokenStore(), (group, token) -> reporter.forRelationshipGroup(group).illegalRelationshipType(), (group, token) -> reporter.forRelationshipGroup(group).relationshipTypeNotInUse(token), cursorContext);
if (!NULL_REFERENCE.is(record.getNext())) {
RelationshipGroupRecord comparativeRecord = comparativeReader.read(record.getNext());
if (!comparativeRecord.inUse()) {
reporter.forRelationshipGroup(record).nextGroupNotInUse();
} else {
if (record.getType() >= comparativeRecord.getType()) {
reporter.forRelationshipGroup(record).invalidTypeSortOrder();
}
if (owningNode != comparativeRecord.getOwningNode()) {
reporter.forRelationshipGroup(record).nextHasOtherOwner(comparativeRecord);
}
}
}
checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstOut(), RelationshipGroupLink.OUT, group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstOutgoingRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstIn(), RelationshipGroupLink.IN, group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstIncomingRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstIncomingRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
checkRelationshipGroupRelationshipLink(relationshipCursor, record, record.getFirstLoop(), RelationshipGroupLink.LOOP, group -> reporter.forRelationshipGroup(group).firstLoopRelationshipNotInUse(), group -> reporter.forRelationshipGroup(group).firstLoopRelationshipNotFirstInChain(), group -> reporter.forRelationshipGroup(group).firstLoopRelationshipOfOtherType(), (group, rel) -> reporter.forRelationshipGroup(group).firstLoopRelationshipDoesNotShareNodeWithGroup(rel), cursorContext);
}
}
}
use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.
the class BatchingNeoStoresTest method apply.
private static void apply(TxState txState, CommandCreationContext commandCreationContext, RecordStorageEngine storageEngine) throws Exception {
List<StorageCommand> commands = new ArrayList<>();
try (RecordStorageReader storageReader = storageEngine.newReader()) {
storageEngine.createCommands(commands, txState, storageReader, commandCreationContext, ResourceLocker.IGNORE, LockTracer.NONE, BASE_TX_ID, v -> v, NULL, INSTANCE);
CommandsToApply apply = new TransactionToApply(new PhysicalTransactionRepresentation(commands, new byte[0], 0, 0, 0, 0, ANONYMOUS), NULL);
storageEngine.apply(apply, TransactionApplicationMode.INTERNAL);
}
}
use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.
the class StoreScanChunkIT method differentChunksHaveDifferentCursors.
@Test
void differentChunksHaveDifferentCursors() {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
RecordStorageEngine recordStorageEngine = database.getDependencyResolver().resolveDependency(RecordStorageEngine.class);
NeoStores neoStores = recordStorageEngine.testAccessNeoStores();
RecordStorageReader storageReader = new RecordStorageReader(neoStores);
TestStoreScanChunk scanChunk1 = new TestStoreScanChunk(storageReader, false);
TestStoreScanChunk scanChunk2 = new TestStoreScanChunk(storageReader, false);
assertNotSame(scanChunk1.getCursor(), scanChunk2.getCursor());
assertNotSame(scanChunk1.getStorePropertyCursor(), scanChunk2.getStorePropertyCursor());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.internal.recordstorage.RecordStorageReader in project neo4j by neo4j.
the class DegreesRebuildFromStore method rebuild.
@Override
public void rebuild(RelationshipGroupDegreesStore.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
// === sketch of a more performant version
// - Read all groups and for every group make a mark in a memory-structure like so:
// (node) -> (type,active directions,out,in,loop)
// - Read all relationships and for every matching node go into the memory-structure
// if it's there then look up the type
// if it's there then see if the direction matches any active direction
// if it does then increment the counter in the correct slot
// - Go though the memory-structure and write to the updater
//
// If not all data can fit in memory then do multiple passes (node id range)
RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
try (RecordStorageReader storageReader = new RecordStorageReader(neoStores);
StorageRelationshipTraversalCursor traversalCursor = storageReader.allocateRelationshipTraversalCursor(cursorContext);
PageCursor groupCursor = groupStore.openPageCursorForReadingWithPrefetching(0, cursorContext)) {
RelationshipGroupRecord groupRecord = groupStore.newRecord();
long highGroupId = groupStore.getHighId();
for (long id = groupStore.getNumberOfReservedLowIds(); id < highGroupId; id++) {
groupStore.getRecordByCursor(id, groupRecord, RecordLoad.LENIENT_CHECK, groupCursor);
if (groupRecord.inUse() && (groupRecord.hasExternalDegreesOut() || groupRecord.hasExternalDegreesIn() || groupRecord.hasExternalDegreesLoop())) {
updateDegree(groupRecord.hasExternalDegreesOut(), groupRecord.getFirstOut(), groupRecord, OUTGOING, traversalCursor, updater);
updateDegree(groupRecord.hasExternalDegreesIn(), groupRecord.getFirstIn(), groupRecord, INCOMING, traversalCursor, updater);
updateDegree(groupRecord.hasExternalDegreesLoop(), groupRecord.getFirstLoop(), groupRecord, LOOP, traversalCursor, updater);
}
}
}
}
Aggregations