You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/30 03:05:34 UTC

[dubbo] branch 3.0 updated: add exception catch for RemovalTask, ensure semaphore release (#8170)

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

albumenj 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 2c737a4  add exception catch for RemovalTask, ensure semaphore release (#8170)
2c737a4 is described below

commit 2c737a4d87a42f0c97d3e627a5424034c2d2630b
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Wed Jun 30 11:05:21 2021 +0800

    add exception catch for RemovalTask, ensure semaphore release (#8170)
---
 .../support/CacheableFailbackRegistry.java         | 42 +++++++++++++---------
 1 file changed, 25 insertions(+), 17 deletions(-)

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 16e0f89..561b794 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
@@ -308,26 +308,34 @@ public abstract class CacheableFailbackRegistry extends FailbackRegistry {
     private static class RemovalTask implements Runnable {
         @Override
         public void run() {
-            logger.info("Clearing cached URLs, size " + waitForRemove.size());
-            Iterator<Map.Entry<ServiceAddressURL, Long>> it = waitForRemove.entrySet().iterator();
-            while (it.hasNext()) {
-                Map.Entry<ServiceAddressURL, Long> entry = it.next();
-                ServiceAddressURL removeURL = entry.getKey();
-                long removeTime = entry.getValue();
-                long current = System.currentTimeMillis();
-                if (current - removeTime >= cacheClearWaitingThresholdInMillis) {
-                    URLAddress urlAddress = removeURL.getUrlAddress();
-                    URLParam urlParam = removeURL.getUrlParam();
-                    if (current - urlAddress.getTimestamp() >= cacheClearWaitingThresholdInMillis) {
-                        stringAddress.remove(urlAddress.getRawAddress());
-                    }
-                    if (current - urlParam.getTimestamp() >= cacheClearWaitingThresholdInMillis) {
-                        stringParam.remove(urlParam.getRawParam());
+            logger.info("Clearing cached URLs, waiting to clear size " + waitForRemove.size());
+            int clearCount = 0;
+            try {
+                Iterator<Map.Entry<ServiceAddressURL, Long>> it = waitForRemove.entrySet().iterator();
+                while (it.hasNext()) {
+                    Map.Entry<ServiceAddressURL, Long> entry = it.next();
+                    ServiceAddressURL removeURL = entry.getKey();
+                    long removeTime = entry.getValue();
+                    long current = System.currentTimeMillis();
+                    if (current - removeTime >= cacheClearWaitingThresholdInMillis) {
+                        URLAddress urlAddress = removeURL.getUrlAddress();
+                        URLParam urlParam = removeURL.getUrlParam();
+                        if (current - urlAddress.getTimestamp() >= cacheClearWaitingThresholdInMillis) {
+                            stringAddress.remove(urlAddress.getRawAddress());
+                        }
+                        if (current - urlParam.getTimestamp() >= cacheClearWaitingThresholdInMillis) {
+                            stringParam.remove(urlParam.getRawParam());
+                        }
+                        it.remove();
+                        clearCount++;
                     }
-                    it.remove();
                 }
+            } catch (Throwable t) {
+                logger.error("Error occurred when clearing cached URLs", t);
+            } finally {
+                semaphore.release();
             }
-            semaphore.release();
+            logger.info("Clear cached URLs, size " + clearCount);
 
             if (CollectionUtils.isNotEmptyMap(waitForRemove)) {
                 // move to next schedule