This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new ae143e3133 Replace logging implementation with ErrorTypeAware Logger 
in AbstractRegistry, AbstractRegistryFactory, and CacheableFailbackRegistry. 
(#10330)
ae143e3133 is described below

commit ae143e31339b2abdcea81ea4be54744738e27c6e
Author: Andy Cheung <[email protected]>
AuthorDate: Sun Jul 17 13:48:40 2022 +0800

    Replace logging implementation with ErrorTypeAware Logger in 
AbstractRegistry, AbstractRegistryFactory, and CacheableFailbackRegistry. 
(#10330)
    
    Adds error code in invocation of logger in CacheFailbackRegistry.
---
 .../dubbo/registry/support/AbstractRegistry.java   | 43 ++++++++++++++++------
 .../registry/support/AbstractRegistryFactory.java  |  4 +-
 .../support/CacheableFailbackRegistry.java         | 36 +++++++++++++-----
 3 files changed, 61 insertions(+), 22 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 f72aa5877f..e7877048ab 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
@@ -17,7 +17,7 @@
 package org.apache.dubbo.registry.support;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
 import org.apache.dubbo.common.utils.CollectionUtils;
@@ -79,8 +79,10 @@ public abstract class AbstractRegistry implements Registry {
     private static final String URL_SPLIT = "\\s+";
     // Max times to retry to save properties to local cache file
     private static final int MAX_RETRY_TIMES_SAVE_PROPERTIES = 3;
+
     // Log output
-    protected final Logger logger = LoggerFactory.getLogger(getClass());
+    protected final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(getClass());
+
     // Local disk cache, where the special key value.registries records the 
list of registry centers, and the others are the list of notified service 
providers
     private final Properties properties = new Properties();
     // File cache timing writing
@@ -229,7 +231,9 @@ public abstract class AbstractRegistry implements Registry {
                     // fix #9341, ignore OverlappingFileLockException
                     logger.info("Failed to save registry cache file for file 
overlapping lock exception, file name " + file.getName());
                 } else {
-                    logger.warn("Failed to save registry cache file after 
retrying " + MAX_RETRY_TIMES_SAVE_PROPERTIES + " times, cause: " + 
e.getMessage(), e);
+                    // 1-9 failed to read / save registry cache file.
+                    logger.warn("1-9", "multiple Dubbo instance are using the 
same file", "",
+                        "Failed to save registry cache file after retrying " + 
MAX_RETRY_TIMES_SAVE_PROPERTIES + " times, cause: " + e.getMessage(), e);
                 }
                 savePropertiesRetryTimes.set(0);
                 return;
@@ -241,12 +245,16 @@ public abstract class AbstractRegistry implements 
Registry {
                 registryCacheExecutor.execute(() -> 
doSaveProperties(lastCacheChanged.incrementAndGet()));
             }
             if (!(e instanceof OverlappingFileLockException)) {
-                logger.warn("Failed to save registry cache file, will retry, 
cause: " + e.getMessage(), e);
+                logger.warn("1-9", "multiple Dubbo instance are using the same 
file",
+                    "However, the retrying count limit is not exceeded. Dubbo 
will still try.",
+                    "Failed to save registry cache file, will retry, cause: " 
+ e.getMessage(), e);
             }
         } finally {
             if (lockfile != null) {
                 if (!lockfile.delete()) {
-                    logger.warn(String.format("Failed to delete lock file 
[%s]", lockfile.getName()));
+                    // 1-10 Failed to delete lock file.
+                    logger.warn("1-10", "", "",
+                        String.format("Failed to delete lock file [%s]", 
lockfile.getName()));
                 }
             }
         }
@@ -262,9 +270,15 @@ public abstract class AbstractRegistry implements Registry 
{
                 logger.info("Loaded registry cache file " + file);
             }
         } catch (IOException e) {
-            logger.warn(e.getMessage(), e);
+            // 1-9 failed to read / save registry cache file.
+            logger.warn("1-9", "multiple Dubbo instance are using the same 
file", "",
+                e.getMessage(), e);
+
         } catch (Throwable e) {
-            logger.warn("Failed to load registry cache file " + file, e);
+            // 1-9 failed to read / save registry cache file.
+
+            logger.warn("1-9", "multiple Dubbo instance are using the same 
file", "",
+                "Failed to load registry cache file " + file, e);
         }
     }
 
@@ -418,7 +432,9 @@ public abstract class AbstractRegistry implements Registry {
                     try {
                         notify(url, listener, filterEmpty(url, urls));
                     } catch (Throwable t) {
-                        logger.error("Failed to notify registry event, urls: " 
+ urls + ", cause: " + t.getMessage(), t);
+                        // 1-7: Failed to notify registry event.
+                        logger.error("1-7", "", "",
+                            "Failed to notify registry event, urls: " + urls + 
", cause: " + t.getMessage(), t);
                     }
                 }
             }
@@ -440,7 +456,8 @@ public abstract class AbstractRegistry implements Registry {
             throw new IllegalArgumentException("notify listener == null");
         }
         if ((CollectionUtils.isEmpty(urls)) && 
!ANY_VALUE.equals(url.getServiceInterface())) {
-            logger.warn("Ignore empty notify urls for subscribe url " + url);
+            // 1-4 Empty address.
+            logger.warn("1-4", "", "", "Ignore empty notify urls for subscribe 
url " + url);
             return;
         }
         if (logger.isInfoEnabled()) {
@@ -517,7 +534,9 @@ public abstract class AbstractRegistry implements Registry {
                             logger.info("Destroy unregister url " + url);
                         }
                     } catch (Throwable t) {
-                        logger.warn("Failed to unregister url " + url + " to 
registry " + getUrl() + " on destroy, cause: " + t.getMessage(), t);
+                        // 1-8: Failed to unregister / unsubscribe url on 
destroy.
+                        logger.warn("1-8", "", "",
+                            "Failed to unregister url " + url + " to registry 
" + getUrl() + " on destroy, cause: " + t.getMessage(), t);
                     }
                 }
             }
@@ -533,7 +552,9 @@ public abstract class AbstractRegistry implements Registry {
                             logger.info("Destroy unsubscribe url " + url);
                         }
                     } catch (Throwable t) {
-                        logger.warn("Failed to unsubscribe url " + url + " to 
registry " + getUrl() + " on destroy, cause: " + t.getMessage(), t);
+                        // 1-8: Failed to unregister / unsubscribe url on 
destroy.
+                        logger.warn("1-8", "", "",
+                            "Failed to unsubscribe url " + url + " to registry 
" + getUrl() + " on destroy, cause: " + t.getMessage(), t);
                     }
                 }
             }
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index 3933c2c148..ce1c07c3b3 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -18,7 +18,7 @@ package org.apache.dubbo.registry.support;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.URLBuilder;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.registry.Registry;
 import org.apache.dubbo.registry.RegistryFactory;
@@ -39,7 +39,7 @@ import static 
org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
  */
 public abstract class AbstractRegistryFactory implements RegistryFactory, 
ScopeModelAware {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(AbstractRegistryFactory.class);
+    private static final ErrorTypeAwareLogger LOGGER = 
LoggerFactory.getErrorTypeAwareLogger(AbstractRegistryFactory.class);
 
     private RegistryManager registryManager;
     protected ApplicationModel applicationModel;
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
index ae26aae57e..a512782d2c 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
@@ -20,7 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.URLBuilder;
 import org.apache.dubbo.common.URLStrParser;
 import org.apache.dubbo.common.config.ConfigurationUtils;
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
 import org.apache.dubbo.common.url.component.DubboServiceAddressURL;
@@ -65,7 +65,8 @@ import static 
org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATE
  * Useful for registries who's sdk returns raw string as provider instance, 
for example, zookeeper and etcd.
  */
 public abstract class CacheableFailbackRegistry extends FailbackRegistry {
-    private static final Logger logger = 
LoggerFactory.getLogger(CacheableFailbackRegistry.class);
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(CacheableFailbackRegistry.class);
+
     private static String[] VARIABLE_KEYS = new 
String[]{ENCODED_TIMESTAMP_KEY, ENCODED_PID_KEY};
 
     protected Map<String, URLAddress> stringAddress = new 
ConcurrentHashMap<>();
@@ -96,7 +97,9 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
             try {
                 result = Integer.parseInt(str);
             } catch (NumberFormatException e) {
-                logger.warn("Invalid registry properties configuration key " + 
key + ", value " + str);
+                // 1-2 Invalid registry properties.
+                logger.warn("1-2", "", "",
+                    "Invalid registry properties configuration key " + key + 
", value " + str);
             }
         }
         return result;
@@ -123,7 +126,9 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
                 }
             }
         } catch (Exception e) {
-            logger.warn("Failed to evict url for " + url.getServiceKey(), e);
+            // 1-3: URL evicting failed.
+            logger.warn("1-3", "", "",
+                "Failed to evict url for " + url.getServiceKey(), e);
         }
     }
 
