Skip to content

Commit

Permalink
KAFKA-15039: Reduce logging level to trace in PartitionChangeBuilder.… (
Browse files Browse the repository at this point in the history
#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]>
  • Loading branch information
rondagostino authored May 31, 2023
1 parent 731c8c9 commit e74e5e7
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,16 @@ private boolean isValidNewLeader(int replica) {
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
Expand All @@ -239,7 +242,7 @@ private void tryElection(PartitionChangeRecord record) {
}
}
} 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);
}
}

Expand Down

0 comments on commit e74e5e7

Please sign in to comment.