1123 opened a new pull request, #24068:
URL: https://github.com/apache/kafka/pull/24068

   ## Summary
   
   Implements the `DescribeTransactions` part of 
[KIP-994](https://cwiki.apache.org/confluence/spaces/KAFKA/pages/276106184/KIP-994+Minor+Enhancements+to+ListTransactions+and+DescribeTransactions+APIs).
 The broker now returns the time of the transaction's last state change, and 
`kafka-transactions.sh --describe` uses it to print a stable duration for 
completed transactions. Before this, the tool printed `now - startTime` for 
every transaction, so the "duration" of a committed or aborted transaction kept 
growing (KAFKA-15546).
   
   The `ListTransactions` `DurationFilter` part of KIP-994 is already in trunk 
(KAFKA-16265, #15384, released in 3.8.0), so this PR does not touch it.
   
   JIRA: https://issues.apache.org/jira/browse/KAFKA-15923
   Related: https://issues.apache.org/jira/browse/KAFKA-15546
   KIP: 
https://cwiki.apache.org/confluence/spaces/KAFKA/pages/276106184/KIP-994+Minor+Enhancements+to+ListTransactions+and+DescribeTransactions+APIs
 (accepted 2024-01-17, 3 binding +1)
   
   ## What changed
   
   **Protocol**
   - `DescribeTransactionsResponse` is bumped to version 1 (`validVersions` 
`0-1`). It adds `TransactionStates[].TransactionLastUpdateTimeMs` (`int64`, 
versions `1+`, default `-1`, `ignorable`).
   - `DescribeTransactionsRequest` is bumped to version 1 to match the 
response. The request fields are unchanged.
   
   **Broker (coordinator)**
   - `TransactionCoordinator.handleDescribeTransactions` fills the new field 
from `TransactionMetadata.txnLastUpdateTimestamp`.
   
   **Admin client**
   - `TransactionDescription` gets a new public constructor that takes 
`OptionalLong transactionLastUpdateTimeMs`, and a new accessor 
`transactionLastUpdateTimeMs()`. The existing constructor is kept and delegates 
with `OptionalLong.empty()`. `equals`, `hashCode` and `toString` include the 
new field.
   - `DescribeTransactionsHandler` maps a negative value (the default, or a 
broker that only speaks version 0) to `OptionalLong.empty()`, the same way it 
already does for the start time.
   
   **CLI**
   - `kafka-transactions.sh --describe`: for `CompleteCommit` and 
`CompleteAbort` the `TransactionDurationMs` column is now `lastUpdateTime - 
startTime`. If the last update time is missing (older broker), it prints `-1`. 
It also prints `-1` if the difference would be negative, which can happen when 
the two timestamps were written on different broker clocks after a failover. 
For other states the column is unchanged (`now - startTime`), and it is still 
`None` when there is no start time. No new column or flag is added.
   
   **Docs**
   - `docs/getting-started/upgrade.md`: a note under "Notable changes in 4.5.0".
   
   ## Compatibility
   
   - New client, old broker: the client negotiates `DescribeTransactions` v0. 
`TransactionDescription#transactionLastUpdateTimeMs()` is empty, and the CLI 
prints `-1` as the duration for completed transactions.
   - Old client, new broker: the client asks for v0. The field is `ignorable`, 
so the broker leaves it out of the v0 response.
   - The old `TransactionDescription` constructor still works, so existing 
callers are source and binary compatible.
   - No new configs or metrics.
   
   ## Testing
   
   Tests added or updated in this PR (I have not pasted any run results here; 
CI will report them):
   - `DescribeTransactionsHandlerTest`: checks the last update time is mapped, 
and is empty when the response carries the default.
   - `KafkaAdminClientTransactionTest`: new test that `describeTransactions` 
returns the last update time; the existing test asserts it is empty when the 
broker does not send it.
   - `RequestResponseTest`: the sample `DescribeTransactionsResponse` now sets 
the new field, so the round trip is exercised for the supported versions.
   - `TransactionCoordinatorTest`: `testDescribeTransactions` checks the field 
is returned; new `testDescribeTransactionsCompleteCommit` checks a completed 
transaction keeps the same start and last update time after the clock advances.
   - `TransactionsCommandTest`: describe output for completed transactions with 
a last update time, completed without one (`-1`), ongoing (uses the clock), no 
start time (`None`), and clock skew (`-1`).
   - `PlaintextAdminIntegrationTest` (`testDescribeTransactions`): checks the 
last update time is present and not before the start time for ongoing, 
committed and aborted transactions, and that it stays the same across two 
describes of a committed transaction.
   


-- 
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]

Reply via email to