This is an automated email from the ASF dual-hosted git repository.
alexpl 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 94ec9405366 IGNITE-26598 Add initiatorId to the SQL_QUERY_HISTORY
system view - Fixes #12518.
94ec9405366 is described below
commit 94ec94053660de5c73d074f436eb826f0c973191
Author: oleg-vlsk <[email protected]>
AuthorDate: Fri Nov 28 09:11:56 2025 +0300
IGNITE-26598 Add initiatorId to the SQL_QUERY_HISTORY system view - Fixes
#12518.
Signed-off-by: Aleksey Plekhanov <[email protected]>
---
docs/_docs/monitoring-metrics/system-views.adoc | 3 +-
.../integration/SqlDiagnosticIntegrationTest.java | 60 +++++++++++++++++----
.../ignite/jdbc/thin/JdbcThinMetadataSelfTest.java | 1 +
.../walker/SqlQueryHistoryViewWalker.java | 26 ++++-----
.../processors/query/running/QueryHistory.java | 32 +++++++++--
.../query/running/QueryHistoryMetricsValue.java | 25 ++++++++-
.../query/running/QueryHistoryTracker.java | 3 +-
.../spi/systemview/view/SqlQueryHistoryView.java | 16 ++++--
.../processors/query/SqlQueryHistorySelfTest.java | 63 ++++++++++++++++++++--
9 files changed, 191 insertions(+), 38 deletions(-)
diff --git a/docs/_docs/monitoring-metrics/system-views.adoc
b/docs/_docs/monitoring-metrics/system-views.adoc
index 109973db9e5..170e27d830a 100644
--- a/docs/_docs/monitoring-metrics/system-views.adoc
+++ b/docs/_docs/monitoring-metrics/system-views.adoc
@@ -115,7 +115,7 @@ control.bat --system-view NODE_METRICS --node-id
a1b77663-b37f-4ddf-87a6-1e2d684
|EVICTION_POLICY_FACTORY | string | String representation of eviction policy
factory
|EXPIRY_POLICY_FACTORY | string | String representation of expiry policy
factory
|CONFLICT_RESOLVER | string | String representation of cache conflict resolver
-|HAS_EXPIRING_ENTRIES | string | Yes if cache has entries pending expire
+|HAS_EXPIRING_ENTRIES | string | Yes if cache has entries pending expire
|INTERCEPTOR | string | String representation of interceptor
|IS_COPY_ON_READ | boolean | Flag indicating whether a copy of the value
stored in the on-heap cache
|IS_EAGER_TTL | boolean | Flag indicating whether expired cache entries will
be eagerly removed from cache
@@ -512,6 +512,7 @@ This view exposes information about currently running SQL
queries.
|SCHEMA_NAME | string | Schema name
|SQL | string | Query text
|LOCAL | boolean | True if local only
+|INITIATOR_ID | string | Latest user-defined initiator ID
|EXECUTIONS | long | Count of executions
|FAILURES | long | Count of failures
|DURATION_MIN | long | Minimal duration of execution
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlDiagnosticIntegrationTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlDiagnosticIntegrationTest.java
index ef625931ba9..31067506281 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlDiagnosticIntegrationTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlDiagnosticIntegrationTest.java
@@ -76,6 +76,8 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.metric.MetricRegistry;
import org.apache.ignite.spi.metric.LongMetric;
+import org.apache.ignite.spi.systemview.view.SqlQueryHistoryView;
+import org.apache.ignite.spi.systemview.view.SystemView;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.ListeningTestLogger;
import org.apache.ignite.testframework.LogListener;
@@ -100,7 +102,9 @@ import static
org.apache.ignite.internal.processors.query.running.HeavyQueriesTr
import static
org.apache.ignite.internal.processors.query.running.HeavyQueriesTracker.LONG_QUERY_ERROR_MSG;
import static
org.apache.ignite.internal.processors.query.running.HeavyQueriesTracker.LONG_QUERY_EXEC_MSG;
import static
org.apache.ignite.internal.processors.query.running.HeavyQueriesTracker.LONG_QUERY_FINISHED_MSG;
+import static
org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_QRY_HIST_VIEW;
import static
org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_USER_QUERIES_REG_NAME;
+import static org.apache.ignite.internal.util.lang.GridFunc.first;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
/**
@@ -997,19 +1001,36 @@ public class SqlDiagnosticIntegrationTest extends
AbstractBasicIntegrationTest {
}
}
+ /** Verifies that user-defined query initiator ID is present in the
SQL_QUERY_HISTORY system view. */
+ @Test
+ public void testSqlFieldsQueryWithInitiatorId() throws Exception {
+ IgniteEx grid = grid(0);
+
+ IgniteCache<Long, Long> cache = prepareTestCache(grid);
+
+ for (String testId : new String[] {"testId0", "testId1"}) {
+ cache.query(new SqlFieldsQuery("select * from
test").setQueryInitiatorId(testId)).getAll();
+
+ assertTrue(waitForCondition(() -> {
+ SystemView<SqlQueryHistoryView> history =
grid.context().systemView().view(SQL_QRY_HIST_VIEW);
+
+ assertNotNull(history);
+
+ if (history.size() != 1)
+ return false;
+
+ SqlQueryHistoryView view = first(history);
+
+ assertNotNull(view);
+
+ return testId.equals(view.initiatorId());
+ }, 3_000));
+ }
+ }
+
/** */
private FieldsQueryCursor<List<?>> runNotFullyFetchedQuery(boolean loc) {
- IgniteCache<Long, Long> cache = grid(0).createCache(new
CacheConfiguration<Long, Long>()
- .setName("test")
- .setQueryEntities(Collections.singleton(new
QueryEntity(Long.class, Long.class)
- .setTableName("test")
- .addQueryField("id", Long.class.getName(), null)
- .addQueryField("val", Long.class.getName(), null)
- .setKeyFieldName("id")
- .setValueFieldName("val"))));
-
- for (long i = 0; i < 10; ++i)
- cache.put(i, i);
+ IgniteCache<Long, Long> cache = prepareTestCache(grid(0));
return cache.query(new SqlFieldsQuery("select * from
test").setLocal(loc).setPageSize(1));
}
@@ -1024,6 +1045,23 @@ public class SqlDiagnosticIntegrationTest extends
AbstractBasicIntegrationTest {
return heavyQueriesTracker().getQueries().isEmpty();
}
+ /** */
+ private static IgniteCache<Long, Long> prepareTestCache(IgniteEx grid) {
+ IgniteCache<Long, Long> cache = grid.createCache(new
CacheConfiguration<Long, Long>()
+ .setName("test")
+ .setQueryEntities(Collections.singleton(new
QueryEntity(Long.class, Long.class)
+ .setTableName("test")
+ .addQueryField("id", Long.class.getName(), null)
+ .addQueryField("val", Long.class.getName(), null)
+ .setKeyFieldName("id")
+ .setValueFieldName("val"))));
+
+ for (long i = 0; i < 10; ++i)
+ cache.put(i, i);
+
+ return cache;
+ }
+
/** */
public static class FunctionsLibrary {
/** */
diff --git
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
index 2a17a63897b..2425aa23134 100644
---
a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
+++
b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinMetadataSelfTest.java
@@ -770,6 +770,7 @@ public class JdbcThinMetadataSelfTest extends
JdbcThinAbstractSelfTest {
"SYS.SQL_QUERIES_HISTORY.SCHEMA_NAME.null",
"SYS.SQL_QUERIES_HISTORY.SQL.null",
"SYS.SQL_QUERIES_HISTORY.LOCAL.null",
+ "SYS.SQL_QUERIES_HISTORY.INITIATOR_ID.null",
"SYS.SQL_QUERIES_HISTORY.EXECUTIONS.null",
"SYS.SQL_QUERIES_HISTORY.FAILURES.null",
"SYS.SQL_QUERIES_HISTORY.DURATION_MIN.null",
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlQueryHistoryViewWalker.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlQueryHistoryViewWalker.java
index 38c99b39445..e4b3c52344e 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlQueryHistoryViewWalker.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/SqlQueryHistoryViewWalker.java
@@ -24,7 +24,7 @@ import
org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker;
/**
* Generated by {@code
org.apache.ignite.codegen.SystemViewRowAttributeWalkerGenerator}.
* {@link SqlQueryHistoryView} attributes walker.
- *
+ *
* @see SqlQueryHistoryView
*/
public class SqlQueryHistoryViewWalker implements
SystemViewRowAttributeWalker<SqlQueryHistoryView> {
@@ -33,11 +33,12 @@ public class SqlQueryHistoryViewWalker implements
SystemViewRowAttributeWalker<S
v.accept(0, "schemaName", String.class);
v.accept(1, "sql", String.class);
v.accept(2, "local", boolean.class);
- v.accept(3, "executions", long.class);
- v.accept(4, "failures", long.class);
- v.accept(5, "durationMin", long.class);
- v.accept(6, "durationMax", long.class);
- v.accept(7, "lastStartTime", Date.class);
+ v.accept(3, "initiatorId", String.class);
+ v.accept(4, "executions", long.class);
+ v.accept(5, "failures", long.class);
+ v.accept(6, "durationMin", long.class);
+ v.accept(7, "durationMax", long.class);
+ v.accept(8, "lastStartTime", Date.class);
}
/** {@inheritDoc} */
@@ -45,15 +46,16 @@ public class SqlQueryHistoryViewWalker implements
SystemViewRowAttributeWalker<S
v.accept(0, "schemaName", String.class, row.schemaName());
v.accept(1, "sql", String.class, row.sql());
v.acceptBoolean(2, "local", row.local());
- v.acceptLong(3, "executions", row.executions());
- v.acceptLong(4, "failures", row.failures());
- v.acceptLong(5, "durationMin", row.durationMin());
- v.acceptLong(6, "durationMax", row.durationMax());
- v.accept(7, "lastStartTime", Date.class, row.lastStartTime());
+ v.accept(3, "initiatorId", String.class, row.initiatorId());
+ v.acceptLong(4, "executions", row.executions());
+ v.acceptLong(5, "failures", row.failures());
+ v.acceptLong(6, "durationMin", row.durationMin());
+ v.acceptLong(7, "durationMax", row.durationMax());
+ v.accept(8, "lastStartTime", Date.class, row.lastStartTime());
}
/** {@inheritDoc} */
@Override public int count() {
- return 8;
+ return 9;
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistory.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistory.java
index 6ce73a7335e..289204ae7f0 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistory.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistory.java
@@ -47,13 +47,22 @@ public class QueryHistory {
* @param startTime Start time of query execution.
* @param duration Duration of query execution.
* @param failed {@code True} query executed unsuccessfully {@code false}
otherwise.
+ * @param initId Initiator ID.
*/
- public QueryHistory(String qry, String schema, boolean loc, long
startTime, long duration, boolean failed) {
+ public QueryHistory(
+ String qry,
+ String schema,
+ boolean loc,
+ long startTime,
+ long duration,
+ boolean failed,
+ @Nullable String initId
+ ) {
key = new QueryHistoryKey(qry, schema, loc);
long failures = failed ? 1 : 0;
- val = new QueryHistoryMetricsValue(1, failures, duration, duration,
startTime);
+ val = new QueryHistoryMetricsValue(1, failures, duration, duration,
startTime, initId);
linkRef = new AtomicReference<>();
}
@@ -72,12 +81,20 @@ public class QueryHistory {
* @return Aggregated metrics.
*/
public QueryHistory aggregateWithNew(QueryHistory m) {
+ long curLastStart = val.lastStartTime();
+ long newLastStart = m.lastStartTime();
+
+ String initiatorId = curLastStart > newLastStart
+ ? val.initiatorId()
+ : m.initiatorId();
+
val = new QueryHistoryMetricsValue(
val.execs() + m.executions(),
val.failures() + m.failures(),
Math.min(val.minTime(), m.minimumTime()),
Math.max(val.maxTime(), m.maximumTime()),
- Math.max(val.lastStartTime(), m.lastStartTime()));
+ Math.max(curLastStart, newLastStart),
+ initiatorId);
return this;
}
@@ -148,6 +165,15 @@ public class QueryHistory {
return val.lastStartTime();
}
+ /**
+ * Gets latest initiator ID.
+ *
+ * @return Latest initiator ID.
+ */
+ public String initiatorId() {
+ return val.initiatorId();
+ }
+
/**
* @return Link to internal node in eviction deque.
*/
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryMetricsValue.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryMetricsValue.java
index 976e1a0930c..5213c47dee3 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryMetricsValue.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryMetricsValue.java
@@ -18,6 +18,8 @@
package org.apache.ignite.internal.processors.query.running;
+import org.jetbrains.annotations.Nullable;
+
/**
* Immutable query metrics.
*/
@@ -37,19 +39,31 @@ class QueryHistoryMetricsValue {
/** Last start time of execution. */
private final long lastStartTime;
+ /** Latest user-defined initiator ID. */
+ private final String initId;
+
/**
* @param execs Number of executions.
* @param failures Number of failure.
* @param minTime Min time of execution.
* @param maxTime Max time of execution.
* @param lastStartTime Last start time of execution.
+ * @param initId Latest initiator ID.
*/
- public QueryHistoryMetricsValue(long execs, long failures, long minTime,
long maxTime, long lastStartTime) {
+ public QueryHistoryMetricsValue(
+ long execs,
+ long failures,
+ long minTime,
+ long maxTime,
+ long lastStartTime,
+ @Nullable String initId
+ ) {
this.execs = execs;
this.failures = failures;
this.minTime = minTime;
this.maxTime = maxTime;
this.lastStartTime = lastStartTime;
+ this.initId = initId;
}
/**
@@ -96,4 +110,13 @@ class QueryHistoryMetricsValue {
public long lastStartTime() {
return lastStartTime;
}
+
+ /**
+ * Gets latest initiator ID.
+ *
+ * @return Latest initiator ID.
+ */
+ public String initiatorId() {
+ return initId;
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryTracker.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryTracker.java
index 6a2650f48a4..1bfb7b5351b 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryTracker.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/QueryHistoryTracker.java
@@ -57,11 +57,12 @@ class QueryHistoryTracker {
String qry = runningQryInfo.query();
String schema = runningQryInfo.schemaName();
+ String initId = runningQryInfo.queryInitiatorId();
boolean loc = runningQryInfo.local();
long startTime = runningQryInfo.startTime();
long duration = U.currentTimeMillis() - startTime;
- QueryHistory hist = new QueryHistory(qry, schema, loc, startTime,
duration, failed);
+ QueryHistory hist = new QueryHistory(qry, schema, loc, startTime,
duration, failed, initId);
QueryHistory mergedHist = qryHist.merge(hist.key(), hist,
QueryHistory::aggregateWithNew);
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SqlQueryHistoryView.java
b/modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SqlQueryHistoryView.java
index f60cd79ee0d..cefe4d430fe 100644
---
a/modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SqlQueryHistoryView.java
+++
b/modules/core/src/main/java/org/apache/ignite/spi/systemview/view/SqlQueryHistoryView.java
@@ -53,32 +53,38 @@ public class SqlQueryHistoryView {
return qry.local();
}
- /** @return Number of executions of the query. */
+ /** @return Latest initiator ID. */
@Order(3)
+ public String initiatorId() {
+ return qry.initiatorId();
+ }
+
+ /** @return Number of executions of the query. */
+ @Order(4)
public long executions() {
return qry.executions();
}
/** @return Number of failed execution of the query. */
- @Order(4)
+ @Order(5)
public long failures() {
return qry.failures();
}
/** @return Minimal query duration. */
- @Order(5)
+ @Order(6)
public long durationMin() {
return qry.minimumTime();
}
/** @return Maximum query duration. */
- @Order(6)
+ @Order(7)
public long durationMax() {
return qry.maximumTime();
}
/** @return Last start time. */
- @Order(7)
+ @Order(8)
public Date lastStartTime() {
return new Date(qry.lastStartTime());
}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlQueryHistorySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlQueryHistorySelfTest.java
index 4257c84b147..6d9f1ed97ef 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlQueryHistorySelfTest.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlQueryHistorySelfTest.java
@@ -41,6 +41,7 @@ import org.apache.ignite.configuration.SqlConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.processors.query.running.QueryHistory;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -49,6 +50,7 @@ import
org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Test;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.internal.util.lang.GridFunc.first;
/**
* Check query history metrics from server node.
@@ -221,6 +223,36 @@ public class SqlQueryHistorySelfTest extends
GridCommonAbstractTest {
checkQueryMetrics(qry);
}
+ /**
+ * Test metrics for SQL fields queries with initiatot ID.
+ */
+ @Test
+ public void testSqlFieldsQueryHistoryWithInitiatorId() {
+ String testId0 = "testId0";
+ String testId1 = "testId1";
+
+ SqlFieldsQuery qry0 = new SqlFieldsQuery("select * from
String").setQueryInitiatorId(testId0);
+
+ checkQueryMetrics(qry0, testId0);
+
+ SqlFieldsQuery qry1 = new SqlFieldsQuery("select * from
String").setQueryInitiatorId(testId1);
+
+ IgniteCache<Integer, String> cache =
queryNode().context().cache().jcache("A");
+
+ cache.query(qry1).getAll();
+
+ Collection<QueryHistory> historyCol =
queryNode().context().query().runningQueryManager()
+ .queryHistoryMetrics().values();
+
+ assertFalse(F.isEmpty(historyCol));
+
+ QueryHistory history = first(historyCol);
+
+ assertNotNull(history);
+
+ assertEquals(testId1, history.initiatorId());
+ }
+
/**
* Test metrics for SQL fields queries.
*
@@ -420,9 +452,21 @@ public class SqlQueryHistorySelfTest extends
GridCommonAbstractTest {
* @param failures Expected number of failures.
* @param first {@code true} if metrics checked for first query only.
*/
- private void checkMetrics(int sz, int idx, int execs, int failures,
- boolean first) {
+ private void checkMetrics(int sz, int idx, int execs, int failures,
boolean first) {
+ checkMetrics(sz, idx, execs, failures, first, null);
+ }
+ /**
+ * Check metrics.
+ *
+ * @param sz Expected size of metrics.
+ * @param idx Index of metrics to check.
+ * @param execs Expected number of executions.
+ * @param failures Expected number of failures.
+ * @param first {@code true} if metrics checked for first query only.
+ * @param initId Initiator ID.
+ */
+ private void checkMetrics(int sz, int idx, int execs, int failures,
boolean first, String initId) {
Collection<QueryHistory> metrics =
queryNode().context().query().runningQueryManager()
.queryHistoryMetrics().values();
@@ -444,6 +488,9 @@ public class SqlQueryHistorySelfTest extends
GridCommonAbstractTest {
if (first)
assertEquals("On first execution minTime == maxTime",
m.minimumTime(), m.maximumTime());
+
+ if (initId != null)
+ assertEquals(initId, m.initiatorId());
}
/**
@@ -476,17 +523,25 @@ public class SqlQueryHistorySelfTest extends
GridCommonAbstractTest {
* @param qry Query.
*/
private void checkQueryMetrics(Query qry) {
+ checkQueryMetrics(qry, null);
+ }
+
+ /**
+ * @param qry Query.
+ * @param initId Initiator ID.
+ */
+ private void checkQueryMetrics(Query qry, String initId) {
IgniteCache<Integer, String> cache =
queryNode().context().cache().jcache("A");
// Execute query.
cache.query(qry).getAll();
- checkMetrics(1, 0, 1, 0, true);
+ checkMetrics(1, 0, 1, 0, true, initId);
// Execute again with the same parameters.
cache.query(qry).getAll();
- checkMetrics(1, 0, 2, 0, false);
+ checkMetrics(1, 0, 2, 0, false, initId);
}
/**