-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28621 SQL: Add H2 map query details to system view and logs #13091
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,9 +33,12 @@ public class GridRunningQueryInfo { | |
| /** */ | ||
| private final long id; | ||
|
|
||
| /** Originating Node ID. */ | ||
| /** Node that owns query. */ | ||
| private final UUID nodeId; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Such renaming is not quite correct. Global query id still uses |
||
|
|
||
| /** Query coordinator node ID. */ | ||
| private final UUID originNodeId; | ||
|
|
||
| /** */ | ||
| private final String qry; | ||
|
|
||
|
|
@@ -67,6 +70,9 @@ public class GridRunningQueryInfo { | |
| /** Originator. */ | ||
| private final String qryInitiatorId; | ||
|
|
||
| /** Map query flag. */ | ||
| private final boolean mapQry; | ||
|
|
||
| /** Enforce join order flag. */ | ||
| private final boolean enforceJoinOrder; | ||
|
|
||
|
|
@@ -80,7 +86,8 @@ public class GridRunningQueryInfo { | |
| * Constructor. | ||
| * | ||
| * @param id Query ID. | ||
| * @param nodeId Originating node ID. | ||
| * @param nodeId Node that owns query. | ||
| * @param originNodeId Query coordinator node ID. | ||
| * @param qry Query text. | ||
| * @param qryType Query type. | ||
| * @param schemaName Schema name. | ||
|
|
@@ -89,13 +96,15 @@ public class GridRunningQueryInfo { | |
| * @param cancel Query cancel. | ||
| * @param loc Local query flag. | ||
| * @param qryInitiatorId Query's initiator identifier. | ||
| * @param mapQry Map query flag. | ||
| * @param enforceJoinOrder Enforce join order flag. | ||
| * @param distributedJoins Distributed joins flag. | ||
| * @param subjId Subject ID. | ||
| */ | ||
| public GridRunningQueryInfo( | ||
| long id, | ||
| UUID nodeId, | ||
| UUID originNodeId, | ||
| String qry, | ||
| GridCacheQueryType qryType, | ||
| String schemaName, | ||
|
|
@@ -104,12 +113,14 @@ public GridRunningQueryInfo( | |
| GridQueryCancel cancel, | ||
| boolean loc, | ||
| String qryInitiatorId, | ||
| boolean mapQry, | ||
| boolean enforceJoinOrder, | ||
| boolean distributedJoins, | ||
| UUID subjId | ||
| ) { | ||
| this.id = id; | ||
| this.nodeId = nodeId; | ||
| this.originNodeId = originNodeId; | ||
| this.qry = qry; | ||
| this.qryType = qryType; | ||
| this.schemaName = schemaName; | ||
|
|
@@ -119,6 +130,7 @@ public GridRunningQueryInfo( | |
| this.loc = loc; | ||
| this.span = MTC.span(); | ||
| this.qryInitiatorId = qryInitiatorId; | ||
| this.mapQry = mapQry; | ||
| this.enforceJoinOrder = enforceJoinOrder; | ||
| this.distributedJoins = distributedJoins; | ||
| this.subjId = subjId; | ||
|
|
@@ -203,12 +215,19 @@ public boolean local() { | |
| } | ||
|
|
||
| /** | ||
| * @return Originating node ID. | ||
| * @return Node that owns query. | ||
| */ | ||
| public UUID nodeId() { | ||
| return nodeId; | ||
| } | ||
|
|
||
| /** | ||
| * @return Query coordinator node ID. | ||
| */ | ||
| public UUID originNodeId() { | ||
| return originNodeId; | ||
| } | ||
|
|
||
| /** | ||
| * @return Span of the running query. | ||
| */ | ||
|
|
@@ -224,6 +243,13 @@ public String queryInitiatorId() { | |
| return qryInitiatorId; | ||
| } | ||
|
|
||
| /** | ||
| * @return {@code true} if query executes map phase. | ||
| */ | ||
| public boolean mapQuery() { | ||
| return mapQry; | ||
| } | ||
|
|
||
| /** | ||
| * @return Distributed joins. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,6 +287,68 @@ public void start(GridSpinBusyLock busyLock) { | |
| public long register(String qry, GridCacheQueryType qryType, String schemaName, boolean loc, | ||
| @Nullable GridQueryCancel cancel, | ||
| String qryInitiatorId, boolean enforceJoinOrder, boolean distributedJoins) { | ||
| return register( | ||
| qry, | ||
| qryType, | ||
| schemaName, | ||
| loc, | ||
| cancel, | ||
| qryInitiatorId, | ||
| enforceJoinOrder, | ||
| distributedJoins, | ||
| localNodeId, | ||
| false | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Registers map-side running query and returns an id associated with the query on the current node. | ||
| * | ||
| * @param qry Query text. | ||
| * @param schemaName Schema name. | ||
| * @param cancel Query cancel. | ||
| * @param qryInitiatorId Query initiator ID. | ||
| * @param originNodeId Query origin node ID. | ||
| * @param enforceJoinOrder Enforce join order flag. | ||
| * @param distributedJoins Distributed joins flag. | ||
| * @return Id of registered query. | ||
| */ | ||
| public long registerMapQuery( | ||
| String qry, | ||
| String schemaName, | ||
| @Nullable GridQueryCancel cancel, | ||
| String qryInitiatorId, | ||
| UUID originNodeId, | ||
| boolean enforceJoinOrder, | ||
| boolean distributedJoins | ||
| ) { | ||
| return register( | ||
| qry, | ||
| SQL_FIELDS, | ||
| schemaName, | ||
| false, | ||
| cancel, | ||
| qryInitiatorId, | ||
| enforceJoinOrder, | ||
| distributedJoins, | ||
| originNodeId, | ||
| true | ||
| ); | ||
| } | ||
|
|
||
| /** Registers running query and returns an id associated with the query. */ | ||
| private long register( | ||
| String qry, | ||
| GridCacheQueryType qryType, | ||
| String schemaName, | ||
| boolean loc, | ||
| @Nullable GridQueryCancel cancel, | ||
| String qryInitiatorId, | ||
| boolean enforceJoinOrder, | ||
| boolean distributedJoins, | ||
| UUID originNodeId, | ||
| boolean mapQry | ||
| ) { | ||
| long qryId = qryIdGen.incrementAndGet(); | ||
|
|
||
| if (qryInitiatorId == null) | ||
|
|
@@ -295,6 +357,7 @@ public long register(String qry, GridCacheQueryType qryType, String schemaName, | |
| final GridRunningQueryInfo run = new GridRunningQueryInfo( | ||
| qryId, | ||
| localNodeId, | ||
| originNodeId, | ||
| qry, | ||
| qryType, | ||
| schemaName, | ||
|
|
@@ -303,6 +366,7 @@ public long register(String qry, GridCacheQueryType qryType, String schemaName, | |
| cancel, | ||
| loc, | ||
| qryInitiatorId, | ||
| mapQry, | ||
| enforceJoinOrder, | ||
| distributedJoins, | ||
| securitySubjectId(ctx) | ||
|
|
@@ -314,7 +378,7 @@ public long register(String qry, GridCacheQueryType qryType, String schemaName, | |
|
|
||
| run.span().addTag(SQL_QRY_ID, run::globalQueryId); | ||
|
|
||
| if (!qryStartedListeners.isEmpty()) { | ||
| if (!mapQry && !qryStartedListeners.isEmpty()) { | ||
| GridQueryStartedInfo info = new GridQueryStartedInfo( | ||
| run.id(), | ||
| localNodeId, | ||
|
|
@@ -375,26 +439,28 @@ public void unregister(long qryId, @Nullable Throwable failReason) { | |
| if (failed) | ||
| qrySpan.addTag(ERROR, failReason::getMessage); | ||
|
|
||
| //We need to collect query history and metrics only for SQL queries. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (isSqlQuery(qry)) { | ||
| qry.runningFuture().onDone(); | ||
|
|
||
| qryHistTracker.collectHistory(qry, failed); | ||
| // We need to collect query history and metrics only for external SQL queries. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (!qry.mapQuery()) { | ||
| qryHistTracker.collectHistory(qry, failed); | ||
|
|
||
| if (!failed) | ||
| successQrsCnt.increment(); | ||
| else { | ||
| failedQrsCnt.increment(); | ||
| if (!failed) | ||
| successQrsCnt.increment(); | ||
| else { | ||
| failedQrsCnt.increment(); | ||
|
|
||
| // We measure cancel metric as "number of times user's queries ended up with query cancelled exception", | ||
| // not "how many user's KILL QUERY command succeeded". These may be not the same if cancel was issued | ||
| // right when query failed due to some other reason. | ||
| if (QueryUtils.wasCancelled(failReason)) | ||
| canceledQrsCnt.increment(); | ||
| // We measure cancel metric as "number of times user's queries ended up with query cancelled exception", | ||
| // not "how many user's KILL QUERY command succeeded". These may be not the same if cancel was issued | ||
| // right when query failed due to some other reason. | ||
| if (QueryUtils.wasCancelled(failReason)) | ||
| canceledQrsCnt.increment(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (ctx.performanceStatistics().enabled() && qry.startTimeNanos() > 0) { | ||
| if (!qry.mapQuery() && ctx.performanceStatistics().enabled() && qry.startTimeNanos() > 0) { | ||
| String flags = null; | ||
|
|
||
| // Create string for flags with not default values. | ||
|
|
@@ -426,7 +492,7 @@ public void unregister(long qryId, @Nullable Throwable failReason) { | |
| !failed); | ||
| } | ||
|
|
||
| if (!qryFinishedListeners.isEmpty()) { | ||
| if (!qry.mapQuery() && !qryFinishedListeners.isEmpty()) { | ||
| GridQueryFinishedInfo info = new GridQueryFinishedInfo( | ||
| qry.id(), | ||
| localNodeId, | ||
|
|
@@ -553,7 +619,7 @@ public Collection<GridRunningQueryInfo> runningQueries(long duration) { | |
| long curTime = U.currentTimeMillis(); | ||
|
|
||
| for (GridRunningQueryInfo runningQryInfo : runs.values()) { | ||
| if (curTime - runningQryInfo.startTime() > duration) | ||
| if (!runningQryInfo.mapQuery() && curTime - runningQryInfo.startTime() > duration) | ||
| res.add(runningQryInfo); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,11 +30,15 @@ public class MapH2QueryInfo extends H2QueryInfo { | |
| /** Segment. */ | ||
| private final int segment; | ||
|
|
||
| /** Running query id. */ | ||
| private final long runningQryId; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "local query id"? |
||
|
|
||
| /** | ||
| * @param stmt Query statement. | ||
| * @param sql Query statement. | ||
| * @param nodeId Originator node id. | ||
| * @param qryId Query id. | ||
| * @param runningQryId Running query id. | ||
| * @param initiatorId Query initiator id. | ||
| * @param reqId Request ID. | ||
| * @param segment Segment. | ||
|
|
@@ -44,19 +48,28 @@ public MapH2QueryInfo( | |
| String sql, | ||
| UUID nodeId, | ||
| long qryId, | ||
| long runningQryId, | ||
| String initiatorId, | ||
| long reqId, | ||
| int segment | ||
| ) { | ||
| super(QueryType.MAP, stmt, sql, nodeId, qryId, initiatorId); | ||
|
|
||
| this.runningQryId = runningQryId; | ||
| this.reqId = reqId; | ||
| this.segment = segment; | ||
| } | ||
|
|
||
| /** @return Running query id. */ | ||
| public long runningQueryId() { | ||
| return runningQryId; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void printInfo(StringBuilder msg) { | ||
| msg.append(", reqId=").append(reqId) | ||
| msg.append(", mapQuery=true") | ||
| .append(", originNodeId=").append(nodeId()) | ||
| .append(", reqId=").append(reqId) | ||
| .append(", segment=").append(segment); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
initiatorIdlikelabel. Maybe it's worth to pass it together with map query request (maybe by another ticket)