Search in sources :

Example 1 with BatchingPropertyKeyTokenRepository

use of org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository in project neo4j by neo4j.

the class BatchingTokenRepositoryTest method shouldFlushNewTokens.

@Test
void shouldFlushNewTokens() {
    // given
    try (NeoStores stores = newNeoStores(StoreType.PROPERTY_KEY_TOKEN, StoreType.PROPERTY_KEY_TOKEN_NAME)) {
        TokenStore<PropertyKeyTokenRecord> tokenStore = stores.getPropertyKeyTokenStore();
        int rounds = 3;
        int tokensPerRound = 4;
        BatchingPropertyKeyTokenRepository repo = new BatchingPropertyKeyTokenRepository(tokenStore);
        // when first creating some tokens
        int expectedId = 0;
        int tokenNameAsInt = 0;
        for (int round = 0; round < rounds; round++) {
            for (int i = 0; i < tokensPerRound; i++) {
                int tokenId = repo.getOrCreateId(String.valueOf(tokenNameAsInt++));
                assertEquals(expectedId + i, tokenId);
            }
            assertEquals(expectedId, tokenStore.getHighId());
            repo.flush(NULL);
            assertEquals(expectedId + tokensPerRound, tokenStore.getHighId());
            expectedId += tokensPerRound;
        }
        repo.flush(NULL);
        List<NamedToken> tokens = tokenStore.getTokens(NULL);
        assertEquals(tokensPerRound * rounds, tokens.size());
        for (NamedToken token : tokens) {
            assertEquals(token.id(), parseInt(token.name()));
        }
    }
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) BatchingPropertyKeyTokenRepository(org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository) NamedToken(org.neo4j.token.api.NamedToken) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) Test(org.junit.jupiter.api.Test)

Example 2 with BatchingPropertyKeyTokenRepository

use of org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository 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)

Aggregations

BatchingPropertyKeyTokenRepository (org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingPropertyKeyTokenRepository)2 Test (org.junit.jupiter.api.Test)1 BatchingLabelTokenRepository (org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingLabelTokenRepository)1 BatchingRelationshipTypeTokenRepository (org.neo4j.internal.batchimport.store.BatchingTokenRepository.BatchingRelationshipTypeTokenRepository)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)1 DelegatingTokenHolder (org.neo4j.token.DelegatingTokenHolder)1 TokenHolders (org.neo4j.token.TokenHolders)1 NamedToken (org.neo4j.token.api.NamedToken)1