Skip to content

Commit f7957db

Browse files
[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
1 parent be7dc7f commit f7957db

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public AbstractRegistry(URL url) {
108108
if (localCacheEnabled) {
109109
// Start file save timer
110110
syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
111-
String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY +
112-
url.getApplication() + "-" + url.getAddress().replaceAll(":", "-") + CACHE;
111+
String defaultFilename = System.getProperty(USER_HOME) + DUBBO_REGISTRY + url.getApplication() +
112+
"-" + url.getAddress().replaceAll(":", "-") + CACHE;
113113
String filename = url.getParameter(FILE_KEY, defaultFilename);
114114
File file = null;
115115
if (ConfigUtils.isNotEmpty(filename)) {
@@ -188,10 +188,11 @@ public void doSaveProperties(long version) {
188188
lockfile.createNewFile();
189189
}
190190
try (RandomAccessFile raf = new RandomAccessFile(lockfile, "rw");
191-
FileChannel channel = raf.getChannel()) {
191+
FileChannel channel = raf.getChannel()) {
192192
FileLock lock = channel.tryLock();
193193
if (lock == null) {
194-
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");
194+
throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", " +
195+
"ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties");
195196
}
196197
// Save
197198
try {
@@ -239,10 +240,12 @@ public void doSaveProperties(long version) {
239240
} else {
240241
registryCacheExecutor.execute(new SaveProperties(lastCacheChanged.incrementAndGet()));
241242
}
242-
logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e);
243+
if (!(e instanceof OverlappingFileLockException)) {
244+
logger.warn("Failed to save registry cache file, will retry, cause: " + e.getMessage(), e);
245+
}
243246
} finally {
244247
if (lockfile != null) {
245-
if(!lockfile.delete()) {
248+
if (!lockfile.delete()) {
246249
logger.warn(String.format("Failed to delete lock file [%s]", lockfile.getName()));
247250
}
248251
}
@@ -276,9 +279,8 @@ public List<URL> getCacheUrls(URL url) {
276279
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
277280
String key = (String) entry.getKey();
278281
String value = (String) entry.getValue();
279-
if (StringUtils.isNotEmpty(key) && key.equals(url.getServiceKey())
280-
&& (Character.isLetter(key.charAt(0)) || key.charAt(0) == '_')
281-
&& StringUtils.isNotEmpty(value)) {
282+
if (StringUtils.isNotEmpty(key) && key.equals(url.getServiceKey()) && (Character.isLetter(key.charAt(0))
283+
|| key.charAt(0) == '_') && StringUtils.isNotEmpty(value)) {
282284
String[] arr = value.trim().split(URL_SPLIT);
283285
List<URL> urls = new ArrayList<>();
284286
for (String u : arr) {
@@ -444,8 +446,7 @@ protected void notify(URL url, NotifyListener listener, List<URL> urls) {
444446
if (listener == null) {
445447
throw new IllegalArgumentException("notify listener == null");
446448
}
447-
if ((CollectionUtils.isEmpty(urls))
448-
&& !ANY_VALUE.equals(url.getServiceInterface())) {
449+
if ((CollectionUtils.isEmpty(urls)) && !ANY_VALUE.equals(url.getServiceInterface())) {
449450
logger.warn("Ignore empty notify urls for subscribe url " + url);
450451
return;
451452
}

0 commit comments

Comments
 (0)