Skip to content
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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

nevdmitry
Copy link
Contributor

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}

assertThat(queryInfo.schema(), is("PUBLIC"));
assertThat(queryInfo.type(), is("QUERY"));

rs.close();
Copy link
Contributor

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()
Copy link
Contributor

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() {
Copy link
Contributor

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");
Copy link
Contributor

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));
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return operation kill handler for specified operation type.
* @return Operation kill handler for specified operation type.

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.

3 participants