mumrah commented on code in PR #13033: URL: https://github.com/apache/kafka/pull/13033#discussion_r1054455358
########## core/src/main/scala/kafka/server/metadata/BrokerMetadataListener.scala: ########## @@ -289,6 +316,59 @@ class BrokerMetadataListener( BatchLoadResults(numBatches, numRecords, NANOSECONDS.toMicros(elapsedNs), numBytes) } + private def applyRecordToDelta( + delta: MetadataDelta, + messageAndVersion: ApiMessageAndVersion, + baseOffset: Long, + index: Int, + snapshotName: Option[String] + ): Unit = { + try { + delta.replay(messageAndVersion.message()) + } catch { + case e: Throwable => snapshotName match { + case None => metadataLoadingFaultHandler.handleFault( + s"Error replaying metadata log record at offset ${baseOffset + index}", e) + case Some(name) => metadataLoadingFaultHandler.handleFault( + s"Error replaying record ${index} from snapshot ${name} at offset ${_highestOffset}", e) + } + } + } + + private def beginTransaction(newTransactionEpoch: Int, newTransactionOffset: Long): Unit = { + if (_transactionEpoch != -1) { + abortTransaction("a new begin transaction record appeared", newTransactionOffset) + } + _transactionEpoch = newTransactionEpoch + _transactionOffset = newTransactionOffset + _transactionRecords = new util.ArrayList[ApiMessageAndVersion] + log.debug("Beginning metadata transaction {}_{}.", _transactionOffset, _transactionEpoch) + } + + private def endTransaction(delta: MetadataDelta, endOffset: Long): Unit = { + log.debug("Ending metadata transaction {}_{} at offset {}", _transactionOffset, _transactionEpoch, endOffset) + var index = 0 + _transactionRecords.forEach(record => { Review Comment: We should guard against a null `_transactionRecords` here. If two EndTransactionRecord-s appeared (somehow..) it would raise an NPE Same comment for this logic in MetadataLoader -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org