Search in sources :

Example 1 with CachedStoreCursors

use of org.neo4j.kernel.impl.store.cursor.CachedStoreCursors in project graph-data-science by neo4j.

the class InMemoryStorageEngineFactory method loadReadOnlyTokens.

private TokenHolders loadReadOnlyTokens(NeoStores stores, boolean lenient, CursorContextFactory cursorContextFactory) {
    try (var cursorContext = cursorContextFactory.create("loadReadOnlyTokens");
        var storeCursors = new CachedStoreCursors(stores, cursorContext)) {
        stores.start(cursorContext);
        TokensLoader loader = lenient ? StoreTokens.allReadableTokens(stores) : StoreTokens.allTokens(stores);
        TokenHolder propertyKeys = new DelegatingTokenHolder(ReadOnlyTokenCreator.READ_ONLY, TokenHolder.TYPE_PROPERTY_KEY);
        TokenHolder labels = new DelegatingTokenHolder(ReadOnlyTokenCreator.READ_ONLY, TokenHolder.TYPE_LABEL);
        TokenHolder relationshipTypes = new DelegatingTokenHolder(ReadOnlyTokenCreator.READ_ONLY, TokenHolder.TYPE_RELATIONSHIP_TYPE);
        propertyKeys.setInitialTokens(lenient ? unique(loader.getPropertyKeyTokens(storeCursors)) : loader.getPropertyKeyTokens(storeCursors));
        labels.setInitialTokens(lenient ? unique(loader.getLabelTokens(storeCursors)) : loader.getLabelTokens(storeCursors));
        relationshipTypes.setInitialTokens(lenient ? unique(loader.getRelationshipTypeTokens(storeCursors)) : loader.getRelationshipTypeTokens(storeCursors));
        return new TokenHolders(propertyKeys, labels, relationshipTypes);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : TokensLoader(org.neo4j.token.api.TokensLoader) CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) TokenHolder(org.neo4j.token.api.TokenHolder) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder)

Example 2 with CachedStoreCursors

use of org.neo4j.kernel.impl.store.cursor.CachedStoreCursors in project neo4j by neo4j.

the class RelationshipGroupDefragmenterTest method init.

private void init(RecordFormats format, int units) throws IOException {
    this.units = units;
    jobScheduler = new ThreadPoolJobScheduler();
    stores = BatchingNeoStores.batchingNeoStores(testDirectory.getFileSystem(), databaseLayout, format, CONFIG, NullLogService.getInstance(), AdditionalInitialIds.EMPTY, Config.defaults(), jobScheduler, PageCacheTracer.NULL, INSTANCE);
    stores.createNew();
    storeCursors = new CachedStoreCursors(stores.getNeoStores(), NULL);
}
Also used : CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler)

Example 3 with CachedStoreCursors

use of org.neo4j.kernel.impl.store.cursor.CachedStoreCursors in project neo4j by neo4j.

the class NodeImporterTest method shouldHandleLargeAmountsOfLabels.

@Test
void shouldHandleLargeAmountsOfLabels() throws IOException {
    // given
    IdMapper idMapper = mock(IdMapper.class);
    JobScheduler scheduler = new ThreadPoolJobScheduler();
    try (Lifespan life = new Lifespan(scheduler);
        BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache(fs, pageCache, NULL, layout, Standard.LATEST_RECORD_FORMATS, Configuration.DEFAULT, NullLogService.getInstance(), AdditionalInitialIds.EMPTY, Config.defaults(), INSTANCE)) {
        stores.createNew();
        try (var storeCursors = new CachedStoreCursors(stores.getNeoStores(), CursorContext.NULL)) {
            // when
            int numberOfLabels = 50;
            long nodeId = 0;
            try (NodeImporter importer = new NodeImporter(stores, idMapper, new DataImporter.Monitor(), NULL, INSTANCE)) {
                importer.id(nodeId);
                String[] labels = new String[numberOfLabels];
                for (int i = 0; i < labels.length; i++) {
                    labels[i] = "Label" + i;
                }
                importer.labels(labels);
                importer.endOfEntity();
            }
            // then
            NodeStore nodeStore = stores.getNodeStore();
            PageCursor nodeCursor = storeCursors.readCursor(NODE_CURSOR);
            NodeRecord record = nodeStore.getRecordByCursor(nodeId, nodeStore.newRecord(), RecordLoad.NORMAL, nodeCursor);
            long[] labels = NodeLabelsField.parseLabelsField(record).get(nodeStore, storeCursors);
            assertEquals(numberOfLabels, labels.length);
        }
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) BatchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) PageCursor(org.neo4j.io.pagecache.PageCursor) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) NodeStore(org.neo4j.kernel.impl.store.NodeStore) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.jupiter.api.Test)

