From 6fbfb67235afe40c4e6c586cead72a0d49c303d7 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Wed, 11 Nov 2015 11:46:44 +0100 Subject: [PATCH] Move SchemaCache and CacheAccessBackdoor into the StoreLayerModule --- .../org/neo4j/kernel/NeoStoreDataSource.java | 60 ++++++++----------- .../impl/cache/BridgingCacheAccess.java | 9 ++- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/NeoStoreDataSource.java b/community/kernel/src/main/java/org/neo4j/kernel/NeoStoreDataSource.java index 0c18e1f8c12a..5a9d7d6f7806 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/NeoStoreDataSource.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/NeoStoreDataSource.java @@ -190,10 +190,6 @@ private interface CacheModule { UpdateableSchemaState updateableSchemaState(); - CacheAccessBackDoor cacheAccess(); - - SchemaCache schemaCache(); - ProcedureCache procedureCache(); } @@ -210,6 +206,9 @@ private interface StoreLayerModule LabelScanStore labelScanStore(); IntegrityValidator integrityValidator(); SchemaIndexProviderMap schemaIndexProviderMap(); + CacheAccessBackDoor cacheAccess(); + + void loadSchemaCache(); } private interface TransactionLogModule @@ -522,10 +521,10 @@ public void start() throws IOException TransactionLogModule transactionLogModule = buildTransactionLogs( storeDir, config, logProvider, scheduler, storeLayerModule.labelScanStore(), - fs, storeLayerModule.neoStores(), cacheModule.cacheAccess(), storeLayerModule.indexingService(), + fs, storeLayerModule.neoStores(), storeLayerModule.cacheAccess(), storeLayerModule.indexingService(), indexProviders.values(), legacyIndexApplierLookup ); - buildRecovery( fs, cacheModule.cacheAccess(), storeLayerModule.indexingService(), + buildRecovery( fs, storeLayerModule.cacheAccess(), storeLayerModule.indexingService(), storeLayerModule.labelScanStore(), storeLayerModule.neoStores(), monitors.newMonitor( RecoveryVisitor.Monitor.class ), monitors.newMonitor( Recovery.Monitor.class ), transactionLogModule.logFiles(), transactionLogModule.storeFlusher(), startupStatistics, @@ -617,11 +616,6 @@ private CacheModule buildCaches( LabelTokenHolder labelTokens, RelationshipTypeT { final UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore( logProvider ); - final SchemaCache schemaCache = new SchemaCache( constraintSemantics, Collections.emptyList() ); - - final CacheAccessBackDoor cacheAccess = new BridgingCacheAccess( schemaCache, updateableSchemaState, - propertyKeyTokenHolder, relationshipTypeTokens, labelTokens ); - final ProcedureCache procedureCache = new ProcedureCache(); life.add( new LifecycleAdapter() @@ -629,7 +623,7 @@ private CacheModule buildCaches( LabelTokenHolder labelTokens, RelationshipTypeT @Override public void start() throws Throwable { - loadSchemaCache(); + storeLayerModule.loadSchemaCache(); } @Override @@ -640,12 +634,6 @@ public void stop() throws Throwable return new CacheModule() { - @Override - public SchemaCache schemaCache() - { - return schemaCache; - } - @Override public ProcedureCache procedureCache() { @@ -657,12 +645,6 @@ public UpdateableSchemaState updateableSchemaState() { return updateableSchemaState; } - - @Override - public CacheAccessBackDoor cacheAccess() - { - return cacheAccess; - } }; } @@ -697,6 +679,8 @@ public void start() throws IOException final IntegrityValidator integrityValidator; final IndexUpdatesValidator indexUpdatesValidator; final LabelScanStore labelScanStore; + final SchemaCache schemaCache; + final CacheAccessBackDoor cacheAccess; final StoreReadLayer storeLayer; try @@ -722,7 +706,9 @@ public void start() throws IOException life.add( labelScanStore ); - SchemaCache schemaCache = cacheModule.schemaCache(); + schemaCache = new SchemaCache( constraintSemantics, Collections.emptyList() ); + cacheAccess = new BridgingCacheAccess( schemaCache, schemaStateChangeCallback, + propertyKeyTokenHolder, relationshipTypeTokens, labelTokens ); ProcedureCache procedureCache = cacheModule.procedureCache(); SchemaStorage schemaStorage = new SchemaStorage( neoStores.getSchemaStore() ); DiskLayer diskLayer = new DiskLayer( propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, schemaStorage, @@ -784,6 +770,19 @@ public SchemaIndexProviderMap schemaIndexProviderMap() { return providerMap; } + + @Override + public CacheAccessBackDoor cacheAccess() + { + return cacheAccess; + } + + @Override + public void loadSchemaCache() + { + List schemaRules = toList( neoStores.getSchemaStore().loadAllSchemaRules() ); + schemaCache.load( schemaRules ); + } }; } @@ -1086,7 +1085,7 @@ private void satisfyDependencies( Object... modules ) { for ( Method method : module.getClass().getMethods() ) { - if ( !method.getDeclaringClass().equals( Object.class ) ) + if ( !method.getDeclaringClass().equals( Object.class ) && method.getReturnType() != void.class ) { try { @@ -1101,13 +1100,6 @@ private void satisfyDependencies( Object... modules ) } } - // Startup sequence done - private void loadSchemaCache() - { - List schemaRules = toList( storeLayerModule.neoStores().getSchemaStore().loadAllSchemaRules() ); - cacheModule.schemaCache().load( schemaRules ); - } - // Only public for testing purpose public NeoStores getNeoStores() { @@ -1347,7 +1339,7 @@ public void beforeModeSwitch() */ public void afterModeSwitch() { - loadSchemaCache(); + storeLayerModule.loadSchemaCache(); // Get rid of all pooled transactions, as they will otherwise reference // components that have been swapped out during the mode switch. kernelModule.kernelTransactions().disposeAll(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/cache/BridgingCacheAccess.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/cache/BridgingCacheAccess.java index edd62d74735d..9a971c1323ba 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/cache/BridgingCacheAccess.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/cache/BridgingCacheAccess.java @@ -19,7 +19,6 @@ */ package org.neo4j.kernel.impl.cache; -import org.neo4j.kernel.impl.api.SchemaState; import org.neo4j.kernel.impl.api.store.SchemaCache; import org.neo4j.kernel.impl.core.CacheAccessBackDoor; import org.neo4j.kernel.impl.core.LabelTokenHolder; @@ -32,18 +31,18 @@ public class BridgingCacheAccess implements CacheAccessBackDoor { private final SchemaCache schemaCache; - private final SchemaState schemaState; + private final Runnable schemaStateChangeCallback; private final PropertyKeyTokenHolder propertyKeyTokenHolder; private final RelationshipTypeTokenHolder relationshipTypeTokenHolder; private final LabelTokenHolder labelTokenHolder; - public BridgingCacheAccess( SchemaCache schemaCache, SchemaState schemaState, + public BridgingCacheAccess( SchemaCache schemaCache, Runnable schemaStateChangeCallback, PropertyKeyTokenHolder propertyKeyTokenHolder, RelationshipTypeTokenHolder relationshipTypeTokenHolder, LabelTokenHolder labelTokenHolder ) { this.schemaCache = schemaCache; - this.schemaState = schemaState; + this.schemaStateChangeCallback = schemaStateChangeCallback; this.propertyKeyTokenHolder = propertyKeyTokenHolder; this.relationshipTypeTokenHolder = relationshipTypeTokenHolder; this.labelTokenHolder = labelTokenHolder; @@ -59,7 +58,7 @@ public void addSchemaRule( SchemaRule rule ) public void removeSchemaRuleFromCache( long id ) { schemaCache.removeSchemaRule( id ); - schemaState.clear(); + schemaStateChangeCallback.run(); } @Override