diff --git a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/CommunityCypherEngineProvider.java b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/CommunityCypherEngineProvider.java index b57fc2b1966ea..6576c944e70de 100644 --- a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/CommunityCypherEngineProvider.java +++ b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/CommunityCypherEngineProvider.java @@ -19,7 +19,7 @@ */ package org.neo4j.cypher.internal.javacompat; -import org.neo4j.cypher.internal.CommunityCompatibilityFactory; +import org.neo4j.cypher.internal.CommunityCompilerFactory; import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.helpers.Service; @@ -57,29 +57,29 @@ protected QueryExecutionEngine createEngine( Dependencies deps, GraphDatabaseAPI Monitors monitors = resolver.resolveDependency( Monitors.class ); Config config = resolver.resolveDependency( Config.class ); LogProvider logProvider = logService.getInternalLogProvider(); - CommunityCompatibilityFactory compatibilityFactory = - new CommunityCompatibilityFactory( queryService, monitors, logProvider ); - deps.satisfyDependencies( compatibilityFactory ); - return createEngine( queryService, config, logProvider, compatibilityFactory ); + CommunityCompilerFactory compilerFactory = + new CommunityCompilerFactory( queryService, monitors, logProvider ); + deps.satisfyDependencies( compilerFactory ); + return createEngine( queryService, config, logProvider, compilerFactory ); } private QueryExecutionEngine createEngine( GraphDatabaseCypherService queryService, Config config, - LogProvider logProvider, CommunityCompatibilityFactory compatibilityFactory ) + LogProvider logProvider, CommunityCompilerFactory compilerFactory ) { return config.get( GraphDatabaseSettings.snapshot_query ) ? - snapshotEngine( queryService, config, logProvider, compatibilityFactory ) : - standardEngine( queryService, logProvider, compatibilityFactory ); + snapshotEngine( queryService, config, logProvider, compilerFactory ) : + standardEngine( queryService, logProvider, compilerFactory ); } private SnapshotExecutionEngine snapshotEngine( GraphDatabaseCypherService queryService, Config config, - LogProvider logProvider, CommunityCompatibilityFactory compatibilityFactory ) + LogProvider logProvider, CommunityCompilerFactory compilerFactory ) { - return new SnapshotExecutionEngine( queryService, config, logProvider, compatibilityFactory ); + return new SnapshotExecutionEngine( queryService, config, logProvider, compilerFactory ); } private ExecutionEngine standardEngine( GraphDatabaseCypherService queryService, LogProvider logProvider, - CommunityCompatibilityFactory compatibilityFactory ) + CommunityCompilerFactory compilerFactory ) { - return new ExecutionEngine( queryService, logProvider, compatibilityFactory ); + return new ExecutionEngine( queryService, logProvider, compilerFactory ); } } diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerFactory.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerFactory.scala new file mode 100644 index 0000000000000..67d6ca8616a20 --- /dev/null +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerFactory.scala @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.cypher.internal + +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.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 +import org.neo4j.cypher.internal.runtime.interpreted.LastCommittedTxIdProvider +import org.neo4j.cypher.{CypherPlannerOption, CypherRuntimeOption, CypherUpdateStrategy, CypherVersion} +import org.neo4j.helpers.Clock +import org.neo4j.kernel.GraphDatabaseQueryService +import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} +import org.neo4j.logging.{Log, LogProvider} +import org.opencypher.v9_0.util.InvalidArgumentException + +/** + * Factory which creates cypher compilers. + */ +trait CompilerFactory { + def createCompiler(cypherVersion: CypherVersion, + cypherPlanner: CypherPlannerOption, + cypherRuntime: CypherRuntimeOption, + cypherUpdateStrategy: CypherUpdateStrategy, + config: CypherPlannerConfiguration): Compiler +} + +class CommunityCompilerFactory(graph: GraphDatabaseQueryService, + kernelMonitors: KernelMonitors, + logProvider: LogProvider + ) extends CompilerFactory { + + private val log: Log = logProvider.getLog(getClass) + + override def createCompiler(cypherVersion: CypherVersion, + cypherPlanner: CypherPlannerOption, + cypherRuntime: CypherRuntimeOption, + cypherUpdateStrategy: CypherUpdateStrategy, + config: CypherPlannerConfiguration + ): Compiler = { + + (cypherVersion, cypherPlanner) match { + + // 2.3 + case (CypherVersion.v2_3, CypherPlannerOption.rule) => + v2_3.Rule23Compiler(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors) + case (CypherVersion.v2_3, _) => + v2_3.Cost23Compiler(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors, log, cypherPlanner, cypherRuntime) + + // 3.1 + case (CypherVersion.v3_1, CypherPlannerOption.rule) => + v3_1.Rule31Compiler(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors) + case (CypherVersion.v3_1, _) => + v3_1.Cost31Compiler(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors, log, cypherPlanner, cypherRuntime, cypherUpdateStrategy) + + // 3.3 or 3.5 + rule + case (_, CypherPlannerOption.rule) => + throw new InvalidArgumentException(s"The rule planner is no longer a valid planner option in Neo4j ${cypherVersion.name}. If you need to use it, please select compatibility mode Cypher 3.1") + + // 3.3 + case (CypherVersion.v3_3, _) => + v3_3compat.Cypher33Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log, + cypherPlanner, cypherRuntime, cypherUpdateStrategy, CommunityRuntimeBuilder, + CommunityRuntimeContextCreatorV3_3, CommunityRuntimeContextCreatorv3_5, LastCommittedTxIdProvider(graph)) + + // 3.5 + case (CypherVersion.v3_5, _) => + Cypher35Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log, + cypherPlanner, cypherRuntime, cypherUpdateStrategy, CommunityRuntimeBuilder, + CommunityRuntimeContextCreatorv3_5, LastCommittedTxIdProvider(graph)) + } + } +} diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerLibrary.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerLibrary.scala index 8d1dc0d0c0949..1235aef2b9877 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerLibrary.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/CompilerLibrary.scala @@ -19,91 +19,15 @@ */ package org.neo4j.cypher.internal -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.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 -import org.neo4j.cypher.internal.runtime.interpreted.LastCommittedTxIdProvider -import org.opencypher.v9_0.util.InvalidArgumentException import org.neo4j.cypher.{CypherPlannerOption, CypherRuntimeOption, CypherUpdateStrategy, CypherVersion} -import org.neo4j.helpers.Clock -import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.impl.util.CopyOnWriteHashMap -import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} -import org.neo4j.logging.{Log, LogProvider} - -sealed trait PlannerSpec -final case class PlannerSpec_v2_3(planner: CypherPlannerOption, runtime: CypherRuntimeOption) extends PlannerSpec -final case class PlannerSpec_v3_1(planner: CypherPlannerOption, runtime: CypherRuntimeOption, updateStrategy: CypherUpdateStrategy) extends PlannerSpec -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 CompilerFactory { - def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Cypher23Compiler - - def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Cypher31Compiler - - def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Cypher33Compiler[_,_,_] - - def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Cypher35Compiler[_,_] - - def createCompiler(cypherVersion: CypherVersion, - cypherPlanner: CypherPlannerOption, - cypherRuntime: CypherRuntimeOption, - cypherUpdateStrategy: CypherUpdateStrategy, - config: CypherPlannerConfiguration): Compiler = { - cypherVersion match { - case CypherVersion.v2_3 => create(PlannerSpec_v2_3(cypherPlanner, cypherRuntime), config) - case CypherVersion.v3_1 => create(PlannerSpec_v3_1(cypherPlanner, cypherRuntime, cypherUpdateStrategy), config) - case CypherVersion.v3_3 => create(PlannerSpec_v3_3(cypherPlanner, cypherRuntime, cypherUpdateStrategy), config) - case CypherVersion.v3_5 => create(PlannerSpec_v3_5(cypherPlanner, cypherRuntime, cypherUpdateStrategy), config) - } - } -} - -class CommunityCompatibilityFactory(graph: GraphDatabaseQueryService, kernelMonitors: KernelMonitors, - logProvider: LogProvider) extends CompilerFactory { - - private val log: Log = logProvider.getLog(getClass) - - override def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Cypher23Compiler = spec.planner match { - case CypherPlannerOption.rule => - v2_3.Rule23Compiler(graph, as2_3(config), Clock.SYSTEM_CLOCK, kernelMonitors) - case _ => - 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.Cypher31Compiler = spec.planner match { - case CypherPlannerOption.rule => - v3_1.Rule31Compiler(graph, as3_1(config), CompilerEngineDelegator.CLOCK, kernelMonitors) - case _ => - 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.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.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): 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 _ => - Cypher35Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, log, - spec.planner, spec.runtime, spec.updateStrategy, CommunityRuntimeBuilder, - CommunityRuntimeContextCreatorv3_5, LastCommittedTxIdProvider(graph)) - } -} +/** + * Keeps track of all cypher compilers, and finds the relevant compiler for a preparsed query. + * + * @param factory factory to create compilers + */ class CompilerLibrary(factory: CompilerFactory) { private val compilers = new CopyOnWriteHashMap[CompilerKey, Compiler] diff --git a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/ExecutionEngineTest.java b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/ExecutionEngineTest.java index 4012bf15e5967..17ebc4918ed7b 100644 --- a/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/ExecutionEngineTest.java +++ b/community/cypher/cypher/src/test/java/org/neo4j/cypher/internal/javacompat/ExecutionEngineTest.java @@ -22,11 +22,10 @@ import org.junit.Rule; import org.junit.Test; -import java.util.Collections; import java.util.List; import java.util.Map; -import org.neo4j.cypher.internal.CommunityCompatibilityFactory; +import org.neo4j.cypher.internal.CommunityCompilerFactory; import org.neo4j.graphdb.Result; import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.kernel.GraphDatabaseQueryService; @@ -62,9 +61,9 @@ public void shouldConvertListsAndMapsWhenPassingFromScalaToJava() throws Excepti Monitors monitors = graph.getDependencyResolver().resolveDependency( Monitors.class ); NullLogProvider nullLogProvider = NullLogProvider.getInstance(); - CommunityCompatibilityFactory compatibilityFactory = - new CommunityCompatibilityFactory( graph, monitors, nullLogProvider ); - ExecutionEngine executionEngine = new ExecutionEngine( graph, nullLogProvider, compatibilityFactory ); + CommunityCompilerFactory compilerFactory = + new CommunityCompilerFactory( graph, monitors, nullLogProvider ); + ExecutionEngine executionEngine = new ExecutionEngine( graph, nullLogProvider, compilerFactory ); Result result; try ( InternalTransaction tx = graph diff --git a/community/cypher/cypher/src/test/scala/org/neo4j/cypher/KillQueryTest.scala b/community/cypher/cypher/src/test/scala/org/neo4j/cypher/KillQueryTest.scala index 84efbf4afd102..7687e9ce515a4 100644 --- a/community/cypher/cypher/src/test/scala/org/neo4j/cypher/KillQueryTest.scala +++ b/community/cypher/cypher/src/test/scala/org/neo4j/cypher/KillQueryTest.scala @@ -23,7 +23,7 @@ import java.util import java.util.concurrent.ArrayBlockingQueue import java.util.concurrent.atomic.AtomicBoolean -import org.neo4j.cypher.internal.{CommunityCompatibilityFactory, ExecutionEngine} +import org.neo4j.cypher.internal.ExecutionEngine import org.neo4j.graphdb.{TransactionTerminatedException, TransientTransactionFailureException} import org.neo4j.internal.kernel.api.Transaction.Type import org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED diff --git a/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/MatchLongPatternAcceptanceTest.scala b/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/MatchLongPatternAcceptanceTest.scala index ecdcb76ffcbfb..e5499709ade4d 100644 --- a/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/MatchLongPatternAcceptanceTest.scala +++ b/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/MatchLongPatternAcceptanceTest.scala @@ -29,7 +29,7 @@ import org.neo4j.cypher._ import org.neo4j.cypher.internal.compiler.v3_5.planner.logical.idp.IDPSolverMonitor import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService import org.neo4j.cypher.internal.runtime.planDescription.InternalPlanDescription -import org.neo4j.cypher.internal.{CommunityCompatibilityFactory, ExecutionEngine} +import org.neo4j.cypher.internal.{CommunityCompilerFactory, ExecutionEngine} import org.neo4j.graphdb.config.Setting import org.neo4j.graphdb.factory.GraphDatabaseSettings import org.neo4j.graphdb.factory.GraphDatabaseSettings.{cypher_idp_solver_duration_threshold, cypher_idp_solver_table_threshold} diff --git a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/EnterpriseCypherEngineProvider.java b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/EnterpriseCypherEngineProvider.java index f1d46814b04e9..98a68335d1645 100644 --- a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/EnterpriseCypherEngineProvider.java +++ b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/javacompat/EnterpriseCypherEngineProvider.java @@ -22,8 +22,8 @@ */ package org.neo4j.cypher.internal.javacompat; -import org.neo4j.cypher.internal.CommunityCompatibilityFactory; -import org.neo4j.cypher.internal.EnterpriseCompatibilityFactory; +import org.neo4j.cypher.internal.CommunityCompilerFactory; +import org.neo4j.cypher.internal.EnterpriseCompilerFactory; import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.helpers.Service; @@ -61,32 +61,33 @@ protected QueryExecutionEngine createEngine( Dependencies deps, GraphDatabaseAPI Monitors monitors = resolver.resolveDependency( Monitors.class ); Config config = resolver.resolveDependency( Config.class ); LogProvider logProvider = logService.getInternalLogProvider(); - CommunityCompatibilityFactory inner = - new CommunityCompatibilityFactory( queryService, monitors, logProvider ); + CommunityCompilerFactory communityCompilerFactory = + new CommunityCompilerFactory( queryService, monitors, logProvider ); - EnterpriseCompatibilityFactory compatibilityFactory = - new EnterpriseCompatibilityFactory( inner, queryService, monitors, logProvider ); - deps.satisfyDependency( compatibilityFactory ); - return createEngine( queryService, config, logProvider, compatibilityFactory ); + EnterpriseCompilerFactory compilerFactory = + new EnterpriseCompilerFactory( communityCompilerFactory, queryService, monitors, logProvider ); + + deps.satisfyDependency( compilerFactory ); + return createEngine( queryService, config, logProvider, compilerFactory ); } private QueryExecutionEngine createEngine( GraphDatabaseCypherService queryService, Config config, - LogProvider logProvider, EnterpriseCompatibilityFactory compatibilityFactory ) + LogProvider logProvider, EnterpriseCompilerFactory compilerFactory ) { return config.get( GraphDatabaseSettings.snapshot_query ) ? - snapshotEngine( queryService, config, logProvider, compatibilityFactory ) : - standardEngine( queryService, logProvider, compatibilityFactory ); + snapshotEngine( queryService, config, logProvider, compilerFactory ) : + standardEngine( queryService, logProvider, compilerFactory ); } private SnapshotExecutionEngine snapshotEngine( GraphDatabaseCypherService queryService, Config config, - LogProvider logProvider, EnterpriseCompatibilityFactory compatibilityFactory ) + LogProvider logProvider, EnterpriseCompilerFactory compilerFactory ) { - return new SnapshotExecutionEngine( queryService, config, logProvider, compatibilityFactory ); + return new SnapshotExecutionEngine( queryService, config, logProvider, compilerFactory ); } private ExecutionEngine standardEngine( GraphDatabaseCypherService queryService, LogProvider logProvider, - EnterpriseCompatibilityFactory compatibilityFactory ) + EnterpriseCompilerFactory compilerFactory ) { - return new ExecutionEngine( queryService, logProvider, compatibilityFactory ); + return new ExecutionEngine( queryService, logProvider, compilerFactory ); } } diff --git a/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompatibilityFactory.scala b/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompatibilityFactory.scala deleted file mode 100644 index f84c82267561d..0000000000000 --- a/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompatibilityFactory.scala +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j Enterprise Edition. The included source - * code can be redistributed and/or modified under the terms of the - * GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - * (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the - * Commons Clause, as found in the associated LICENSE.txt file. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * Neo4j object code can be licensed independently from the source - * under separate terms from the AGPL. Inquiries can be directed to: - * licensing@neo4j.com - * - * More information is also available at: - * https://neo4j.com/licensing/ - */ -package org.neo4j.cypher.internal - -import org.neo4j.cypher.CypherPlannerOption -import org.neo4j.cypher.internal.compatibility.v3_5.Cypher35Compiler -import org.neo4j.cypher.internal.compatibility.{v2_3, v3_1, v3_3 => v3_3compat} -import org.neo4j.cypher.internal.compiler.v3_5._ -import org.neo4j.cypher.internal.runtime.compiled.EnterpriseRuntimeContextCreator -import org.neo4j.cypher.internal.runtime.interpreted.LastCommittedTxIdProvider -import org.neo4j.cypher.internal.runtime.vectorized.dispatcher.{ParallelDispatcher, SingleThreadedExecutor} -import org.neo4j.cypher.internal.spi.codegen.GeneratedQueryStructure -import org.neo4j.graphdb.factory.GraphDatabaseSettings -import org.neo4j.kernel.GraphDatabaseQueryService -import org.neo4j.kernel.configuration.Config -import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} -import org.neo4j.logging.LogProvider -import org.neo4j.scheduler.JobScheduler - -class EnterpriseCompatibilityFactory(inner: CompilerFactory, graph: GraphDatabaseQueryService, - kernelMonitors: KernelMonitors, - logProvider: LogProvider) extends CompilerFactory { - override def create(spec: PlannerSpec_v2_3, config: CypherPlannerConfiguration): v2_3.Cypher23Compiler = - inner.create(spec, config) - - override def create(spec: PlannerSpec_v3_1, config: CypherPlannerConfiguration): v3_1.Cypher31Compiler = - inner.create(spec, config) - - override def create(spec: PlannerSpec_v3_3, config: CypherPlannerConfiguration): v3_3compat.Cypher33Compiler[_,_,_] = - inner.create(spec, config) - - override def create(spec: PlannerSpec_v3_5, config: CypherPlannerConfiguration): Cypher35Compiler[_,_] = - (spec.planner, spec.runtime) match { - case (CypherPlannerOption.rule, _) => inner.create(spec, config) - - case _ => - val settings = graph.getDependencyResolver.resolveDependency(classOf[Config]) - val morselSize: Int = settings.get(GraphDatabaseSettings.cypher_morsel_size) - val workers: Int = settings.get(GraphDatabaseSettings.cypher_worker_count) - val dispatcher = - if (workers == 1) new SingleThreadedExecutor(morselSize) - else { - val numberOfThreads = if (workers == 0) Runtime.getRuntime.availableProcessors() else workers - val jobScheduler = graph.getDependencyResolver.resolveDependency(classOf[JobScheduler]) - val executorService = jobScheduler.workStealingExecutor(JobScheduler.Groups.cypherWorker, numberOfThreads) - - new ParallelDispatcher(morselSize, numberOfThreads, executorService) - } - Cypher35Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, logProvider.getLog(getClass), - spec.planner, spec.runtime, spec.updateStrategy, EnterpriseRuntimeBuilder, - EnterpriseRuntimeContextCreator(GeneratedQueryStructure, dispatcher), - LastCommittedTxIdProvider(graph)) - } -} diff --git a/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompilerFactory.scala b/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompilerFactory.scala new file mode 100644 index 0000000000000..bc185f0be240c --- /dev/null +++ b/enterprise/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/EnterpriseCompilerFactory.scala @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j Enterprise Edition. The included source + * code can be redistributed and/or modified under the terms of the + * GNU AFFERO GENERAL PUBLIC LICENSE Version 3 + * (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the + * Commons Clause, as found in the associated LICENSE.txt file. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * Neo4j object code can be licensed independently from the source + * under separate terms from the AGPL. Inquiries can be directed to: + * licensing@neo4j.com + * + * More information is also available at: + * https://neo4j.com/licensing/ + */ +package org.neo4j.cypher.internal + +import org.neo4j.cypher.internal.compatibility.v3_5.Cypher35Compiler +import org.neo4j.cypher.internal.compiler.v3_5._ +import org.neo4j.cypher.internal.runtime.compiled.EnterpriseRuntimeContextCreator +import org.neo4j.cypher.internal.runtime.interpreted.LastCommittedTxIdProvider +import org.neo4j.cypher.internal.runtime.vectorized.dispatcher.{ParallelDispatcher, SingleThreadedExecutor} +import org.neo4j.cypher.internal.spi.codegen.GeneratedQueryStructure +import org.neo4j.cypher.{CypherPlannerOption, CypherRuntimeOption, CypherUpdateStrategy, CypherVersion} +import org.neo4j.graphdb.factory.GraphDatabaseSettings +import org.neo4j.kernel.GraphDatabaseQueryService +import org.neo4j.kernel.configuration.Config +import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} +import org.neo4j.logging.LogProvider +import org.neo4j.scheduler.JobScheduler + +class EnterpriseCompilerFactory(community: CommunityCompilerFactory, + graph: GraphDatabaseQueryService, + kernelMonitors: KernelMonitors, + logProvider: LogProvider + ) extends CompilerFactory { + + override def createCompiler(cypherVersion: CypherVersion, + cypherPlanner: CypherPlannerOption, + cypherRuntime: CypherRuntimeOption, + cypherUpdateStrategy: CypherUpdateStrategy, + config: CypherPlannerConfiguration + ): Compiler = { + + if (cypherVersion == CypherVersion.v3_5 && cypherPlanner != CypherPlannerOption.rule) { + + val settings = graph.getDependencyResolver.resolveDependency(classOf[Config]) + val morselSize: Int = settings.get(GraphDatabaseSettings.cypher_morsel_size) + val workers: Int = settings.get(GraphDatabaseSettings.cypher_worker_count) + val dispatcher = + if (workers == 1) new SingleThreadedExecutor(morselSize) + else { + val numberOfThreads = if (workers == 0) Runtime.getRuntime.availableProcessors() else workers + val jobScheduler = graph.getDependencyResolver.resolveDependency(classOf[JobScheduler]) + val executorService = jobScheduler.workStealingExecutor(JobScheduler.Groups.cypherWorker, numberOfThreads) + + new ParallelDispatcher(morselSize, numberOfThreads, executorService) + } + + Cypher35Compiler(config, CompilerEngineDelegator.CLOCK, kernelMonitors, logProvider.getLog(getClass), + cypherPlanner, cypherRuntime, cypherUpdateStrategy, EnterpriseRuntimeBuilder, + EnterpriseRuntimeContextCreator(GeneratedQueryStructure, dispatcher), + LastCommittedTxIdProvider(graph)) + + } else + community.createCompiler(cypherVersion, cypherPlanner, cypherRuntime, cypherUpdateStrategy, config) + } +}