Search in sources :

Example 1 with NULL

use of org.neo4j.io.pagecache.context.CursorContext.NULL 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 NULL

use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.

the class BatchingNeoStoresTest method someDataInTheDatabase.

private void someDataInTheDatabase(Config config) throws Exception {
    NullLog nullLog = NullLog.getInstance();
    try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
        PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
        Lifespan life = new Lifespan()) {
        // TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
        DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.propertyKeyDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.labelDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.relationshipTypeDoCreateForName(name, internal, id);
            }
        };
        TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
        IndexConfigCompleter indexConfigCompleter = index -> index;
        RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
        RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
        // Create the relationship type token
        TxState txState = new TxState();
        NeoStores neoStores = storageEngine.testAccessNeoStores();
        CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
        commandCreationContext.initialize(NULL);
        propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
        labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
        relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
        int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
        apply(txState, commandCreationContext, storageEngine);
        // Finally, we're initialized and ready to create two nodes and a relationship
        txState = new TxState();
        long node1 = commandCreationContext.reserveNode();
        long node2 = commandCreationContext.reserveNode();
        txState.nodeDoCreate(node1);
        txState.nodeDoCreate(node2);
        txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
        apply(txState, commandCreationContext, storageEngine);
        neoStores.flush(NULL);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DefaultIdController(org.neo4j.internal.id.DefaultIdController) NullLogService(org.neo4j.logging.internal.NullLogService) Predicates(org.neo4j.function.Predicates) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) LockVerificationMonitor(org.neo4j.internal.recordstorage.LockVerificationMonitor) NullLogProvider(org.neo4j.logging.NullLogProvider) ANY_LABEL(org.neo4j.token.api.TokenConstants.ANY_LABEL) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) JobSchedulerFactory(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory) NullLog(org.neo4j.logging.NullLog) Input(org.neo4j.internal.batchimport.input.Input) PageCache(org.neo4j.io.pagecache.PageCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) LockService(org.neo4j.lock.LockService) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Stream(java.util.stream.Stream) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) RelationshipType(org.neo4j.graphdb.RelationshipType) ANONYMOUS(org.neo4j.internal.kernel.api.security.AuthSubject.ANONYMOUS) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) EMPTY(org.neo4j.internal.batchimport.AdditionalInitialIds.EMPTY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BASE_TX_ID(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_ID) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) ArrayList(java.util.ArrayList) 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) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) MemoryPools(org.neo4j.memory.MemoryPools) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD(org.neo4j.internal.batchimport.store.BatchingNeoStores.DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) LockTracer(org.neo4j.lock.LockTracer) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Configuration(org.neo4j.internal.batchimport.Configuration) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PanicEventGenerator(org.neo4j.monitoring.PanicEventGenerator) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandLockVerification(org.neo4j.internal.recordstorage.CommandLockVerification) TokenStore(org.neo4j.kernel.impl.store.TokenStore) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LATEST_RECORD_FORMATS(org.neo4j.kernel.impl.store.format.standard.Standard.LATEST_RECORD_FORMATS) ResourceLocker(org.neo4j.lock.ResourceLocker) CountsAccessor(org.neo4j.counts.CountsAccessor) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) TokenHolders(org.neo4j.token.TokenHolders) CountsBuilder(org.neo4j.internal.counts.CountsBuilder) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Clocks(org.neo4j.time.Clocks) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) NullLog(org.neo4j.logging.NullLog) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) DefaultIdController(org.neo4j.internal.id.DefaultIdController) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) MemoryPools(org.neo4j.memory.MemoryPools) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) TokenHolders(org.neo4j.token.TokenHolders) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCache(org.neo4j.io.pagecache.PageCache)

Example 3 with NULL

use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.

the class DelayedBufferTest method shouldHandleTheWholeWorkloadShebang.

