Skip to content

IGNITE-28621 SQL: Add H2 map query details to system view and logs#13091

Open
chesnokoff wants to merge 2 commits intoapache:masterfrom
chesnokoff:ignite-28621-sql-map
Open

IGNITE-28621 SQL: Add H2 map query details to system view and logs#13091
chesnokoff wants to merge 2 commits intoapache:masterfrom
chesnokoff:ignite-28621-sql-map

Conversation

@chesnokoff
Copy link
Copy Markdown
Contributor

Thank you for submitting the pull request to the Apache Ignite.

In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:

The Contribution Checklist

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see tab PR Check at TC.Bot - Instance 1 or TC.Bot - Instance 2)

Notes

If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com #ignite channel.

@chesnokoff chesnokoff force-pushed the ignite-28621-sql-map branch from 849559a to 83b64fc Compare April 30, 2026 12:22
cursor.iterator().next();

for (int i = 0; i < 2; i++) {
int nodeIdx = i;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effective final variable

Comment on lines -684 to -726
/** Test map query flag in running queries system view. */
@Test
public void testMapQueryRunningQueriesView() throws Exception {
IgniteEx ignite = startGrids(2);

IgniteCache<Integer, String> cache = ignite.createCache(
new CacheConfiguration<Integer, String>(DEFAULT_CACHE_NAME)
.setCacheMode(CacheMode.PARTITIONED)
.setIndexedTypes(Integer.class, String.class)
);

for (int i = 0; i < 10; i++)
cache.put(i, Integer.toString(i));

awaitPartitionMapExchange();

String initiatorId = UUID.randomUUID().toString();

try (FieldsQueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SELECT * FROM String")
.setQueryInitiatorId(initiatorId)
.setPageSize(1))) {
cursor.iterator().next();

for (int i = 0; i < 2; i++) {
int nodeIdx = i;
UUID nodeId = grid(nodeIdx).localNode().id();

assertTrue(waitForCondition(() -> {
SystemView<SqlQueryView> view = grid(nodeIdx).context().systemView().view(SQL_QRY_VIEW);

for (SqlQueryView qry : view) {
if (qry.mapQuery()
&& nodeId.equals(qry.nodeId())
&& ignite.localNode().id().equals(qry.originNodeId())
&& initiatorId.equals(qry.initiatorId()))
return true;
}

return false;
}, 5_000));
}
}
}
Copy link
Copy Markdown
Contributor Author

@chesnokoff chesnokoff May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, created this test to check map queries but now I think the test may be flaky so I decided to rollback it (the test passed for visa)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it non flaky you can use some user-defined function with latch or sleep.

@alex-plekhanov
Copy link
Copy Markdown
Contributor

Any test for SqlQueryView?
Any test for query leakage (register - success - check that unregistered, register - throw an error on init of map phase - check that unregistered, register - throw an error on next page request - chech that unregistered)?
Any test for DML queries?

if (failed)
qrySpan.addTag(ERROR, failReason::getMessage);

//We need to collect query history and metrics only for SQL queries.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can replace all futher changes in this method with just:

if (qry.mapQuery())
    return;

qry.runningFuture().onDone();

qryHistTracker.collectHistory(qry, failed);
// We need to collect query history and metrics only for external SQL queries.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External is not a good definition here. I think something like Initiated by user is better.


List<List<?>> res = node.context().query().querySqlFields(
new SqlFieldsQuery("SELECT sql, initiator_id FROM SYS.SQL_QUERIES"), false).getAll();
new SqlFieldsQuery("SELECT sql, initiator_id FROM SYS.SQL_QUERIES WHERE MAP_QUERY = FALSE"), false).getAll();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an issue. Users use initiatorId like label. Maybe it's worth to pass it together with map query request (maybe by another ticket)


/** Originating Node ID. */
/** Node that owns query. */
private final UUID nodeId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such renaming is not quite correct. Global query id still uses nodeId as originator node. Performance statistics use nodeId as originator node (yes, it's currently only collected for reduce node, but it still not correct to pass current node as originator node). Also I'm not sure we need current node field at all. Maybe we should keep old naming and pass originator node id to this field for map queries.

private final int segment;

/** Running query id. */
private final long runningQryId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "local query id"?

if (qryInfo != null)
h2.heavyQueriesTracker().stopTracking(qryInfo, e);

h2.runningQueryManager().unregister(runningQryId, e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to unregister also in onNextPageRequest (in case of error)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onNextPageRequest -> qryResults.cancel() (L974) -> MapQueryResult#close() -> Result#close -> h2.runningQueryManager().unregister(qryInfo.localQueryId(), null)

So looks like we already unregister it

Comment on lines -684 to -726
/** Test map query flag in running queries system view. */
@Test
public void testMapQueryRunningQueriesView() throws Exception {
IgniteEx ignite = startGrids(2);

IgniteCache<Integer, String> cache = ignite.createCache(
new CacheConfiguration<Integer, String>(DEFAULT_CACHE_NAME)
.setCacheMode(CacheMode.PARTITIONED)
.setIndexedTypes(Integer.class, String.class)
);

for (int i = 0; i < 10; i++)
cache.put(i, Integer.toString(i));

awaitPartitionMapExchange();

String initiatorId = UUID.randomUUID().toString();

try (FieldsQueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SELECT * FROM String")
.setQueryInitiatorId(initiatorId)
.setPageSize(1))) {
cursor.iterator().next();

for (int i = 0; i < 2; i++) {
int nodeIdx = i;
UUID nodeId = grid(nodeIdx).localNode().id();

assertTrue(waitForCondition(() -> {
SystemView<SqlQueryView> view = grid(nodeIdx).context().systemView().view(SQL_QRY_VIEW);

for (SqlQueryView qry : view) {
if (qry.mapQuery()
&& nodeId.equals(qry.nodeId())
&& ignite.localNode().id().equals(qry.originNodeId())
&& initiatorId.equals(qry.initiatorId()))
return true;
}

return false;
}, 5_000));
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it non flaky you can use some user-defined function with latch or sleep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants