Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Dec 21, 2024
1 parent 5d9043f commit b0383f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
getChildren();
}
} else {
log.error("creatingParentContainersIfNeeded() failed (rc = {})", event.getResultCode());
log.error("[id={}] creatingParentContainersIfNeeded() failed (rc = {})", id, event.getResultCode());
}
}
};
Expand All @@ -528,7 +528,7 @@ private synchronized void internalStart() {
reset();
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
log.error("failed to check resetting leadership.", e);
log.error("[id={}] failed to check resetting leadership.", id, e);
}
}
}
Expand All @@ -545,10 +545,10 @@ private void checkLeadership(List<String> children) throws Exception {
List<String> sortedChildren = LockInternals.getSortedChildren(LOCK_NAME, sorter, children);
int ourIndex = (localOurPath != null) ? sortedChildren.indexOf(ZKPaths.getNodeFromPath(localOurPath)) : -1;

log.debug("checkLeadership with id: {}, ourPath: {}, children: {}", id, localOurPath, sortedChildren);
log.debug("[id={}] checkLeadership with ourPath: {}, children: {}", id, localOurPath, sortedChildren);

if (ourIndex < 0) {
log.error("failed to find our node; resetting (index: {})", ourIndex);
log.error("[id={}] failed to find our node; resetting (index: {})", id, ourIndex);
reset();
return;
}
Expand Down Expand Up @@ -582,7 +582,7 @@ public void process(WatchedEvent event) {
getChildren();
} catch (Exception ex) {
ThreadUtils.checkInterrupted(ex);
log.error("failed to check the leadership.", ex);
log.error("[id={}] failed to check the leadership.", id, ex);
}
}
}
Expand All @@ -592,7 +592,7 @@ public void process(WatchedEvent event) {
@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
if (event.getResultCode() == KeeperException.Code.NONODE.intValue()) {
// previous node is gone - retry getChildren
log.debug("[id={}] previous node is gone; retry getChildren", id);
getChildren();
}
}
Expand All @@ -608,16 +608,15 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
checkLeadership(event.getChildren());
} else if (event.getResultCode() == KeeperException.Code.NONODE.intValue()) {
// latchPath has gone - reset
//
log.debug("[id={}] latchPath has gone; reset", id);
// This is possible when RECONNECTED during:
// (1) Scale the zk cluster to 0 nodes.
// (2) Scale it back.
//
// See also https://issues.apache.org/jira/browse/CURATOR-724
reset();
} else {
log.error("getChildren() failed (rc = {})", event.getResultCode());
log.error("[id={}] getChildren() failed (rc = {})", id, event.getResultCode());
}
}
};
Expand All @@ -638,7 +637,7 @@ protected void handleStateChange(ConnectionState newState) {
getChildren();
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
log.error("failed to recheck leadership on reconnected", e);
log.error("[id={}] failed to recheck leadership on reconnected", id, e);
setLeadership(false);
}
break;
Expand Down Expand Up @@ -676,7 +675,7 @@ private synchronized void setLeadership(boolean newValue) {

private void setNode(String newValue) throws Exception {
String oldPath = ourPath.getAndSet(newValue);
log.debug("setNode with id: {}, oldPath: {}, newValue: {}", id, oldPath, newValue);
log.debug("[id={}] setNode with oldPath: {}, newValue: {}", id, oldPath, newValue);
if (oldPath != null) {
client.delete().guaranteed().inBackground().forPath(oldPath);
}
Expand Down
2 changes: 1 addition & 1 deletion curator-recipes/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ log4j.additivity.org.apache.curator=false

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %c %x %m [%t]%n
log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p %c %x %m [%t]%n

0 comments on commit b0383f5

Please sign in to comment.