Skip to content

Commit

Permalink
[hotfix][runtime] Refactors logging code in DefaultLeaderElectionServ…
Browse files Browse the repository at this point in the history
…ice.

Signed-off-by: Matthias Pohl <[email protected]>
  • Loading branch information
XComp committed Apr 12, 2023
1 parent 76d7e1b commit e03a60a
Showing 1 changed file with 41 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ public final void stop() throws Exception {

@Override
public void confirmLeadership(UUID leaderSessionID, String leaderAddress) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Confirm leader session ID {} for leader {}.", leaderSessionID, leaderAddress);
}
LOG.debug("Confirm leader session ID {} for leader {}.", leaderSessionID, leaderAddress);

checkNotNull(leaderSessionID);

Expand All @@ -127,23 +124,17 @@ public void confirmLeadership(UUID leaderSessionID, String leaderAddress) {
if (running) {
confirmLeaderInformation(leaderSessionID, leaderAddress);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Ignoring the leader session Id {} confirmation, since the "
+ "LeaderElectionService has already been stopped.",
leaderSessionID);
}
LOG.debug(
"Ignoring the leader session Id {} confirmation, since the LeaderElectionService has already been stopped.",
leaderSessionID);
}
} else {
// Received an old confirmation call
if (!leaderSessionID.equals(this.issuedLeaderSessionID)) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Receive an old confirmation call of leader session ID {}, "
+ "current issued session ID is {}",
leaderSessionID,
issuedLeaderSessionID);
}
LOG.debug(
"Receive an old confirmation call of leader session ID {}, current issued session ID is {}",
leaderSessionID,
issuedLeaderSessionID);
} else {
LOG.warn(
"The leader session ID {} was confirmed even though the "
Expand All @@ -161,10 +152,7 @@ public boolean hasLeadership(@Nonnull UUID leaderSessionId) {
return leaderElectionDriver.hasLeadership()
&& leaderSessionId.equals(issuedLeaderSessionID);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(
"hasLeadership is called after the service is stopped, returning false.");
}
LOG.debug("hasLeadership is called after the service is stopped, returning false.");
return false;
}
}
Expand Down Expand Up @@ -199,21 +187,16 @@ public void onGrantLeadership(UUID newLeaderSessionId) {
issuedLeaderSessionID = newLeaderSessionId;
clearConfirmedLeaderInformation();

if (LOG.isDebugEnabled()) {
LOG.debug(
"Grant leadership to contender {} with session ID {}.",
leaderContender.getDescription(),
issuedLeaderSessionID);
}
LOG.debug(
"Grant leadership to contender {} with session ID {}.",
leaderContender.getDescription(),
issuedLeaderSessionID);

leaderContender.grantLeadership(issuedLeaderSessionID);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Ignoring the grant leadership notification since the {} has "
+ "already been closed.",
leaderElectionDriver);
}
LOG.debug(
"Ignoring the grant leadership notification since the {} has already been closed.",
leaderElectionDriver);
}
}
}
Expand All @@ -222,31 +205,25 @@ public void onGrantLeadership(UUID newLeaderSessionId) {
public void onRevokeLeadership() {
synchronized (lock) {
if (running) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Revoke leadership of {} ({}@{}).",
leaderContender.getDescription(),
confirmedLeaderInformation.getLeaderSessionID(),
confirmedLeaderInformation.getLeaderAddress());
}
LOG.debug(
"Revoke leadership of {} ({}@{}).",
leaderContender.getDescription(),
confirmedLeaderInformation.getLeaderSessionID(),
confirmedLeaderInformation.getLeaderAddress());

issuedLeaderSessionID = null;
clearConfirmedLeaderInformation();

leaderContender.revokeLeadership();

if (LOG.isDebugEnabled()) {
LOG.debug("Clearing the leader information on {}.", leaderElectionDriver);
}
LOG.debug("Clearing the leader information on {}.", leaderElectionDriver);
// Clear the old leader information on the external storage
leaderElectionDriver.writeLeaderInformation(LeaderInformation.empty());
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Ignoring the revoke leadership notification since the {} "
+ "has already been closed.",
leaderElectionDriver);
}
LOG.debug(
"Ignoring the revoke leadership notification since the {} "
+ "has already been closed.",
leaderElectionDriver);
}
}
}
Expand All @@ -255,39 +232,30 @@ public void onRevokeLeadership() {
public void onLeaderInformationChange(LeaderInformation leaderInformation) {
synchronized (lock) {
if (running) {
if (LOG.isTraceEnabled()) {
LOG.trace(
"Leader node changed while {} is the leader with session ID {}. New leader information {}.",
leaderContender.getDescription(),
confirmedLeaderInformation.getLeaderSessionID(),
leaderInformation);
}
LOG.trace(
"Leader node changed while {} is the leader with session ID {}. New leader information {}.",
leaderContender.getDescription(),
confirmedLeaderInformation.getLeaderSessionID(),
leaderInformation);
if (!confirmedLeaderInformation.isEmpty()) {
final LeaderInformation confirmedLeaderInfo = this.confirmedLeaderInformation;
if (leaderInformation.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Writing leader information by {} since the external storage is empty.",
leaderContender.getDescription());
}
LOG.debug(
"Writing leader information by {} since the external storage is empty.",
leaderContender.getDescription());
leaderElectionDriver.writeLeaderInformation(confirmedLeaderInfo);
} else if (!leaderInformation.equals(confirmedLeaderInfo)) {
// the data field does not correspond to the expected leader information
if (LOG.isDebugEnabled()) {
LOG.debug(
"Correcting leader information by {}.",
leaderContender.getDescription());
}
LOG.debug(
"Correcting leader information by {}.",
leaderContender.getDescription());
leaderElectionDriver.writeLeaderInformation(confirmedLeaderInfo);
}
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Ignoring change notification since the {} has "
+ "already been closed.",
leaderElectionDriver);
}
LOG.debug(
"Ignoring change notification since the {} has " + "already been closed.",
leaderElectionDriver);
}
}
}
Expand All @@ -298,10 +266,7 @@ private class LeaderElectionFatalErrorHandler implements FatalErrorHandler {
public void onFatalError(Throwable throwable) {
synchronized (lock) {
if (!running) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"Ignoring error notification since the service has been stopped.");
}
LOG.debug("Ignoring error notification since the service has been stopped.");
return;
}

Expand Down

0 comments on commit e03a60a

Please sign in to comment.