Search in sources :

Example 1 with CommunityIdTypeConfigurationProvider

use of org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider in project neo4j by neo4j.

the class NeoStoreDataSourceRule method getDataSource.

public NeoStoreDataSource getDataSource(File storeDir, FileSystemAbstraction fs, PageCache pageCache, Map<String, String> additionalConfig, DatabaseHealth databaseHealth) {
    CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
    NullLogService logService = NullLogService.getInstance();
    return getDataSource(storeDir, fs, idGeneratorFactory, idTypeConfigurationProvider, pageCache, additionalConfig, databaseHealth, logService);
}
Also used : CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) NullLogService(org.neo4j.kernel.impl.logging.NullLogService)

Example 2 with CommunityIdTypeConfigurationProvider

use of org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider in project neo4j by neo4j.

the class BufferingIdGeneratorFactoryTest method shouldDelayFreeingOfAggressivelyReusedIds.

@Test
public void shouldDelayFreeingOfAggressivelyReusedIds() throws Exception {
    // GIVEN
    MockedIdGeneratorFactory actual = new MockedIdGeneratorFactory();
    ControllableSnapshotSupplier boundaries = new ControllableSnapshotSupplier();
    BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(actual, boundaries, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider());
    IdGenerator idGenerator = bufferingIdGeneratorFactory.open(new File("doesnt-matter"), 10, IdType.STRING_BLOCK, 0, Integer.MAX_VALUE);
    // WHEN
    idGenerator.freeId(7);
    verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
    // after some maintenance and transaction still not closed
    bufferingIdGeneratorFactory.maintenance();
    verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
    // although after transactions have all closed
    boundaries.setMostRecentlyReturnedSnapshotToAllClosed();
    bufferingIdGeneratorFactory.maintenance();
    // THEN
    verify(actual.get(IdType.STRING_BLOCK)).freeId(7);
}
Also used : CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) File(java.io.File) Test(org.junit.Test)

Example 3 with CommunityIdTypeConfigurationProvider

use of org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider in project neo4j by neo4j.

the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.

@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
    final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {

        private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();

        @Override
        public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
            if (idType == IdType.LABEL_TOKEN) {
                IdGenerator generator = generators.get(idType);
                if (generator == null) {
                    IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
                    generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {

                        @Override
                        public long nextId() {
                            // Same exception as the one thrown by IdGeneratorImpl
                            throw new UnderlyingStorageException("Id capacity exceeded");
                        }
                    };
                    generators.put(idType, generator);
                }
                return generator;
            }
            return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
        }
    };
    TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {

        @Override
        protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
            return new GraphDatabaseBuilder.DatabaseCreator() {

                @Override
                public GraphDatabaseService newDatabase(Map<String, String> config) {
                    return newDatabase(Config.embeddedDefaults(config));
                }

                @Override
                public GraphDatabaseService newDatabase(@Nonnull Config config) {
                    return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {

                        @Override
                        protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
                            Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {

                                @Override
                                protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
                                    return idFactory;
                                }
                            };
                            new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {

                                @Override
                                protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
                                    return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
                                }
                            }.initFacade(storeDir, config, dependencies, this);
                        }
                    };
                }
            };
        }
    };
    return dbFactory.newImpermanentDatabase();
}
Also used : EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Matchers.not(org.hamcrest.Matchers.not) Statement(org.neo4j.kernel.api.Statement) IdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider) Matchers.hasItems(org.hamcrest.Matchers.hasItems) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Cursor(org.neo4j.cursor.Cursor) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) Assert.assertThat(org.junit.Assert.assertThat) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Iterables.map(org.neo4j.helpers.collection.Iterables.map) EditionModule(org.neo4j.kernel.impl.factory.EditionModule) Map(java.util.Map) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) Assert.fail(org.junit.Assert.fail) Neo4jMatchers.inTx(org.neo4j.test.mockito.matcher.Neo4jMatchers.inTx) Collectors.toSet(java.util.stream.Collectors.toSet) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PrimitiveIntCollections.consume(org.neo4j.collection.primitive.PrimitiveIntCollections.consume) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Set(java.util.Set) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) IdType(org.neo4j.kernel.impl.store.id.IdType) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) TestGraphDatabaseFactoryState(org.neo4j.test.TestGraphDatabaseFactoryState) PropertyItem(org.neo4j.storageengine.api.PropertyItem) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) IdTypeConfiguration(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfiguration) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) Neo4jMatchers.hasNoLabels(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNoLabels) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Neo4jMatchers.hasLabel(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasLabel) Neo4jMatchers.hasNoNodes(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNoNodes) Neo4jMatchers.hasLabels(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasLabels) Nonnull(javax.annotation.Nonnull) ImpermanentDatabaseRule(org.neo4j.test.rule.ImpermanentDatabaseRule) Config(org.neo4j.kernel.configuration.Config) Iterator(java.util.Iterator) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Label.label(org.neo4j.graphdb.Label.label) Iterables.asList(org.neo4j.helpers.collection.Iterables.asList) File(java.io.File) Rule(org.junit.Rule) Iterables(org.neo4j.helpers.collection.Iterables) Neo4jMatchers.hasNodes(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNodes) NodeItem(org.neo4j.storageengine.api.NodeItem) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) IdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) TestGraphDatabaseFactoryState(org.neo4j.test.TestGraphDatabaseFactoryState) Nonnull(javax.annotation.Nonnull) EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) IdType(org.neo4j.kernel.impl.store.id.IdType) EditionModule(org.neo4j.kernel.impl.factory.EditionModule) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) IdTypeConfiguration(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfiguration) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) File(java.io.File) Map(java.util.Map)