@@ -138,7 +143,10 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
                 rawProvider = stripOffVariableKeys(rawProvider);
                 ServiceAddressURL cachedURL = createURL(rawProvider, 
copyOfConsumer, getExtraParameters());
                 if (cachedURL == null) {
-                    logger.warn("Invalid address, failed to parse into URL " + 
rawProvider);
+                    // 1-1: Address invalid.
+                    logger.warn("1-1", "", "",
+                        "Invalid address, failed to parse into URL " + 
rawProvider);
+
                     continue;
                 }
                 newURLs.put(rawProvider, cachedURL);
@@ -151,7 +159,9 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
                 if (cachedURL == null) {
                     cachedURL = createURL(rawProvider, copyOfConsumer, 
getExtraParameters());
                     if (cachedURL == null) {
-                        logger.warn("Invalid address, failed to parse into URL 
" + rawProvider);
+                        logger.warn("1-1", "", "",
+                            "Invalid address, failed to parse into URL " + 
rawProvider);
+
                         continue;
                     }
                 }
@@ -186,7 +196,8 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
             String category = i < 0 ? path : path.substring(i + 1);
             if (!PROVIDERS_CATEGORY.equals(category) || 
!getUrl().getParameter(ENABLE_EMPTY_PROTECTION_KEY, true)) {
                 if (PROVIDERS_CATEGORY.equals(category)) {
-                    logger.warn("Service " + consumer.getServiceKey() + " 
received empty address list and empty protection is disabled, will clear 
current available addresses");
+                    logger.warn("1-4", "", "",
+                        "Service " + consumer.getServiceKey() + " received 
empty address list and empty protection is disabled, will clear current 
available addresses");
                 }
                 URL empty = URLBuilder.from(consumer)
                     .setProtocol(EMPTY_PROTOCOL)
@@ -208,7 +219,10 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
         }
         String[] parts = URLStrParser.parseRawURLToArrays(rawProvider, 
paramStartIdx);
         if (parts.length <= 1) {
-            logger.warn("Received url without any parameters " + rawProvider);
+            // 1-5 Received URL without any parameters.
+            logger.warn("1-5", "", "",
+                "Received url without any parameters " + rawProvider);
+
             return DubboServiceAddressURL.valueOf(rawProvider, consumerURL);
         }
 
@@ -341,7 +355,11 @@ public abstract class CacheableFailbackRegistry extends 
FailbackRegistry {
                     }
                 }
             } catch (Throwable t) {
-                logger.error("Error occurred when clearing cached URLs", t);
+                // 1-6 Error when clearing cached URLs.
+
+                logger.error("1-6", "", "",
+                    "Error occurred when clearing cached URLs", t);
+
             } finally {
                 semaphore.release();
             }

Reply via email to