diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/ExecutionPlan.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/ExecutionPlan.scala index 7f54220d05a84..856832f132602 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/ExecutionPlan.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/ExecutionPlan.scala @@ -22,6 +22,7 @@ package org.neo4j.cypher.internal import org.neo4j.cypher.internal.spi.v3_2.TransactionalContextWrapper import org.neo4j.graphdb.Transaction import org.neo4j.kernel.api.Statement +import org.neo4j.kernel.api.query.PlannerInfo final case class TransactionInfo(tx: Transaction, isTopLevelTx: Boolean, statement: Statement) @@ -33,5 +34,5 @@ trait ExecutionPlan { def isStale(lastCommittedTxId: LastCommittedTxIdProvider, ctx: TransactionalContextWrapper): Boolean - def plannerInfo: org.neo4j.kernel.api.ExecutingQuery.PlannerInfo + def plannerInfo: PlannerInfo } diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v2_3/Compatibility.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v2_3/Compatibility.scala index 2e903805571c5..272666fc87663 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v2_3/Compatibility.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v2_3/Compatibility.scala @@ -33,8 +33,9 @@ import org.neo4j.cypher.internal.spi.v2_3.{TransactionBoundGraphStatistics, Tran import org.neo4j.cypher.internal.spi.v3_2.TransactionalContextWrapper import org.neo4j.graphdb.{Node, Relationship} import org.neo4j.kernel.GraphDatabaseQueryService -import org.neo4j.kernel.api.ExecutingQuery.PlannerInfo -import org.neo4j.kernel.api.{IndexUsage, KernelAPI} +import org.neo4j.kernel.api.query.PlannerInfo +import org.neo4j.kernel.api.KernelAPI +import org.neo4j.kernel.api.index.IndexUsage import org.neo4j.kernel.impl.core.NodeManager import org.neo4j.kernel.impl.query.QueryExecutionMonitor import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_1/Compatibility.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_1/Compatibility.scala index 6955e36a09055..dedd0a46399c0 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_1/Compatibility.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_1/Compatibility.scala @@ -32,8 +32,9 @@ import org.neo4j.cypher.internal.spi.v3_1.{TransactionalContextWrapper => Transa import org.neo4j.cypher.internal.spi.v3_2.{TransactionalContextWrapper => TransactionalContextWrapperV3_2} import org.neo4j.cypher.internal.{frontend, _} import org.neo4j.kernel.GraphDatabaseQueryService -import org.neo4j.kernel.api.ExecutingQuery.PlannerInfo -import org.neo4j.kernel.api.{IndexUsage, KernelAPI} +import org.neo4j.kernel.api.query.PlannerInfo +import org.neo4j.kernel.api.KernelAPI +import org.neo4j.kernel.api.index.IndexUsage import org.neo4j.kernel.impl.query.QueryExecutionMonitor import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} import org.neo4j.logging.Log diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_2/Compatibility.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_2/Compatibility.scala index 1ebe2695a0531..9f66a783ef501 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_2/Compatibility.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/compatibility/v3_2/Compatibility.scala @@ -29,9 +29,9 @@ import org.neo4j.cypher.internal.frontend.v3_2.helpers.rewriting.RewriterStepSeq import org.neo4j.cypher.internal.frontend.v3_2.phases.{CompilationPhaseTracer, RecordingNotificationLogger} import org.neo4j.cypher.internal.spi.v3_2.TransactionBoundQueryContext.IndexSearchMonitor import org.neo4j.cypher.internal.spi.v3_2._ -import org.neo4j.kernel.api.ExecutingQuery.PlannerInfo -import org.neo4j.kernel.api.IndexUsage.{legacyIndexUsage, schemaIndexUsage} +import org.neo4j.kernel.api.index.IndexUsage.{legacyIndexUsage, schemaIndexUsage} import org.neo4j.kernel.api.KernelAPI +import org.neo4j.kernel.api.query.PlannerInfo import org.neo4j.kernel.impl.query.QueryExecutionMonitor import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} import org.neo4j.logging.Log diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQuery.java b/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQuery.java index 8dd542ee8f898..2b3eea4a121bc 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQuery.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQuery.java @@ -19,15 +19,13 @@ */ package org.neo4j.kernel.api; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.function.LongSupplier; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.neo4j.kernel.api.query.*; import org.neo4j.kernel.impl.locking.ActiveLock; import org.neo4j.kernel.impl.locking.LockTracer; import org.neo4j.kernel.impl.locking.LockWaitEvent; @@ -36,7 +34,6 @@ import org.neo4j.time.CpuClock; import org.neo4j.time.SystemNanoClock; -import static java.util.Collections.emptyList; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.atomic.AtomicLongFieldUpdater.newUpdater; @@ -45,56 +42,6 @@ */ public class ExecutingQuery { - public static class QueryInfo - { - public final String text; - public final Map parameters; - public final String planner; - public final String runtime; - private final List indexes; - - private QueryInfo( String text, Map parameters, PlannerInfo plannerInfo ) - { - this.text = text; - this.parameters = parameters; - if ( plannerInfo != null ) - { - this.planner = plannerInfo.planner; - this.runtime = plannerInfo.runtime; - this.indexes = plannerInfo.indexes; - } - else - { - this.planner = null; - this.runtime = null; - this.indexes = emptyList(); - } - } - - public List> indexes() - { - List> used = new ArrayList<>( this.indexes.size() ); - for ( IndexUsage index : indexes ) - { - used.add( index.asMap() ); - } - return used; - } - } - - public static class PlannerInfo - { - final String planner; - final String runtime; - final List indexes; - - public PlannerInfo( String planner, String runtime, List indexes ) - { - this.planner = planner; - this.runtime = runtime; - this.indexes = indexes; - } - } private static final AtomicLongFieldUpdater WAIT_TIME = newUpdater( ExecutingQuery.class, "waitTimeNanos" ); @@ -115,7 +62,7 @@ public PlannerInfo( String planner, String runtime, List indexes ) private final Map metaData; /** Uses write barrier of {@link #status}. */ private PlannerInfo plannerInfo; - private volatile ExecutingQueryStatus status = ExecutingQueryStatus.planning(); + private volatile ExecutingQueryStatus status = SimpleState.planning(); /** Updated through {@link #WAIT_TIME} */ @SuppressWarnings( "unused" ) private volatile long waitTimeNanos; @@ -150,7 +97,7 @@ public void planningCompleted( PlannerInfo plannerInfo ) { this.plannerInfo = plannerInfo; this.planningDone = clock.millis(); - this.status = ExecutingQueryStatus.running(); // write barrier - must be last + this.status = SimpleState.running(); // write barrier - must be last } @Override @@ -284,7 +231,7 @@ private LockWaitEvent waitForLock( boolean exclusive, ResourceType resourceType, return event; } - private class WaitingOnLockEvent extends ExecutingQueryStatus.WaitingOnLock implements LockWaitEvent + private class WaitingOnLockEvent extends WaitingOnLock implements LockWaitEvent { private final ExecutingQueryStatus previous = status; @@ -305,7 +252,7 @@ public void close() } @Override - boolean isPlanning() + public boolean isPlanning() { return previous.isPlanning(); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQueryStatus.java b/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQueryStatus.java deleted file mode 100644 index 5e2157cc4c81a..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/ExecutingQueryStatus.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.kernel.api; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.neo4j.storageengine.api.lock.ResourceType; -import org.neo4j.time.SystemNanoClock; - -import static java.util.Collections.singletonMap; -import static java.util.Collections.unmodifiableMap; - -/** - * Internal representation of the status of an executing query. - *

- * This is used for inspecting the state of a query. - * - * @see ExecutingQuery#status - */ -abstract class ExecutingQueryStatus -{ - abstract long waitTimeNanos( SystemNanoClock clock ); - - abstract Map toMap( SystemNanoClock clock ); - - static ExecutingQueryStatus planning() - { - return SimpleState.PLANNING; - } - - static ExecutingQueryStatus running() - { - return SimpleState.RUNNING; - } - - abstract boolean isPlanning(); - - static class WaitingOnLock extends ExecutingQueryStatus - { - private final String mode; - private final ResourceType resourceType; - private final long[] resourceIds; - private final long startTimeNanos; - - WaitingOnLock( String mode, ResourceType resourceType, long[] resourceIds, long startTimeNanos ) - { - this.mode = mode; - this.resourceType = resourceType; - this.resourceIds = resourceIds; - this.startTimeNanos = startTimeNanos; - } - - @Override - long waitTimeNanos( SystemNanoClock clock ) - { - return clock.nanos() - startTimeNanos; - } - - @Override - Map toMap( SystemNanoClock clock ) - { - Map map = new HashMap<>(); - map.put( "state", "WAITING" ); - map.put( "lockMode", mode ); - map.put( "waitTimeMillis", TimeUnit.NANOSECONDS.toMillis( waitTimeNanos( clock ) ) ); - map.put( "resourceType", resourceType.toString() ); - map.put( "resourceIds", resourceIds ); - return map; - } - - @Override - boolean isPlanning() - { - return false; - } - } - - private static final class SimpleState extends ExecutingQueryStatus - { - static final ExecutingQueryStatus PLANNING = new SimpleState( "PLANNING", true ); - static final ExecutingQueryStatus RUNNING = new SimpleState( "RUNNING", false ); - private final Map state; - private final boolean planning; - - private SimpleState( String state, boolean planning ) - { - this( singletonMap( "state", state ), planning ); - } - - private SimpleState( Map state, boolean planning ) - { - this.state = unmodifiableMap( state ); - this.planning = planning; - } - - @Override - long waitTimeNanos( SystemNanoClock clock ) - { - return 0; - } - - @Override - Map toMap( SystemNanoClock clock ) - { - return state; - } - - @Override - boolean isPlanning() - { - return planning; - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/IndexUsage.java b/community/kernel/src/main/java/org/neo4j/kernel/api/IndexUsage.java deleted file mode 100644 index 249e321148588..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/IndexUsage.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.kernel.api; - -import java.util.HashMap; -import java.util.Map; - -public abstract class IndexUsage -{ - public static IndexUsage schemaIndexUsage( String identifier, String label, String propertyKey ) - { - return new SchemaIndexUsage( identifier, label, propertyKey ); - } - - public static IndexUsage legacyIndexUsage( String identifier, String entityType, String index ) - { - return new LegacyIndexUsage( identifier, index, entityType ); - } - - abstract Map asMap(); - - final String identifier; - - private IndexUsage( String identifier ) - { - this.identifier = identifier; - } - - private static class SchemaIndexUsage extends IndexUsage - { - private final String label; - private final String propertyKey; - - private SchemaIndexUsage( String identifier, String label, String propertyKey ) - { - super( identifier ); - this.label = label; - this.propertyKey = propertyKey; - } - - Map asMap() - { - Map map = new HashMap<>(); - map.put( "indexType", "SCHEMA INDEX" ); - map.put( "entityType", "NODE" ); - map.put( "identifier", identifier ); - map.put( "label", label ); - map.put( "propertyKey", propertyKey ); - return map; - } - } - - private static class LegacyIndexUsage extends IndexUsage - { - private final String index; - private final String entityType; - - private LegacyIndexUsage( String identifier, String index, String entityType ) - { - super( identifier ); - this.index = index; - this.entityType = entityType; - } - - @Override - Map asMap() - { - Map map = new HashMap<>(); - map.put( "indexType", "LEGACY INDEX" ); - map.put( "entityType", entityType ); - map.put( "identifier", identifier ); - map.put( "indexName", index ); - return map; - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUsage.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUsage.java new file mode 100644 index 0000000000000..f952beb4f890d --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUsage.java @@ -0,0 +1,44 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.index; + +import java.util.Map; + +public abstract class IndexUsage +{ + public static IndexUsage schemaIndexUsage( String identifier, String label, String propertyKey ) + { + return new SchemaIndexUsage( identifier, label, propertyKey ); + } + + public static IndexUsage legacyIndexUsage( String identifier, String entityType, String index ) + { + return new LegacyIndexUsage( identifier, index, entityType ); + } + + public abstract Map asMap(); + + final String identifier; + + IndexUsage( String identifier ) + { + this.identifier = identifier; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/LegacyIndexUsage.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/LegacyIndexUsage.java new file mode 100644 index 0000000000000..038baa330a1bb --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/LegacyIndexUsage.java @@ -0,0 +1,47 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.index; + +import java.util.HashMap; +import java.util.Map; + +class LegacyIndexUsage extends IndexUsage +{ + private final String index; + private final String entityType; + + LegacyIndexUsage( String identifier, String index, String entityType ) + { + super( identifier ); + this.index = index; + this.entityType = entityType; + } + + @Override + public Map asMap() + { + Map map = new HashMap<>(); + map.put( "indexType", "LEGACY INDEX" ); + map.put( "entityType", entityType ); + map.put( "identifier", identifier ); + map.put( "indexName", index ); + return map; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/SchemaIndexUsage.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/SchemaIndexUsage.java new file mode 100644 index 0000000000000..f325d16c0d71b --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/SchemaIndexUsage.java @@ -0,0 +1,47 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.index; + +import java.util.HashMap; +import java.util.Map; + +class SchemaIndexUsage extends IndexUsage +{ + private final String label; + private final String propertyKey; + + SchemaIndexUsage( String identifier, String label, String propertyKey ) + { + super( identifier ); + this.label = label; + this.propertyKey = propertyKey; + } + + public Map asMap() + { + Map map = new HashMap<>(); + map.put( "indexType", "SCHEMA INDEX" ); + map.put( "entityType", "NODE" ); + map.put( "identifier", identifier ); + map.put( "label", label ); + map.put( "propertyKey", propertyKey ); + return map; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/query/ExecutingQueryStatus.java b/community/kernel/src/main/java/org/neo4j/kernel/api/query/ExecutingQueryStatus.java new file mode 100644 index 0000000000000..93daae9e78033 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/query/ExecutingQueryStatus.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.query; + +import java.util.Map; + +import org.neo4j.kernel.api.ExecutingQuery; +import org.neo4j.time.SystemNanoClock; + +/** + * Internal representation of the status of an executing query. + *

+ * This is used for inspecting the state of a query. + * + * @see ExecutingQuery#status + */ +public abstract class ExecutingQueryStatus +{ + public abstract long waitTimeNanos( SystemNanoClock clock ); + + public abstract Map toMap( SystemNanoClock clock ); + + public abstract boolean isPlanning(); + +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/query/PlannerInfo.java b/community/kernel/src/main/java/org/neo4j/kernel/api/query/PlannerInfo.java new file mode 100644 index 0000000000000..9596bb04857d2 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/query/PlannerInfo.java @@ -0,0 +1,53 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.query; + +import java.util.List; + +import org.neo4j.kernel.api.index.IndexUsage; + +public class PlannerInfo +{ + final String planner; + final String runtime; + final List indexes; + + public PlannerInfo( String planner, String runtime, List indexes ) + { + this.planner = planner; + this.runtime = runtime; + this.indexes = indexes; + } + + public String planner() + { + return planner; + } + + public String runtime() + { + return runtime; + } + + public List indexes() + { + return indexes; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/query/QueryInfo.java b/community/kernel/src/main/java/org/neo4j/kernel/api/query/QueryInfo.java new file mode 100644 index 0000000000000..58028060d4601 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/query/QueryInfo.java @@ -0,0 +1,65 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.query; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.neo4j.kernel.api.index.IndexUsage; + +import static java.util.Collections.emptyList; + +public class QueryInfo +{ + public final String text; + public final Map parameters; + public final String planner; + public final String runtime; + private final List indexes; + + public QueryInfo( String text, Map parameters, PlannerInfo plannerInfo ) + { + this.text = text; + this.parameters = parameters; + if ( plannerInfo != null ) + { + this.planner = plannerInfo.planner(); + this.runtime = plannerInfo.runtime(); + this.indexes = plannerInfo.indexes(); + } + else + { + this.planner = null; + this.runtime = null; + this.indexes = emptyList(); + } + } + + public List> indexes() + { + List> used = new ArrayList<>( this.indexes.size() ); + for ( IndexUsage index : indexes ) + { + used.add( index.asMap() ); + } + return used; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/query/SimpleState.java b/community/kernel/src/main/java/org/neo4j/kernel/api/query/SimpleState.java new file mode 100644 index 0000000000000..3b59fe68eefee --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/query/SimpleState.java @@ -0,0 +1,68 @@ +package org.neo4j.kernel.api.query; + +/* + * 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 . + */ + +import java.util.Map; + +import org.neo4j.time.SystemNanoClock; + +import static java.util.Collections.singletonMap; +import static java.util.Collections.unmodifiableMap; + +public final class SimpleState extends ExecutingQueryStatus +{ + private static final ExecutingQueryStatus PLANNING = new SimpleState( singletonMap( "state", "PLANNING" ) ); + private static final ExecutingQueryStatus RUNNING = new SimpleState( singletonMap( "state", "RUNNING" ) ); + private final Map state; + + public static ExecutingQueryStatus planning() + { + return PLANNING; + } + + public static ExecutingQueryStatus running() + { + return RUNNING; + } + + private SimpleState( Map state ) + { + this.state = unmodifiableMap( state ); + } + + @Override + public long waitTimeNanos( SystemNanoClock clock ) + { + return 0; + } + + @Override + public Map toMap( SystemNanoClock clock ) + { + return state; + } + + @Override + public boolean isPlanning() + { + return this == PLANNING; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/query/WaitingOnLock.java b/community/kernel/src/main/java/org/neo4j/kernel/api/query/WaitingOnLock.java new file mode 100644 index 0000000000000..d3eb3a3be5f55 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/query/WaitingOnLock.java @@ -0,0 +1,67 @@ +/* + * 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 . + */ +package org.neo4j.kernel.api.query; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.neo4j.storageengine.api.lock.ResourceType; +import org.neo4j.time.SystemNanoClock; + +public class WaitingOnLock extends ExecutingQueryStatus +{ + private final String mode; + private final ResourceType resourceType; + private final long[] resourceIds; + private final long startTimeNanos; + + public WaitingOnLock( String mode, ResourceType resourceType, long[] resourceIds, long startTimeNanos ) + { + this.mode = mode; + this.resourceType = resourceType; + this.resourceIds = resourceIds; + this.startTimeNanos = startTimeNanos; + } + + @Override + public long waitTimeNanos( SystemNanoClock clock ) + { + return clock.nanos() - startTimeNanos; + } + + @Override + public Map toMap( SystemNanoClock clock ) + { + Map map = new HashMap<>(); + map.put( "state", "WAITING" ); + map.put( "lockMode", mode ); + map.put( "waitTimeMillis", TimeUnit.NANOSECONDS.toMillis( waitTimeNanos( clock ) ) ); + map.put( "resourceType", resourceType.toString() ); + map.put( "resourceIds", resourceIds ); + return map; + } + + @Override + public boolean isPlanning() + { + return false; + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryTest.java index b11b298a0ee3c..106663ad2395e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryTest.java @@ -31,6 +31,7 @@ import org.hamcrest.TypeSafeMatcher; import org.junit.Test; +import org.neo4j.kernel.api.query.PlannerInfo; import org.neo4j.kernel.impl.locking.LockWaitEvent; import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo; import org.neo4j.storageengine.api.lock.ResourceType; @@ -80,7 +81,7 @@ public void shouldTransitionBetweenStates() throws Exception assertThat( query.status(), hasEntry( "state", "PLANNING" ) ); // when - query.planningCompleted( new ExecutingQuery.PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); + query.planningCompleted( new PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); // then assertThat( query.status(), hasEntry( "state", "RUNNING" ) ); @@ -106,7 +107,7 @@ public void shouldReportPlanningTime() throws Exception // when clock.forward( 16, TimeUnit.MILLISECONDS ); - query.planningCompleted( new ExecutingQuery.PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); + query.planningCompleted( new PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); clock.forward( 200, TimeUnit.MILLISECONDS ); // then @@ -118,7 +119,7 @@ public void shouldReportPlanningTime() throws Exception public void shouldReportWaitTime() throws Exception { // given - query.planningCompleted( new ExecutingQuery.PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); + query.planningCompleted( new PlannerInfo( "the-planner", "the-runtime", emptyList() ) ); // then assertEquals( singletonMap( "state", "RUNNING" ), query.status() ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryStatusTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/query/ExecutingQueryStatusTest.java similarity index 71% rename from community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryStatusTest.java rename to community/kernel/src/test/java/org/neo4j/kernel/api/query/ExecutingQueryStatusTest.java index 9785af9206527..776e7d0ea37fa 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/ExecutingQueryStatusTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/query/ExecutingQueryStatusTest.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.kernel.api; +package org.neo4j.kernel.api.query; import java.time.ZonedDateTime; import java.util.HashMap; @@ -27,12 +27,13 @@ import org.junit.Test; import org.neo4j.kernel.impl.locking.ActiveLock; +import org.neo4j.storageengine.api.lock.ResourceType; +import org.neo4j.storageengine.api.lock.WaitStrategy; import org.neo4j.time.Clocks; import org.neo4j.time.FakeClock; import static java.util.Collections.singletonMap; import static org.junit.Assert.assertEquals; -import static org.neo4j.kernel.api.ExecutingQueryTest.resourceType; public class ExecutingQueryStatusTest { @@ -42,7 +43,7 @@ public class ExecutingQueryStatusTest public void shouldProduceSensibleMapRepresentationInRunningState() throws Exception { // when - Map status = ExecutingQueryStatus.running().toMap( clock ); + Map status = SimpleState.running().toMap( clock ); // then assertEquals( singletonMap( "state", "RUNNING" ), status ); @@ -52,7 +53,7 @@ public void shouldProduceSensibleMapRepresentationInRunningState() throws Except public void shouldProduceSensibleMapRepresentationInPlanningState() throws Exception { // when - Map status = ExecutingQueryStatus.planning().toMap( clock ); + Map status = SimpleState.planning().toMap( clock ); // then assertEquals( singletonMap( "state", "PLANNING" ), status ); @@ -63,8 +64,8 @@ public void shouldProduceSensibleMapRepresentationInWaitingState() throws Except { // given long[] resourceIds = {17}; - ExecutingQueryStatus.WaitingOnLock status = - new ExecutingQueryStatus.WaitingOnLock( + WaitingOnLock status = + new WaitingOnLock( ActiveLock.EXCLUSIVE_MODE, resourceType( "NODE" ), resourceIds, @@ -83,4 +84,33 @@ public void shouldProduceSensibleMapRepresentationInWaitingState() throws Except expected.put( "resourceIds", resourceIds ); assertEquals( expected, statusMap ); } + static ResourceType resourceType(String name ) + { + return new ResourceType() + { + @Override + public String toString() + { + return name(); + } + + @Override + public int typeId() + { + throw new UnsupportedOperationException( "not used" ); + } + + @Override + public WaitStrategy waitStrategy() + { + throw new UnsupportedOperationException( "not used" ); + } + + @Override + public String name() + { + return name; + } + }; + } } diff --git a/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java b/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java index cabafb60a552d..b06ac5a8be292 100644 --- a/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java +++ b/enterprise/kernel/src/main/java/org/neo4j/kernel/enterprise/builtinprocs/QueryStatusResult.java @@ -27,6 +27,7 @@ import org.neo4j.kernel.api.ExecutingQuery; import org.neo4j.kernel.api.exceptions.InvalidArgumentsException; +import org.neo4j.kernel.api.query.QueryInfo; import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo; import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME; @@ -87,7 +88,7 @@ public class QueryStatusResult private QueryStatusResult( QueryId queryId, String username, - ExecutingQuery.QueryInfo query, + QueryInfo query, long startTime, long elapsedTime, ClientConnectionInfo clientConnection, @@ -95,8 +96,8 @@ private QueryStatusResult( long cpuTimeMillis, Map status, long activeLockCount, - long waitTimeMillis - ) { + long waitTimeMillis ) + { this.queryId = queryId.toString(); this.username = username; this.query = query.text; @@ -121,8 +122,8 @@ private QueryStatusResult( private static String formatTime( final long startTime ) { return OffsetDateTime - .ofInstant( Instant.ofEpochMilli( startTime ), ZoneId.systemDefault() ) - .format( ISO_OFFSET_DATE_TIME ); + .ofInstant( Instant.ofEpochMilli( startTime ), ZoneId.systemDefault() ) + .format( ISO_OFFSET_DATE_TIME ); } private static String formatInterval( final long l )