This is an automated email from the ASF dual-hosted git repository.

namelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c2b42dd4ec IGNITE-19628 Added IndexQuery to performance statistics 
(#10758)
5c2b42dd4ec is described below

commit 5c2b42dd4ecb04620339213219f4572013147fb4
Author: Nikita Amelchev <[email protected]>
AuthorDate: Tue Jun 6 15:47:23 2023 +0300

    IGNITE-19628 Added IndexQuery to performance statistics (#10758)
---
 .../query/calcite/QueryRegistryImpl.java           |  2 --
 .../query/GridCacheDistributedQueryFuture.java     | 30 ++++++++++++++++++++++
 .../query/GridCacheDistributedQueryManager.java    | 23 ++++-------------
 .../PerformanceStatisticsProcessor.java            | 20 +++++++++++++++
 .../processors/query/GridRunningQueryInfo.java     | 13 ----------
 .../processors/query/RunningQueryManager.java      | 18 +------------
 .../query/h2/twostep/GridMapQueryExecutor.java     |  2 +-
 .../query/h2/twostep/GridReduceQueryExecutor.java  |  5 +---
 .../PerformanceStatisticsQueryTest.java            | 19 ++++++++++++++
 9 files changed, 77 insertions(+), 55 deletions(-)

diff --git 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/QueryRegistryImpl.java
 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/QueryRegistryImpl.java
index 01929aba1e4..d023a258e1a 100644
--- 
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/QueryRegistryImpl.java
+++ 
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/QueryRegistryImpl.java
@@ -65,8 +65,6 @@ public class QueryRegistryImpl extends AbstractService 
implements QueryRegistry
             long locId = qryMgr.register(rootQry.sql(), 
GridCacheQueryType.SQL_FIELDS, rootQry.context().schemaName(),
                 false, createCancelToken(qry), initiatorId, false, false, 
false);
 
-            qryMgr.trackRequestId(locId);
-
             rootQry.localQueryId(locId);
 
             return qry;
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryFuture.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryFuture.java
index 46ba4fbce17..2b12a3b784c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryFuture.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryFuture.java
@@ -42,6 +42,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 
 import static 
org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.INDEX;
 import static 
org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.TEXT;
+import static 
org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor.indexQueryText;
 
 /**
  * Distributed query future.
@@ -68,6 +69,9 @@ public class GridCacheDistributedQueryFuture<K, V, R> extends 
GridCacheQueryFutu
     /** Metadata for IndexQuery. */
     private final CompletableFuture<IndexQueryResultMeta> idxQryMetaFut;
 
+    /** Query start time in nanoseconds to measure duration. */
+    private final long startTimeNanos;
+
     /**
      * @param ctx Cache context.
      * @param reqId Request ID.
@@ -109,6 +113,8 @@ public class GridCacheDistributedQueryFuture<K, V, R> 
extends GridCacheQueryFutu
 
             reducer = qry.query().type() == TEXT ? new 
TextQueryReducer<>(streamsMap) : new UnsortedCacheQueryReducer<>(streamsMap);
         }
+
+        startTimeNanos = ctx.kernalContext().performanceStatistics().enabled() 
? System.nanoTime() : 0;
     }
 
     /**
@@ -315,4 +321,28 @@ public class GridCacheDistributedQueryFuture<K, V, R> 
extends GridCacheQueryFutu
             firstPageLatch.countDown();
         }
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean onDone(Collection<R> res, Throwable err) {
+        if (cctx.kernalContext().performanceStatistics().enabled() && 
startTimeNanos > 0) {
+            GridCacheQueryType type = qry.query().type();
+
+            String text;
+
+            if (type == INDEX)
+                text = indexQueryText(cctx.name(), qry.query().idxQryDesc());
+            else
+                text = cctx.name();
+
+            cctx.kernalContext().performanceStatistics().query(
+                type,
+                text,
+                reqId,
+                startTimeNanos,
+                System.nanoTime() - startTimeNanos,
+                err == null);
+        }
+
+        return super.onDone(res, err);
+    }
 }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
index f7b3f7a8b8f..95a842c79cf 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheDistributedQueryManager.java
@@ -552,9 +552,6 @@ public class GridCacheDistributedQueryManager<K, V> extends 
GridCacheQueryManage
 
         boolean performanceStatsEnabled = 
cctx.kernalContext().performanceStatistics().enabled();
 
-        long startTime = performanceStatsEnabled ? System.currentTimeMillis() 
: 0;
-        long startTimeNanos = performanceStatsEnabled ? System.nanoTime() : 0;
-
         GridCloseableIterator locIter0 = null;
 
         for (ClusterNode node : nodes) {
@@ -650,23 +647,13 @@ public class GridCacheDistributedQueryManager<K, V> 
extends GridCacheQueryManage
                 if (fut != null)
                     fut.cancel();
 
-                if (performanceStatsEnabled) {
-                    cctx.kernalContext().performanceStatistics().query(
+                if (performanceStatsEnabled && (logicalReads > 0 || 
physicalReads > 0)) {
+                    cctx.kernalContext().performanceStatistics().queryReads(
                         SCAN,
-                        cctx.name(),
+                        cctx.localNodeId(),
                         ((GridCacheDistributedQueryFuture)fut).requestId(),
-                        startTime,
-                        System.nanoTime() - startTimeNanos,
-                        true);
-
-                    if (logicalReads > 0 || physicalReads > 0) {
-                        
cctx.kernalContext().performanceStatistics().queryReads(
-                            SCAN,
-                            cctx.localNodeId(),
-                            ((GridCacheDistributedQueryFuture)fut).requestId(),
-                            logicalReads,
-                            physicalReads);
-                    }
+                        logicalReads,
+                        physicalReads);
                 }
             }
         };
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsProcessor.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsProcessor.java
index 6c53de7b293..0d720b4ced8 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsProcessor.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsProcessor.java
@@ -24,17 +24,20 @@ import java.util.UUID;
 import java.util.function.Consumer;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.query.IndexQueryCriterion;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteFeatures;
 import org.apache.ignite.internal.NodeStoppingException;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.cache.query.IndexQueryDesc;
 import 
org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
 import 
org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
 import 
org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
 import org.apache.ignite.internal.util.GridIntList;
 import org.apache.ignite.internal.util.distributed.DistributedProcess;
 import org.apache.ignite.internal.util.lang.GridPlainRunnable;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteFuture;
@@ -160,6 +163,8 @@ public class PerformanceStatisticsProcessor extends 
GridProcessorAdapter {
     /**
      * @param type Cache query type.
      * @param text Query text in case of SQL query. Cache name in case of SCAN 
query.
+     *             In case of an INDEX query, the text represents the pattern:
+     *             <pre>{@code <cacheName>:<indexName>:<valueType>:<comma 
separated fields>}</pre>
      * @param id Query id.
      * @param startTime Start time in milliseconds.
      * @param duration Duration in nanoseconds.
@@ -406,4 +411,19 @@ public class PerformanceStatisticsProcessor extends 
GridProcessorAdapter {
         /** This method is called whenever the performance statistics 
collecting is started. */
         public void onStarted();
     }
+
+    /** @return Text representation of index query. */
+    public static String indexQueryText(String cacheName, IndexQueryDesc desc) 
{
+        StringBuilder s = new StringBuilder();
+
+        s.append(cacheName);
+        s.append(':');
+        s.append(desc.idxName());
+        s.append(':');
+        s.append(desc.valType());
+        s.append(':');
+        s.append(String.join(",", F.viewReadOnly(desc.criteria(), 
IndexQueryCriterion::field)));
+
+        return s.toString();
+    }
 }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
