-
Notifications
You must be signed in to change notification settings - Fork 100
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-23489 Add rest endpoint to retrieve active transactions and running queries #5080
base: main
Are you sure you want to change the base?
Conversation
1a2be0c
to
4e3ad71
Compare
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/sql/SqlQueryApi.java
Outdated
Show resolved
Hide resolved
...s/rest-api/src/main/java/org/apache/ignite/internal/rest/api/transaction/TransactionApi.java
Outdated
Show resolved
Hide resolved
...t/src/integrationTest/java/org/apache/ignite/internal/rest/sql/ItSqlQueryControllerTest.java
Outdated
Show resolved
Hide resolved
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/sql/SqlQueryApi.java
Outdated
Show resolved
Hide resolved
modules/rest/src/main/java/org/apache/ignite/internal/rest/sql/SqlQueryController.java
Outdated
Show resolved
Hide resolved
...s/rest-api/src/main/java/org/apache/ignite/internal/rest/api/transaction/TransactionApi.java
Outdated
Show resolved
Hide resolved
...t/src/integrationTest/java/org/apache/ignite/internal/rest/sql/ItSqlQueryControllerTest.java
Outdated
Show resolved
Hide resolved
assertThat(queryInfo.schema(), is("PUBLIC")); | ||
assertThat(queryInfo.type(), is("QUERY")); | ||
|
||
rs.close(); |
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.
does it make sense to close rs
in try-with-resources? or in finally
section? looks like the assertion error can lead other tests to fail with due to unclosed cursor.
|
||
IgniteSql igniteSql = CLUSTER.aliveNode().sql(); | ||
// run query with results pageSize=1 | ||
ResultSet<SqlRow> rs = CLUSTER.aliveNode().sql() |
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.
Up to you, but I suggest to extract these common lines into a separate method
private static ResultSet<SqlRow> runQuery(String sql) {
IgniteSql igniteSql = CLUSTER.aliveNode().sql();
Statement stmt = igniteSql.statementBuilder().query(sql).pageSize(1).build();
return CLUSTER.aliveNode().sql().execute(null, stmt);
}
HttpClient client; | ||
|
||
@Test | ||
void shouldReturnAllTransactions() { |
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.
I suggest to rework this test a bit
Transaction roTx = node(0).transactions().begin(new TransactionOptions().readOnly(true));
Transaction rwTx = node(0).transactions().begin(new TransactionOptions().readOnly(false));
Map<UUID, TransactionInfo> transactions = getTransactions(client);
{
TransactionInfo transactionInfo = transactions.get(((InternalTransaction) roTx).id());
assertThat(transactionInfo, notNullValue());
assertThat(transactionInfo.type(), is("READ_ONLY"));
assertThat(transactionInfo.state(), nullValue());
assertThat(transactionInfo.priority(), is("NORMAL"));
roTx.rollback();
}
{
TransactionInfo transactionInfo = transactions.get(((InternalTransaction) rwTx).id());
assertThat(transactionInfo, notNullValue());
assertThat(transactionInfo.type(), is("READ_WRITE"));
assertThat(transactionInfo.state(), is("PENDING"));
assertThat(transactionInfo.priority(), is("NORMAL"));
rwTx.rollback();
}
void shouldReturnTransactionById() { | ||
Transaction tx = node(0).transactions().begin(); | ||
|
||
sql(tx, "SELECT 1"); |
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.
do we really need this? 🤔
@Override | ||
public CompletableFuture<Void> cancelQuery(UUID queryId) { | ||
return killHandlerRegistry.handler(CancellableOperationType.QUERY).cancelAsync(queryId.toString()) | ||
.thenCompose(result -> handleOperationResult(queryId, result)); |
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.
why not thenApply
as in method query(UUID queryId)
?
/** | ||
* Thrown when sql query cancel failed. | ||
*/ | ||
public class SqlQueryCancelException extends IgniteInternalException { |
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.
I probably don't understand how this works, but when does this exception occur?
|
||
@Override | ||
public CompletableFuture<Void> cancelTransaction(UUID transactionId) { | ||
// Waiting https://issues.apache.org/jira/browse/IGNITE-23488 |
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.
Firstly, I think comment should start from "TODO",
Secondly, I think it's worth creating a separate JIRA issue that will be blocked by IGNITE-23488, and the link should be to that issue.
/** | ||
* Returns operation kill handler for specified operation type. | ||
* | ||
* @param type operation type. |
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.
* @param type operation type. | |
* @param type Operation type. |
Also remove @SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
class annotation
* Returns operation kill handler for specified operation type. | ||
* | ||
* @param type operation type. | ||
* @return operation kill handler for specified operation type. |
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.
* @return operation kill handler for specified operation type. | |
* @return Operation kill handler for specified operation type. |
Introduce new rest endpoints
GET /management/v1/transactions/
GET /management/v1/transactions/{tx_id}
DELETE /management/v1/transactions/{tx_id}
GET /management/v1/sql/queries/
GET /management/v1/sql/queries/{query_id}
DELETE /management/v1/sql/queries/{query_id}