IGNITE-28621 SQL: Add H2 map query details to system view and logs#13091
IGNITE-28621 SQL: Add H2 map query details to system view and logs#13091chesnokoff wants to merge 2 commits intoapache:masterfrom
Conversation
849559a to
83b64fc
Compare
| cursor.iterator().next(); | ||
|
|
||
| for (int i = 0; i < 2; i++) { | ||
| int nodeIdx = i; |
There was a problem hiding this comment.
effective final variable
| /** 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)); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
To make it non flaky you can use some user-defined function with latch or sleep.
|
Any test for SqlQueryView? |
| if (failed) | ||
| qrySpan.addTag(ERROR, failReason::getMessage); | ||
|
|
||
| //We need to collect query history and metrics only for SQL queries. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Maybe "local query id"?
| if (qryInfo != null) | ||
| h2.heavyQueriesTracker().stopTracking(qryInfo, e); | ||
|
|
||
| h2.runningQueryManager().unregister(runningQryId, e); |
There was a problem hiding this comment.
Do we need to unregister also in onNextPageRequest (in case of error)?
There was a problem hiding this comment.
onNextPageRequest -> qryResults.cancel() (L974) -> MapQueryResult#close() -> Result#close -> h2.runningQueryManager().unregister(qryInfo.localQueryId(), null)
So looks like we already unregister it
| /** 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)); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
To make it non flaky you can use some user-defined function with latch or sleep.
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
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summarywhereXXXX- number of JIRA issue.(see the Maintainers list)
the
green visaattached to the JIRA ticket (see tabPR Checkat 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.