-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9293; Fix NPE in DumpLogSegments offsets parser and display tombstone keys #7820
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,16 +16,16 @@ | |
| */ | ||
| package kafka.coordinator.transaction | ||
|
|
||
| import kafka.common.MessageFormatter | ||
| import org.apache.kafka.clients.consumer.ConsumerRecord | ||
| import org.apache.kafka.common.{KafkaException, TopicPartition} | ||
| import org.apache.kafka.common.protocol.types.Type._ | ||
| import org.apache.kafka.common.protocol.types._ | ||
| import java.io.PrintStream | ||
| import java.nio.ByteBuffer | ||
| import java.nio.charset.StandardCharsets | ||
|
|
||
| import org.apache.kafka.common.record.{CompressionType, RecordBatch} | ||
| import kafka.common.MessageFormatter | ||
| import org.apache.kafka.clients.consumer.ConsumerRecord | ||
| import org.apache.kafka.common.protocol.types.Type._ | ||
| import org.apache.kafka.common.protocol.types._ | ||
| import org.apache.kafka.common.record.{CompressionType, Record, RecordBatch} | ||
| import org.apache.kafka.common.{KafkaException, TopicPartition} | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
|
|
@@ -130,7 +130,7 @@ object TransactionLog { | |
| * | ||
| * @return key bytes | ||
| */ | ||
| private[coordinator] def keyToBytes(transactionalId: String): Array[Byte] = { | ||
| private[transaction] def keyToBytes(transactionalId: String): Array[Byte] = { | ||
| import KeySchema._ | ||
| val key = new Struct(CURRENT) | ||
| key.set(TXN_ID_FIELD, transactionalId) | ||
|
|
@@ -146,7 +146,7 @@ object TransactionLog { | |
| * | ||
| * @return value payload bytes | ||
| */ | ||
| private[coordinator] def valueToBytes(txnMetadata: TxnTransitMetadata): Array[Byte] = { | ||
| private[transaction] def valueToBytes(txnMetadata: TxnTransitMetadata): Array[Byte] = { | ||
| import ValueSchema._ | ||
| val value = new Struct(Current) | ||
| value.set(ProducerIdField, txnMetadata.producerId) | ||
|
|
@@ -266,6 +266,29 @@ object TransactionLog { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Exposed for printing records using [[kafka.tools.DumpLogSegments]] | ||
| */ | ||
| def formatRecordKeyAndValue(record: Record): (Option[String], Option[String]) = { | ||
| val txnKey = TransactionLog.readTxnRecordKey(record.key) | ||
| val keyString = s"transaction_metadata::transactionalId=${txnKey.transactionalId}" | ||
|
|
||
| val txnMetadata = TransactionLog.readTxnRecordValue(txnKey.transactionalId, record.value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good suggestion. Pushed a change. |
||
| val valueString = if (txnMetadata == null) { | ||
| "<DELETE>" | ||
| } else { | ||
| s"producerId:${txnMetadata.producerId}," + | ||
| s"producerEpoch:${txnMetadata.producerEpoch}," + | ||
| s"state=${txnMetadata.state}," + | ||
| s"partitions=${txnMetadata.topicPartitions}," + | ||
| s"txnLastUpdateTimestamp=${txnMetadata.txnLastUpdateTimestamp}," + | ||
| s"txnTimeoutMs=${txnMetadata.txnTimeoutMs}" | ||
| } | ||
|
|
||
| (Some(keyString), Some(valueString)) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| case class TxnKey(version: Short, transactionalId: String) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can one or the other string be missing? Or will they always be present or absent together? Just wondering if this should be
Option[Pair[String, String]]or somethingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the API is a bit awkward, but I think both cases are possible. For example, a tombstone will have a key, but not a value.