Search in sources :

Example 1 with TokenCreator

use of org.neo4j.token.TokenCreator in project neo4j by neo4j.

the class RecordStorageEngineFactory method createMigrationTargetSchemaRuleAccess.

public static SchemaRuleMigrationAccess createMigrationTargetSchemaRuleAccess(NeoStores stores, CursorContext cursorContext, MemoryTracker memoryTracker) {
    SchemaStore dstSchema = stores.getSchemaStore();
    TokenCreator propertyKeyTokenCreator = (name, internal) -> {
        PropertyKeyTokenStore keyTokenStore = stores.getPropertyKeyTokenStore();
        DynamicStringStore nameStore = keyTokenStore.getNameStore();
        byte[] bytes = PropertyStore.encodeString(name);
        List<DynamicRecord> nameRecords = new ArrayList<>();
        AbstractDynamicStore.allocateRecordsFromBytes(nameRecords, bytes, nameStore, cursorContext, memoryTracker);
        nameRecords.forEach(record -> nameStore.prepareForCommit(record, cursorContext));
        nameRecords.forEach(record -> nameStore.updateRecord(record, cursorContext));
        nameRecords.forEach(record -> nameStore.setHighestPossibleIdInUse(record.getId()));
        int nameId = Iterables.first(nameRecords).getIntId();
        PropertyKeyTokenRecord keyTokenRecord = keyTokenStore.newRecord();
        long tokenId = keyTokenStore.nextId(cursorContext);
        keyTokenRecord.setId(tokenId);
        keyTokenRecord.initialize(true, nameId);
        keyTokenRecord.setInternal(internal);
        keyTokenRecord.setCreated();
        keyTokenStore.prepareForCommit(keyTokenRecord, cursorContext);
        keyTokenStore.updateRecord(keyTokenRecord, cursorContext);
        keyTokenStore.setHighestPossibleIdInUse(keyTokenRecord.getId());
        return Math.toIntExact(tokenId);
    };
    TokenHolders dstTokenHolders = tokenHoldersForSchemaStore(stores, propertyKeyTokenCreator, cursorContext);
    return new SchemaRuleMigrationAccessImpl(stores, new SchemaStorage(dstSchema, dstTokenHolders, () -> KernelVersion.LATEST), cursorContext, memoryTracker);
}
Also used : Arrays(java.util.Arrays) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) SchemaRule(org.neo4j.internal.schema.SchemaRule) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) AbstractDynamicStore(org.neo4j.kernel.impl.store.AbstractDynamicStore) Config(org.neo4j.configuration.Config) RecordStoreVersion(org.neo4j.kernel.impl.storemigration.RecordStoreVersion) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ScanOnOpenReadOnlyIdGeneratorFactory(org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory) ConstraintRuleAccessor(org.neo4j.storageengine.api.ConstraintRuleAccessor) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) StorageFilesState(org.neo4j.storageengine.api.StorageFilesState) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) Set(java.util.Set) UUID(java.util.UUID) LockService(org.neo4j.lock.LockService) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) DbmsReadOnlyChecker(org.neo4j.configuration.helpers.DbmsReadOnlyChecker) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) StoreType(org.neo4j.kernel.impl.store.StoreType) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) Optional(java.util.Optional) ServiceProvider(org.neo4j.annotations.service.ServiceProvider) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) StoreVersion(org.neo4j.storageengine.api.StoreVersion) IdController(org.neo4j.internal.id.IdController) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) RecordStorageMigrator(org.neo4j.kernel.impl.storemigration.RecordStorageMigrator) KernelVersion(org.neo4j.kernel.KernelVersion) LogProvider(org.neo4j.logging.LogProvider) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) ArrayList(java.util.ArrayList) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Iterables(org.neo4j.internal.helpers.collection.Iterables) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StoreId(org.neo4j.storageengine.api.StoreId) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) SchemaRuleMigrationAccess(org.neo4j.storageengine.migration.SchemaRuleMigrationAccess) RecordFormatSelector.selectForStoreOrConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig) CommandReaderFactory(org.neo4j.storageengine.api.CommandReaderFactory) IdGeneratorMigrator(org.neo4j.kernel.impl.storemigration.IdGeneratorMigrator) RecordFormatSelector.selectForVersion(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForVersion) IOException(java.io.IOException) StoreMigrationParticipant(org.neo4j.storageengine.migration.StoreMigrationParticipant) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) LogService(org.neo4j.logging.internal.LogService) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) StoreVersionCheck(org.neo4j.storageengine.api.StoreVersionCheck) SchemaState(org.neo4j.internal.schema.SchemaState) RecordStoreRollingUpgradeCompatibility(org.neo4j.kernel.impl.storemigration.RecordStoreRollingUpgradeCompatibility) BatchImporterFactory(org.neo4j.internal.batchimport.BatchImporterFactory) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) META_DATA(org.neo4j.kernel.impl.store.StoreType.META_DATA) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RollingUpgradeCompatibility(org.neo4j.storageengine.migration.RollingUpgradeCompatibility) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) TokenHolders(org.neo4j.token.TokenHolders) TokenCreator(org.neo4j.token.TokenCreator) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Example 2 with TokenCreator