@Test
void shouldHandleTheWholeWorkloadShebang() throws Throwable {
    // GIVEN
    final int size = 1_000;
    final long bufferTime = 3;
    VerifyingConsumer consumer = new VerifyingConsumer(size);
    final FakeClock clock = Clocks.fakeClock();
    Supplier<Long> chunkThreshold = clock::millis;
    AtomicBoolean end = new AtomicBoolean();
    Predicate<Long> safeThreshold = time -> end.get() || clock.millis() - bufferTime >= time;
    final DelayedBuffer<Long> buffer = new DelayedBuffer<>(chunkThreshold, safeThreshold, 10, consumer);
    MaintenanceThread maintenance = new MaintenanceThread(buffer, 5);
    Race adders = new Race();
    final int numberOfAdders = 20;
    final byte[] offeredIds = new byte[size];
    for (int i = 0; i < numberOfAdders; i++) {
        final int finalI = i;
        adders.addContestant(() -> {
            for (int j = 0; j < size; j++) {
                if (j % numberOfAdders == finalI) {
                    buffer.offer(j);
                    offeredIds[j] = 1;
                    clock.forward(2, MILLISECONDS);
                }
            }
        });
    }
    // WHEN (multi-threaded) offering of ids
    adders.go();
    // ... ensuring the test is sane itself (did we really offer all these IDs?)
    for (int i = 0; i < size; i++) {
        assertEquals((byte) 1, offeredIds[i], "ID " + i);
    }
    maintenance.halt();
    end.set(true);
    buffer.maintenance(NULL);
    buffer.close();
    // THEN
    consumer.assertHaveOnlySeenRange(0, size - 1);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Suppliers.singleton(org.neo4j.function.Suppliers.singleton) Predicate(java.util.function.Predicate) CursorContext(org.neo4j.io.pagecache.context.CursorContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CONCURRENT(org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT) Supplier(java.util.function.Supplier) Test(org.junit.jupiter.api.Test) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) FakeClock(org.neo4j.time.FakeClock) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Execution(org.junit.jupiter.api.parallel.Execution) Clocks(org.neo4j.time.Clocks) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) Race(org.neo4j.test.Race) Numbers.safeCastLongToInt(org.neo4j.internal.helpers.Numbers.safeCastLongToInt) Mockito.mock(org.mockito.Mockito.mock) FakeClock(org.neo4j.time.FakeClock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Race(org.neo4j.test.Race) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.jupiter.api.Test)

Example 4 with NULL

use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.

the class GBPTreeGenericCountsStoreTest method assertCountsMatchesExpected.

private void assertCountsMatchesExpected(ConcurrentMap<CountsKey, AtomicLong> source, long baseCount) {
    ConcurrentMap<CountsKey, AtomicLong> expected = new ConcurrentHashMap<>();
    source.entrySet().stream().filter(// counts store won't have entries w/ 0 count
    entry -> entry.getValue().get() != 0).forEach(// copy them over to the one we're going to verify
    entry -> expected.put(entry.getKey(), entry.getValue()));
    countsStore.visitAllCounts((key, count) -> {
        AtomicLong expectedCount = expected.remove(key);
        if (expectedCount == null) {
            assertEquals(baseCount, count, () -> format("Counts store has wrong count for (absent) %s", key));
        } else {
            assertEquals(baseCount + expectedCount.get(), count, () -> format("Counts store has wrong count for %s", key));
        }
    }, NULL);
    assertTrue(expected.isEmpty(), expected::toString);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NoSuchFileException(java.nio.file.NoSuchFileException) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) RandomExtension(org.neo4j.test.extension.RandomExtension) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) ANY_LABEL(org.neo4j.token.api.TokenConstants.ANY_LABEL) ByteBuffer(java.nio.ByteBuffer) NO_MONITOR(org.neo4j.internal.counts.GBPTreeCountsStore.NO_MONITOR) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Future(java.util.concurrent.Future) StoreChannel(org.neo4j.io.fs.StoreChannel) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Path(java.nio.file.Path) Exceptions(org.neo4j.internal.helpers.Exceptions) PageCache(org.neo4j.io.pagecache.PageCache) EMPTY_REBUILD(org.neo4j.internal.counts.GBPTreeGenericCountsStore.EMPTY_REBUILD) ArrayQueueOutOfOrderSequence(org.neo4j.util.concurrent.ArrayQueueOutOfOrderSequence) OtherThreadExecutor.command(org.neo4j.test.OtherThreadExecutor.command) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) GBPTreeCountsStore.nodeKey(org.neo4j.internal.counts.GBPTreeCountsStore.nodeKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Rebuilder(org.neo4j.internal.counts.GBPTreeGenericCountsStore.Rebuilder) EMPTY_LONG_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_LONG_ARRAY) Race.throwing(org.neo4j.test.Race.throwing) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OutOfOrderSequence(org.neo4j.util.concurrent.OutOfOrderSequence) TreeFileNotFoundException(org.neo4j.index.internal.gbptree.TreeFileNotFoundException) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) BASE_TX_ID(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_ID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) ReadOnlyDbException(org.neo4j.kernel.api.exceptions.ReadOnlyDbException) Inject(org.neo4j.test.extension.Inject) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GBPTreeCountsStore.relationshipKey(org.neo4j.internal.counts.GBPTreeCountsStore.relationshipKey) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) MemoryTracker(org.neo4j.memory.MemoryTracker) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) ANY_RELATIONSHIP_TYPE(org.neo4j.token.api.TokenConstants.ANY_RELATIONSHIP_TYPE) Race(org.neo4j.test.Race) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with NULL

