-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-12426: Missing logic to create partition.metadata files in RaftReplicaManager #10282
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 8 commits
9effa4f
63439be
de493a9
be36e6c
5e3372a
51b8f7e
4e1a7c7
2893d15
ad65a25
2e5c8f6
fac1f7a
c221911
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 |
|---|---|---|
|
|
@@ -241,12 +241,16 @@ case object SnapshotGenerated extends LogStartOffsetIncrementReason { | |
| * @param producerIdExpirationCheckIntervalMs How often to check for producer ids which need to be expired | ||
| * @param hadCleanShutdown boolean flag to indicate if the Log had a clean/graceful shutdown last time. true means | ||
| * clean shutdown whereas false means a crash. | ||
| * @param topicId optional Uuid to specify the topic ID for the topic if it exists. Should only be specified when | ||
| * first creating the log through Partition.makeLeader or Partition.makeFollower. When reloading a log, | ||
| * this field will be populated by reading the topic ID value from partition.metadata if it exists. | ||
| * @param keepPartitionMetadataFile boolean flag to indicate whether the partition.metadata file should be kept in the | ||
| * log directory. A partition.metadata file is only created when the controller's | ||
| * inter-broker protocol version is at least 2.8. This file will persist the topic ID on | ||
| * the broker. If inter-broker protocol is downgraded below 2.8, a topic ID may be lost | ||
| * and a new ID generated upon re-upgrade. If the inter-broker protocol version is below | ||
| * 2.8, partition.metadata will be deleted to avoid ID conflicts upon re-upgrade. | ||
| * log directory. A partition.metadata file is only created when the raft controller is used | ||
| * or the ZK controller's inter-broker protocol version is at least 2.8. | ||
| * This file will persist the topic ID on the broker. If inter-broker protocol for a ZK controller | ||
| * is downgraded below 2.8, a topic ID may be lost and a new ID generated upon re-upgrade. | ||
| * If the inter-broker protocol version on a ZK cluster is below 2.8, partition.metadata | ||
| * will be deleted to avoid ID conflicts upon re-upgrade. | ||
| */ | ||
| @threadsafe | ||
| class Log(@volatile private var _dir: File, | ||
|
|
@@ -262,6 +266,7 @@ class Log(@volatile private var _dir: File, | |
| val producerStateManager: ProducerStateManager, | ||
| logDirFailureChannel: LogDirFailureChannel, | ||
| private val hadCleanShutdown: Boolean = true, | ||
| @volatile var topicId : Option[Uuid] = None, | ||
|
jolshan marked this conversation as resolved.
Outdated
|
||
| val keepPartitionMetadataFile: Boolean = true) extends Logging with KafkaMetricsGroup { | ||
|
jolshan marked this conversation as resolved.
Outdated
|
||
|
|
||
| import kafka.log.Log._ | ||
|
|
@@ -315,8 +320,6 @@ class Log(@volatile private var _dir: File, | |
|
|
||
| @volatile var partitionMetadataFile : PartitionMetadataFile = null | ||
|
|
||
| @volatile var topicId : Uuid = Uuid.ZERO_UUID | ||
|
|
||
| locally { | ||
| // create the log directory if it doesn't exist | ||
| Files.createDirectories(dir.toPath) | ||
|
|
@@ -349,11 +352,20 @@ class Log(@volatile private var _dir: File, | |
|
|
||
| // Delete partition metadata file if the version does not support topic IDs. | ||
| // Recover topic ID if present and topic IDs are supported | ||
| // If we were provided a topic ID when creating the log, partition metadata files are supported, and one does not yet exist | ||
| // write to the partition metadata file. | ||
| // Ensure we do not try to assign a provided topicId that is inconsistent with the ID on file. | ||
| if (partitionMetadataFile.exists()) { | ||
| if (!keepPartitionMetadataFile) | ||
| partitionMetadataFile.delete() | ||
| else | ||
| topicId = partitionMetadataFile.read().topicId | ||
| else { | ||
| val fileTopicId = partitionMetadataFile.read().topicId | ||
| if (topicId.isDefined && fileTopicId != topicId.get) | ||
|
Contributor
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. You should be able to do something like
Member
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. seems like if the option is None, this will return true, so I'll do |
||
| throw new IllegalStateException(s"Tried to assign topic ID $topicId to log, but log already contained topicId $fileTopicId") | ||
|
jolshan marked this conversation as resolved.
Outdated
|
||
| topicId = Some(fileTopicId) | ||
| } | ||
| } else if (topicId.isDefined && keepPartitionMetadataFile) { | ||
|
Contributor
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. My feeling is that we should be able to get rid of
Member
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. We could run into issues with downgrade and reupgrade. If we downgrade below 2.8 on ZK brokers, we may overwrite the topic ID on reupgrade. But the file will have the old version.
Contributor
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. Not sure I follow the scenario. Why would we overwrite the file on re-upgrade and what would be the problem with that?
Member
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. We would rewrite in ZK, not the file. So we would always get an inconsistent topic ID. We can overwrite in ZK when we add partitions/change ISR since this information is stored in the ZNode along with topic ID. When we write to it using an older version, we can't keep the topic ID field and it is lost.
Contributor
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. Ok, I think I get it. |
||
| partitionMetadataFile.write(topicId.get) | ||
|
jolshan marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -2600,11 +2612,12 @@ object Log { | |
| producerIdExpirationCheckIntervalMs: Int, | ||
| logDirFailureChannel: LogDirFailureChannel, | ||
| lastShutdownClean: Boolean = true, | ||
| topicId: Option[Uuid] = None, | ||
| keepPartitionMetadataFile: Boolean = true): Log = { | ||
| val topicPartition = Log.parseTopicPartitionName(dir) | ||
| val producerStateManager = new ProducerStateManager(topicPartition, dir, maxProducerIdExpirationMs) | ||
| new Log(dir, config, logStartOffset, recoveryPoint, scheduler, brokerTopicStats, time, maxProducerIdExpirationMs, | ||
| producerIdExpirationCheckIntervalMs, topicPartition, producerStateManager, logDirFailureChannel, lastShutdownClean, keepPartitionMetadataFile) | ||
| producerIdExpirationCheckIntervalMs, topicPartition, producerStateManager, logDirFailureChannel, lastShutdownClean, topicId, keepPartitionMetadataFile) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import kafka.log.Log | |
| import kafka.server.checkpoints.OffsetCheckpoints | ||
| import kafka.server.metadata.{MetadataBrokers, MetadataPartition} | ||
| import kafka.utils.Implicits.MapExtensionMethods | ||
| import org.apache.kafka.common.TopicPartition | ||
| import org.apache.kafka.common.{TopicPartition, Uuid} | ||
| import org.apache.kafka.common.errors.KafkaStorageException | ||
|
|
||
| import scala.collection.{Map, Set, mutable} | ||
|
|
@@ -72,7 +72,8 @@ class RaftReplicaChangeDelegate(helper: RaftReplicaChangeDelegateHelper) { | |
| def makeLeaders(prevPartitionsAlreadyExisting: Set[MetadataPartition], | ||
| partitionStates: Map[Partition, MetadataPartition], | ||
| highWatermarkCheckpoints: OffsetCheckpoints, | ||
| metadataOffset: Option[Long]): Set[Partition] = { | ||
| metadataOffset: Option[Long], | ||
| topicIds: String => Option[Uuid]): Set[Partition] = { | ||
|
Contributor
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. I guess we could use a strong type here since topicIds are required for KIP-500, but maybe not worth it since we are delegating to |
||
| val partitionsMadeLeaders = mutable.Set[Partition]() | ||
| val traceLoggingEnabled = helper.stateChangeLogger.isTraceEnabled | ||
| val deferredBatches = metadataOffset.isEmpty | ||
|
|
@@ -94,7 +95,7 @@ class RaftReplicaChangeDelegate(helper: RaftReplicaChangeDelegateHelper) { | |
| try { | ||
| val isrState = state.toLeaderAndIsrPartitionState( | ||
| !prevPartitionsAlreadyExisting(state)) | ||
| if (partition.makeLeader(isrState, highWatermarkCheckpoints)) { | ||
| if (partition.makeLeader(isrState, highWatermarkCheckpoints, topicIds(partition.topic))) { | ||
| partitionsMadeLeaders += partition | ||
| if (traceLoggingEnabled) { | ||
| helper.stateChangeLogger.trace(s"$partitionLogMsgPrefix: completed the become-leader state change.") | ||
|
|
@@ -125,7 +126,8 @@ class RaftReplicaChangeDelegate(helper: RaftReplicaChangeDelegateHelper) { | |
| currentBrokers: MetadataBrokers, | ||
| partitionStates: Map[Partition, MetadataPartition], | ||
| highWatermarkCheckpoints: OffsetCheckpoints, | ||
| metadataOffset: Option[Long]): Set[Partition] = { | ||
| metadataOffset: Option[Long], | ||
| topicIds: String => Option[Uuid]): Set[Partition] = { | ||
| val traceLoggingEnabled = helper.stateChangeLogger.isTraceEnabled | ||
| val deferredBatches = metadataOffset.isEmpty | ||
| val topLevelLogPrefix = if (deferredBatches) | ||
|
|
@@ -164,10 +166,10 @@ class RaftReplicaChangeDelegate(helper: RaftReplicaChangeDelegateHelper) { | |
| s"since the new leader ${state.leaderId} is unavailable.") | ||
| // Create the local replica even if the leader is unavailable. This is required to ensure that we include | ||
| // the partition's high watermark in the checkpoint file (see KAFKA-1647) | ||
| partition.createLogIfNotExists(isNew, isFutureReplica = false, highWatermarkCheckpoints) | ||
| partition.createLogIfNotExists(isNew, isFutureReplica = false, highWatermarkCheckpoints, topicIds(partition.topic)) | ||
| } else { | ||
| val isrState = state.toLeaderAndIsrPartitionState(isNew) | ||
| if (partition.makeFollower(isrState, highWatermarkCheckpoints)) { | ||
| if (partition.makeFollower(isrState, highWatermarkCheckpoints, topicIds(partition.topic))) { | ||
| partitionsMadeFollower += partition | ||
| if (traceLoggingEnabled) { | ||
| helper.stateChangeLogger.trace(s"$partitionLogMsgPrefix: completed the " + | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.