jsancio commented on code in PR #12265: URL: https://github.com/apache/kafka/pull/12265#discussion_r916060600
########## core/src/main/scala/kafka/server/metadata/BrokerMetadataListener.scala: ########## @@ -117,26 +117,32 @@ class BrokerMetadataListener( } finally { reader.close() } - _publisher.foreach(publish) - // If we detected a change in metadata.version, generate a local snapshot - val metadataVersionChanged = Option(_delta.featuresDelta()).exists { featuresDelta => - featuresDelta.metadataVersionChange().isPresent + _bytesSinceLastSnapshot = _bytesSinceLastSnapshot + results.numBytes + if (shouldSnapshot()) { + maybeStartSnapshot() } - snapshotter.foreach { snapshotter => - _bytesSinceLastSnapshot = _bytesSinceLastSnapshot + results.numBytes - if (shouldSnapshot() || metadataVersionChanged) { - if (snapshotter.maybeStartSnapshot(_highestTimestamp, _delta.apply())) { - _bytesSinceLastSnapshot = 0L - } - } - } + _publisher.foreach(publish) } } private def shouldSnapshot(): Boolean = { - _bytesSinceLastSnapshot >= maxBytesBetweenSnapshots + (_bytesSinceLastSnapshot >= maxBytesBetweenSnapshots) || metadataVersionChanged() + } + + private def metadataVersionChanged(): Boolean = { + _publisher.nonEmpty && Option(_delta.featuresDelta()).exists { featuresDelta => Review Comment: I see. Before this PR the broker was generating a snapshot when handling committed records that didn't contain a feature change because we only reset `_delta` after the listener calls `publish`. This PR makes sense to me. Let's document this decision in this method. -- 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