index 927239533cc..65686bcf213 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridRunningQueryInfo.java
@@ -74,9 +74,6 @@ public class GridRunningQueryInfo {
     /** Distributed joins flag. */
     private final boolean distributedJoins;
 
-    /** Request ID. */
-    private long reqId;
-
     /** Subject ID. */
     private final UUID subjId;
 
@@ -232,11 +229,6 @@ public class GridRunningQueryInfo {
         return span;
     }
 
-    /** @return Request ID. */
-    public long requestId() {
-        return reqId;
-    }
-
     /**
      * @return Query's originator string (client host+port, user name,
      * job name or any user's information about query initiator).
@@ -266,11 +258,6 @@ public class GridRunningQueryInfo {
         return lazy;
     }
 
-    /** @param reqId Request ID. */
-    public void requestId(long reqId) {
-        this.reqId = reqId;
-    }
-
     /** @return Subject ID. */
     public UUID subjectId() {
         return subjId;
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
index c98bf4cf87c..013f0538c6e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/RunningQueryManager.java
@@ -130,9 +130,6 @@ public class RunningQueryManager {
     /** Logger. */
     private final IgniteLogger log;
 
-    /** Current running query info. */
-    private final ThreadLocal<GridRunningQueryInfo> currQryInfo = new 
ThreadLocal<>();
-
     /** */
     private final ReadWriteLock lock = new ReentrantReadWriteLock();
 
@@ -276,9 +273,6 @@ public class RunningQueryManager {
 
         GridRunningQueryInfo preRun = runs.putIfAbsent(qryId, run);
 
-        if (ctx.performanceStatistics().enabled())
-            currQryInfo.set(run);
-
         assert preRun == null : "Running query already registered [prev_qry=" 
+ preRun + ", newQry=" + run + ']';
 
         run.span().addTag(SQL_QRY_ID, run::globalQueryId);
@@ -405,7 +399,7 @@ public class RunningQueryManager {
                 ctx.performanceStatistics().query(
                     qry.queryType(),
                     qry.query(),
-                    qry.requestId(),
+                    qry.id(),
                     qry.startTime(),
                     System.nanoTime() - qry.startTimeNanos(),
                     !failed);
@@ -416,16 +410,6 @@ public class RunningQueryManager {
         }
     }
 
-    /** @param reqId Request ID of query to track. */
-    public void trackRequestId(long reqId) {
-        if (ctx.performanceStatistics().enabled()) {
-            GridRunningQueryInfo info = currQryInfo.get();
-
-            if (info != null)
-                info.requestId(reqId);
-        }
-    }
-
     /**
      * Return SQL queries which executing right now.
      *
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
index 27f2b72e324..18bb7abb412 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMapQueryExecutor.java
@@ -602,7 +602,7 @@ public class GridMapQueryExecutor {
                     ctx.performanceStatistics().queryReads(
                         GridCacheQueryType.SQL_FIELDS,
                         node.id(),
-                        reqId,
+                        qryId,
                         stat.logicalReads(),
                         stat.physicalReads());
                 }
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index bd14af32c44..0a56fb32b60 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -97,6 +97,7 @@ import org.h2.util.IntArray;
 import org.h2.value.Value;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+
 import static java.util.Collections.singletonList;
 import static java.util.Collections.singletonMap;
 import static 
org.apache.ignite.IgniteSystemProperties.IGNITE_SQL_RETRY_TIMEOUT;
@@ -426,8 +427,6 @@ public class GridReduceQueryExecutor {
 
             final long qryReqId = qryReqIdGen.incrementAndGet();
 
-            h2.runningQueryManager().trackRequestId(qryReqId);
-
             boolean release = true;
 
             try {
@@ -936,8 +935,6 @@ public class GridReduceQueryExecutor {
 
         final long reqId = qryReqIdGen.incrementAndGet();
 
-        h2.runningQueryManager().trackRequestId(reqId);
-
         final DmlDistributedUpdateRun r = new 
DmlDistributedUpdateRun(nodes.size());
 
         int flags = enforceJoinOrder ? 
GridH2QueryRequest.FLAG_ENFORCE_JOIN_ORDER : 0;
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsQueryTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsQueryTest.java
index 4aa14fa1494..d6e912ef19c 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsQueryTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsQueryTest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.query.FieldsQueryCursor;
+import org.apache.ignite.cache.query.IndexQuery;
 import org.apache.ignite.cache.query.Query;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -42,19 +43,23 @@ import 
org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.cache.query.IndexQueryDesc;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import static org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.gt;
 import static org.apache.ignite.cluster.ClusterState.ACTIVE;
 import static org.apache.ignite.cluster.ClusterState.INACTIVE;
+import static 
org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.INDEX;
 import static 
org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SCAN;
 import static 
org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SQL_FIELDS;
 import static 
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.CLIENT;
 import static 
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.SERVER;
 import static 
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.THIN_CLIENT;
+import static 
org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor.indexQueryText;
 import static 
org.apache.ignite.internal.processors.query.QueryUtils.DFLT_SCHEMA;
 import static org.junit.Assume.assumeFalse;
 
@@ -177,6 +182,20 @@ public class PerformanceStatisticsQueryTest extends 
AbstractPerformanceStatistic
         checkQuery(SCAN, qry, DEFAULT_CACHE_NAME);
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    public void testIndexQuery() throws Exception {
+        IndexQuery<Integer, Integer> qry = new IndexQuery<>(Integer.class);
+
+        qry.setPageSize(pageSize);
+        qry.setCriteria(gt("_KEY", 0));
+
+        String expText = indexQueryText(DEFAULT_CACHE_NAME,
+            new IndexQueryDesc(qry.getCriteria(), qry.getIndexName(), 
qry.getValueType()));
+
+        checkQuery(INDEX, qry, expText);
+    }
+
     /** @throws Exception If failed. */
     @Test
     public void testSqlFieldsQuery() throws Exception {

Reply via email to