Skip to content

Commit

Permalink
Move SchemaCache and CacheAccessBackdoor into the StoreLayerModule
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Nov 16, 2015
1 parent 71e13ff commit 6fbfb67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
Expand Up @@ -190,10 +190,6 @@ private interface CacheModule
{
UpdateableSchemaState updateableSchemaState();

CacheAccessBackDoor cacheAccess();

SchemaCache schemaCache();

ProcedureCache procedureCache();
}

Expand All @@ -210,6 +206,9 @@ private interface StoreLayerModule
LabelScanStore labelScanStore();
IntegrityValidator integrityValidator();
SchemaIndexProviderMap schemaIndexProviderMap();
CacheAccessBackDoor cacheAccess();

void loadSchemaCache();
}

private interface TransactionLogModule
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -617,19 +616,14 @@ private CacheModule buildCaches( LabelTokenHolder labelTokens, RelationshipTypeT
{
final UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore( logProvider );

final SchemaCache schemaCache = new SchemaCache( constraintSemantics, Collections.<SchemaRule>emptyList() );

final CacheAccessBackDoor cacheAccess = new BridgingCacheAccess( schemaCache, updateableSchemaState,
propertyKeyTokenHolder, relationshipTypeTokens, labelTokens );

final ProcedureCache procedureCache = new ProcedureCache();

life.add( new LifecycleAdapter()
{
@Override
public void start() throws Throwable
{
loadSchemaCache();
storeLayerModule.loadSchemaCache();
}

@Override
Expand All @@ -640,12 +634,6 @@ public void stop() throws Throwable

return new CacheModule()
{
@Override
public SchemaCache schemaCache()
{
return schemaCache;
}

@Override
public ProcedureCache procedureCache()
{
Expand All @@ -657,12 +645,6 @@ public UpdateableSchemaState updateableSchemaState()
{
return updateableSchemaState;
}

@Override
public CacheAccessBackDoor cacheAccess()
{
return cacheAccess;
}
};
}

Expand Down Expand Up @@ -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
Expand All @@ -722,7 +706,9 @@ public void start() throws IOException
life.add( labelScanStore );


SchemaCache schemaCache = cacheModule.schemaCache();
schemaCache = new SchemaCache( constraintSemantics, Collections.<SchemaRule>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,
Expand Down Expand Up @@ -784,6 +770,19 @@ public SchemaIndexProviderMap schemaIndexProviderMap()
{
return providerMap;
}

@Override
public CacheAccessBackDoor cacheAccess()
{
return cacheAccess;
}

@Override
public void loadSchemaCache()
{
List<SchemaRule> schemaRules = toList( neoStores.getSchemaStore().loadAllSchemaRules() );
schemaCache.load( schemaRules );
}
};
}

Expand Down Expand Up @@ -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
{
Expand All @@ -1101,13 +1100,6 @@ private void satisfyDependencies( Object... modules )
}
}

// Startup sequence done
private void loadSchemaCache()
{
List<SchemaRule> schemaRules = toList( storeLayerModule.neoStores().getSchemaStore().loadAllSchemaRules() );
cacheModule.schemaCache().load( schemaRules );
}

// Only public for testing purpose
public NeoStores getNeoStores()
{
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -59,7 +58,7 @@ public void addSchemaRule( SchemaRule rule )
public void removeSchemaRuleFromCache( long id )
{
schemaCache.removeSchemaRule( id );
schemaState.clear();
schemaStateChangeCallback.run();
}

@Override
Expand Down

0 comments on commit 6fbfb67

Please sign in to comment.