alvarotuso opened a new pull request, #71319:
URL: https://github.com/apache/doris/pull/71319
### Background
In cloud mode the FE keeps no transaction state of its own, so `SHOW
TRANSACTION WHERE LABEL = '...'` and `WHERE ID = ...` read the transaction from
the meta service. Its `get_txn` call takes a label or an id and returns the
whole transaction record; for a label, it returns the label's latest
transaction. A second call, `get_txn_id`, only maps a label, optionally
filtered by status, to a transaction id.
### What problem does this PR solve?
Issue Number: None
Related PR: #41718 (introduced the label lookup this PR changes), #70726
(open, changes the same label lookup code; conflicts), #70905 (earlier version
of this change, closed)
PR Type: Enhancement
Problem Summary:
In cloud mode, `SHOW TRANSACTION WHERE LABEL = '<label>'` makes three
meta-service calls to return one row: `get_txn` by label, which already returns
the label's latest transaction, then `get_txn_id` filtered by that
transaction's status, then `get_txn` again by the resulting id. This PR builds
the row from the first response, so a label lookup is one call. Lookups by id,
retries, and the messages for a missing label or a failed lookup are unchanged.
### Details
- **Before and after:** Three calls become one `get_txn`, and the row is the
same: `get_txn` picks the label's largest transaction id, and a label is reused
only after its latest transaction aborts, so the status-filtered `get_txn_id`
returned that same id. Two cases differ. A transaction whose status changed
between the old first and second call read as missing and now doesn't. A
failure of the old third call reported `transaction with id N does not exist`;
every failure now reports `transaction with label <label> does not exist`, as
the first two calls already did.
- **Configs and defaults:** None.
- **Impact on existing users:** None beyond the two cases above.
`getLabelState`, behind `GET /api/{db}/get_load_state`, is unchanged: its body
moved as is into the helper it now calls. Shared-nothing mode keeps its
in-memory lookups.
- **Results:** On a 3-FE test cluster running a port of this change to a
3.1-based cloud build, a label lookup drops from about 15 ms to about 6 ms, the
cost of a lookup by id; FE logs show one `get_txn` call and no `get_txn_id`
call per label lookup. Each run is one session on the master FE alternating 300
lookups by label and 300 by id, timed by the audit log's `Time(ms)`, first 20
of each dropped:
| Lookup | Build | mean | p50 | p95 | p99 |
|---|---|---|---|---|---|
| by label | before | 14.9 ms | 15 | 17 | 18 |
| by label | after | 6.2 ms | 6 | 8 | 9 |
| by id (unchanged path) | before | 5.1 ms | 5 | 7 | 7 |
| by id (unchanged path) | after | 5.9 ms | 5 | 8 | 10 |
### Testing
- `CloudGlobalTransactionMgrTest`, new cases with a mocked meta service: for
each transaction status, a label lookup sends one `get_txn` by label and no
`get_txn_id`, and the row matches the response; `TXN_ID_NOT_FOUND`,
`KV_TXN_GET_ERR` and an `RpcException` each report `transaction with label ...
does not exist` after one call.
- `GlobalTransactionMgrTest#testGetSingleTranInfoByLabel`, new:
shared-nothing mode finds a label and reports a missing one.
- `CloudGlobalTransactionMgrTest` (69 tests), `GlobalTransactionMgrTest`
(16) and `ShowTransactionCommandTest` (1) pass on `da231dba996`, run locally in
a Linux arm64 container with JDK 17.
- On the test cluster above: lookups by label and by id of a visible
transaction, of a label reused after a rollback (returns the newer, visible
transaction), and of a missing label and id each return the expected row or
error.
- Not run: `show_p0/test_show_txn_error_msg`,
`query_p0/show/test_show_transaction` and `auth_p0/test_show_transaction_auth`,
which cover a found and a missing label and the privilege check; the p0 and
cloud_p0 pipeline configs don't exclude them.
### Notes for Reviewers
- `getTransactionStateByLabel` is `getLabelState`'s former body, returning
the whole `TransactionState`. Its strings still name `getLabelState`, as moved
code in this file usually does; `get_load_state` returns that exception message
to clients.
- `getTransactionId(dbId, label)` keeps its two calls; after this PR its
only caller is `BrokerLoadJob`.
- #70726 rewrites `getLabelState` and `getTransactionId` in the same file,
so whichever merges second needs a rebase.
### Release note
In cloud mode, `SHOW TRANSACTION WHERE LABEL = '...'` reads the transaction
with one meta-service call instead of three, which makes it about as fast as a
lookup by id.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified: the regression suites listed in
Testing were not run
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: code, tests, this description
- Human review: fully reviewed by the author and iterated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]