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);
}
}
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());
}
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();
}
}
Aggregations