Skip to content

Commit

Permalink
Inner 227 not print unexpected warn log when try to release a cluster…
Browse files Browse the repository at this point in the history
… lock (actiontech#1469)
  • Loading branch information
sunsun314 authored and yanhuqing666 committed Nov 6, 2019
1 parent 533396a commit b411504
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/main/java/com/actiontech/dble/cluster/impl/UcoreSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,32 @@ public void run() {
try {
LOGGER.debug("renew lock of session start:" + sessionId + " " + path);
if ("".equals(ClusterHelper.getKV(path).getValue())) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ");
log("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ", null);
// alert
Thread.currentThread().interrupt();
} else if (!renewLock(sessionId)) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path);
log("renew lock of session failure:" + sessionId + " " + path, null);
// alert
} else {
LOGGER.debug("renew lock of session success:" + sessionId + " " + path);
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10000));
} catch (Exception e) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path, e);
log("renew lock of session failure:" + sessionId + " " + path, e);
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(5000));
}
}
}

private void log(String message, Exception e) {
if (!Thread.currentThread().isInterrupted()) {
if (e == null) {
LOGGER.warn(message);
} else {
LOGGER.warn(message, e);
}
}
}
});
lockMap.put(path, renewThread);
renewThread.setName("UCORE_RENEW_" + path);
Expand Down Expand Up @@ -148,11 +158,11 @@ public void run() {
public void unlockKey(String path, String sessionId) {
UcoreInterface.UnlockOnSessionInput put = UcoreInterface.UnlockOnSessionInput.newBuilder().setKey(path).setSessionId(sessionId).build();
try {
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
Thread renewThread = lockMap.get(path);
if (renewThread != null) {
renewThread.interrupt();
}
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
} catch (Exception e) {
LOGGER.info(sessionId + " unlockKey " + path + " error ," + stub, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,32 @@ public void run() {
try {
LOGGER.debug("renew lock of session start:" + sessionId + " " + path);
if ("".equals(ClusterHelper.getKV(path).getValue())) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ");
log("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ", null);
// alert
Thread.currentThread().interrupt();
} else if (!renewLock(sessionId)) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path);
log("renew lock of session failure:" + sessionId + " " + path, null);
// alert
} else {
LOGGER.debug("renew lock of session success:" + sessionId + " " + path);
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10000));
} catch (Exception e) {
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path, e);
log("renew lock of session failure:" + sessionId + " " + path, e);
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(5000));
}
}
}

private void log(String message, Exception e) {
if (!Thread.currentThread().isInterrupted()) {
if (e == null) {
LOGGER.warn(message);
} else {
LOGGER.warn(message, e);
}
}
}
});
lockMap.put(path, renewThread);
renewThread.setName("UCORE_RENEW_" + path);
Expand All @@ -104,11 +114,11 @@ public void run() {
public void unlockKey(String path, String sessionId) {
UshardInterface.UnlockOnSessionInput put = UshardInterface.UnlockOnSessionInput.newBuilder().setKey(path).setSessionId(sessionId).build();
try {
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
Thread renewThread = lockMap.get(path);
if (renewThread != null) {
renewThread.interrupt();
}
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
} catch (Exception e) {
LOGGER.info(sessionId + " unlockKey " + path + " error ," + stub, e);
}
Expand Down

0 comments on commit b411504

Please sign in to comment.