Skip to content

Commit

Permalink
Rename *Compatibility* to *Compiler*
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and alexaverbuch committed May 25, 2018
1 parent 4e0eddb commit 86dd6b1
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 123 deletions.
Expand Up @@ -23,7 +23,7 @@

import org.neo4j.cypher.CypherException;
import org.neo4j.cypher.internal.CacheTracer;
import org.neo4j.cypher.internal.CompatibilityFactory;
import org.neo4j.cypher.internal.CompilerFactory;
import org.neo4j.cypher.internal.CypherConfiguration;
import org.neo4j.cypher.internal.StringCacheMonitor;
import org.neo4j.cypher.internal.tracing.CompilationTracer;
Expand Down Expand Up @@ -57,7 +57,7 @@ public class ExecutionEngine implements QueryExecutionEngine
* @param queryService The database to wrap
* @param logProvider A {@link LogProvider} for cypher-statements
*/
public ExecutionEngine( GraphDatabaseQueryService queryService, LogProvider logProvider, CompatibilityFactory compatibilityFactory )
public ExecutionEngine( GraphDatabaseQueryService queryService, LogProvider logProvider, CompilerFactory compilerFactory )
{
DependencyResolver resolver = queryService.getDependencyResolver();
Monitors monitors = resolver.resolveDependency( Monitors.class );
Expand All @@ -71,7 +71,7 @@ public ExecutionEngine( GraphDatabaseQueryService queryService, LogProvider logP
tracer,
cacheTracer,
cypherConfiguration,
compatibilityFactory,
compilerFactory,
logProvider,
Clock.systemUTC() );
}
Expand Down
Expand Up @@ -19,9 +19,7 @@
*/
package org.neo4j.cypher.internal.javacompat;

import java.util.Map;

import org.neo4j.cypher.internal.CompatibilityFactory;
import org.neo4j.cypher.internal.CompilerFactory;
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.pagecache.tracing.cursor.context.VersionContext;
Expand All @@ -44,9 +42,9 @@ public class SnapshotExecutionEngine extends ExecutionEngine
private final int maxQueryExecutionAttempts;

SnapshotExecutionEngine( GraphDatabaseQueryService queryService, Config config, LogProvider logProvider,
CompatibilityFactory compatibilityFactory )
CompilerFactory compilerFactory )
{
super( queryService, logProvider, compatibilityFactory );
super( queryService, logProvider, compilerFactory );
this.maxQueryExecutionAttempts = config.get( GraphDatabaseSettings.snapshot_query_retries );
}

