chia7712 commented on code in PR #20456:
URL: https://github.com/apache/kafka/pull/20456#discussion_r2639438335
##########
core/src/main/scala/kafka/coordinator/transaction/TransactionStateManager.scala:
##########
@@ -495,19 +495,19 @@ class TransactionStateManager(brokerId: Int,
memRecords.batches.forEach { batch =>
for (record <- batch.asScala) {
require(record.hasKey, "Transaction state log's key should not
be null")
- TransactionLog.readTxnRecordKey(record.key) match {
- case Left(version) =>
- warn(s"Unknown message key with version $version" +
- s" while loading transaction state from $topicPartition.
Ignoring it. " +
- "It could be a left over from an aborted upgrade.")
- case Right(transactionalId) =>
- // load transaction metadata along with transaction state
- TransactionLog.readTxnRecordValue(transactionalId,
record.value) match {
- case None =>
- loadedTransactions.remove(transactionalId)
- case Some(txnMetadata) =>
- loadedTransactions.put(transactionalId, txnMetadata)
- }
+ try {
+ val transactionalId =
TransactionLog.readTxnRecordKey(record.key).asInstanceOf[String]
Review Comment:
```scala
val transactionalId = try
Some(TransactionLog.readTxnRecordKey(record.key))
catch {
case e: IllegalStateException =>
warn(s"Unknown message key version while loading
transaction state from $topicPartition. " +
s"Ignoring it. It could be a left over from an aborted
upgrade. Error: ${e.getMessage}")
None
}
transactionalId.foreach { txnId =>
// load transaction metadata along with transaction state
val txnMetadata = TransactionLog.readTxnRecordValue(txnId,
record.value)
if (txnMetadata == null) {
loadedTransactions.remove(txnId)
} else {
loadedTransactions.put(txnId, txnMetadata)
}
}
```
--
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]