Search in sources :

Example 1 with IdGeneratorFactory

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

the class CountsComputerTest method rebuildCounts.

private void rebuildCounts(long lastCommittedTransactionId, ProgressReporter progressReporter) throws IOException {
    cleanupCountsForRebuilding();
    IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    StoreFactory storeFactory = new StoreFactory(databaseLayout, CONFIG, idGenFactory, pageCache, fileSystem, LOG_PROVIDER, PageCacheTracer.NULL, writable());
    try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
        int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
        CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId, NumberArrayFactories.AUTO_WITHOUT_PAGECACHE, databaseLayout, progressReporter, PageCacheTracer.NULL, INSTANCE);
        try (GBPTreeCountsStore countsStore = createCountsStore(countsComputer)) {
            countsStore.start(NULL, INSTANCE);
            countsStore.checkpoint(NULL);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) IOException(java.io.IOException) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory)

Example 2 with IdGeneratorFactory

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

the class RecordStorageMigratorIT method mustMigrateSchemaStoreToNewFormat.

@ParameterizedTest
@MethodSource("versions")
void mustMigrateSchemaStoreToNewFormat(String version, LogPosition expectedLogPosition, Function<TransactionId, Boolean> txIdComparator) throws Exception {
    // Given we have an old store full of random schema rules.
    Path prepare = testDirectory.directory("prepare");
    var fs = testDirectory.getFileSystem();
    MigrationTestUtils.prepareSampleLegacyDatabase(version, fs, databaseLayout.databaseDirectory(), prepare);
    // and a state of the migration saying that it has done the actual migration
    LogService logService = NullLogService.getInstance();
    // Uses this special scan-on-open IGF because when the new IndexedIdGenerator was introduced this test would break
    // when trying to open an older store, before doing migration.
    IdGeneratorFactory igf = new ScanOnOpenOverwritingIdGeneratorFactory(fs, databaseLayout.getDatabaseName());
    LogProvider logProvider = logService.getInternalLogProvider();
    // Prepare all the tokens we'll need.
    StoreFactory legacyStoreFactory = new StoreFactory(databaseLayout, CONFIG, igf, pageCache, fs, StandardV3_4.RECORD_FORMATS, logProvider, PageCacheTracer.NULL, writable(), immutable.empty());
    NeoStores stores = legacyStoreFactory.openNeoStores(false, StoreType.LABEL_TOKEN, StoreType.LABEL_TOKEN_NAME, StoreType.RELATIONSHIP_TYPE_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN_NAME, StoreType.PROPERTY_KEY_TOKEN, StoreType.PROPERTY_KEY_TOKEN_NAME);
    createTokens(stores.getLabelTokenStore(), MAX_LABEL_ID);
    createTokens(stores.getRelationshipTypeTokenStore(), MAX_RELATIONSHIP_TYPE_ID);
    createTokens(stores.getPropertyKeyTokenStore(), MAX_PROPERTY_KEY_ID);
    stores.close();
    // Prepare the legacy schema store we'll migrate.
    Path storeFile = databaseLayout.schemaStore();
    Path idFile = databaseLayout.idSchemaStore();
    SchemaStore35 schemaStore35 = new SchemaStore35(storeFile, idFile, CONFIG, IdType.SCHEMA, igf, pageCache, logProvider, StandardV3_4.RECORD_FORMATS, writable(), DEFAULT_DATABASE_NAME, immutable.empty());
    schemaStore35.initialise(false, NULL);
    SplittableRandom rng = new SplittableRandom(randomRule.seed());
    LongHashSet indexes = new LongHashSet();
    LongHashSet constraints = new LongHashSet();
    for (int i = 0; i < 10; i++) {
        long id = schemaStore35.nextId(NULL);
        MutableLongSet target = rng.nextInt(3) < 2 ? indexes : constraints;
        target.add(id);
    }
    List<SchemaRule> generatedRules = new ArrayList<>();
    RealIdsRandomSchema randomSchema = new RealIdsRandomSchema(rng, indexes, constraints);
    while (randomSchema.hasMoreIds()) {
        try {
            SchemaRule schemaRule = randomSchema.nextSchemaRule();
            if (schemaRule instanceof ConstraintDescriptor) {
                ConstraintDescriptor constraint = (ConstraintDescriptor) schemaRule;
                if (constraint.isIndexBackedConstraint() && !constraint.asIndexBackedConstraint().hasOwnedIndexId()) {
                    // Filter out constraints that are supposed to own indexes, but don't, because those are illegal to persist.
                    randomSchema.rollback();
                    continue;
                }
            }
            randomSchema.commit();
            generatedRules.add(schemaRule);
            List<DynamicRecord> dynamicRecords = allocateFrom(schemaStore35, schemaRule, NULL);
            for (DynamicRecord dynamicRecord : dynamicRecords) {
                schemaStore35.updateRecord(dynamicRecord, NULL);
            }
        } catch (NoSuchElementException ignore) {
        // We're starting to run low on ids, but just ignore this and loop as along as there are still some left.
        }
    }
    schemaStore35.flush(NULL);
    schemaStore35.close();
    RecordStoreVersionCheck check = getVersionCheck(pageCache, databaseLayout);
    String versionToMigrateFrom = getVersionToMigrateFrom(check);
    MigrationProgressMonitor progressMonitor = SILENT;
    RecordStorageMigrator migrator = new RecordStorageMigrator(fs, pageCache, CONFIG, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
    // When we migrate it to the new store format.
    String versionToMigrateTo = getVersionToMigrateTo(check);
    ProgressReporter reporter = progressMonitor.startSection("section");
    migrator.migrate(databaseLayout, migrationLayout, reporter, versionToMigrateFrom, versionToMigrateTo, EMPTY);
    migrator.moveMigratedFiles(migrationLayout, databaseLayout, versionToMigrateFrom, versionToMigrateTo);
    generatedRules.sort(Comparator.comparingLong(SchemaRule::getId));
    // Then the new store should retain an exact representation of the old-format schema rules.
    StoreFactory storeFactory = new StoreFactory(databaseLayout, CONFIG, igf, pageCache, fs, logProvider, PageCacheTracer.NULL, writable());
    try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
        SchemaStore schemaStore = neoStores.getSchemaStore();
        TokenHolders tokenHolders = StoreTokens.readOnlyTokenHolders(neoStores, NULL);
        SchemaStorage storage = new SchemaStorage(schemaStore, tokenHolders, () -> KernelVersion.LATEST);
        List<SchemaRule> migratedRules = new ArrayList<>();
        storage.getAll(NULL).iterator().forEachRemaining(migratedRules::add);
        // Nerf the rule names, since migration may change those around.
        migratedRules = migratedRules.stream().map(r -> r.withName("a")).collect(Collectors.toList());
        generatedRules = generatedRules.stream().map(r -> r.withName("a")).collect(Collectors.toList());
        assertThat(migratedRules).isEqualTo(generatedRules);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.internal.schema.SchemaRule) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) SchemaStorage(org.neo4j.internal.recordstorage.SchemaStorage) TokenHolders(org.neo4j.token.TokenHolders) Path(java.nio.file.Path) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ProgressReporter(org.neo4j.common.ProgressReporter) SchemaStore35(org.neo4j.kernel.impl.storemigration.legacy.SchemaStore35) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) NullLogProvider.nullLogProvider(org.neo4j.logging.NullLogProvider.nullLogProvider) LogProvider(org.neo4j.logging.LogProvider) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MigrationProgressMonitor(org.neo4j.storageengine.migration.MigrationProgressMonitor) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SplittableRandom(java.util.SplittableRandom) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) NoSuchElementException(java.util.NoSuchElementException) ScanOnOpenOverwritingIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenOverwritingIdGeneratorFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with IdGeneratorFactory

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