Expand Down
Expand Up @@ -28,6 +28,6 @@ import org.neo4j.values.virtual.MapValue
* @param paramNames Names of all parameters for this query, explicit and auto-parametrized.
* @param extractedParams The names and values of the auto-parametrized parameters for this query.
*/
case class CachedExecutableQuery(plan: ExecutionPlan,
paramNames: Seq[String],
extractedParams: MapValue)
case class CacheableExecutableQuery(plan: ExecutionPlan,
paramNames: Seq[String],
extractedParams: MapValue)
Expand Up @@ -40,5 +40,5 @@ trait Compiler {
tracer: CompilationPhaseTracer,
preParsingNotifications: Set[org.neo4j.graphdb.Notification],
transactionalContext: TransactionalContext
): CachedExecutableQuery
): CacheableExecutableQuery
}
Expand Up @@ -53,7 +53,7 @@ class CompilerEngineDelegator(graph: GraphDatabaseQueryService,
kernelMonitors: KernelMonitors,
config: CypherConfiguration,
logProvider: LogProvider,
compatibilityCache: CompatibilityCache) {
compilerLibrary: CompilerLibrary) {

import org.neo4j.cypher.internal.CompilerEngineDelegator._

Expand Down Expand Up @@ -84,7 +84,7 @@ class CompilerEngineDelegator(graph: GraphDatabaseQueryService,
def compile(preParsedQuery: PreParsedQuery,
tracer: CompilationPhaseTracer,
transactionalContext: TransactionalContext
): CachedExecutableQuery = {
): CacheableExecutableQuery = {

var notifications = Set.newBuilder[org.neo4j.graphdb.Notification]
val supportedRuntimes3_1 = Seq(CypherRuntimeOption.interpreted, CypherRuntimeOption.default)
Expand All @@ -100,18 +100,18 @@ class CompilerEngineDelegator(graph: GraphDatabaseQueryService,
}
}

def innerCompile(preParsedQuery: PreParsedQuery): CachedExecutableQuery = {
def innerCompile(preParsedQuery: PreParsedQuery): CacheableExecutableQuery = {

if ((preParsedQuery.version == CypherVersion.v3_3 || preParsedQuery.version == CypherVersion.v3_5) && preParsedQuery.planner == CypherPlannerOption.rule) {
notifications += rulePlannerUnavailableFallbackNotification(preParsedQuery.offset)
innerCompile(preParsedQuery.copy(version = CypherVersion.v3_1))

} else if (preParsedQuery.version == CypherVersion.v3_5) {
val compiler3_5 = compatibilityCache.selectCompiler(preParsedQuery.version,
preParsedQuery.planner,
preParsedQuery.runtime,
preParsedQuery.updateStrategy,
compilerConfig)
val compiler3_5 = compilerLibrary.selectCompiler(preParsedQuery.version,
preParsedQuery.planner,
preParsedQuery.runtime,
preParsedQuery.updateStrategy,
compilerConfig)

try {
compiler3_5.compile(preParsedQuery, tracer, notifications.result(), transactionalContext)
Expand All @@ -130,11 +130,11 @@ class CompilerEngineDelegator(graph: GraphDatabaseQueryService,

} else {

val compiler = compatibilityCache.selectCompiler(preParsedQuery.version,
preParsedQuery.planner,
preParsedQuery.runtime,
preParsedQuery.updateStrategy,
compilerConfig)
val compiler = compilerLibrary.selectCompiler(preParsedQuery.version,
preParsedQuery.planner,
preParsedQuery.runtime,
preParsedQuery.updateStrategy,
compilerConfig)

compiler.compile(preParsedQuery, tracer, notifications.result(), transactionalContext)
}
Expand Down
Expand Up @@ -19,12 +19,10 @@
*/
package org.neo4j.cypher.internal

import java.util.concurrent.ConcurrentHashMap

import org.neo4j.cypher.internal.compatibility.v2_3.helpers._
import org.neo4j.cypher.internal.compatibility.v3_1.helpers._
import org.neo4j.cypher.internal.compatibility.v3_3.{CommunityRuntimeContextCreator => CommunityRuntimeContextCreatorV3_3}
import org.neo4j.cypher.internal.compatibility.v3_5.Compatibility
import org.neo4j.cypher.internal.compatibility.v3_5.Cypher35Compiler
import org.neo4j.cypher.internal.compatibility.v3_5.runtime.{CommunityRuntimeBuilder, CommunityRuntimeContextCreator => CommunityRuntimeContextCreatorv3_5}
import org.neo4j.cypher.internal.compatibility.{v2_3, v3_1, v3_3 => v3_3compat}
import org.neo4j.cypher.internal.compiler.v3_5.CypherPlannerConfiguration
Expand All @@ -43,16 +41,16 @@ final case class PlannerSpec_v3_1(planner: CypherPlannerOption, runtime: CypherR
final case class PlannerSpec_v3_3(planner: CypherPlannerOption, runtime: CypherRuntimeOption, updateStrategy: CypherUpdateStrategy) extends PlannerSpec
final case class PlannerSpec_v3_5(planner: CypherPlannerOption, runtime: CypherRuntimeOption, updateStrategy: CypherUpdateStrategy) extends PlannerSpec

trait CompatibilityFactory {
def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Compatibility
trait CompilerFactory {
def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Cypher23Compiler

def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Compatibility
def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Cypher31Compiler

def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Compatibility[_,_,_]
def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Cypher33Compiler[_,_,_]

def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Compatibility[_,_]
def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Cypher35Compiler[_,_]

def selectCompiler(cypherVersion: CypherVersion,
def createCompiler(cypherVersion: CypherVersion,
cypherPlanner: CypherPlannerOption,
cypherRuntime: CypherRuntimeOption,
cypherUpdateStrategy: CypherUpdateStrategy,
Expand All @@ -67,77 +65,58 @@ trait CompatibilityFactory {
}

class CommunityCompatibilityFactory(graph: GraphDatabaseQueryService, kernelMonitors: KernelMonitors,
logProvider: LogProvider) extends CompatibilityFactory {
logProvider: LogProvider) extends CompilerFactory {

private val log: Log = logProvider.getLog(getClass)

override def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Compatibility = spec.planner match {
override def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Cypher23Compiler = spec.planner match {
case CypherPlannerOption.rule =>
v2_3.RuleCompatibility(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors)
v2_3.Rule23Compiler(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors)
case _ =>
v2_3.CostCompatibility(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors, log, spec.planner, spec.runtime)
v2_3.Cost23Compiler(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors, log, spec.planner, spec.runtime)
}

override def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Compatibility = spec.planner match {
override def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Cypher31Compiler = spec.planner match {
case CypherPlannerOption.rule =>
v3_1.RuleCompatibility(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors)
v3_1.Rule31Compiler(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors)
case _ =>
v3_1.CostCompatibility(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors, log, spec.planner, spec.runtime, spec.updateStrategy)
v3_1.Cost31Compiler(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors, log, spec.planner, spec.runtime, spec.updateStrategy)
}

override def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Compatibility[_,_,_] =
override def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Cypher33Compiler[_,_,_] =
(spec.planner, spec.runtime) match {
case (CypherPlannerOption.rule, _) =>
throw new InvalidArgumentException("The rule planner is no longer a valid planner option in Neo4j 3.3. If you need to use it, please select compatibility mode Cypher 3.1")
case _ =>
v3_3compat.Compatibility(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log,
v3_3compat.Cypher33Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log,
spec.planner, spec.runtime, spec.updateStrategy, CommunityRuntimeBuilder,
CommunityRuntimeContextCreatorV3_3, CommunityRuntimeContextCreatorv3_5, LastCommittedTxIdProvider(graph))
}

override def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Compatibility[_,_] =
override def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Cypher35Compiler[_,_] =
(spec.planner, spec.runtime) match {
case (CypherPlannerOption.rule, _) =>
throw new InvalidArgumentException("The rule planner is no longer a valid planner option in Neo4j 3.4. If you need to use it, please select compatibility mode Cypher 3.1")
case _ =>
Compatibility(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log,
Cypher35Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log,
spec.planner, spec.runtime, spec.updateStrategy, CommunityRuntimeBuilder,
CommunityRuntimeContextCreatorv3_5, LastCommittedTxIdProvider(graph))
}
}

class CompatibilityCache(factory: CompatibilityFactory) extends CompatibilityFactory {

import scala.collection.convert.decorateAsScala._

private val cache_v2_3 = new ConcurrentHashMap[PlannerSpec_v2_3, v2_3.Compatibility].asScala
private val cache_v3_1 = new ConcurrentHashMap[PlannerSpec_v3_1, v3_1.Compatibility].asScala
private val cache_v3_3 = new ConcurrentHashMap[PlannerSpec_v3_3, v3_3compat.Compatibility[_,_,_]].asScala
private val cache_v3_5 = new ConcurrentHashMap[PlannerSpec_v3_5, Compatibility[_,_]].asScala
class CompilerLibrary(factory: CompilerFactory) {

private val compilers = new CopyOnWriteHashMap[CompilerKey, Compiler]

override def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Compatibility =
cache_v2_3.getOrElseUpdate(spec, factory.create(spec, config))

override def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Compatibility =
cache_v3_1.getOrElseUpdate(spec, factory.create(spec, config))

override def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Compatibility[_,_,_] =
cache_v3_3.getOrElseUpdate(spec, factory.create(spec, config))

override def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Compatibility[_,_] =
cache_v3_5.getOrElseUpdate(spec, factory.create(spec, config))

override def selectCompiler(cypherVersion: CypherVersion,
cypherPlanner: CypherPlannerOption,
cypherRuntime: CypherRuntimeOption,
cypherUpdateStrategy: CypherUpdateStrategy,
config: CypherPlannerConfiguration): Compiler = {
def selectCompiler(cypherVersion: CypherVersion,
cypherPlanner: CypherPlannerOption,
cypherRuntime: CypherRuntimeOption,
cypherUpdateStrategy: CypherUpdateStrategy,
config: CypherPlannerConfiguration): Compiler = {
val key = CompilerKey(cypherVersion, cypherPlanner, cypherRuntime, cypherUpdateStrategy)
val compiler = compilers.get(key)
if (compiler == null) {
compilers.put(key, factory.selectCompiler(cypherVersion, cypherPlanner, cypherRuntime, cypherUpdateStrategy, config))
compilers.put(key, factory.createCompiler(cypherVersion, cypherPlanner, cypherRuntime, cypherUpdateStrategy, config))
compilers.get(key)
} else compiler
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,
val tracer: CompilationTracer,
val cacheTracer: CacheTracer[String],
val config: CypherConfiguration,
val compatibilityFactory: CompatibilityFactory,
val compatibilityFactory: CompilerFactory,
val logProvider: LogProvider,
val clock: Clock = Clock.systemUTC() ) {

Expand All @@ -56,7 +56,7 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,

private val preParser = new PreParser(config.version, config.planner, config.runtime, config.queryCacheSize)
private val lastCommittedTxIdProvider = LastCommittedTxIdProvider(queryService)
private def planReusabilitiy(cachedExecutableQuery: CachedExecutableQuery,
private def planReusabilitiy(cachedExecutableQuery: CacheableExecutableQuery,
transactionalContext: TransactionalContext): ReusabilityState =
cachedExecutableQuery.plan.reusabilityState(lastCommittedTxIdProvider, transactionalContext)

Expand All @@ -69,15 +69,15 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,
})

private val planStalenessCaller =
new PlanStalenessCaller[CachedExecutableQuery](clock,
new PlanStalenessCaller[CacheableExecutableQuery](clock,
config.statsDivergenceCalculator,
lastCommittedTxIdProvider,
planReusabilitiy)
private val queryCache: QueryCache[String, CachedExecutableQuery] =
private val queryCache: QueryCache[String, CacheableExecutableQuery] =
new QueryCache(config.queryCacheSize, planStalenessCaller, cacheTracer)

private val compilerEngineDelegator: CompilerEngineDelegator =
new CompilerEngineDelegator(queryService, kernelMonitors, config, logProvider, new CompatibilityCache(compatibilityFactory))
new CompilerEngineDelegator(queryService, kernelMonitors, config, logProvider, new CompilerLibrary(compatibilityFactory))

private val parsedQueries = new LFUCache[String, ParsedQuery](config.queryCacheSize)

Expand Down Expand Up @@ -119,7 +119,7 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,
private def getOrCompile(context: TransactionalContext,
preParsedQuery: PreParsedQuery,
tracer: QueryCompilationEvent
): CachedExecutableQuery = {
): CacheableExecutableQuery = {
val cacheKey = preParsedQuery.statementWithVersionAndPlanner

// create transaction and query context
Expand Down
Expand Up @@ -144,5 +144,5 @@ class QueryCache[QUERY_KEY <: AnyRef, EXECUTABLE_QUERY <: AnyRef](val maximumSiz
}

object QueryCache {
val NOT_PRESENT: CachedExecutableQuery = null
val NOT_PRESENT: CacheableExecutableQuery = null
}
Expand Up @@ -28,13 +28,13 @@ import org.neo4j.kernel.impl.core.EmbeddedProxySPI
import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors}
import org.neo4j.logging.Log

case class CostCompatibility(graph: GraphDatabaseQueryService,
config: CypherCompilerConfiguration,
clock: Clock,
kernelMonitors: KernelMonitors,
log: Log,
planner: CypherPlannerOption,
runtime: CypherRuntimeOption) extends Compatibility {
case class Cost23Compiler(graph: GraphDatabaseQueryService,
config: CypherCompilerConfiguration,
clock: Clock,
kernelMonitors: KernelMonitors,
log: Log,
planner: CypherPlannerOption,
runtime: CypherRuntimeOption) extends Cypher23Compiler {

protected val compiler = {
val plannerName = planner match {
Expand Down

0 comments on commit 86dd6b1

Please sign in to comment.