use of org.neo4j.token.TokenCreator in project neo4j by neo4j.

the class SchemaStorageReadAndWriteTest method before.

@BeforeAll
void before() throws Exception {
    testDirectory.prepareDirectory(getClass(), "test");
    var storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
    neoStores = storeFactory.openNeoStores(true, StoreType.SCHEMA, StoreType.PROPERTY_KEY_TOKEN, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN);
    AtomicInteger tokenIdCounter = new AtomicInteger();
    TokenCreator tokenCreator = (name, internal) -> tokenIdCounter.incrementAndGet();
    TokenHolders tokens = new TokenHolders(new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(tokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
    tokens.setInitialTokens(StoreTokens.allTokens(neoStores), NULL);
    tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.propertyKeyTokens().size()));
    tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.labelTokens().size()));
    tokenIdCounter.set(Math.max(tokenIdCounter.get(), tokens.relationshipTypeTokens().size()));
    storage = new SchemaStorage(neoStores.getSchemaStore(), tokens, () -> KernelVersion.LATEST);
}
Also used : RepeatedTest(org.junit.jupiter.api.RepeatedTest) SchemaRule(org.neo4j.internal.schema.SchemaRule) TokenCreator(org.neo4j.token.TokenCreator) KernelVersion(org.neo4j.kernel.KernelVersion) Config(org.neo4j.configuration.Config) NullLogProvider(org.neo4j.logging.NullLogProvider) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) AfterAll(org.junit.jupiter.api.AfterAll) TokenHolder(org.neo4j.token.api.TokenHolder) TestInstance(org.junit.jupiter.api.TestInstance) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) PageCache(org.neo4j.io.pagecache.PageCache) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) EphemeralPageCacheExtension(org.neo4j.test.extension.pagecache.EphemeralPageCacheExtension) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) EphemeralNeo4jLayoutExtension(org.neo4j.test.extension.EphemeralNeo4jLayoutExtension) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) TokenHolders(org.neo4j.token.TokenHolders) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) TokenHolders(org.neo4j.token.TokenHolders) TokenCreator(org.neo4j.token.TokenCreator) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Config (org.neo4j.configuration.Config)2 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)2 RecoveryCleanupWorkCollector.immediate (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate)2 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)2 SchemaRule (org.neo4j.internal.schema.SchemaRule)2 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)2 PageCache (org.neo4j.io.pagecache.PageCache)2 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)2 KernelVersion (org.neo4j.kernel.KernelVersion)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)2 StoreType (org.neo4j.kernel.impl.store.StoreType)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2 DelegatingTokenHolder (org.neo4j.token.DelegatingTokenHolder)2 TokenCreator (org.neo4j.token.TokenCreator)2 TokenHolders (org.neo4j.token.TokenHolders)2 TokenHolder (org.neo4j.token.api.TokenHolder)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1