From 9b3ea088b9854fc15fbdff8ecbd248dd744d79a4 Mon Sep 17 00:00:00 2001 From: aofall <10182210+aofall@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:44:06 +0800 Subject: [PATCH 1/2] feat: Support disable Curator EnsembleTracker Support disable Curator EnsembleTracker and compatible with curator4 --- .../zookeeper/util/CuratorFrameworkUtils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java index 83b47fc1c1f..aaea81a97c6 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java @@ -24,6 +24,7 @@ import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery; import org.apache.dubbo.rpc.model.ScopeModelUtil; +import java.lang.reflect.Method; import java.util.Collection; import java.util.List; import java.util.Map; @@ -32,6 +33,7 @@ import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.CuratorFrameworkFactory.Builder; import org.apache.curator.framework.api.ACLProvider; import org.apache.curator.framework.imps.CuratorFrameworkState; import org.apache.curator.retry.ExponentialBackoffRetry; @@ -43,6 +45,7 @@ import static org.apache.curator.x.discovery.ServiceInstance.builder; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.ZOOKEEPER_ENSEMBLE_TRACKER_KEY; import static org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.DEFAULT_GROUP; import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BASE_SLEEP_TIME; import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BLOCK_UNTIL_CONNECTED_UNIT; @@ -72,6 +75,16 @@ public static CuratorFramework buildCuratorFramework(URL connectionURL, Zookeepe CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(connectionURL.getBackupAddress()) .retryPolicy(buildRetryPolicy(connectionURL)); + try { + // use reflect to check method exist to compatibility with curator4, can remove in dubbo3.3 and direct call + // the method because 3.3 only supported curator5 + Class builderClass = builder.getClass(); + Method ignore = builderClass.getMethod("ensembleTracker", boolean.class); + boolean ensembleTrackerFlag = connectionURL.getParameter(ZOOKEEPER_ENSEMBLE_TRACKER_KEY, true); + builder.ensembleTracker(ensembleTrackerFlag); + } catch (NoSuchMethodException | SecurityException ignore) { + } + String userInformation = connectionURL.getUserInformation(); if (StringUtils.isNotEmpty(userInformation)) { builder = builder.authorization("digest", userInformation.getBytes()); From 466f58613b837524a70ba2d6b7413ed2a7c38b75 Mon Sep 17 00:00:00 2001 From: aofall Date: Tue, 27 Aug 2024 21:04:47 +0800 Subject: [PATCH 2/2] Use Throwable instead detail Exception --- .../dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java index aaea81a97c6..c373e2983ad 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java @@ -82,7 +82,7 @@ public static CuratorFramework buildCuratorFramework(URL connectionURL, Zookeepe Method ignore = builderClass.getMethod("ensembleTracker", boolean.class); boolean ensembleTrackerFlag = connectionURL.getParameter(ZOOKEEPER_ENSEMBLE_TRACKER_KEY, true); builder.ensembleTracker(ensembleTrackerFlag); - } catch (NoSuchMethodException | SecurityException ignore) { + } catch (Throwable ignore) { } String userInformation = connectionURL.getUserInformation();