This is an automated email from the ASF dual-hosted git repository. menghaoran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new 4ca05d4b9d4 Optimize persist ephemeral in curator zookeeper repository (#20102) 4ca05d4b9d4 is described below commit 4ca05d4b9d47e87cab96392867813e8ad4946739 Author: gin <jacky7...@163.com> AuthorDate: Fri Aug 12 16:21:09 2022 +0800 Optimize persist ephemeral in curator zookeeper repository (#20102) --- .../repository/cluster/zookeeper/CuratorZookeeperRepository.java | 8 +++++--- .../cluster/zookeeper/CuratorZookeeperRepositoryTest.java | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-prov [...] index d96d87502de..2f24571133a 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepository.java @@ -30,6 +30,7 @@ import org.apache.curator.utils.CloseableUtils; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; +import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryException; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; @@ -40,6 +41,7 @@ import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.Zookeep import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.ZookeeperPropertyKey; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException.OperationTimeoutException; +import org.apache.zookeeper.KeeperException.NodeExistsException; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; @@ -188,13 +190,13 @@ public final class CuratorZookeeperRepository implements ClusterPersistRepositor @Override public void persistEphemeral(final String key, final String value) { try { - if (isExisted(key)) { - client.delete().deletingChildrenIfNeeded().forPath(key); - } client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(StandardCharsets.UTF_8)); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON + if (ex instanceof NodeExistsException) { + throw new ClusterPersistRepositoryException(ex); + } CuratorZookeeperExceptionHandler.handleException(ex); } } diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepositoryTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository- [...] index f62e4bfea44..50f9e092fcb 100644 --- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepositoryTest.java +++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/CuratorZookeeperRepositoryTest.java @@ -188,10 +188,8 @@ public final class CuratorZookeeperRepositoryTest { @Test @SneakyThrows public void assertPersistEphemeralExist() { - when(existsBuilder.forPath("/test/ephemeral")).thenReturn(new Stat()); when(protect.withMode(CreateMode.EPHEMERAL)).thenReturn(protect); REPOSITORY.persistEphemeral("/test/ephemeral", "value4"); - verify(backgroundVersionable).forPath("/test/ephemeral"); verify(protect).forPath("/test/ephemeral", "value4".getBytes(StandardCharsets.UTF_8)); }