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

[DocDB] Expose endpoint in pg_client_session to cancel a transaction #16696

Closed
1 task done
robertsami opened this issue Apr 4, 2023 · 0 comments
Closed
1 task done
Assignees
Labels
area/docdb YugabyteDB core features kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue

Comments

@robertsami
Copy link
Contributor

robertsami commented Apr 4, 2023

Jira Link: DB-6068

Description

In order to offer a ysql yb_cancel_transaction command, we need an endpoint in yb_client_session which can be hit by a stored procedure implemented in postgres. It should take a transaction_id as a request parameter and trigger a request to the appropriate coordinator, forwarding the response back to postgres

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@robertsami robertsami added area/docdb YugabyteDB core features status/awaiting-triage Issue awaiting triage labels Apr 4, 2023
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Apr 4, 2023
@yugabyte-ci yugabyte-ci added kind/enhancement This is an enhancement of an existing feature and removed kind/bug This issue is a bug status/awaiting-triage Issue awaiting triage labels Apr 5, 2023
basavaraj29 added a commit to basavaraj29/yugabyte-db that referenced this issue May 4, 2023
…l a transaction

Summary: The diff introduces support for cancelling a transaction given it transaction id and status tablet id (will need table id of local transaction status table in a geo-partitioned setup).

Test Plan:
create a cluster using the following
```
./bin/yb-ctl create --rf=3 --placement_info "cloud0.rack1.zone,cloud0.rack2.zone,cloud0.rack3.zone" --data_dir ~/yugabyte-data --tserver_flags 'ysql_num_shards_per_tserver=1,ysql_pg_conf_csv="statement_timeout=0",enable_wait_queues=true,enable_deadlock_detection=true,enable_intentsdb_page=true' --master_flags 'enable_stream_compression=true,stream_compression_algo=2,auto_create_local_transaction_tables=true,auto_promote_nonlocal_transactions_to_global=true,enable_ysql_tablespaces_for_placement=true,ysql_tablespace_info_refresh_secs=1,load_balancer_max_concurrent_adds=10,load_balancer_max_concurrent_removals=10,load_balancer_max_concurrent_moves=10,load_balancer_max_concurrent_moves_per_table=10,client_read_write_timeout_ms=60000'
```

```
CREATE TABLESPACE tablespace1 WITH (replica_placement='{"num_replicas": 1,"placement_blocks":[{"cloud": "cloud0","region": "rack1","zone": "zone","min_num_replicas": 1}]}');
CREATE TABLESPACE tablespace2 WITH (replica_placement='{"num_replicas": 1,"placement_blocks":[{"cloud": "cloud0","region": "rack2","zone": "zone","min_num_replicas": 1}]}');
CREATE TABLESPACE tablespace3 WITH (replica_placement='{"num_replicas": 1,"placement_blocks":[{"cloud": "cloud0","region": "rack3","zone": "zone","min_num_replicas": 1}]}');
CREATE TABLE test(value int PRIMARY KEY, other_value int) PARTITION BY RANGE(value);
CREATE TABLE test1 PARTITION OF test FOR VALUES FROM (0) TO (4) TABLESPACE tablespace1;
CREATE TABLE test2 PARTITION OF test FOR VALUES FROM (4) TO (8) TABLESPACE tablespace2;
CREATE TABLE test3 PARTITION OF test FOR VALUES FROM (8) TO (12) TABLESPACE tablespace3;
INSERT INTO test(value, other_value) VALUES (0,0),(1,1),(4,4),(8,8),(5,5),(9,9);
```

now launch a transaction touching keys [0, 3] whose status tablets are hosted on 127.0.0.1. and then we can test the cancel transaction feature using
```
build/latest/bin/yb-ts-cli cancel_transaction <txn_id> <status_tablet_id>
```

Reviewers: esheng, tvesely, rsami

Subscribers: ybase, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D24476
basavaraj29 added a commit that referenced this issue Jun 14, 2023
…saction

Summary:
This diff introduces support for cancelling a transaction given its transaction id. Providing a status tablet id is left as optional.

When a status tablet id provided, we just check that tablet alone. When left empty, we check all the global txn status tablets and the local txn status tablets and try to cancel the txn. If we are unable to cancel the transaction for some reason, the `error` field in the `CancelTransactionResponsePB` is populated, which is returned back to pg as a status using the `status` field in `PgCancelTransactionResponsePB`.

Note: When a transaction undergoes promotion, there is a minor period in which both the old and the new status tablet assume they are responsible for the transaction. In such cases, where multiple tablets report cancelation statuses, any reported error(s) take precedence. So it might also happen that we actually abort the txn, but report an error to the client. Subsequent cancel calls should report a `NOT_FOUND` in that case. We do this to be on the safer side as reporting `ABORTED` while the txn may still be active is not at all acceptable.
Jira: DB-6068

Test Plan:
./yb_build.sh --cxx-test pgwrapper_pg_cancel_transaction-test
./yb_build.sh --cxx-test pgwrapper_pg_get_lock_status-test

Old plan, but still can test using the following
git cherry-pick commit basavaraj29@a864741 and basavaraj29@5ab76b0

create a cluster using the following
```
./bin/yb-ctl create --rf=3 --placement_info "cloud0.rack1.zone,cloud0.rack2.zone,cloud0.rack3.zone" --data_dir ~/yugabyte-data --tserver_flags 'ysql_num_shards_per_tserver=1,ysql_pg_conf_csv="statement_timeout=0",enable_wait_queues=true,enable_deadlock_detection=true,enable_intentsdb_page=true' --master_flags 'auto_create_local_transaction_tables=true,auto_promote_nonlocal_transactions_to_global=true,enable_ysql_tablespaces_for_placement=true,ysql_tablespace_info_refresh_secs=1,client_read_write_timeout_ms=60000'
```

```
CREATE TABLESPACE tablespace1 WITH (replica_placement='{"num_replicas": 1,"placement_blocks":[{"cloud": "cloud0","region": "rack1","zone": "zone","min_num_replicas": 1}]}');
CREATE TABLE test(k int PRIMARY KEY, v int);
INSERT INTO test(k, v) VALUES (0,0),(1,1);
CREATE TABLE foo(k int, v int) TABLESPACE tablespace1;
INSERT INTO foo(k, v) VALUES (0,0),(1,1);
```

operating on foo produces a local txn, and operating on test produces a global txn
```
build/latest/bin/yb-ts-cli cancel_transaction <txn_id> [<status_tablet_id>]
```

Reviewers: esheng, tvesely, rsami

Reviewed By: rsami

Subscribers: ybase, bogdan

Differential Revision: https://phorge.dev.yugabyte.com/D24476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docdb YugabyteDB core features kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
Status: Done
Development

No branches or pull requests

4 participants