Example 4 with CommunityIdTypeConfigurationProvider

use of org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider in project neo4j by neo4j.

the class NeoStoreDataSourceTest method logModuleSetUpError.

@Test
public void logModuleSetUpError() throws Exception {
    Config config = Config.embeddedDefaults(stringMap());
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    Throwable openStoresError = new RuntimeException("Can't set up modules");
    doThrow(openStoresError).when(idGeneratorFactory).create(any(File.class), anyLong(), anyBoolean());
    CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
    AssertableLogProvider logProvider = new AssertableLogProvider();
    SimpleLogService logService = new SimpleLogService(logProvider, logProvider);
    PageCache pageCache = pageCacheRule.getPageCache(fs.get());
    NeoStoreDataSource dataSource = dsRule.getDataSource(dir.graphDbDir(), fs.get(), idGeneratorFactory, idTypeConfigurationProvider, pageCache, config, mock(DatabaseHealth.class), logService);
    try {
        dataSource.start();
        fail("Exception expected");
    } catch (Exception e) {
        assertEquals(openStoresError, e);
    }
    logProvider.assertAtLeastOnce(inLog(NeoStoreDataSource.class).warn(equalTo("Exception occurred while setting up store modules. Attempting to close things down."), equalTo(openStoresError)));
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) SimpleLogService(org.neo4j.kernel.impl.logging.SimpleLogService) Config(org.neo4j.kernel.configuration.Config) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 5 with CommunityIdTypeConfigurationProvider

use of org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider in project neo4j by neo4j.

the class BufferingIdGeneratorFactoryTest method shouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell.

@Test
public void shouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell() throws Exception {
    // GIVEN
    MockedIdGeneratorFactory actual = new MockedIdGeneratorFactory();
    final FakeClock clock = Clocks.fakeClock();
    final long safeZone = MINUTES.toMillis(1);
    ControllableSnapshotSupplier boundaries = new ControllableSnapshotSupplier();
    BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(actual, boundaries, t -> clock.millis() - t.snapshotTime() >= safeZone, new CommunityIdTypeConfigurationProvider());
    IdGenerator idGenerator = bufferingIdGeneratorFactory.open(new File("doesnt-matter"), 10, IdType.STRING_BLOCK, 0, Integer.MAX_VALUE);
    // WHEN
    idGenerator.freeId(7);
    verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
    // after some maintenance and transaction still not closed
    bufferingIdGeneratorFactory.maintenance();
    verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
    // although after transactions have all closed
    boundaries.setMostRecentlyReturnedSnapshotToAllClosed();
    bufferingIdGeneratorFactory.maintenance();
    // ... the clock would still say "nope" so no interaction
    verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
    // then finally after time has passed as well
    clock.forward(70, SECONDS);
    bufferingIdGeneratorFactory.maintenance();
    // THEN
    verify(actual.get(IdType.STRING_BLOCK)).freeId(7);
}
Also used : CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) FakeClock(org.neo4j.time.FakeClock) File(java.io.File) Test(org.junit.Test)

Aggregations

CommunityIdTypeConfigurationProvider (org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider)6 File (java.io.File)4 Test (org.junit.Test)4 Config (org.neo4j.kernel.configuration.Config)3 IdGeneratorFactory (org.neo4j.kernel.impl.store.id.IdGeneratorFactory)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 Nonnull (javax.annotation.Nonnull)1 Matchers.hasItems (org.hamcrest.Matchers.hasItems)1 Matchers.not (org.hamcrest.Matchers.not)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1