Skip to content

Commit

Permalink
Avoid usage of kernel dependencies in QueryContext.
Browse files Browse the repository at this point in the history
Use compatibility friendly wrapper instead.
  • Loading branch information
MishaDemianenko committed Apr 4, 2017
1 parent aff3e20 commit 07e4b5d
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 27 deletions.
Expand Up @@ -26,7 +26,6 @@ import org.neo4j.cypher.internal.compiler.v3_2.commands.expressions.{Expander, K
import org.neo4j.cypher.internal.compiler.v3_2.pipes.matching.PatternNode import org.neo4j.cypher.internal.compiler.v3_2.pipes.matching.PatternNode
import org.neo4j.cypher.internal.frontend.v3_2.SemanticDirection import org.neo4j.cypher.internal.frontend.v3_2.SemanticDirection
import org.neo4j.graphdb.{Node, Path, PropertyContainer, Relationship} import org.neo4j.graphdb.{Node, Path, PropertyContainer, Relationship}
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider


import scala.collection.Iterator import scala.collection.Iterator


Expand Down
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.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 <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v3_2.spi

/**
* Expose various query execution kernel statistics
*/
trait KernelStatisticProvider {
/**
* @return observed page cache hits that was caused by particular query execution
*/
def getPageCacheHits: Long

/**
* @return observer page cache misses that was caused by particular query execution
*/
def getPageCacheMisses: Long
}

object EmptyKernelStatisticProvider extends KernelStatisticProvider {
override def getPageCacheHits: Long = 0

override def getPageCacheMisses: Long = 0
}
Expand Up @@ -26,7 +26,6 @@ import org.neo4j.cypher.internal.compiler.v3_2.pipes.matching.PatternNode
import org.neo4j.cypher.internal.compiler.v3_2.{IndexDescriptor, InternalQueryStatistics} import org.neo4j.cypher.internal.compiler.v3_2.{IndexDescriptor, InternalQueryStatistics}
import org.neo4j.cypher.internal.frontend.v3_2.SemanticDirection import org.neo4j.cypher.internal.frontend.v3_2.SemanticDirection
import org.neo4j.graphdb.{Node, Path, PropertyContainer, Relationship} import org.neo4j.graphdb.{Node, Path, PropertyContainer, Relationship}
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider


import scala.collection.Iterator import scala.collection.Iterator


Expand Down
Expand Up @@ -25,9 +25,8 @@ import org.neo4j.cypher.internal.compiler.v3_2.commands.expressions.{NestedPipeE
import org.neo4j.cypher.internal.compiler.v3_2.pipes._ import org.neo4j.cypher.internal.compiler.v3_2.pipes._
import org.neo4j.cypher.internal.compiler.v3_2.planDescription.InternalPlanDescription.Arguments.{DbHits, PageCacheHits, PageCacheMisses, Rows} import org.neo4j.cypher.internal.compiler.v3_2.planDescription.InternalPlanDescription.Arguments.{DbHits, PageCacheHits, PageCacheMisses, Rows}
import org.neo4j.cypher.internal.compiler.v3_2.planDescription._ import org.neo4j.cypher.internal.compiler.v3_2.planDescription._
import org.neo4j.cypher.internal.compiler.v3_2.spi.{QueryContext, QueryTransactionalContext} import org.neo4j.cypher.internal.compiler.v3_2.spi.{EmptyKernelStatisticProvider, KernelStatisticProvider, QueryContext, QueryTransactionalContext}
import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider


class ProfilerTest extends CypherFunSuite { class ProfilerTest extends CypherFunSuite {


Expand Down Expand Up @@ -280,7 +279,7 @@ class ProfilerTest extends CypherFunSuite {
profiled2.query.asInstanceOf[ProfilingPipeQueryContext].count should equal(1) profiled2.query.asInstanceOf[ProfilingPipeQueryContext].count should equal(1)
} }


private def prepareQueryContext(statisticProvider: KernelStatisticProvider = KernelStatisticProvider.EMPTY) = { private def prepareQueryContext(statisticProvider: KernelStatisticProvider = EmptyKernelStatisticProvider) = {
val queryContext = mock[QueryContext] val queryContext = mock[QueryContext]
val transactionalContext = mock[QueryTransactionalContext] val transactionalContext = mock[QueryTransactionalContext]
when(queryContext.transactionalContext).thenReturn(transactionalContext) when(queryContext.transactionalContext).thenReturn(transactionalContext)
Expand Down
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.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 <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compatibility.v3_2

import org.neo4j.cypher.internal.compiler.v3_2.spi.KernelStatisticProvider
import org.neo4j.kernel.impl.query.statistic.StatisticProvider

class ProfileKernelStatisticProvider(statisticProvider: StatisticProvider) extends KernelStatisticProvider {

override def getPageCacheHits: Long = {
statisticProvider.getPageCacheHits
}

override def getPageCacheMisses: Long = {
statisticProvider.getPageCacheMisses
}
}
Expand Up @@ -20,7 +20,8 @@
package org.neo4j.cypher.internal.spi.v3_2 package org.neo4j.cypher.internal.spi.v3_2


import org.neo4j.cypher.internal.ExecutionPlan import org.neo4j.cypher.internal.ExecutionPlan
import org.neo4j.cypher.internal.compiler.v3_2.spi.QueryTransactionalContext import org.neo4j.cypher.internal.compatibility.v3_2.ProfileKernelStatisticProvider
import org.neo4j.cypher.internal.compiler.v3_2.spi.{KernelStatisticProvider, QueryTransactionalContext}
import org.neo4j.graphdb.{Lock, PropertyContainer} import org.neo4j.graphdb.{Lock, PropertyContainer}
import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api.KernelTransaction.Revertable import org.neo4j.kernel.api.KernelTransaction.Revertable
Expand All @@ -29,7 +30,6 @@ import org.neo4j.kernel.api.security.SecurityContext
import org.neo4j.kernel.api.txstate.TxStateHolder import org.neo4j.kernel.api.txstate.TxStateHolder
import org.neo4j.kernel.api.{ReadOperations, Statement} import org.neo4j.kernel.api.{ReadOperations, Statement}
import org.neo4j.kernel.impl.query.TransactionalContext import org.neo4j.kernel.impl.query.TransactionalContext
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider


case class TransactionalContextWrapper(tc: TransactionalContext) extends QueryTransactionalContext { case class TransactionalContextWrapper(tc: TransactionalContext) extends QueryTransactionalContext {


Expand Down Expand Up @@ -68,5 +68,5 @@ case class TransactionalContextWrapper(tc: TransactionalContext) extends QueryTr


def notifyPlanningCompleted(plan: ExecutionPlan): Unit = tc.executingQuery().planningCompleted(plan.plannerInfo) def notifyPlanningCompleted(plan: ExecutionPlan): Unit = tc.executingQuery().planningCompleted(plan.plannerInfo)


def kernelStatisticProvider : KernelStatisticProvider = tc.kernelStatisticProvider() def kernelStatisticProvider: KernelStatisticProvider = new ProfileKernelStatisticProvider(tc.kernelStatisticProvider())
} }
Expand Up @@ -39,7 +39,7 @@
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker; import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker;
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider; import org.neo4j.kernel.impl.query.statistic.StatisticProvider;


public class Neo4jTransactionalContext implements TransactionalContext public class Neo4jTransactionalContext implements TransactionalContext
{ {
Expand Down Expand Up @@ -280,9 +280,9 @@ public SecurityContext securityContext()
} }


@Override @Override
public KernelStatisticProvider kernelStatisticProvider() public StatisticProvider kernelStatisticProvider()
{ {
return new TransactionalContextKernelStatisticProvider( statement.executionStatisticsOperations().getPageCursorTracer() ); return new TransactionalContextStatisticProvider( statement.executionStatisticsOperations().getPageCursorTracer() );
} }


private void collectTransactionExecutionStatistic() private void collectTransactionExecutionStatistic()
Expand All @@ -302,11 +302,11 @@ Neo4jTransactionalContext create(
); );
} }


private class TransactionalContextKernelStatisticProvider implements KernelStatisticProvider private class TransactionalContextStatisticProvider implements StatisticProvider
{ {
private final PageCursorTracer pageCursorTracer; private final PageCursorTracer pageCursorTracer;


private TransactionalContextKernelStatisticProvider( PageCursorTracer pageCursorTracer ) private TransactionalContextStatisticProvider( PageCursorTracer pageCursorTracer )
{ {
this.pageCursorTracer = pageCursorTracer; this.pageCursorTracer = pageCursorTracer;
} }
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.neo4j.kernel.api.query.ExecutingQuery; import org.neo4j.kernel.api.query.ExecutingQuery;
import org.neo4j.kernel.api.security.SecurityContext; import org.neo4j.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.txstate.TxStateHolder; import org.neo4j.kernel.api.txstate.TxStateHolder;
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider; import org.neo4j.kernel.impl.query.statistic.StatisticProvider;


public interface TransactionalContext public interface TransactionalContext
{ {
Expand Down Expand Up @@ -78,7 +78,7 @@ public interface TransactionalContext


SecurityContext securityContext(); SecurityContext securityContext();


KernelStatisticProvider kernelStatisticProvider(); StatisticProvider kernelStatisticProvider();


KernelTransaction.Revertable restrictCurrentTransaction( SecurityContext context ); KernelTransaction.Revertable restrictCurrentTransaction( SecurityContext context );
} }
Expand Up @@ -19,9 +19,9 @@
*/ */
package org.neo4j.kernel.impl.query.statistic; package org.neo4j.kernel.impl.query.statistic;


public interface KernelStatisticProvider public interface StatisticProvider
{ {
KernelStatisticProvider EMPTY = new KernelStatisticProvider() StatisticProvider EMPTY = new StatisticProvider()
{ {
@Override @Override
public long getPageCacheHits() public long getPageCacheHits()
Expand Down
Expand Up @@ -41,7 +41,7 @@
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker; import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker;
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider; import org.neo4j.kernel.impl.query.statistic.StatisticProvider;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
Expand Down Expand Up @@ -268,7 +268,7 @@ public void accumulateExecutionStatisticOverCommitAndRestart()
tracer.setFaults( 2 ); tracer.setFaults( 2 );
tracer.setHits( 5 ); tracer.setHits( 5 );


KernelStatisticProvider statisticProvider = transactionalContext.kernelStatisticProvider(); StatisticProvider statisticProvider = transactionalContext.kernelStatisticProvider();


assertEquals( "Expect to see accumulated number of page cache misses.",6, statisticProvider.getPageCacheMisses() ); assertEquals( "Expect to see accumulated number of page cache misses.",6, statisticProvider.getPageCacheMisses() );
assertEquals( "Expected to see accumulated number of page cache hits.", 15, statisticProvider.getPageCacheHits() ); assertEquals( "Expected to see accumulated number of page cache hits.", 15, statisticProvider.getPageCacheHits() );
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.QueryExecutionEvent; import org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.QueryExecutionEvent;
import org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.QueryExecutionTracer; import org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.QueryExecutionTracer;
import org.neo4j.cypher.internal.compiler.v3_2.planDescription.Id; import org.neo4j.cypher.internal.compiler.v3_2.planDescription.Id;
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider; import org.neo4j.cypher.internal.compiler.v3_2.spi.KernelStatisticProvider;


public class ProfilingTracer implements QueryExecutionTracer public class ProfilingTracer implements QueryExecutionTracer
{ {
Expand Down
Expand Up @@ -20,9 +20,9 @@
package org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.profiling package org.neo4j.cypher.internal.compiled_runtime.v3_2.codegen.profiling


import org.neo4j.cypher.internal.compiler.v3_2.planDescription.Id import org.neo4j.cypher.internal.compiler.v3_2.planDescription.Id
import org.neo4j.cypher.internal.compiler.v3_2.spi.{EmptyKernelStatisticProvider, KernelStatisticProvider}
import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite
import org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracer import org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracer
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider


class ProfilingTracerTest extends CypherFunSuite { class ProfilingTracerTest extends CypherFunSuite {


Expand All @@ -39,7 +39,7 @@ class ProfilingTracerTest extends CypherFunSuite {
// given // given
val clock = new Clock val clock = new Clock
val operatorId = new Id val operatorId = new Id
val tracer = new ProfilingTracer(clock, KernelStatisticProvider.EMPTY) val tracer = new ProfilingTracer(clock, EmptyKernelStatisticProvider)
val event = tracer.executeOperator(operatorId) val event = tracer.executeOperator(operatorId)


// when // when
Expand All @@ -54,7 +54,7 @@ class ProfilingTracerTest extends CypherFunSuite {
// given // given
val clock = new Clock val clock = new Clock
val operatorId = new Id val operatorId = new Id
val tracer = new ProfilingTracer(clock, KernelStatisticProvider.EMPTY) val tracer = new ProfilingTracer(clock, EmptyKernelStatisticProvider)


// when // when
val event1 = tracer.executeOperator(operatorId) val event1 = tracer.executeOperator(operatorId)
Expand All @@ -72,7 +72,7 @@ class ProfilingTracerTest extends CypherFunSuite {
test("shouldReportDbHitsOfQueryExecution") { test("shouldReportDbHitsOfQueryExecution") {
// given // given
val operatorId = new Id val operatorId = new Id
val tracer = new ProfilingTracer(KernelStatisticProvider.EMPTY) val tracer = new ProfilingTracer(EmptyKernelStatisticProvider)
val event = tracer.executeOperator(operatorId) val event = tracer.executeOperator(operatorId)


// when // when
Expand All @@ -89,7 +89,7 @@ class ProfilingTracerTest extends CypherFunSuite {
test("shouldReportRowsOfQueryExecution") { test("shouldReportRowsOfQueryExecution") {
// given // given
val operatorId = new Id val operatorId = new Id
val tracer = new ProfilingTracer(KernelStatisticProvider.EMPTY) val tracer = new ProfilingTracer(EmptyKernelStatisticProvider)
val event = tracer.executeOperator(operatorId) val event = tracer.executeOperator(operatorId)


// when // when
Expand Down
Expand Up @@ -31,7 +31,7 @@ import org.neo4j.cypher.internal.compiler.v3_2.planDescription.InternalPlanDescr
import org.neo4j.cypher.internal.compiler.v3_2.planDescription._ import org.neo4j.cypher.internal.compiler.v3_2.planDescription._
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans
import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans._ import org.neo4j.cypher.internal.compiler.v3_2.planner.logical.plans._
import org.neo4j.cypher.internal.compiler.v3_2.spi.{QueryContext, QueryTransactionalContext} import org.neo4j.cypher.internal.compiler.v3_2.spi.{KernelStatisticProvider, QueryContext, QueryTransactionalContext}
import org.neo4j.cypher.internal.frontend.v3_2.ast.SignedDecimalIntegerLiteral import org.neo4j.cypher.internal.frontend.v3_2.ast.SignedDecimalIntegerLiteral
import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.frontend.v3_2.test_helpers.CypherFunSuite
import org.neo4j.cypher.internal.ir.v3_2.{Cardinality, CardinalityEstimation, IdName, PlannerQuery} import org.neo4j.cypher.internal.ir.v3_2.{Cardinality, CardinalityEstimation, IdName, PlannerQuery}
Expand All @@ -41,7 +41,6 @@ import org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracer
import org.neo4j.kernel.api._ import org.neo4j.kernel.api._
import org.neo4j.kernel.api.security.AnonymousContext import org.neo4j.kernel.api.security.AnonymousContext
import org.neo4j.kernel.impl.core.{NodeManager, NodeProxy} import org.neo4j.kernel.impl.core.{NodeManager, NodeProxy}
import org.neo4j.kernel.impl.query.statistic.KernelStatisticProvider
import org.neo4j.test.TestGraphDatabaseFactory import org.neo4j.test.TestGraphDatabaseFactory


class CompiledProfilingTest extends CypherFunSuite with CodeGenSugar { class CompiledProfilingTest extends CypherFunSuite with CodeGenSugar {
Expand Down

0 comments on commit 07e4b5d

Please sign in to comment.