Add error code 0-5, and more code of issuing error code 0-3, with code optimization. (#10598)
* Add error code 0-5, with more code of issuing error code 0-3.
* Add hint message of FileCacheStoreFactory.
* Spell and code optimization.
* "0-3" -> COMMON_CACHE_PATH_INACCESSIBLE
* Change "0-3", "0-5" to corresponding constants.
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
index b3a3bc9..84601ef 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
@@ -37,7 +37,9 @@
import java.util.HashMap;
import java.util.Map;
-import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_FILE_EXCEED_MAXIMUM_LIMIT;
+import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_MAX_ENTRY_COUNT_LIMIT_EXCEED;
+import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_MAX_FILE_SIZE_LIMIT_EXCEED;
+import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_PATH_INACCESSIBLE;
/**
* Local file interaction class that can back different caches.
@@ -75,12 +77,14 @@
}
if (count > entrySize) {
- logger.warn(COMMON_CACHE_FILE_EXCEED_MAXIMUM_LIMIT, "mis-configuration of system properties",
+ logger.warn(COMMON_CACHE_MAX_FILE_SIZE_LIMIT_EXCEED, "mis-configuration of system properties",
"Check Java system property 'dubbo.mapping.cache.entrySize' and 'dubbo.meta.cache.entrySize'.",
"Cache file was truncated for exceeding the maximum entry size: " + entrySize);
}
} catch (IOException e) {
- logger.warn("Load cache failed ", e);
+ logger.warn(COMMON_CACHE_PATH_INACCESSIBLE, "inaccessible of cache path", "",
+ "Load cache failed ", e);
+
throw e;
}
return properties;
@@ -94,6 +98,9 @@
directoryLock.channel().close();
deleteFile(lockFile);
} catch (IOException e) {
+ logger.error(COMMON_CACHE_PATH_INACCESSIBLE, "inaccessible of cache path", "",
+ "Failed to release cache path's lock file:" + lockFile, e);
+
throw new RuntimeException("Failed to release cache path's lock file:" + lockFile, e);
}
}
@@ -108,23 +115,30 @@
new LimitedLengthBufferedWriter(
new OutputStreamWriter(
new FileOutputStream(cacheFile, false), StandardCharsets.UTF_8), maxFileSize)) {
+
bw.write("#" + comment);
bw.newLine();
bw.write("#" + new Date());
bw.newLine();
+
for (Map.Entry<String, String> e : properties.entrySet()) {
String key = e.getKey();
String val = e.getValue();
bw.write(key + "=" + val);
bw.newLine();
}
+
bw.flush();
+
long remainSize = bw.getRemainSize();
if (remainSize < 0) {
- logger.info("Cache file was truncated for exceeding the maximum file size " + maxFileSize + " byte. Exceeded by " + (-remainSize) + " byte.");
+ logger.warn(COMMON_CACHE_MAX_ENTRY_COUNT_LIMIT_EXCEED, "mis-configuration of system properties",
+ "Check Java system property 'dubbo.mapping.cache.maxFileSize' and 'dubbo.meta.cache.maxFileSize'.",
+ "Cache file was truncated for exceeding the maximum file size " + maxFileSize + " byte. Exceeded by " + (-remainSize) + " byte.");
}
} catch (IOException e) {
- logger.warn("Update cache error.");
+ logger.warn(COMMON_CACHE_PATH_INACCESSIBLE, "inaccessible of cache path", "",
+ "Update cache error.", e);
}
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
index 5710b53..a49f19a 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
@@ -185,7 +185,7 @@
}
if (dirLock == null) {
- throw new PathNotExclusiveException(fileName + " is not exclusive.");
+ throw new PathNotExclusiveException(fileName + " is not exclusive. Maybe multiple Dubbo instances are using the same folder.");
}
builder.directoryLock(dirLock).lockFile(lockFile);
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java
index 1b7537b..a7c2177 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/concurrent/RejectException.java
@@ -19,7 +19,7 @@
import org.apache.dubbo.common.threadpool.MemorySafeLinkedBlockingQueue;
/**
- * Exception thrown by an {@link MemorySafeLinkedBlockingQueue} when a element cannot be accepted.
+ * Exception thrown by an {@link MemorySafeLinkedBlockingQueue} when an element cannot be accepted.
*/
public class RejectException extends RuntimeException {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java
index cd43c54..2612c7b 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java
@@ -287,24 +287,32 @@
WatchKey watchKey = null;
try {
watchKey = watchService.take();
- if (watchKey.isValid()) {
- for (WatchEvent event : watchKey.pollEvents()) {
- WatchEvent.Kind kind = event.kind();
- // configChangeType's key to match WatchEvent's Kind
- ConfigChangeType configChangeType = CONFIG_CHANGE_TYPES_MAP.get(kind.name());
- if (configChangeType != null) {
- Path configDirectoryPath = (Path) watchKey.watchable();
- Path currentPath = (Path) event.context();
- Path configFilePath = configDirectoryPath.resolve(currentPath);
- File configDirectory = configDirectoryPath.toFile();
- executeMutually(configDirectory, () -> {
- fireConfigChangeEvent(configDirectory, configFilePath.toFile(), configChangeType);
- signalConfigDirectory(configDirectory);
- return null;
- });
- }
- }
+
+ if (!watchKey.isValid()) {
+ continue;
}
+
+ for (WatchEvent event : watchKey.pollEvents()) {
+ WatchEvent.Kind kind = event.kind();
+ // configChangeType's key to match WatchEvent's Kind
+ ConfigChangeType configChangeType = CONFIG_CHANGE_TYPES_MAP.get(kind.name());
+
+ if (configChangeType == null) {
+ continue;
+ }
+
+ Path configDirectoryPath = (Path) watchKey.watchable();
+ Path currentPath = (Path) event.context();
+ Path configFilePath = configDirectoryPath.resolve(currentPath);
+ File configDirectory = configDirectoryPath.toFile();
+
+ executeMutually(configDirectory, () -> {
+ fireConfigChangeEvent(configDirectory, configFilePath.toFile(), configChangeType);
+ signalConfigDirectory(configDirectory);
+ return null;
+ });
+ }
+
} catch (Exception e) {
return;
} finally {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoadbalanceRules.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoadbalanceRules.java
index c0e9285..daeff6c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoadbalanceRules.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoadbalanceRules.java
@@ -17,7 +17,7 @@
package org.apache.dubbo.common.constants;
/**
- * constant for Loadbalance strategy
+ * constant for Load-balance strategy
*/
public interface LoadbalanceRules {
@@ -27,7 +27,7 @@
String RANDOM = "random";
/**
- * Round robin load balance.
+ * Round-robin load balance.
**/
String ROUND_ROBIN = "roundrobin";
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java
index a508f1a..ae41ddf 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java
@@ -29,7 +29,10 @@
String COMMON_CACHE_PATH_INACCESSIBLE = "0-3";
- String COMMON_CACHE_FILE_EXCEED_MAXIMUM_LIMIT = "0-4";
+ String COMMON_CACHE_MAX_FILE_SIZE_LIMIT_EXCEED = "0-4";
+
+
+ String COMMON_CACHE_MAX_ENTRY_COUNT_LIMIT_EXCEED = "0-5";
// registry module
String REGISTRY_ADDRESS_INVALID = "1-1";
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/profiler/Profiler.java b/dubbo-common/src/main/java/org/apache/dubbo/common/profiler/Profiler.java
index 4fc50d9..5d2c420 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/profiler/Profiler.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/profiler/Profiler.java
@@ -25,7 +25,7 @@
public static final String PROFILER_KEY = "DUBBO_INVOKE_PROFILER";
public static final int MAX_ENTRY_SIZE = 1000;
- private final static InternalThreadLocal<ProfilerEntry> bizProfiler = new InternalThreadLocal<>();
+ private static final InternalThreadLocal<ProfilerEntry> bizProfiler = new InternalThreadLocal<>();
public static ProfilerEntry start(String message) {
return new ProfilerEntry(message);
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
index 2fd6516..cb34f71 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
@@ -42,8 +42,8 @@
/**
* {@link FileSystemDynamicConfiguration} Test
*/
-// Test often failed on Github Actions Platform because of file system on Azure
-// Change to Disabled because DisabledIfEnvironmentVariable does not work on Github.
+// Test often failed on GitHub Actions Platform because of file system on Azure
+// Change to Disabled because DisabledIfEnvironmentVariable does not work on GitHub.
@Disabled
public class FileSystemDynamicConfigurationTest {