@@ -85,13 +85,6 @@ import scala.jdk.OptionConverters.{RichOption, RichOptional, RichOptionalInt}
85
85
* @param _topicId optional Uuid to specify the topic ID for the topic if it exists. Should only be specified when
86
86
* first creating the log through Partition.makeLeader or Partition.makeFollower. When reloading a log,
87
87
* this field will be populated by reading the topic ID value from partition.metadata if it exists.
88
- * @param keepPartitionMetadataFile boolean flag to indicate whether the partition.metadata file should be kept in the
89
- * log directory. A partition.metadata file is only created when the raft controller is used
90
- * or the ZK controller and this broker's inter-broker protocol version is at least 2.8.
91
- * This file will persist the topic ID on the broker. If inter-broker protocol for a ZK controller
92
- * is downgraded below 2.8, a topic ID may be lost and a new ID generated upon re-upgrade.
93
- * If the inter-broker protocol version on a ZK cluster is below 2.8, partition.metadata
94
- * will be deleted to avoid ID conflicts upon re-upgrade.
95
88
* @param remoteStorageSystemEnable flag to indicate whether the system level remote log storage is enabled or not.
96
89
*/
97
90
@ threadsafe
@@ -102,7 +95,6 @@ class UnifiedLog(@volatile var logStartOffset: Long,
102
95
@ volatile var leaderEpochCache : LeaderEpochFileCache ,
103
96
val producerStateManager : ProducerStateManager ,
104
97
@ volatile private var _topicId : Option [Uuid ],
105
- val keepPartitionMetadataFile : Boolean ,
106
98
val remoteStorageSystemEnable : Boolean = false ,
107
99
@ volatile private var logOffsetsListener : LogOffsetsListener = LogOffsetsListener .NO_OP_OFFSETS_LISTENER ) extends Logging with AutoCloseable {
108
100
@@ -190,40 +182,26 @@ class UnifiedLog(@volatile var logStartOffset: Long,
190
182
191
183
/**
192
184
* Initialize topic ID information for the log by maintaining the partition metadata file and setting the in-memory _topicId.
193
- * Delete partition metadata file if the version does not support topic IDs.
194
185
* Set _topicId based on a few scenarios:
195
- * - Recover topic ID if present and topic IDs are supported . Ensure we do not try to assign a provided topicId that is inconsistent
186
+ * - Recover topic ID if present. Ensure we do not try to assign a provided topicId that is inconsistent
196
187
* with the ID on file.
197
- * - If we were provided a topic ID when creating the log, partition metadata files are supported, and one does not yet exist
188
+ * - If we were provided a topic ID when creating the log and one does not yet exist
198
189
* set _topicId and write to the partition metadata file.
199
- * - Otherwise set _topicId to None
200
190
*/
201
191
private def initializeTopicId (): Unit = {
202
192
val partMetadataFile = partitionMetadataFile.getOrElse(
203
193
throw new KafkaException (" The partitionMetadataFile should have been initialized" ))
204
194
205
195
if (partMetadataFile.exists()) {
206
- if (keepPartitionMetadataFile) {
207
- val fileTopicId = partMetadataFile.read().topicId
208
- if (_topicId.isDefined && ! _topicId.contains(fileTopicId))
209
- throw new InconsistentTopicIdException (s " Tried to assign topic ID $topicId to log for topic partition $topicPartition, " +
210
- s " but log already contained topic ID $fileTopicId" )
211
-
212
- _topicId = Some (fileTopicId)
196
+ val fileTopicId = partMetadataFile.read().topicId
197
+ if (_topicId.isDefined && ! _topicId.contains(fileTopicId))
198
+ throw new InconsistentTopicIdException (s " Tried to assign topic ID $topicId to log for topic partition $topicPartition, " +
199
+ s " but log already contained topic ID $fileTopicId" )
213
200
214
- } else {
215
- try partMetadataFile.delete()
216
- catch {
217
- case e : IOException =>
218
- error(s " Error while trying to delete partition metadata file $partMetadataFile" , e)
219
- }
220
- }
221
- } else if (keepPartitionMetadataFile) {
201
+ _topicId = Some (fileTopicId)
202
+ } else {
222
203
_topicId.foreach(partMetadataFile.record)
223
204
scheduler.scheduleOnce(" flush-metadata-file" , () => maybeFlushMetadataFile())
224
- } else {
225
- // We want to keep the file and the in-memory topic ID in sync.
226
- _topicId = None
227
205
}
228
206
}
229
207
@@ -493,17 +471,15 @@ class UnifiedLog(@volatile var logStartOffset: Long,
493
471
}
494
472
495
473
case None =>
496
- if (keepPartitionMetadataFile) {
497
- _topicId = Some (topicId)
498
- partitionMetadataFile match {
499
- case Some (partMetadataFile) =>
500
- if (! partMetadataFile.exists()) {
501
- partMetadataFile.record(topicId)
502
- scheduler.scheduleOnce(" flush-metadata-file" , () => maybeFlushMetadataFile())
503
- }
504
- case _ => warn(s " The topic id $topicId will not be persisted to the partition metadata file " +
505
- " since the partition is deleted" )
506
- }
474
+ _topicId = Some (topicId)
475
+ partitionMetadataFile match {
476
+ case Some (partMetadataFile) =>
477
+ if (! partMetadataFile.exists()) {
478
+ partMetadataFile.record(topicId)
479
+ scheduler.scheduleOnce(" flush-metadata-file" , () => maybeFlushMetadataFile())
480
+ }
481
+ case _ => warn(s " The topic id $topicId will not be persisted to the partition metadata file " +
482
+ " since the partition is deleted" )
507
483
}
508
484
}
509
485
}
@@ -1989,7 +1965,6 @@ object UnifiedLog extends Logging {
1989
1965
logDirFailureChannel : LogDirFailureChannel ,
1990
1966
lastShutdownClean : Boolean = true ,
1991
1967
topicId : Option [Uuid ],
1992
- keepPartitionMetadataFile : Boolean ,
1993
1968
numRemainingSegments : ConcurrentMap [String , Integer ] = new ConcurrentHashMap [String , Integer ],
1994
1969
remoteStorageSystemEnable : Boolean = false ,
1995
1970
logOffsetsListener : LogOffsetsListener = LogOffsetsListener .NO_OP_OFFSETS_LISTENER ): UnifiedLog = {
@@ -2034,7 +2009,6 @@ object UnifiedLog extends Logging {
2034
2009
leaderEpochCache,
2035
2010
producerStateManager,
2036
2011
topicId,
2037
- keepPartitionMetadataFile,
2038
2012
remoteStorageSystemEnable,
2039
2013
logOffsetsListener)
2040
2014
}
0 commit comments