Skip to content

Commit

Permalink
IGNITE-19880 Fixed negative duration in the SQL query system view (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nastya828 authored and J-Bakuli committed Nov 10, 2023
1 parent 2e2430d commit 99a374f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.ignite.configuration.SqlConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.jsr166.ConcurrentLinkedDeque8;
import org.jsr166.ConcurrentLinkedDeque8.Node;

Expand Down Expand Up @@ -58,7 +59,7 @@ void collectHistory(GridRunningQueryInfo runningQryInfo, boolean failed) {
String schema = runningQryInfo.schemaName();
boolean loc = runningQryInfo.local();
long startTime = runningQryInfo.startTime();
long duration = System.currentTimeMillis() - startTime;
long duration = U.currentTimeMillis() - startTime;

QueryHistory hist = new QueryHistory(qry, schema, loc, startTime, duration, failed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public long register(String qry, GridCacheQueryType qryType, String schemaName,
qry,
qryType,
schemaName,
System.currentTimeMillis(),
U.currentTimeMillis(),
ctx.performanceStatistics().enabled() ? System.nanoTime() : 0,
cancel,
loc,
Expand Down Expand Up @@ -411,7 +411,7 @@ public void unregister(long qryId, @Nullable Throwable failReason) {
qry.queryType(),
qry.schemaName(),
qry.startTime(),
System.currentTimeMillis(),
U.currentTimeMillis(),
qry.local(),
qry.enforceJoinOrder(),
qry.lazy(),
Expand Down Expand Up @@ -523,7 +523,7 @@ private boolean isSqlQuery(GridRunningQueryInfo runningQryInfo) {
public Collection<GridRunningQueryInfo> runningQueries(long duration) {
Collection<GridRunningQueryInfo> res = new ArrayList<>();

long curTime = System.currentTimeMillis();
long curTime = U.currentTimeMillis();

for (GridRunningQueryInfo runningQryInfo : runs.values()) {
if (curTime - runningQryInfo.startTime() > duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteRunnable;
import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
import org.apache.ignite.spi.systemview.view.SqlQueryView;
import org.apache.ignite.spi.systemview.view.SystemView;
import org.apache.ignite.spi.systemview.view.sql.SqlTableView;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Assert;
Expand All @@ -93,6 +95,7 @@
import static java.util.stream.Collectors.toSet;
import static org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION;
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME;
import static org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_QRY_VIEW;
import static org.apache.ignite.internal.util.IgniteUtils.MB;
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
import static org.junit.Assert.assertNotEquals;
Expand Down Expand Up @@ -668,6 +671,24 @@ public void testRunningQueriesView() throws Exception {
assertTrue(cache.query(new SqlFieldsQuery(sql)).getAll().isEmpty());
}

/**
* Test running queries duration in system view.
*/
@Test
public void testRunningQueriesViewDuration() throws Exception {
IgniteEx ignite = startGrid(0);

SqlFieldsQuery sql = new SqlFieldsQuery("SELECT * FROM (VALUES (1),(2))").setPageSize(1);

for (int i = 0; i < 5; i++) {
ignite.context().query().querySqlFields(sql, true).iterator().hasNext();

SystemView<SqlQueryView> view = ignite.context().systemView().view(SQL_QRY_VIEW);

view.forEach(v -> assertTrue(v.duration() >= 0));
}
}

/**
* Test that we can't use cache tables and system views in the same query.
*/
Expand Down

0 comments on commit 99a374f

Please sign in to comment.