Example 4 with CachedStoreCursors

use of org.neo4j.kernel.impl.store.cursor.CachedStoreCursors in project neo4j by neo4j.

the class ApplyRecoveredTransactionsTest method before.

@BeforeEach
void before() {
    idGeneratorFactory = new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName());
    StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
    neoStores = storeFactory.openAllNeoStores(true);
    storeCursors = new CachedStoreCursors(neoStores, NULL);
}
Also used : CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CachedStoreCursors

use of org.neo4j.kernel.impl.store.cursor.CachedStoreCursors in project neo4j by neo4j.

the class ConsistencyCheckingApplierTest method setUp.

@BeforeEach
void setUp() {
    Config config = Config.defaults(neo4j_home, directory.homePath());
    RecordDatabaseLayout layout = RecordDatabaseLayout.of(config);
    neoStores = new StoreFactory(layout, config, new DefaultIdGeneratorFactory(directory.getFileSystem(), immediate(), DEFAULT_DATABASE_NAME), pageCache, directory.getFileSystem(), NullLogProvider.getInstance(), PageCacheTracer.NULL, writable()).openAllNeoStores(true);
    RelationshipStore relationshipStore = neoStores.getRelationshipStore();
    storeCursors = new CachedStoreCursors(neoStores, CursorContext.NULL);
    checker = new ConsistencyCheckingApplier(relationshipStore, CursorContext.NULL);
    BatchContext batchContext = mock(BatchContext.class);
    when(batchContext.getLockGroup()).thenReturn(new LockGroup());
    applier = new NeoStoreTransactionApplier(CommandVersion.AFTER, neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE, 0, batchContext, CursorContext.NULL, storeCursors);
    appliers = new TransactionApplier[] { checker, applier };
}
Also used : CachedStoreCursors(org.neo4j.kernel.impl.store.cursor.CachedStoreCursors) LockGroup(org.neo4j.lock.LockGroup) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecordDatabaseLayout(org.neo4j.io.layout.recordstorage.RecordDatabaseLayout) ConsistencyCheckingApplier(org.neo4j.internal.recordstorage.ConsistencyCheckingApplierFactory.ConsistencyCheckingApplier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CachedStoreCursors (org.neo4j.kernel.impl.store.cursor.CachedStoreCursors)51 CursorContext (org.neo4j.io.pagecache.context.CursorContext)23 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)21 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)19 NeoStores (org.neo4j.kernel.impl.store.NeoStores)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 TokenHolders (org.neo4j.token.TokenHolders)10 Test (org.junit.jupiter.api.Test)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)9 Config (org.neo4j.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)8 PageCursor (org.neo4j.io.pagecache.PageCursor)7 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)7 StoreCursors (org.neo4j.storageengine.api.cursor.StoreCursors)7 Value (org.neo4j.values.storable.Value)7 IOException (java.io.IOException)6 RecordDatabaseLayout (org.neo4j.io.layout.recordstorage.RecordDatabaseLayout)6 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)6 Path (java.nio.file.Path)5