Search in sources :

Example 21 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class DirectRecordStoreMigrator method migrate.

public void migrate(File fromStoreDir, RecordFormats fromFormat, File toStoreDir, RecordFormats toFormat, MigrationProgressMonitor.Section progressMonitor, StoreType[] types, StoreType... additionalTypesToOpen) {
    StoreType[] storesToOpen = ArrayUtil.concat(types, additionalTypesToOpen);
    progressMonitor.start(storesToOpen.length);
    try (NeoStores fromStores = new StoreFactory(fromStoreDir, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, fromFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen);
        NeoStores toStores = new StoreFactory(toStoreDir, withPersistedStoreHeadersAsConfigFrom(fromStores, storesToOpen), new DefaultIdGeneratorFactory(fs), pageCache, fs, toFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen)) {
        for (StoreType type : types) {
            // This condition will exclude counts store first and foremost.
            if (type.isRecordStore()) {
                migrate(fromStores.getRecordStore(type), toStores.getRecordStore(type));
                progressMonitor.progress(1);
            }
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory)

Example 22 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.

private void launchCustomIndexPopulation(Map<String, Integer> labelNameIdMap, int propertyId, List<NodeUpdates> updates) throws Exception {
    NeoStores neoStores = getNeoStores();
    LabelScanStore labelScanStore = getLabelScanStore();
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    try (Transaction transaction = embeddedDatabase.beginTx()) {
        Statement statement = transactionStatementContextBridge.get();
        DynamicIndexStoreView storeView = new DynamicIndexStoreViewWrapper(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, updates);
        SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(getSchemaIndexProvider());
        JobScheduler scheduler = getJobScheduler();
        StatementTokenNameLookup tokenNameLookup = new StatementTokenNameLookup(statement.readOperations());
        indexService = IndexingServiceFactory.createIndexingService(Config.empty(), scheduler, providerMap, storeView, tokenNameLookup, getIndexRules(neoStores), NullLogProvider.getInstance(), IndexingService.NO_MONITOR, () -> {
        });
        indexService.start();
        IndexRule[] rules = createIndexRules(labelNameIdMap, propertyId);
        indexService.createIndexes(rules);
        transaction.success();
    }
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DynamicIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.DynamicIndexStoreView) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) SchemaIndexProviderMap(org.neo4j.kernel.impl.api.index.SchemaIndexProviderMap) Transaction(org.neo4j.graphdb.Transaction) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 23 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class StoreIteratorRelationshipCursorTest method newRecordCursorsWithMockedNeoStores.

private static RecordCursors newRecordCursorsWithMockedNeoStores(RelationshipStore relationshipStore) {
    NeoStores neoStores = mock(NeoStores.class);
    NodeStore nodeStore = newStoreMockWithRecordCursor(NodeStore.class);
    RelationshipGroupStore relGroupStore = newStoreMockWithRecordCursor(RelationshipGroupStore.class);
    PropertyStore propertyStore = newStoreMockWithRecordCursor(PropertyStore.class);
    DynamicStringStore dynamicStringStore = newStoreMockWithRecordCursor(DynamicStringStore.class);
    DynamicArrayStore dynamicArrayStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
    DynamicArrayStore dynamicLabelStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
    when(neoStores.getRelationshipGroupStore()).thenReturn(relGroupStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getStringStore()).thenReturn(dynamicStringStore);
    when(propertyStore.getArrayStore()).thenReturn(dynamicArrayStore);
    when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
    return new RecordCursors(neoStores);
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) DynamicArrayStore(org.neo4j.kernel.impl.store.DynamicArrayStore) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 24 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class ManyPropertyKeysIT method databaseWithManyPropertyKeys.

private GraphDatabaseAPI databaseWithManyPropertyKeys(int propertyKeyCount) throws IOException {
    PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get());
    StoreFactory storeFactory = new StoreFactory(storeDir, pageCache, fileSystemRule.get(), NullLogProvider.getInstance());
    NeoStores neoStores = storeFactory.openAllNeoStores(true);
    PropertyKeyTokenStore store = neoStores.getPropertyKeyTokenStore();
    for (int i = 0; i < propertyKeyCount; i++) {
        PropertyKeyTokenRecord record = new PropertyKeyTokenRecord((int) store.nextId());
        record.setInUse(true);
        Collection<DynamicRecord> nameRecords = store.allocateNameRecords(PropertyStore.encodeString(key(i)));
        record.addNameRecords(nameRecords);
        record.setNameId((int) Iterables.first(nameRecords).getId());
        store.updateRecord(record);
    }
    neoStores.close();
    return database();
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) PageCache(org.neo4j.io.pagecache.PageCache) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)

Example 25 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.

@Test
public void shouldValidateUniquenessIndexes() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    doThrow(new UniquePropertyValueValidationException(constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException())).when(indexes).validateIndex(2L);
    ConstraintRule record = ConstraintRule.constraintRule(1L, constraint, 2L);
    // When
    try {
        validator.validateSchemaRule(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)77 Test (org.junit.Test)48 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)17 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)14 NodeStore (org.neo4j.kernel.impl.store.NodeStore)12 File (java.io.File)11 Transaction (org.neo4j.graphdb.Transaction)11 ArrayList (java.util.ArrayList)9 PageCache (org.neo4j.io.pagecache.PageCache)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 Node (org.neo4j.graphdb.Node)8 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)8 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)7 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 NeoStoreBatchTransactionApplier (org.neo4j.kernel.impl.transaction.command.NeoStoreBatchTransactionApplier)6 CacheAccessBackDoor (org.neo4j.kernel.impl.core.CacheAccessBackDoor)5 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)5