Search in sources :

Example 76 with CursorContext

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;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 77 with CursorContext

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;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 78 with CursorContext

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();
        }
    }
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) AdminAccessMode(org.neo4j.internal.kernel.api.security.AdminAccessMode) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 79 with CursorContext

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);
}
Also used : Arrays(java.util.Arrays) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) SchemaRule(org.neo4j.internal.schema.SchemaRule) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) AbstractDynamicStore(org.neo4j.kernel.impl.store.AbstractDynamicStore) Config(org.neo4j.configuration.Config) RecordStoreVersion(org.neo4j.kernel.impl.storemigration.RecordStoreVersion) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ScanOnOpenReadOnlyIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory) ConstraintRuleAccessor(org.neo4j.storageengine.api.ConstraintRuleAccessor) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) StorageFilesState(org.neo4j.storageengine.api.StorageFilesState) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) Set(java.util.Set) UUID(java.util.UUID) LockService(org.neo4j.lock.LockService) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) DbmsReadOnlyChecker(org.neo4j.configuration.helpers.DbmsReadOnlyChecker) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) StoreType(org.neo4j.kernel.impl.store.StoreType) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) Optional(java.util.Optional) ServiceProvider(org.neo4j.annotations.service.ServiceProvider) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) StoreVersion(org.neo4j.storageengine.api.StoreVersion) IdController(org.neo4j.internal.id.IdController) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) KernelVersion(org.neo4j.kernel.KernelVersion) LogProvider(org.neo4j.logging.LogProvider) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) ArrayList(java.util.ArrayList) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Iterables(org.neo4j.internal.helpers.collection.Iterables) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StoreId(org.neo4j.storageengine.api.StoreId) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) SchemaRuleMigrationAccess(org.neo4j.storageengine.migration.SchemaRuleMigrationAccess) RecordFormatSelector.selectForStoreOrConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig) CommandReaderFactory(org.neo4j.storageengine.api.CommandReaderFactory) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) RecordFormatSelector.selectForVersion(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForVersion) IOException(java.io.IOException) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) LogService(org.neo4j.logging.internal.LogService) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) SchemaState(org.neo4j.internal.schema.SchemaState) RecordStoreRollingUpgradeCompatibility(org.neo4j.kernel.impl.storemigration.RecordStoreRollingUpgradeCompatibility) BatchImporterFactory(org.neo4j.internal.batchimport.BatchImporterFactory) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) META_DATA(org.neo4j.kernel.impl.store.StoreType.META_DATA) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RollingUpgradeCompatibility(org.neo4j.storageengine.migration.RollingUpgradeCompatibility) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) TokenCreator(org.neo4j.token.TokenCreator) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Example 80 with CursorContext

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);
    }
}
Also used : Path(java.nio.file.Path) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

CursorContext (org.neo4j.io.pagecache.context.CursorContext)161 Test (org.junit.jupiter.api.Test)74 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)52 PageCursor (org.neo4j.io.pagecache.PageCursor)40 IOException (java.io.IOException)31 UncheckedIOException (java.io.UncheckedIOException)27 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)27 Path (java.nio.file.Path)17 PagedFile (org.neo4j.io.pagecache.PagedFile)17 ArrayList (java.util.ArrayList)16 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)15 MutableLong (org.apache.commons.lang3.mutable.MutableLong)13 MemoryTracker (org.neo4j.memory.MemoryTracker)12 PageCache (org.neo4j.io.pagecache.PageCache)11 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)10 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 List (java.util.List)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8