This is an automated email from the ASF dual-hosted git repository.
codingsinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new cd55cd7 add a switch to turn off cache URLs locally (#5804)
cd55cd7 is described below
commit cd55cd78caccb12ee64478381618120ba89e466a
Author: zechao zheng <[email protected]>
AuthorDate: Sun Mar 1 18:20:22 2020 +0800
add a switch to turn off cache URLs locally (#5804)
---
.../java/org/apache/dubbo/registry/Constants.java | 5 ++++
.../dubbo/registry/support/AbstractRegistry.java | 35 ++++++++++++----------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
index 1bf4168..638af54 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java
@@ -59,6 +59,11 @@ public interface Constants {
String REGISTRY_FILESAVE_SYNC_KEY = "save.file";
/**
+ * Whether to cache locally, default is true
+ */
+ String REGISTRY__LOCAL_FILE_CACHE_ENABLED = "file.cache";
+
+ /**
* Reconnection period in milliseconds for register center
*/
String REGISTRY_RECONNECT_PERIOD_KEY = "reconnect.period";
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 a005f63..efcd7e9 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
@@ -63,6 +63,7 @@ import static
org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGO
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
import static
org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
import static org.apache.dubbo.registry.Constants.REGISTRY_FILESAVE_SYNC_KEY;
+import static
org.apache.dubbo.registry.Constants.REGISTRY__LOCAL_FILE_CACHE_ENABLED;
/**
* AbstractRegistry. (SPI, Prototype, ThreadSafe)
@@ -82,7 +83,7 @@ public abstract class AbstractRegistry implements Registry {
// File cache timing writing
private final ExecutorService registryCacheExecutor =
Executors.newFixedThreadPool(1, new
NamedThreadFactory("DubboSaveRegistryCache", true));
// Is it synchronized to save the file
- private final boolean syncSaveFile;
+ private boolean syncSaveFile;
private final AtomicLong lastCacheChanged = new AtomicLong();
private final AtomicInteger savePropertiesRetryTimes = new AtomicInteger();
private final Set<URL> registered = new ConcurrentHashSet<>();
@@ -94,24 +95,26 @@ public abstract class AbstractRegistry implements Registry {
public AbstractRegistry(URL url) {
setUrl(url);
- // Start file save timer
- syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
- String defaultFilename = System.getProperty("user.home") +
"/.dubbo/dubbo-registry-" + url.getParameter(APPLICATION_KEY) + "-" +
url.getAddress().replaceAll(":", "-") + ".cache";
- String filename = url.getParameter(FILE_KEY, defaultFilename);
- File file = null;
- if (ConfigUtils.isNotEmpty(filename)) {
- file = new File(filename);
- if (!file.exists() && file.getParentFile() != null &&
!file.getParentFile().exists()) {
- if (!file.getParentFile().mkdirs()) {
- throw new IllegalArgumentException("Invalid registry cache
file " + file + ", cause: Failed to create directory " + file.getParentFile() +
"!");
+ if (url.getParameter(REGISTRY__LOCAL_FILE_CACHE_ENABLED, true)) {
+ // Start file save timer
+ syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
+ String defaultFilename = System.getProperty("user.home") +
"/.dubbo/dubbo-registry-" + url.getParameter(APPLICATION_KEY) + "-" +
url.getAddress().replaceAll(":", "-") + ".cache";
+ String filename = url.getParameter(FILE_KEY, defaultFilename);
+ File file = null;
+ if (ConfigUtils.isNotEmpty(filename)) {
+ file = new File(filename);
+ if (!file.exists() && file.getParentFile() != null &&
!file.getParentFile().exists()) {
+ if (!file.getParentFile().mkdirs()) {
+ throw new IllegalArgumentException("Invalid registry
cache file " + file + ", cause: Failed to create directory " +
file.getParentFile() + "!");
+ }
}
}
+ this.file = file;
+ // When starting the subscription center,
+ // we need to read the local cache file for future Registry fault
tolerance processing.
+ loadProperties();
+ notify(url.getBackupUrls());
}
- this.file = file;
- // When starting the subscription center,
- // we need to read the local cache file for future Registry fault
tolerance processing.
- loadProperties();
- notify(url.getBackupUrls());
}
protected static List<URL> filterEmpty(URL url, List<URL> urls) {