Search in sources :

Example 21 with TokenHolders

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

the class BatchingNeoStores method instantiateStores.

private void instantiateStores() throws IOException {
    neoStores = newStoreFactory(databaseLayout, idGeneratorFactory, pageCacheTracer, immutable.empty()).openAllNeoStores(true);
    propertyKeyRepository = new BatchingPropertyKeyTokenRepository(neoStores.getPropertyKeyTokenStore());
    labelRepository = new BatchingLabelTokenRepository(neoStores.getLabelTokenStore());
    relationshipTypeRepository = new BatchingRelationshipTypeTokenRepository(neoStores.getRelationshipTypeTokenStore());
    tokenHolders = new TokenHolders(new DelegatingTokenHolder((key, internal) -> propertyKeyRepository.getOrCreateId(key, internal), TYPE_PROPERTY_KEY), new DelegatingTokenHolder((key, internal) -> labelRepository.getOrCreateId(key, internal), TYPE_LABEL), new DelegatingTokenHolder((key, internal) -> relationshipTypeRepository.getOrCreateId(key, internal), TYPE_RELATIONSHIP_TYPE));
    tokenHolders.propertyKeyTokens().setInitialTokens(neoStores.getPropertyKeyTokenStore().getTokens(CursorContext.NULL));
    temporaryNeoStores = instantiateTempStores();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(BATCHING_STORE_CREATION_TAG))) {
        neoStores.start(cursorContext);
        temporaryNeoStores.start(cursorContext);
        MetaDataStore metaDataStore = neoStores.getMetaDataStore();
        metaDataStore.setLastCommittedAndClosedTransactionId(initialIds.lastCommittedTransactionId(), initialIds.lastCommittedTransactionChecksum(), BASE_TX_COMMIT_TIMESTAMP, initialIds.lastCommittedTransactionLogByteOffset(), initialIds.lastCommittedTransactionLogVersion(), cursorContext);
        metaDataStore.setCheckpointLogVersion(initialIds.checkpointLogVersion(), cursorContext);
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) BatchingLabelTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingLabelTokenRepository) BatchingRelationshipTypeTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingRelationshipTypeTokenRepository) BatchingPropertyKeyTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Example 22 with TokenHolders

use of org.neo4j.token.TokenHolders 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

TokenHolders (org.neo4j.token.TokenHolders)22 DelegatingTokenHolder (org.neo4j.token.DelegatingTokenHolder)12 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 NeoStores (org.neo4j.kernel.impl.store.NeoStores)9 PageCache (org.neo4j.io.pagecache.PageCache)8 JobScheduler (org.neo4j.scheduler.JobScheduler)8 SchemaRule (org.neo4j.internal.schema.SchemaRule)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Config (org.neo4j.configuration.Config)6 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)6 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 TokenHolder (org.neo4j.token.api.TokenHolder)6 Path (java.nio.file.Path)5 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)5 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)5 IndexStatisticsStore (org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore)5 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)5