Search in sources :

Example 1 with IndexedIdGenerator

use of org.neo4j.internal.id.indexed.IndexedIdGenerator in project neo4j by neo4j.

the class DefaultIdGeneratorFactory method create.

@Override
public IdGenerator create(PageCache pageCache, Path fileName, IdType idType, long highId, boolean throwIfFileExists, long maxId, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, ImmutableSet<OpenOption> openOptions) throws IOException {
    // but there's a naked id generator, then delete the id generator so that it too starts from a clean state.
    if (fs.fileExists(fileName)) {
        fs.deleteFile(fileName);
    }
    IndexedIdGenerator generator = new IndexedIdGenerator(pageCache, fileName, recoveryCleanupWorkCollector, idType, allowLargeIdCaches, () -> highId, maxId, readOnlyChecker, config, cursorContext, defaultIdMonitor(fs, fileName, config), databaseName, openOptions);
    generator.checkpoint(cursorContext);
    generators.put(idType, generator);
    return generator;
}
Also used : IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator)

Example 2 with IndexedIdGenerator

use of org.neo4j.internal.id.indexed.IndexedIdGenerator in project neo4j by neo4j.

the class DefaultIdGeneratorFactory method open.

@Override
public IdGenerator open(PageCache pageCache, Path filename, IdType idType, LongSupplier highIdScanner, long maxId, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, ImmutableSet<OpenOption> openOptions) throws IOException {
    IndexedIdGenerator generator = instantiate(fs, pageCache, recoveryCleanupWorkCollector, filename, highIdScanner, maxId, idType, readOnlyChecker, config, cursorContext, databaseName, openOptions);
    generators.put(idType, generator);
    return generator;
}
Also used : IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator)

Example 3 with IndexedIdGenerator

use of org.neo4j.internal.id.indexed.IndexedIdGenerator in project neo4j by neo4j.

the class IdGeneratorMigratorTest method assertIdGeneratorContainsIds.

private void assertIdGeneratorContainsIds(Path idFilePath, IdType idType, int rounds, int numDeleted, int numCreated, long startingId) throws IOException {
    try (IdGenerator idGenerator = new IndexedIdGenerator(pageCache, idFilePath, immediate(), idType, false, () -> -1, Long.MAX_VALUE, writable(), Config.defaults(), DEFAULT_DATABASE_NAME, CursorContext.NULL)) {
        idGenerator.start(ignored -> {
            throw new RuntimeException("Should not ask for free ids");
        }, CursorContext.NULL);
        long nextExpectedId = startingId;
        for (int i = 0; i < rounds; i++) {
            for (int d = 0; d < numDeleted; d++) {
                assertEquals(nextExpectedId++, idGenerator.nextId(CursorContext.NULL));
            }
            nextExpectedId += numCreated;
        }
    }
}
Also used : IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator) IndexedIdGenerator(org.neo4j.internal.id.indexed.IndexedIdGenerator) IdGenerator(org.neo4j.internal.id.IdGenerator)

Example 4 with IndexedIdGenerator

use of org.neo4j.internal.id.indexed.IndexedIdGenerator 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)

Aggregations

IndexedIdGenerator (org.neo4j.internal.id.indexed.IndexedIdGenerator)4 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 LongSupplier (java.util.function.LongSupplier)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Config (org.neo4j.configuration.Config)1 DatabaseReadOnlyChecker (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker)1 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)1 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)1 IdGenerator (org.neo4j.internal.id.IdGenerator)1 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)1 IdType (org.neo4j.internal.id.IdType)1 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 DelegatingPageCache (org.neo4j.io.pagecache.DelegatingPageCache)1 PageCache (org.neo4j.io.pagecache.PageCache)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1