Search in sources :

Example 1 with IndexConfigCompleter

use of org.neo4j.internal.schema.IndexConfigCompleter in project neo4j by neo4j.

the class BatchingNeoStoresTest method someDataInTheDatabase.

private void someDataInTheDatabase(Config config) throws Exception {
    NullLog nullLog = NullLog.getInstance();
    try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
        PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
        Lifespan life = new Lifespan()) {
        // TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
        DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.propertyKeyDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.labelDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.relationshipTypeDoCreateForName(name, internal, id);
            }
        };
        TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
        IndexConfigCompleter indexConfigCompleter = index -> index;
        RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
        RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
        // Create the relationship type token
        TxState txState = new TxState();
        NeoStores neoStores = storageEngine.testAccessNeoStores();
        CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
        commandCreationContext.initialize(NULL);
        propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
        labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
        relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
        int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
        apply(txState, commandCreationContext, storageEngine);
        // Finally, we're initialized and ready to create two nodes and a relationship
        txState = new TxState();
        long node1 = commandCreationContext.reserveNode();
        long node2 = commandCreationContext.reserveNode();
        txState.nodeDoCreate(node1);
        txState.nodeDoCreate(node2);
        txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
        apply(txState, commandCreationContext, storageEngine);
        neoStores.flush(NULL);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DefaultIdController(org.neo4j.internal.id.DefaultIdController) NullLogService(org.neo4j.logging.internal.NullLogService) Predicates(org.neo4j.function.Predicates) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) LockVerificationMonitor(org.neo4j.internal.recordstorage.LockVerificationMonitor) NullLogProvider(org.neo4j.logging.NullLogProvider) ANY_LABEL(org.neo4j.token.api.TokenConstants.ANY_LABEL) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) JobSchedulerFactory(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory) NullLog(org.neo4j.logging.NullLog) Input(org.neo4j.internal.batchimport.input.Input) PageCache(org.neo4j.io.pagecache.PageCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) LockService(org.neo4j.lock.LockService) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Stream(java.util.stream.Stream) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) RelationshipType(org.neo4j.graphdb.RelationshipType) ANONYMOUS(org.neo4j.internal.kernel.api.security.AuthSubject.ANONYMOUS) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) EMPTY(org.neo4j.internal.batchimport.AdditionalInitialIds.EMPTY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BASE_TX_ID(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_ID) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) ArrayList(java.util.ArrayList) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Values(org.neo4j.values.storable.Values) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) MemoryPools(org.neo4j.memory.MemoryPools) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD(org.neo4j.internal.batchimport.store.BatchingNeoStores.DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) LockTracer(org.neo4j.lock.LockTracer) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Configuration(org.neo4j.internal.batchimport.Configuration) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PanicEventGenerator(org.neo4j.monitoring.PanicEventGenerator) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandLockVerification(org.neo4j.internal.recordstorage.CommandLockVerification) TokenStore(org.neo4j.kernel.impl.store.TokenStore) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LATEST_RECORD_FORMATS(org.neo4j.kernel.impl.store.format.standard.Standard.LATEST_RECORD_FORMATS) ResourceLocker(org.neo4j.lock.ResourceLocker) CountsAccessor(org.neo4j.counts.CountsAccessor) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) TokenHolders(org.neo4j.token.TokenHolders) CountsBuilder(org.neo4j.internal.counts.CountsBuilder) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Clocks(org.neo4j.time.Clocks) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) NullLog(org.neo4j.logging.NullLog) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) DefaultIdController(org.neo4j.internal.id.DefaultIdController) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) MemoryPools(org.neo4j.memory.MemoryPools) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) TokenHolders(org.neo4j.token.TokenHolders) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCache(org.neo4j.io.pagecache.PageCache)

Example 2 with IndexConfigCompleter

use of org.neo4j.internal.schema.IndexConfigCompleter in project neo4j by neo4j.

the class SchemaCacheTest method shouldCompleteConfigurationOfIndexesAddedToCache.

@Test
void shouldCompleteConfigurationOfIndexesAddedToCache() {
    IndexCapability capability = new IndexCapability() {

        @Override
        public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
            return IndexOrderCapability.NONE;
        }

        @Override
        public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
            return IndexValueCapability.NO;
        }
    };
    List<IndexDescriptor> completed = new ArrayList<>();
    IndexConfigCompleter completer = index -> {
        completed.add(index);
        return index.withIndexCapability(capability);
    };
    SchemaCache cache = new SchemaCache(new ConstraintSemantics(), completer);
    IndexDescriptor index1 = newIndexRule(1, 2, 3);
    ConstraintDescriptor constraint1 = uniquenessConstraint(2, 2, 3, 1);
    IndexDescriptor index2 = newIndexRule(3, 4, 5);
    ConstraintDescriptor constraint2 = uniquenessConstraint(4, 4, 5, 3);
    IndexDescriptor index3 = newIndexRule(5, 5, 5);
    cache.load(asList(index1, constraint1));
    cache.addSchemaRule(index2);
    cache.addSchemaRule(constraint2);
    cache.addSchemaRule(index3);
    assertEquals(List.of(index1, index2, index3), completed);
    assertEquals(capability, cache.getIndex(index1.getId()).getCapability());
    assertEquals(capability, cache.getIndex(index2.getId()).getCapability());
    assertEquals(capability, cache.getIndex(index3.getId()).getCapability());
}
Also used : IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ConstraintDescriptorFactory.uniqueForLabel(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory.uniqueForLabel) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) Iterables(org.neo4j.internal.helpers.collection.Iterables) Arrays.asList(java.util.Arrays.asList) SchemaDescriptor.forRelType(org.neo4j.internal.schema.SchemaDescriptor.forRelType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) Iterator(java.util.Iterator) Iterators(org.neo4j.internal.helpers.collection.Iterators) ConstraintType(org.neo4j.internal.schema.ConstraintType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) Set(java.util.Set) ValueCategory(org.neo4j.values.storable.ValueCategory) Iterators.single(org.neo4j.internal.helpers.collection.Iterators.single) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Collections(java.util.Collections) NODE(org.neo4j.common.EntityType.NODE) Race(org.neo4j.test.Race) ValueCategory(org.neo4j.values.storable.ValueCategory) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexCapability(org.neo4j.internal.schema.IndexCapability) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexConfigCompleter

use of org.neo4j.internal.schema.IndexConfigCompleter in project neo4j by neo4j.

the class SchemaCache method load.

public void load(Iterable<SchemaRule> rules) {
    cacheUpdateLock.lock();
    try {
        ConstraintRuleAccessor constraintSemantics = schemaCacheState.constraintSemantics;
        IndexConfigCompleter indexConfigCompleter = schemaCacheState.indexConfigCompleter;
        this.schemaCacheState = new SchemaCacheState(constraintSemantics, indexConfigCompleter, rules);
    } finally {
        cacheUpdateLock.unlock();
    }
}
Also used : IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) ConstraintRuleAccessor(org.neo4j.storageengine.api.ConstraintRuleAccessor)

Aggregations

IndexConfigCompleter (org.neo4j.internal.schema.IndexConfigCompleter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Test (org.junit.jupiter.api.Test)2 IOException (java.io.IOException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singleton (java.util.Collections.singleton)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)1 NODE (org.neo4j.common.EntityType.NODE)1