Search in sources :

Example 1 with RelationshipVisitor

use of org.neo4j.storageengine.api.RelationshipVisitor in project neo4j by neo4j.

the class NeoStoresTest method relDelete.

private void relDelete(long id) {
    RelationshipVisitor<RuntimeException> visitor = (relId, type, startNode, endNode) -> transactionState.relationshipDoDelete(relId, type, startNode, endNode);
    if (!transactionState.relationshipVisit(id, visitor)) {
        try (StorageRelationshipScanCursor cursor = storageReader.allocateRelationshipScanCursor(NULL)) {
            cursor.single(id);
            if (!cursor.next()) {
                throw new RuntimeException("Relationship " + id + " not found");
            }
            visitor.visit(id, cursor.type(), cursor.sourceNodeReference(), cursor.targetNodeReference());
        }
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) DefaultIdController(org.neo4j.internal.id.DefaultIdController) CursorContext(org.neo4j.io.pagecache.context.CursorContext) NORMAL(org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) NullLogProvider(org.neo4j.logging.NullLogProvider) INTERNAL(org.neo4j.storageengine.api.TransactionApplicationMode.INTERNAL) EMPTY_BYTE_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) StorageRelationshipScanCursor(org.neo4j.storageengine.api.StorageRelationshipScanCursor) Duration(java.time.Duration) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) Path(java.nio.file.Path) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) StoreTokens.createReadOnlyTokenHolder(org.neo4j.internal.recordstorage.StoreTokens.createReadOnlyTokenHolder) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) Dependencies(org.neo4j.collection.Dependencies) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) IdType(org.neo4j.internal.id.IdType) EphemeralNeo4jLayoutExtension(org.neo4j.test.extension.EphemeralNeo4jLayoutExtension) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RelationshipType(org.neo4j.graphdb.RelationshipType) Mockito.mock(org.mockito.Mockito.mock) AUTH_DISABLED(org.neo4j.internal.kernel.api.security.AuthSubject.AUTH_DISABLED) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TransactionId(org.neo4j.storageengine.api.TransactionId) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StorageReader(org.neo4j.storageengine.api.StorageReader) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NONE(org.neo4j.lock.LockTracer.NONE) NullLogProvider.nullLogProvider(org.neo4j.logging.NullLogProvider.nullLogProvider) UTF8(org.neo4j.string.UTF8) IOException(java.io.IOException) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) KernelException(org.neo4j.exceptions.KernelException) TokenHolders(org.neo4j.token.TokenHolders) CURRENT_FORMAT_LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) LockVerificationMonitor(org.neo4j.internal.recordstorage.LockVerificationMonitor) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) ByteBuffer(java.nio.ByteBuffer) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) StoreChannel(org.neo4j.io.fs.StoreChannel) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) StorageRelationshipTraversalCursor(org.neo4j.storageengine.api.StorageRelationshipTraversalCursor) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) Record(org.neo4j.kernel.impl.store.record.Record) PageCache(org.neo4j.io.pagecache.PageCache) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) BASE_TX_COMMIT_TIMESTAMP(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) Test(org.junit.jupiter.api.Test) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) NO_LOCK_SERVICE(org.neo4j.lock.LockService.NO_LOCK_SERVICE) StorageProperty(org.neo4j.storageengine.api.StorageProperty) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) RelationshipVisitor(org.neo4j.storageengine.api.RelationshipVisitor) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Values(org.neo4j.values.storable.Values) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) TokenHolder(org.neo4j.token.api.TokenHolder) PropertyReceiver(org.neo4j.internal.recordstorage.TransactionRecordState.PropertyReceiver) Inject(org.neo4j.test.extension.Inject) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ALL_RELATIONSHIPS(org.neo4j.storageengine.api.RelationshipSelection.ALL_RELATIONSHIPS) GraphDatabaseInternalSettings.counts_store_rotation_timeout(org.neo4j.configuration.GraphDatabaseInternalSettings.counts_store_rotation_timeout) OpenOption(java.nio.file.OpenOption) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) IGNORE(org.neo4j.lock.ResourceLocker.IGNORE) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandLockVerification(org.neo4j.internal.recordstorage.CommandLockVerification) Health(org.neo4j.monitoring.Health) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) EphemeralPageCacheExtension(org.neo4j.test.extension.pagecache.EphemeralPageCacheExtension) FIELD_NOT_PRESENT(org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat.FIELD_NOT_PRESENT) Relationship(org.neo4j.graphdb.Relationship) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StorageRelationshipScanCursor(org.neo4j.storageengine.api.StorageRelationshipScanCursor)

Example 2 with RelationshipVisitor

use of org.neo4j.storageengine.api.RelationshipVisitor in project neo4j by neo4j.

the class RelationshipModifications method idsAsBatch.

static RelationshipBatch idsAsBatch(LongSet ids, IdDataDecorator idDataDecorator) {
    return new RelationshipBatch() {

        @Override
        public int size() {
            return ids.size();
        }

        @Override
        public boolean isEmpty() {
            return ids.isEmpty();
        }

        @Override
        public boolean contains(long id) {
            return ids.contains(id);
        }

        @Override
        public long first() {
            return ids.longIterator().next();
        }

        @Override
        public <E extends Exception> void forEach(RelationshipVisitor<E> relationship) throws E {
            LongIterator iterator = ids.longIterator();
            while (iterator.hasNext()) {
                long id = iterator.next();
                idDataDecorator.accept(id, relationship);
            }
        }
    };
}
Also used : RelationshipVisitor(org.neo4j.storageengine.api.RelationshipVisitor) LongIterator(org.eclipse.collections.api.iterator.LongIterator)

Aggregations

RelationshipVisitor (org.neo4j.storageengine.api.RelationshipVisitor)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 LongSupplier (java.util.function.LongSupplier)1 EMPTY_BYTE_ARRAY (org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY)1 Sets.immutable (org.eclipse.collections.api.factory.Sets.immutable)1 LongIterator (org.eclipse.collections.api.iterator.LongIterator)1 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1