Search in sources :

Example 11 with IdGeneratorFactory

use of org.neo4j.internal.id.IdGeneratorFactory in project neo4j by neo4j.

the class IdContextFactoryBuilderTest method createContextWithFactoryWrapper.

@Test
void createContextWithFactoryWrapper() {
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    Function<IdGeneratorFactory, IdGeneratorFactory> factoryWrapper = ignored -> idGeneratorFactory;
    IdContextFactory contextFactory = IdContextFactoryBuilder.of(fs, jobScheduler, defaults(), PageCacheTracer.NULL).withFactoryWrapper(factoryWrapper).build();
    DatabaseIdContext idContext = contextFactory.createIdContext(databaseIdRepository.getByName("database").get());
    assertSame(idGeneratorFactory, idContext.getIdGeneratorFactory());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) Config.defaults(org.neo4j.configuration.Config.defaults) DatabaseIdFactory.from(org.neo4j.kernel.database.DatabaseIdFactory.from) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Function(java.util.function.Function) BufferedIdController(org.neo4j.internal.id.BufferedIdController) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) Inject(org.neo4j.test.extension.Inject) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Path(java.nio.file.Path) DatabaseIdRepository(org.neo4j.kernel.database.DatabaseIdRepository) PageCache(org.neo4j.io.pagecache.PageCache) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) UUID(java.util.UUID) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IdType(org.neo4j.internal.id.IdType) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Mockito.mock(org.mockito.Mockito.mock) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 12 with IdGeneratorFactory

use of org.neo4j.internal.id.IdGeneratorFactory in project neo4j by neo4j.

the class NeoStoresTest method reinitializeStores.

private void reinitializeStores(DatabaseLayout databaseLayout) {
    Dependencies dependencies = new Dependencies();
    Config config = Config.defaults(GraphDatabaseSettings.fail_on_missing_files, false);
    dependencies.satisfyDependency(config);
    closeStorageEngine();
    IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
    TokenHolders tokenHolders = new TokenHolders(createReadOnlyTokenHolder(TokenHolder.TYPE_PROPERTY_KEY), createReadOnlyTokenHolder(TokenHolder.TYPE_LABEL), createReadOnlyTokenHolder(TokenHolder.TYPE_RELATIONSHIP_TYPE));
    storageEngine = new RecordStorageEngine(databaseLayout, config, pageCache, fs, nullLogProvider(), tokenHolders, new DatabaseSchemaState(nullLogProvider()), new StandardConstraintRuleAccessor(), i -> i, NO_LOCK_SERVICE, mock(Health.class), idGeneratorFactory, new DefaultIdController(), immediate(), PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE);
    life = new LifeSupport();
    life.add(storageEngine);
    life.add(storageEngine.schemaAndTokensLifecycle());
    life.start();
    NeoStores neoStores = storageEngine.testAccessNeoStores();
    pStore = neoStores.getPropertyStore();
    nodeStore = neoStores.getNodeStore();
    storageReader = storageEngine.newReader();
}
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) DefaultIdController(org.neo4j.internal.id.DefaultIdController) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) Config(org.neo4j.configuration.Config) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) Dependencies(org.neo4j.collection.Dependencies) TokenHolders(org.neo4j.token.TokenHolders) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor)

Example 13 with IdGeneratorFactory

use of org.neo4j.internal.id.IdGeneratorFactory in project neo4j by neo4j.

the class NeoStoreOpenFailureTest method mustCloseAllStoresIfNeoStoresFailToOpen.

@Test
@DisabledForRoot
void mustCloseAllStoresIfNeoStoresFailToOpen() {
    Config config = Config.defaults();
    IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    LogProvider logProvider = NullLogProvider.getInstance();
    RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
    RecordFormatPropertyConfigurator.configureRecordFormat(formats, config);
    boolean create = true;
    StoreType[] storeTypes = StoreType.values();
    ImmutableSet<OpenOption> openOptions = immutable.empty();
    NeoStores neoStores = new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions);
    Path schemaStore = neoStores.getSchemaStore().getStorageFile();
    neoStores.close();
    // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
    assumeTrue(schemaStore.toFile().setReadable(false));
    assumeTrue(schemaStore.toFile().setWritable(false));
    assertThrows(RuntimeException.class, () -> new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions));
    // We verify that the successfully opened stores were closed again by the failed NeoStores open,
    // by closing the page cache, which will throw if not all files have been unmapped.
    pageCache.close();
}
Also used : Path(java.nio.file.Path) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) OpenOption(java.nio.file.OpenOption) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 14 with IdGeneratorFactory

use of org.neo4j.internal.id.IdGeneratorFactory in project neo4j by neo4j.

the class NodeStoreTest method newNodeStore.

private NodeStore newNodeStore(FileSystemAbstraction fs, PageCache pageCache) {
    IdGeneratorFactory idGeneratorFactory = spy(new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()) {

        @Override
        protected IndexedIdGenerator instantiate(FileSystemAbstraction fs, PageCache pageCache, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Path fileName, LongSupplier highIdSupplier, long maxValue, IdType idType, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, String databaseName, ImmutableSet<OpenOption> openOptions) {
            return spy(super.instantiate(fs, pageCache, recoveryCleanupWorkCollector, fileName, highIdSupplier, maxValue, idType, readOnlyChecker, config, cursorContext, databaseName, openOptions));
        }
    });
    StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
    neoStores = factory.openAllNeoStores(true);
    nodeStore = neoStores.getNodeStore();
    return nodeStore;
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) IdType(org.neo4j.internal.id.IdType) OpenOption(java.nio.file.OpenOption) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) LongSupplier(java.util.function.LongSupplier) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache)

Example 15 with IdGeneratorFactory

use of org.neo4j.internal.id.IdGeneratorFactory in project neo4j by neo4j.

the class CommunityEditionModuleIntegrationTest method createBufferedIdComponentsByDefault.

@Test
void createBufferedIdComponentsByDefault() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        DependencyResolver dependencyResolver = database.getDependencyResolver();
        IdController idController = dependencyResolver.resolveDependency(IdController.class);
        IdGeneratorFactory idGeneratorFactory = dependencyResolver.resolveDependency(IdGeneratorFactory.class);
        assertThat(idController).isInstanceOf(BufferedIdController.class);
        assertThat(idGeneratorFactory).isInstanceOf(BufferingIdGeneratorFactory.class);
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) BufferedIdController(org.neo4j.internal.id.BufferedIdController) IdController(org.neo4j.internal.id.IdController) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Aggregations

IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)15 Path (java.nio.file.Path)9 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)9 Config (org.neo4j.configuration.Config)8 Test (org.junit.jupiter.api.Test)6 LongSupplier (java.util.function.LongSupplier)5 IdType (org.neo4j.internal.id.IdType)5 PageCache (org.neo4j.io.pagecache.PageCache)5 IOException (java.io.IOException)4 BufferedIdController (org.neo4j.internal.id.BufferedIdController)4 BufferingIdGeneratorFactory (org.neo4j.internal.id.BufferingIdGeneratorFactory)4 OpenOption (java.nio.file.OpenOption)3 Sets.immutable (org.eclipse.collections.api.factory.Sets.immutable)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 Mockito.mock (org.mockito.Mockito.mock)3 DatabaseReadOnlyChecker (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker)3 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)3 IdGenerator (org.neo4j.internal.id.IdGenerator)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 NULL (org.neo4j.io.pagecache.context.CursorContext.NULL)3