This is an automated email from the ASF dual-hosted git repository.
rndgstn pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new e74e5e7ac5b KAFKA-15039: Reduce logging level to trace in
PartitionChangeBuilder.… (#13780)
e74e5e7ac5b is described below
commit e74e5e7ac5be7e5dccd7f6addccf74397680a293
Author: Ron Dagostino <[email protected]>
AuthorDate: Wed May 31 16:26:01 2023 -0400
KAFKA-15039: Reduce logging level to trace in PartitionChangeBuilder.…
(#13780)
…tryElection()
A CPU profile in a large cluster showed
PartitionChangeBuilder.tryElection() taking significant CPU due to logging. We
adjust the logging statements in that method for clean elections from DEBUG
level to TRACE to mitigate the impact of this logging under normal operations.
Unclean elections are now logged at the INFO level rather than DEBUG.
Reviewers: Jason Gustafson <[email protected]>, Colin P. McCabe
<[email protected]>
---
.../kafka/controller/PartitionChangeBuilder.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git
a/metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java
b/metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java
index 9c630dfc697..28ee770c2a0 100644
---
a/metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java
+++
b/metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java
@@ -220,13 +220,16 @@ public class PartitionChangeBuilder {
private void tryElection(PartitionChangeRecord record) {
ElectionResult electionResult = electLeader();
if (electionResult.node != partition.leader) {
- log.debug(
- "Setting new leader for topicId {}, partition {} to {} using
{} election",
- topicId,
- partitionId,
- electionResult.node,
- electionResult.unclean ? "an unclean" : "a clean"
- );
+ // generating log messages for partition elections can get
expensive on large clusters,
+ // so only log clean elections at TRACE level; log unclean
elections at INFO level
+ // to ensure the message is emitted since an unclean election can
lead to data loss.
+ if (electionResult.unclean) {
+ log.info("Setting new leader for topicId {}, partition {} to
{} using an unclean election",
+ topicId, partitionId, electionResult.node);
+ } else {
+ log.trace("Setting new leader for topicId {}, partition {} to
{} using a clean election",
+ topicId, partitionId, electionResult.node);
+ }
record.setLeader(electionResult.node);
if (electionResult.unclean) {
// If the election was unclean, we have to forcibly set the
ISR to just the
@@ -239,7 +242,7 @@ public class PartitionChangeBuilder {
}
}
} else {
- log.debug("Failed to find a new leader with current state: {}",
this);
+ log.trace("Failed to find a new leader with current state: {}",
this);
}
}