use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.

the class GBPTreeGenericCountsStoreTest method generateAndApplyTransaction.

/**
 * Generates a transaction, i.e. a counts change set. The data is random, but uses a seed which is the seed of the {@link RandomRule} in this test
 * as well as the the supplied txId. Calling this method in any given test multiple times with any specific txId will generate the same data.
 *
 * @param expected map of counts to update with the generated changes.
 * @param txId transaction id to generate transaction data for and ultimately apply to the counts store (and the expected map).
 */
private void generateAndApplyTransaction(ConcurrentMap<CountsKey, AtomicLong> expected, long txId) {
    Random rng = new Random(random.seed() + txId);
    try (CountUpdater updater = countsStore.updater(txId, NULL)) {
        if (updater != null) {
            int numberOfKeys = rng.nextInt(10);
            for (int j = 0; j < numberOfKeys; j++) {
                // chance to get -1
                long delta = rng.nextInt(11) - 1;
                CountsKey expectedKey;
                if (rng.nextBoolean()) {
                    // Node
                    int labelId = randomTokenId(rng);
                    updater.increment(nodeKey(labelId), delta);
                    expectedKey = nodeKey(labelId);
                } else {
                    // Relationship
                    int startLabelId = randomTokenId(rng);
                    int type = randomTokenId(rng);
                    int endLabelId = randomTokenId(rng);
                    updater.increment(relationshipKey(startLabelId, type, endLabelId), delta);
                    expectedKey = relationshipKey(startLabelId, type, endLabelId);
                }
                expected.computeIfAbsent(expectedKey, k -> new AtomicLong()).addAndGet(delta);
            }
        }
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) NoSuchFileException(java.nio.file.NoSuchFileException) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) RandomExtension(org.neo4j.test.extension.RandomExtension) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) ANY_LABEL(org.neo4j.token.api.TokenConstants.ANY_LABEL) ByteBuffer(java.nio.ByteBuffer) NO_MONITOR(org.neo4j.internal.counts.GBPTreeCountsStore.NO_MONITOR) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Future(java.util.concurrent.Future) StoreChannel(org.neo4j.io.fs.StoreChannel) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Path(java.nio.file.Path) Exceptions(org.neo4j.internal.helpers.Exceptions) PageCache(org.neo4j.io.pagecache.PageCache) EMPTY_REBUILD(org.neo4j.internal.counts.GBPTreeGenericCountsStore.EMPTY_REBUILD) ArrayQueueOutOfOrderSequence(org.neo4j.util.concurrent.ArrayQueueOutOfOrderSequence) OtherThreadExecutor.command(org.neo4j.test.OtherThreadExecutor.command) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) GBPTreeCountsStore.nodeKey(org.neo4j.internal.counts.GBPTreeCountsStore.nodeKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Rebuilder(org.neo4j.internal.counts.GBPTreeGenericCountsStore.Rebuilder) EMPTY_LONG_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_LONG_ARRAY) Race.throwing(org.neo4j.test.Race.throwing) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OutOfOrderSequence(org.neo4j.util.concurrent.OutOfOrderSequence) TreeFileNotFoundException(org.neo4j.index.internal.gbptree.TreeFileNotFoundException) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) BASE_TX_ID(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_ID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) ReadOnlyDbException(org.neo4j.kernel.api.exceptions.ReadOnlyDbException) Inject(org.neo4j.test.extension.Inject) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GBPTreeCountsStore.relationshipKey(org.neo4j.internal.counts.GBPTreeCountsStore.relationshipKey) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) MemoryTracker(org.neo4j.memory.MemoryTracker) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) ANY_RELATIONSHIP_TYPE(org.neo4j.token.api.TokenConstants.ANY_RELATIONSHIP_TYPE) Race(org.neo4j.test.Race) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) AtomicLong(java.util.concurrent.atomic.AtomicLong) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Aggregations

NULL (org.neo4j.io.pagecache.context.CursorContext.NULL)31 Test (org.junit.jupiter.api.Test)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)22 IOException (java.io.IOException)20 Inject (org.neo4j.test.extension.Inject)20 ArrayList (java.util.ArrayList)19 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)19 List (java.util.List)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 INSTANCE (org.neo4j.memory.EmptyMemoryTracker.INSTANCE)18 PageCache (org.neo4j.io.pagecache.PageCache)17 CursorContext (org.neo4j.io.pagecache.context.CursorContext)17 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)16 Path (java.nio.file.Path)15 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)15 RandomRule (org.neo4j.test.rule.RandomRule)15 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Config (org.neo4j.configuration.Config)14 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)14