the class RecordStorageEngineRule method get.

private RecordStorageEngine get(FileSystemAbstraction fs, PageCache pageCache, Health databaseHealth, DatabaseLayout databaseLayout, Function<TransactionApplierFactoryChain, TransactionApplierFactoryChain> transactionApplierTransformer, IndexUpdateListener indexUpdateListener, LockService lockService, TokenHolders tokenHolders, Config config, ConstraintRuleAccessor constraintSemantics, IndexConfigCompleter indexConfigCompleter) {
    IdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
    NullLogProvider nullLogProvider = NullLogProvider.getInstance();
    RecordStorageEngine engine = new ExtendedRecordStorageEngine(databaseLayout, config, pageCache, fs, nullLogProvider, tokenHolders, mock(SchemaState.class), constraintSemantics, indexConfigCompleter, lockService, databaseHealth, idGeneratorFactory, new DefaultIdController(), transactionApplierTransformer);
    engine.addIndexUpdateListener(indexUpdateListener);
    life.add(engine);
    return engine;
}
Also used : DefaultIdController(org.neo4j.internal.id.DefaultIdController) SchemaState(org.neo4j.internal.schema.SchemaState) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) NullLogProvider(org.neo4j.logging.NullLogProvider)

Example 4 with IdGeneratorFactory

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

the class IdContextFactory method createBufferingIdContext.

private DatabaseIdContext createBufferingIdContext(Function<NamedDatabaseId, ? extends IdGeneratorFactory> idGeneratorFactoryProvider, JobScheduler jobScheduler, PageCacheTracer cacheTracer, NamedDatabaseId namedDatabaseId) {
    IdGeneratorFactory idGeneratorFactory = idGeneratorFactoryProvider.apply(namedDatabaseId);
    BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(idGeneratorFactory);
    BufferedIdController bufferingController = createBufferedIdController(bufferingIdGeneratorFactory, jobScheduler, cacheTracer, namedDatabaseId.name());
    return createIdContext(bufferingIdGeneratorFactory, bufferingController);
}
Also used : BufferedIdController(org.neo4j.internal.id.BufferedIdController) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory)

Example 5 with IdGeneratorFactory

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

the class TokenStoreTestTemplate method setUp.

@BeforeEach
void setUp() throws IOException {
    Path file = dir.file("label-tokens.db");
    Path idFile = dir.file("label-tokens.db.id");
    Path namesFile = dir.file("label-tokens.db.names");
    Path namesIdFile = dir.file("label-tokens.db.names.id");
    IdGeneratorFactory generatorFactory = new DefaultIdGeneratorFactory(fs, immediate(), DEFAULT_DATABASE_NAME);
    LogProvider logProvider = NullLogProvider.getInstance();
    RecordFormats formats = RecordFormatSelector.defaultFormat();
    Config config = Config.defaults();
    nameStore = new DynamicStringStore(namesFile, namesIdFile, config, IdType.LABEL_TOKEN_NAME, generatorFactory, pageCache, logProvider, TokenStore.NAME_STORE_BLOCK_SIZE, formats.dynamic(), formats.storeVersion(), writable(), DEFAULT_DATABASE_NAME, immutable.empty());
    store = instantiateStore(file, idFile, generatorFactory, pageCache, logProvider, nameStore, formats, config);
    nameStore.initialise(true, NULL);
    store.initialise(true, NULL);
    nameStore.start(NULL);
    store.start(NULL);
}
Also used : Path(java.nio.file.Path) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) 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) BeforeEach(org.junit.jupiter.api.BeforeEach)

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