|
@@ -256,7 +256,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
appData = new byte[data.length];
|
|
|
System.arraycopy(data, 0, appData, 0, data.length);
|
|
|
|
|
|
- LOG.debug("Attempting active election for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Attempting active election for " + this);
|
|
|
+ }
|
|
|
joinElectionInternal();
|
|
|
}
|
|
|
|
|
@@ -406,9 +408,11 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
public synchronized void processResult(int rc, String path, Object ctx,
|
|
|
String name) {
|
|
|
if (isStaleClient(ctx)) return;
|
|
|
- LOG.debug("CreateNode result: " + rc + " for path: " + path
|
|
|
- + " connectionState: " + zkConnectionState +
|
|
|
- " for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("CreateNode result: " + rc + " for path: " + path
|
|
|
+ + " connectionState: " + zkConnectionState +
|
|
|
+ " for " + this);
|
|
|
+ }
|
|
|
|
|
|
Code code = Code.get(rc);
|
|
|
if (isSuccess(code)) {
|
|
@@ -467,10 +471,11 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
|
|
|
assert wantToBeInElection :
|
|
|
"Got a StatNode result after quitting election";
|
|
|
-
|
|
|
- LOG.debug("StatNode result: " + rc + " for path: " + path
|
|
|
- + " connectionState: " + zkConnectionState + " for " + this);
|
|
|
-
|
|
|
+
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("StatNode result: " + rc + " for path: " + path
|
|
|
+ + " connectionState: " + zkConnectionState + " for " + this);
|
|
|
+ }
|
|
|
|
|
|
Code code = Code.get(rc);
|
|
|
if (isSuccess(code)) {
|
|
@@ -535,10 +540,12 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
synchronized void processWatchEvent(ZooKeeper zk, WatchedEvent event) {
|
|
|
Event.EventType eventType = event.getType();
|
|
|
if (isStaleClient(zk)) return;
|
|
|
- LOG.debug("Watcher event type: " + eventType + " with state:"
|
|
|
- + event.getState() + " for path:" + event.getPath()
|
|
|
- + " connectionState: " + zkConnectionState
|
|
|
- + " for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Watcher event type: " + eventType + " with state:"
|
|
|
+ + event.getState() + " for path:" + event.getPath()
|
|
|
+ + " connectionState: " + zkConnectionState
|
|
|
+ + " for " + this);
|
|
|
+ }
|
|
|
|
|
|
if (eventType == Event.EventType.None) {
|
|
|
// the connection state has changed
|
|
@@ -597,7 +604,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
monitorActiveStatus();
|
|
|
break;
|
|
|
default:
|
|
|
- LOG.debug("Unexpected node event: " + eventType + " for path: " + path);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Unexpected node event: " + eventType + " for path: " + path);
|
|
|
+ }
|
|
|
monitorActiveStatus();
|
|
|
}
|
|
|
|
|
@@ -646,7 +655,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
|
|
|
private void monitorActiveStatus() {
|
|
|
assert wantToBeInElection;
|
|
|
- LOG.debug("Monitoring active leader for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Monitoring active leader for " + this);
|
|
|
+ }
|
|
|
statRetryCount = 0;
|
|
|
monitorLockNodeAsync();
|
|
|
}
|
|
@@ -737,7 +748,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
int connectionRetryCount = 0;
|
|
|
boolean success = false;
|
|
|
while(!success && connectionRetryCount < maxRetryNum) {
|
|
|
- LOG.debug("Establishing zookeeper connection for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Establishing zookeeper connection for " + this);
|
|
|
+ }
|
|
|
try {
|
|
|
createConnection();
|
|
|
success = true;
|
|
@@ -765,7 +778,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
watcher = null;
|
|
|
}
|
|
|
zkClient = getNewZooKeeper();
|
|
|
- LOG.debug("Created new connection for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Created new connection for " + this);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@InterfaceAudience.Private
|
|
@@ -773,7 +788,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
if (zkClient == null) {
|
|
|
return;
|
|
|
}
|
|
|
- LOG.debug("Terminating ZK connection for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Terminating ZK connection for " + this);
|
|
|
+ }
|
|
|
ZooKeeper tempZk = zkClient;
|
|
|
zkClient = null;
|
|
|
watcher = null;
|
|
@@ -800,8 +817,10 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
try {
|
|
|
Stat oldBreadcrumbStat = fenceOldActive();
|
|
|
writeBreadCrumbNode(oldBreadcrumbStat);
|
|
|
-
|
|
|
- LOG.debug("Becoming active for " + this);
|
|
|
+
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Becoming active for " + this);
|
|
|
+ }
|
|
|
appClient.becomeActive();
|
|
|
state = State.ACTIVE;
|
|
|
return true;
|
|
@@ -906,7 +925,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
|
|
|
private void becomeStandby() {
|
|
|
if (state != State.STANDBY) {
|
|
|
- LOG.debug("Becoming standby for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Becoming standby for " + this);
|
|
|
+ }
|
|
|
state = State.STANDBY;
|
|
|
appClient.becomeStandby();
|
|
|
}
|
|
@@ -914,7 +935,9 @@ public class ActiveStandbyElector implements StatCallback, StringCallback {
|
|
|
|
|
|
private void enterNeutralMode() {
|
|
|
if (state != State.NEUTRAL) {
|
|
|
- LOG.debug("Entering neutral mode for " + this);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("Entering neutral mode for " + this);
|
|
|
+ }
|
|
|
state = State.NEUTRAL;
|
|
|
appClient.enterNeutralMode();
|
|
|
}
|