Skip to content
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

KAFKA-17285: Consider using Utils.closeQuietly to replace CoreUtils.swallow when handling Closeable objects #16843

Open
wants to merge 14 commits into
base: trunk
Choose a base branch
from

Conversation

bboyleonp666
Copy link
Contributor

Use Utils.closeQuietly to replace CoreUtils.swallow in kafka.network.Acceptor#closeAll.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@bboyleonp666
Copy link
Contributor Author

Using Utils.closeQuietly to replace CoreUtils.swallow will also change the logging level from ERROR to WARNING, which makes sense to me, since the close() called before the thread starting is not supposed to happen. The warning message is enough for this behavior.

@bboyleonp666 bboyleonp666 marked this pull request as ready for review August 10, 2024 05:32
@chia7712
Copy link
Contributor

@bboyleonp666 could you please grep code base to fix all similar issues?

@bboyleonp666
Copy link
Contributor Author

Sure. Let me take a look at the code base.

@bboyleonp666
Copy link
Contributor Author

@chia7712 While handling this, I have noticed that there are lots of methods that uses shutdown() instead of close() when calling CoreUtils.swallow(). Currently, only close() is handled by Utils.closeQuietly() and I cannot find a method that can gracefully deal with shutdown() method. Are there any methods that can do this? If not, I wonder if we are going to add one similarly. Maybe name it shutdownQuietly?

@chia7712
Copy link
Contributor

Are there any methods that can do this? If not, I wonder if we are going to add one similarly. Maybe name it shutdownQuietly?

the shutdown is not a kind of interface, so I guess it would be hard to add "one helper" to handle "all" cases. Maybe this PR can focus on deal with the AutoClosable object.

@bboyleonp666
Copy link
Contributor Author

I agree with you. I have already merged the commits in trunk.

@chia7712
Copy link
Contributor

@bboyleonp666 please rebase code to fix build error. Also, please fix following usages:

CoreUtils.swallow(zookeeper.getZKDatabase.close(), this)

finally CoreUtils.swallow(authZ.close(), this)

CoreUtils.swallow(channel.close(), logging, Level.ERROR)

CoreUtils.swallow(reader.close(), logging)

CoreUtils.swallow(zkClient.close(), logging)

CoreUtils.swallow(createTopicPolicy.foreach(_.close()), this)

CoreUtils.swallow(alterConfigPolicy.foreach(_.close()), this)

@chia7712
Copy link
Contributor

chia7712 commented Sep 1, 2024

@bboyleonp666 any updates?

@bboyleonp666
Copy link
Contributor Author

I was on a long trip just back to work recently. I will update this soon, thanks for reminding.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@bboyleonp666 thanks for your updates

core/src/test/scala/unit/kafka/zk/EmbeddedZookeeper.scala Outdated Show resolved Hide resolved
@bboyleonp666
Copy link
Contributor Author

bboyleonp666 commented Sep 7, 2024

@bboyleonp666 please rebase code to fix build error. Also, please fix following usages:

CoreUtils.swallow(zookeeper.getZKDatabase.close(), this)

Since zookeeper.getZKDatabase is not a Closeable, we are not able to use Utils.closeQuietly() to replace it. I will keep it as it is.

CoreUtils.swallow(createTopicPolicy.foreach(_.close()), this)

CoreUtils.swallow(alterConfigPolicy.foreach(_.close()), this)

The lines here use foreach to close the resources, while CoreUtils.swallow() is not limited to an object type like Utils.closeQuietly() does. I wonder whether we should keep using foreach to keep the code concise and consistent or should we make it a for loop to achieve the same effect? What's your opinion? @chia7712

@chia7712
Copy link
Contributor

chia7712 commented Sep 7, 2024

The lines here use foreach to close the resources, while CoreUtils.swallow() is not limited to an object type like Utils.closeQuietly() does. I wonder whether we should keep using foreach to keep the code concise and consistent or should we make it a for loop to achieve the same effect? What's your opinion? @chia7712

how about: createTopicPolicy.foreach(Utils.closeQuietly(_, "close create topic policy"))

@bboyleonp666
Copy link
Contributor Author

Looks great. Let me apply this change to all the instances that I can find.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@bboyleonp666 thanks for updated patch

core/src/main/scala/kafka/server/BrokerServer.scala Outdated Show resolved Hide resolved
core/src/main/scala/kafka/server/ControllerServer.scala Outdated Show resolved Hide resolved
core/src/main/scala/kafka/server/KafkaServer.scala Outdated Show resolved Hide resolved
core/src/main/scala/kafka/server/KafkaServer.scala Outdated Show resolved Hide resolved
core/src/main/scala/kafka/server/ZkAdminManager.scala Outdated Show resolved Hide resolved
@chia7712
Copy link
Contributor

@bboyleonp666 could you please fix conflicts?

@github-actions github-actions bot added core Kafka Broker storage Pull requests that target the storage module labels Sep 28, 2024
@bboyleonp666
Copy link
Contributor Author

Hi @chia7712, thank you. Just resolved and waiting for the checks.

@@ -766,14 +766,13 @@ class BrokerServer(
CoreUtils.swallow(socketServer.shutdown(), this)
if (brokerTopicStats != null)
CoreUtils.swallow(brokerTopicStats.close(), this)
Copy link
Contributor

Choose a reason for hiding this comment

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

BrokerTopicStats extends Closeable now, so you can apply Utils.closeQuietly, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. Let me update this one.

Copy link
Contributor Author

@bboyleonp666 bboyleonp666 Sep 30, 2024

Choose a reason for hiding this comment

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

Apply this one in commit fd93c6b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved core Kafka Broker storage Pull requests that target the storage module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants