jsancio commented on code in PR #12414:
URL: https://github.com/apache/kafka/pull/12414#discussion_r934580125
##
core/src/main/scala/kafka/server/metadata/BrokerMetadataSnapshotter.scala:
##
@@ -63,7 +63,7 @@ class BrokerMetadataSnapshotter(
)
if (writer.nonEmpty) {
_currentSnapshotOffset = image.highestOffsetAndEpoch().offset
-info(s"Creating a new snapshot at offset ${_currentSnapshotOffset}...")
+info(s"Creating a new snapshot at offset ${_currentSnapshotOffset}
because ${snapshotReason}...")
Review Comment:
What do you think about moving this log line to the `KafkaMetadataLog` type?
That code is shared between the Controller and the Broker.
##
core/src/main/scala/kafka/server/metadata/BrokerMetadataListener.scala:
##
@@ -119,16 +119,29 @@ class BrokerMetadataListener(
}
_bytesSinceLastSnapshot = _bytesSinceLastSnapshot + results.numBytes
- if (shouldSnapshot()) {
-maybeStartSnapshot()
+
+ val shouldTakeSnapshot: Option[String] = shouldSnapshot()
+ if (shouldTakeSnapshot.isDefined) {
+maybeStartSnapshot(shouldTakeSnapshot.get)
}
_publisher.foreach(publish)
}
}
- private def shouldSnapshot(): Boolean = {
-(_bytesSinceLastSnapshot >= maxBytesBetweenSnapshots) ||
metadataVersionChanged()
+ private def shouldSnapshot(): Option[String] = {
Review Comment:
Let's have a stricter type. I suspect that we are going to add more reasons
for generating snapshots. What do you think if we create a Java enum
`SnapshotReason` in the `raft` module and `org.apache.kafka.snapshot` package?
We can also changed the signature of `RaftClient#creaeSnapshot` to
```
Optional> createSnapshot(
long committedOffset,
int committedEpoch,
long lastContainedLogTime,
SnapshotReason reason
);
```
You can take a look at `LogStartOffsetIncrementReason` in
`core/src/main/scala/kafka/log/UnifiedLog.scala` for an example in Scala. We
want this as an enum in Java since it will be used in `KafkaRaftClient`.
##
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##
@@ -1325,7 +1325,7 @@ private void maybeGenerateSnapshot(long batchSizeInBytes)
{
snapshotRegistry.getOrCreateSnapshot(lastCommittedOffset);
}
-log.info("Generating a snapshot that includes (epoch={},
offset={}) after {} committed bytes since the last snapshot.",
+log.info("Generating a snapshot that includes (epoch={},
offset={}) after {} committed bytes since the last snapshot, because max bytes
exceeded.",
Review Comment:
What do you think about moving this log line to the `KafkaMetadataLog` type?
That code is shared between the Controller and the Broker.
##
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##
@@ -1325,7 +1325,7 @@ private void maybeGenerateSnapshot(long batchSizeInBytes)
{
snapshotRegistry.getOrCreateSnapshot(lastCommittedOffset);
}
-log.info("Generating a snapshot that includes (epoch={},
offset={}) after {} committed bytes since the last snapshot.",
+log.info("Generating a snapshot that includes (epoch={},
offset={}) after {} committed bytes since the last snapshot, because max bytes
exceeded.",
Review Comment:
Hmm. So it looks like in the Controller we don't generate a snapshot when
the metadata version changes.
@mumrah How should we resolve this?
--
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