Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-19880 Fix negative duration in the SQL query system view #10958

Merged
merged 16 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading