Skip to content

Support Transaction Tags and Request Tags#128

Merged
yfuruyama merged 4 commits into
cloudspannerecosystem:masterfrom
takabow:feature/transaction_tag
Apr 20, 2022
Merged

Support Transaction Tags and Request Tags#128
yfuruyama merged 4 commits into
cloudspannerecosystem:masterfrom
takabow:feature/transaction_tag

Conversation

@takabow
Copy link
Copy Markdown
Contributor

@takabow takabow commented Apr 15, 2022

This PR adds Cloud Spanner's transaction tags and request tags support to spanner-cli.

Transaction tags are tags set at the beginning of a transaction that makes the transaction identifiable. Request tags can be set for each request and identify individual requests.

According to this document, read-write transaction supports transaction tags and request tags. Read-only transaction only supports request tags.

So, I implemented this feature as follows.

Transaction Tags and Request Tags support in spanner-cli

In a read-write transaction, you can add arbitrary tags following BEGIN RW TAG <tags>.
spanner-cli adds the tags set in BEGIN RW TAG as transaction tags.
This tag will also be used as request tags within the transaction.

# Read-write transaction
# transaction_tag = tx1
+--------------------+
| BEGIN RW TAG tx1;  |
|                    |
| SELECT val         |
| FROM tab1      +-----request_tag = tx1
| WHERE id = 1;      |
|                    |
| UPDATE tab1        |
| SET val = 10   +-----request_tag = tx1
| WHERE id = 1;      |
|                    |
| COMMIT;            |
+--------------------+

In a read-only transaction, you can add arbitrary tags following BEGIN RO TAG <tags>.
Since read-only transaction in Cloud Spanner doesn't support transaction tags, spanner-cli adds the tags set in BEGIN RO TAG as request tags.

# Read-only transaction
# transaction_tag = N/A
+--------------------+
| BEGIN RO TAG tx2;  |
|                    |
| SELECT SUM(val)    |
| FROM tab1      +-----request_tag = tx2
| WHERE id = 1;      |
|                    |
| CLOSE;             |
+--------------------+

Comment thread README.md Outdated
Comment thread session.go Outdated
Comment thread README.md Outdated
Comment thread session.go Outdated
Comment thread session.go Outdated
Comment thread session.go Outdated
Comment thread session_test.go Outdated
Comment thread session_test.go Outdated
Comment thread statement.go Outdated
Comment thread statement.go Outdated
@yfuruyama
Copy link
Copy Markdown
Collaborator

Thank you @takabow for creating this change! PTAL the above comments.

@yfuruyama yfuruyama self-requested a review April 20, 2022 00:01
Copy link
Copy Markdown
Collaborator

@yfuruyama yfuruyama left a comment

Choose a reason for hiding this comment

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

LGTM!

@yfuruyama yfuruyama merged commit 8ac33c9 into cloudspannerecosystem:master Apr 20, 2022
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.

2 participants