use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class AllStoreHolder method countsForNodeInTxState.
private long countsForNodeInTxState(int labelId) {
long count = 0;
if (ktx.hasTxStateWithChanges()) {
CountsDelta counts = new CountsDelta();
try {
TransactionState txState = ktx.txState();
CursorContext cursorContext = ktx.cursorContext();
try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
txState.accept(countingVisitor);
}
if (counts.hasChanges()) {
count += counts.nodeCount(labelId, cursorContext);
}
} catch (KernelException e) {
throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
}
}
return count;
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class AllStoreHolder method countsForRelationshipInTxState.
private long countsForRelationshipInTxState(int startLabelId, int typeId, int endLabelId) {
long count = 0;
if (ktx.hasTxStateWithChanges()) {
CursorContext cursorContext = ktx.cursorContext();
CountsDelta counts = new CountsDelta();
try {
TransactionState txState = ktx.txState();
try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
txState.accept(countingVisitor);
}
if (counts.hasChanges()) {
count += counts.relationshipCount(startLabelId, typeId, endLabelId, cursorContext);
}
} catch (KernelException e) {
throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
}
}
return count;
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class AllStoreHolder method relationshipExists.
@Override
public boolean relationshipExists(long reference) {
ktx.assertOpen();
if (hasTxStateWithChanges()) {
TransactionState txState = txState();
if (txState.relationshipIsDeletedInThisTx(reference)) {
return false;
} else if (txState.relationshipIsAddedInThisTx(reference)) {
return true;
}
}
AccessMode mode = ktx.securityContext().mode();
CursorContext cursorContext = ktx.cursorContext();
boolean existsInRelStore = storageReader.relationshipExists(reference, cursorContext);
if (mode.allowsTraverseAllRelTypes()) {
return existsInRelStore;
} else if (!existsInRelStore) {
return false;
} else {
// DefaultNodeCursor already contains traversal checks within next()
try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext)) {
ktx.dataRead().singleRelationship(reference, rels);
return rels.next();
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class RecordStorageEngineFactory method createMigrationTargetSchemaRuleAccess.
public static SchemaRuleMigrationAccess createMigrationTargetSchemaRuleAccess(NeoStores stores, CursorContext cursorContext, MemoryTracker memoryTracker) {
SchemaStore dstSchema = stores.getSchemaStore();
TokenCreator propertyKeyTokenCreator = (name, internal) -> {
PropertyKeyTokenStore keyTokenStore = stores.getPropertyKeyTokenStore();
DynamicStringStore nameStore = keyTokenStore.getNameStore();
byte[] bytes = PropertyStore.encodeString(name);
List<DynamicRecord> nameRecords = new ArrayList<>();
AbstractDynamicStore.allocateRecordsFromBytes(nameRecords, bytes, nameStore, cursorContext, memoryTracker);
nameRecords.forEach(record -> nameStore.prepareForCommit(record, cursorContext));
nameRecords.forEach(record -> nameStore.updateRecord(record, cursorContext));
nameRecords.forEach(record -> nameStore.setHighestPossibleIdInUse(record.getId()));
int nameId = Iterables.first(nameRecords).getIntId();
PropertyKeyTokenRecord keyTokenRecord = keyTokenStore.newRecord();
long tokenId = keyTokenStore.nextId(cursorContext);
keyTokenRecord.setId(tokenId);
keyTokenRecord.initialize(true, nameId);
keyTokenRecord.setInternal(internal);
keyTokenRecord.setCreated();
keyTokenStore.prepareForCommit(keyTokenRecord, cursorContext);
keyTokenStore.updateRecord(keyTokenRecord, cursorContext);
keyTokenStore.setHighestPossibleIdInUse(keyTokenRecord.getId());
return Math.toIntExact(tokenId);
};
TokenHolders dstTokenHolders = tokenHoldersForSchemaStore(stores, propertyKeyTokenCreator, cursorContext);
return new SchemaRuleMigrationAccessImpl(stores, new SchemaStorage(dstSchema, dstTokenHolders, () -> KernelVersion.LATEST), cursorContext, memoryTracker);
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class PageCacheTest method noFaultLinkedWriteOnPagesNotInMemory.
@Test
void noFaultLinkedWriteOnPagesNotInMemory() throws Exception {
DefaultPageCacheTracer cacheTracer = new DefaultPageCacheTracer();
getPageCache(fs, maxPages, cacheTracer);
Path file = file("a");
generateFileWithRecords(file, recordsPerFilePage * 2, recordSize);
long initialFaults = cacheTracer.faults();
try (PagedFile pf = map(file, filePageSize);
CursorContext cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("noFaultLinkedWriteOnPagesNotInMemory"));
PageCursor nofault = pf.io(0, PF_SHARED_WRITE_LOCK | PF_NO_FAULT, cursorContext);
PageCursor linkedNoFault = nofault.openLinkedCursor(0)) {
verifyNoFaultAccessToPagesNotInMemory(cacheTracer, cursorContext, linkedNoFault, initialFaults);
verifyNoFaultWriteIsOutOfBounds(linkedNoFault);
}
}
Aggregations