Skip to content

KAFKA-15633: Fix overwrite of meta.properties at startup to handle JBOD.#14578

Closed
pprovenzano wants to merge 5 commits intoapache:trunkfrom
pprovenzano:JBOD-Kafka-15633
Closed

KAFKA-15633: Fix overwrite of meta.properties at startup to handle JBOD.#14578
pprovenzano wants to merge 5 commits intoapache:trunkfrom
pprovenzano:JBOD-Kafka-15633

Conversation

@pprovenzano
Copy link
Copy Markdown
Contributor

Fix startup to write back the updated meta.properties file with the new directory.id.
Fix reading of the meta.properties file to ignore the directory.id when validating that all the meta.properties files belong to the same cluster.

… directory.id.

Fix reading of the meta.properties file to ignore the directory.id when validating that
all the meta.properties files belong to the same cluster.
We create the file and in this case we MUST create a random Uuid for it.
@pprovenzano
Copy link
Copy Markdown
Contributor Author

pprovenzano commented Oct 19, 2023

Adding of the directory.id in any form will prevent the cluster from rolling back to a previous AK version.

@hudeqi hudeqi added the core Kafka Broker label Oct 19, 2023
@pprovenzano
Copy link
Copy Markdown
Contributor Author

Adding of the directory.id in any form will prevent the cluster from rolling back to a previous AK version.

This actually is only an issue for people running JBOD. Those with only one directory per broker will be fine.

Copy link
Copy Markdown
Member

@soarez soarez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a test for this. Perhaps we can add or extend one of the existing integration tests?

Comment thread core/src/main/scala/kafka/server/BrokerMetadataCheckpoint.scala Outdated
try {
brokerCheckpoint.read() match {
case Some(properties) =>
// XXX Should we check for duplicates here
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is LogManager.directoryIds() a better place to check for duplicates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it there. Let me know what you think

Comment on lines +1029 to +1032
val props = brokerMetadata.toProperties.clone().asInstanceOf[Properties]
// If the Uuid is not set then we set it here because originally we ignored
// directories with no meta.properties file and we are creating it here.
props.setProperty("directory.id", logManager.directoryId(logDir).getOrElse(Uuid.randomUuid()).toString)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogManager is already generating a directory ID if missing, in directoryIds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I fixed LogManager to generate the directory ID for all cases where it is missing. This includes if the meta.properties is missing which can only occur if we are in ZK mde. It does not create the missing meta.properties file until after the broker is registered with ZK.

@pprovenzano pprovenzano changed the title KAFKA-15633: Fix overwrite of meta.properties at startup to handle JBOD. [WIP] KAFKA-15633: Fix overwrite of meta.properties at startup to handle JBOD. Oct 24, 2023
@pprovenzano
Copy link
Copy Markdown
Contributor Author

I think we should add a test for this. Perhaps we can add or extend one of the existing integration tests?

I'd like to do that as a separate PR.

Comment on lines +300 to +302
if (s.contains(uuid)) {
throw new RuntimeException(s"Found duplicate directory.ids ${uuid.toString}")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to maintaining a mutable set and modifying it from within the flatMap lamda could be to compare the size of the result with .toSet.size or .toSeq.distinct.size e.g.

if (dirIds.values.toSet.size != dirIds.values.size)
  throw new RuntimeException(s"Found duplicate directory.ids ${uuid.toString}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps KafkaException is more suitable than RuntimeException?

Comment on lines +296 to +297
case None => {
Uuid.randomUuid()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, maybe I'm missing something. So if meta.properties does not exist for some directory, we generate a random one, but it seems the generated value isn't persisted? That means the same log directory will get a different ID ever time the broker restarts, which will generate a lot of unnecessary reassignments...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will get persisted. The only case where we allow a directory to not have a meta.properties file is in Zk mode. In Zk mode on startup, all directories without a meta.properties file have one created immediately after the broker is registered with ZooKeeper.

@pprovenzano
Copy link
Copy Markdown
Contributor Author

Closing this PR in favor of #14628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants