org.apache.ignite.internal.processors.query

## Class RunningQueryManager

- java.lang.Object
- - org.apache.ignite.internal.processors.query.RunningQueryManager

    public class RunningQueryManager
    extends Object

Keep information about all running queries.

### Field Summary

Fields
`static String` `SQL_QRY_HIST_VIEW`
`static String` `SQL_QRY_HIST_VIEW_DESC`
`static String` `SQL_QRY_VIEW`
`static String` `SQL_QRY_VIEW_DESC`
`static String` `SQL_USER_QUERIES_REG_NAME` Name of the MetricRegistry which metrics measure stats of queries initiated by user.
`static long` `UNDEFINED_QUERY_ID` Undefined query ID value.

### Constructor Summary

Constructors
Constructor and Description
`RunningQueryManager(GridKernalContext ctx)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `cancelLocalQuery(long qryId)` Cancel query.
`void` `cancelQuery(long queryId, @Nullable UUID nodeId, boolean async)` Cancel query running on remote or local Node.
`Collection<GridRunningQueryInfo>` `longRunningQueries(long duration)` Return long running user queries.
`void` `onDisconnected()` Client disconnected callback.
`Map<QueryHistoryKey,QueryHistory>` `queryHistoryMetrics()` Gets query history statistics.
`long` `register(String qry, GridCacheQueryType qryType, String schemaName, boolean loc, @Nullable GridQueryCancel cancel, String qryInitiatorId)` Registers running query and returns an id associated with the query.
`void` `resetQueryHistoryMetrics()` Reset query history.
`@Nullable GridRunningQueryInfo` `runningQueryInfo(long qryId)` Gets info about running query by their id.
`List<GridRunningQueryInfo>` `runningSqlQueries()` Return SQL queries which executing right now.
`void` `start(GridSpinBusyLock busyLock)`
`void` `stop()` Cancel all executing queries and deregistering all of them.
`String` `toString()`
`void` `trackRequestId(long reqId)`
`void` `unregister(long qryId, @Nullable Throwable failReason)` Unregister running query.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### SQL_USER_QUERIES_REG_NAME

    public static final String SQL_USER_QUERIES_REG_NAME

Name of the MetricRegistry which metrics measure stats of queries initiated by user.

See Also:
  Constant Field Values

#### SQL_QRY_VIEW

    public static final String SQL_QRY_VIEW

#### SQL_QRY_VIEW_DESC

    public static final String SQL_QRY_VIEW_DESC

See Also:
  Constant Field Values

#### SQL_QRY_HIST_VIEW

    public static final String SQL_QRY_HIST_VIEW

#### SQL_QRY_HIST_VIEW_DESC

    public static final String SQL_QRY_HIST_VIEW_DESC

See Also:
  Constant Field Values

#### UNDEFINED_QUERY_ID

    public static final long UNDEFINED_QUERY_ID

Undefined query ID value.

See Also:
  Constant Field Values

### Constructor Detail

#### RunningQueryManager

    public RunningQueryManager(GridKernalContext ctx)

Constructor.

Parameters:
  `ctx` - Context.

### Method Detail

#### start

    public void start(GridSpinBusyLock busyLock)

#### register

    public long register(String qry,
                         GridCacheQueryType qryType,
                         String schemaName,
                         boolean loc,
                         @Nullable
                         @Nullable GridQueryCancel cancel,
                         String qryInitiatorId)

Registers running query and returns an id associated with the query.

Parameters:
  `qry` - Query text.
  `qryType` - Query type.
  `schemaName` - Schema name.
  `loc` - Local query flag.
  `cancel` - Query cancel. Should be passed in case query is cancelable, or `null` otherwise.
Returns:
  Id of registered query. Id is a positive number.

#### unregister

    public void unregister(long qryId,
                           @Nullable
                           @Nullable Throwable failReason)

Unregister running query.

Parameters:
  `qryId` - id of the query, which is given by `register` method.
  `failReason` - exception that caused query execution fail, or `null` if query succeded.

#### trackRequestId

    public void trackRequestId(long reqId)

Parameters:
  `reqId` - Request ID of query to track.

#### runningSqlQueries

    public List<GridRunningQueryInfo> runningSqlQueries()

Return SQL queries which executing right now.

Returns:
  List of SQL running queries.

#### longRunningQueries

    public Collection<GridRunningQueryInfo> longRunningQueries(long duration)

Return long running user queries.

Parameters:
  `duration` - Duration of long query.
Returns:
  Collection of queries which running longer than given duration.

#### cancelLocalQuery

    public void cancelLocalQuery(long qryId)

Cancel query.

Parameters:
  `qryId` - Query id.

#### stop

    public void stop()

Cancel all executing queries and deregistering all of them.

#### cancelQuery

    public void cancelQuery(long queryId,
                            @Nullable
                            @Nullable UUID nodeId,
                            boolean async)

Cancel query running on remote or local Node.

Parameters:
  `queryId` - Query id.
  `nodeId` - Node id, if `null`, cancel local query.
  `async` - If `true`, execute asynchronously.

#### onDisconnected

    public void onDisconnected()

Client disconnected callback.

#### queryHistoryMetrics

    public Map<QueryHistoryKey,QueryHistory> queryHistoryMetrics()

Gets query history statistics. Size of history could be configured via `SqlConfiguration.setSqlQueryHistorySize(int)`

Returns:
  Queries history statistics aggregated by query text, schema and local flag.

#### runningQueryInfo

    @Nullable
    public @Nullable GridRunningQueryInfo runningQueryInfo(long qryId)

Gets info about running query by their id.

Parameters:
  `qryId` - Query Id.
Returns:
  Running query info or `null` in case no running query for given id.

#### resetQueryHistoryMetrics

    public void resetQueryHistoryMetrics()

Reset query history.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022