You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by cr...@apache.org on 2022/05/22 01:03:17 UTC
[dubbo] branch 3.0 updated: [3.0] fix #10042, ignore overlapping lock exception and print log (#10048)
This is an automated email from the ASF dual-hosted git repository.
crazyhzm pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new f7957db329 [3.0] fix #10042, ignore overlapping lock exception and print log (#10048)
f7957db329 is described below
commit f7957db329c58fd67be0d61d49ccf5cc98971922
Author: Wang Chengming <63...@qq.com>
AuthorDate: Sun May 22 09:02:57 2022 +0800
[3.0] fix #10042, ignore overlapping lock exception and print log (#10048)
* fix #10042, ignore overlapping lock exception and print log
* fix #10042, ignore overlapping lock exception and print log
* code format
* fix #10042, ignore overlapping lock exception and print log
* fix #10042, ignore overlapping lock exception and print log
* fix #10042, ignore overlapping lock exception and print log
---
.../dubbo/registry/support/AbstractRegistry.java | 23 +++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index 181b281902..6250892c21 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -108,8 +108,8 @@ public abstract class AbstractRegistry implements Registry {
if (localCacheEnabled) {
// Start file save timer
syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
- String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY +
- url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + CACHE;
+ String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY + url.getApplication() +
+ "-" + url.getAddress().replaceAll(":", "-") + CACHE;
String filename = url.getParameter(FILE_KEY, defaultFilename);
File file = null;
if (ConfigUtils.isNotEmpty(filename)) {
@@ -188,10 +188,11 @@ public abstract class AbstractRegistry implements Registry {
lockfile.createNewFile();
}
try (RandomAccessFile raf = new RandomAccessFile(lockfile, "rw");
- FileChannel channel = raf.getChannel()) {
+ FileChannel channel = raf.getChannel()) {
FileLock lock = channel.tryLock();
if (lock == null) {
- throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties");
+ throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", " +
+ "ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties");
}
// Save
try {
@@ -239,10 +240,12 @@ public abstract class AbstractRegistry implements Registry {
} else {
registryCacheExecutor.execute(new SaveProperties(lastCacheChanged.incrementAndGet()));
}
- logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e);
+ if (!(e instanceof OverlappingFileLockException)) {
+ logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e);
+ }
} finally {
if (lockfile != null) {
- if(!lockfile.delete()) {
+ if (!lockfile.delete()) {
logger.warn(String.format("Failed to delete lock file [%s]", lockfile.getName()));
}
}
@@ -276,9 +279,8 @@ public abstract class AbstractRegistry implements Registry {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
- if (StringUtils.isNotEmpty(key) && key.equals(url.getServiceKey())
- && (Character.isLetter(key.charAt(0)) || key.charAt(0) == '_')
- && StringUtils.isNotEmpty(value)) {
+ if (StringUtils.isNotEmpty(key) && key.equals(url.getServiceKey()) && (Character.isLetter(key.charAt(0))
+ || key.charAt(0) == '_') && StringUtils.isNotEmpty(value)) {
String[] arr = value.trim().split(URL_SPLIT);
List<URL> urls = new ArrayList<>();
for (String u : arr) {
@@ -444,8 +446,7 @@ public abstract class AbstractRegistry implements Registry {
if (listener == null) {
throw new IllegalArgumentException("notify listener == null");
}
- if ((CollectionUtils.isEmpty(urls))
- && !ANY_VALUE.equals(url.getServiceInterface())) {
+ if ((CollectionUtils.isEmpty(urls)) && !ANY_VALUE.equals(url.getServiceInterface())) {
logger.warn("Ignore empty notify urls for subscribe url " + url);
return;
}