KAFKA-13883: Implement NoOpRecord and metadata metrics#12183
KAFKA-13883: Implement NoOpRecord and metadata metrics#12183cmccabe merged 11 commits intoapache:trunkfrom
Conversation
bbad90f to
d94afda
Compare
| OptionalLong.empty() | ||
| } | ||
|
|
||
| val maxIdleIntervalNs = config.metadataMaxIdleIntervalMs match { |
There was a problem hiding this comment.
It's more traditional to have conversion stuff like this in KafkaConfig. If you had a function like maxIdleIntervalNs there, it could return Option[Long] and we could convert that into OptionalLong as needed (I think a simple asScala can do it if you have the optional converter imported...)
There was a problem hiding this comment.
Okay. I fixed this. asJava converts it to a Optional[Long] so I did it manually.
| val MetadataLogDirDoc = "This configuration determines where we put the metadata log for clusters in KRaft mode. " + | ||
| "If it is not set, the metadata log is placed in the first log directory from log.dirs." | ||
| val MetadataSnapshotMaxNewRecordBytesDoc = "This is the maximum number of bytes in the log between the latest snapshot and the high-watermark needed before generating a new snapshot." | ||
| val MetadataMaxIdleIntervalMsDoc = "This configuration controls how often the active " + |
There was a problem hiding this comment.
Can we disallow negative values for this? 0 for disabled seems clear enough.
|
|
||
| /************* Metadata Configuration ***********/ | ||
| val metadataSnapshotMaxNewRecordBytes = getLong(KafkaConfig.MetadataSnapshotMaxNewRecordBytesProp) | ||
| val metadataMaxIdleIntervalMs: Option[Int] = { |
There was a problem hiding this comment.
Like I wrote above, seems like the accessor we want should give us nanoseconds not milliseconds. I suppose the value in nanoseconds should be a long too...
| .define(MetadataLogSegmentMillisProp, LONG, Defaults.LogRollHours * 60 * 60 * 1000L, null, HIGH, MetadataLogSegmentMillisDoc) | ||
| .define(MetadataMaxRetentionBytesProp, LONG, Defaults.LogRetentionBytes, null, HIGH, MetadataMaxRetentionBytesDoc) | ||
| .define(MetadataMaxRetentionMillisProp, LONG, Defaults.LogRetentionHours * 60 * 60 * 1000L, null, HIGH, MetadataMaxRetentionMillisDoc) | ||
| .define(MetadataMaxIdleIntervalMsProp, INT, Defaults.MetadataMaxIdleIntervalMs, null, LOW, MetadataMaxIdleIntervalMsDoc) |
There was a problem hiding this comment.
can we valiate that this is not negative? like I wrote above, there seems to be no reason to allow negative values
| import org.apache.kafka.common.metrics.Metrics | ||
| import org.apache.kafka.common.metrics.MetricConfig | ||
|
|
||
| final class BrokerMetrics private (metrics: Metrics) extends AutoCloseable { |
There was a problem hiding this comment.
How do you feel about BrokerServerMetrics as a name for this? That might make it more clear that this doesn't apply to KafkaServer...
|
|
||
| // Support for leader recovery for unclean leader election (KIP-704) | ||
| IBP_3_2_IV0(4, "3.2", "IV0", false), | ||
| IBP_3_2_IV0(4, "3.2", "IV0", true), |
There was a problem hiding this comment.
Thanks for fixing this. We'll have to make a note in the PR description as well
|
|
||
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
|
||
| import java.util.ArrayList; |
There was a problem hiding this comment.
I kind of prefer the style where all the java.util imports are in a single block, can we do that here?
| if (controllerMetrics == null) { | ||
| throw new RuntimeException("You must specify controllerMetrics."); | ||
| if (metadataVersion == null) { | ||
| throw new IllegalStateException("Metadata version must be set before building"); |
There was a problem hiding this comment.
Let's just default to the latest version. It's very tedious to have to set this in every single unit test (most of which don't care)
| private ReplicaPlacer replicaPlacer = new StripedReplicaPlacer(new Random()); | ||
| private long snapshotMaxNewRecordBytes = Long.MAX_VALUE; | ||
| private OptionalLong leaderImbalanceCheckIntervalNs = OptionalLong.empty(); | ||
| private OptionalLong maxIdleIntervalNs = OptionalLong.empty(); |
There was a problem hiding this comment.
It's an interesting choice to have this off by default. I guess it probably would complicate a bunch of junit tests since it would create records we're not expecting. So maybe this is the correct way to go for now.
| leaderImbalanceCheckIntervalNs, sessionTimeoutNs, controllerMetrics, | ||
| createTopicPolicy, alterConfigPolicy, configurationValidator, authorizer, | ||
| staticConfig, bootstrapMetadata); | ||
| return new QuorumController( |
There was a problem hiding this comment.
sigh. all right, fine. I guess we might as well do one line per parameter.
There was a problem hiding this comment.
Hehe. I thought it was improvement. I always find the previous style harder to read and update.
| // the default append linger for KRaft is 25ms. | ||
| controllerMetrics.setLastAppliedRecordTimestamp(time.milliseconds()); | ||
| } else { | ||
| // This is called with an offset of -1 when the active controller renounced leadership |
There was a problem hiding this comment.
Maybe the comment should just mention that lastAppliedRecordOffset tracks last committed offset for standbys.
The bit about writeOffset being -1 is a bit low-level (it is true but that feels more like an implementation detail here...)
|
Merging since the failure is unrelated. The failure at in the ZK tests and this is a KRaft only change: |
Public Changes
Implementation Changes
The KRaft controller schedules an event to write NoOpRecord to the metadata log if the metadata version supports this feature. This event is scheduled at the interval defined in metadata.max.idle.interval.ms. Brokers and controllers were improved to ignore the NoOpRecord when replaying the metadata log.
The replica control manager was also changed to accept a metadata version supplier to determine if leader recovery state is supported.
Other Changes
Fixed a bug where metadata version 3.3-IV1 was not marked as changing the metadata.
Committer Checklist (excluded from commit message)