This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 5857260 Update curator & guava version (#6760)
5857260 is described below
commit 5857260ed31ac3ef3511910770acb0ff61d352b1
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Aug 11 17:26:48 2020 +0800
Update curator & guava version (#6760)
* Update curator & guava version
* Remove deprecated api for curator
---
pom.xml | 4 +-
.../pom.xml | 4 --
.../zookeeper/CuratorZookeeperRepository.java | 50 +++++++++++-----------
.../zookeeper/CuratorZookeeperRepositoryTest.java | 8 ++--
.../engine/ShardingScalingExecuteEngine.java | 4 +-
5 files changed, 34 insertions(+), 36 deletions(-)
diff --git a/pom.xml b/pom.xml
index f6f5c7d..a463a3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.locale>zh_CN</project.build.locale>
- <guava.version>18.0</guava.version>
+ <guava.version>29.0-jre</guava.version>
<gson.version>2.8.6</gson.version>
<slf4j.version>1.7.7</slf4j.version>
@@ -76,7 +76,7 @@
<jboss-logging.version>3.2.1.Final</jboss-logging.version>
<btm.version>2.1.3</btm.version>
- <curator.version>2.10.0</curator.version>
+ <curator.version>5.1.0</curator.version>
<opentracing.version>0.30.0</opentracing.version>
<apollo.client.version>1.5.0</apollo.client.version>
<nacos.client.verison>1.1.4</nacos.client.verison>
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-etcd/pom.xml
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-etcd/pom.xml
index c1de2a5..05745e8 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-etcd/pom.xml
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-etcd/pom.xml
@@ -26,10 +26,6 @@
<artifactId>shardingsphere-orchestration-repository-etcd</artifactId>
<name>${project.artifactId}</name>
- <properties>
- <guava.version>20.0</guava.version>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepository.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orch
[...]
index bb4701a..8bebc06 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepository.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepository.java
@@ -24,9 +24,10 @@ import lombok.Setter;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.ACLProvider;
+import org.apache.curator.framework.api.transaction.TransactionOp;
import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.TreeCache;
-import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.CuratorCache;
+import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import
org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
@@ -41,12 +42,14 @@ import
org.apache.zookeeper.KeeperException.OperationTimeoutException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.ACL;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -55,7 +58,7 @@ import java.util.concurrent.TimeUnit;
*/
public final class CuratorZookeeperRepository implements
ConfigurationRepository, RegistryRepository {
- private final Map<String, TreeCache> caches = new HashMap<>();
+ private final Map<String, CuratorCache> caches = new HashMap<>();
private CuratorFramework client;
@@ -120,18 +123,18 @@ public final class CuratorZookeeperRepository implements
ConfigurationRepository
@Override
public String get(final String key) {
- TreeCache cache = findTreeCache(key);
+ CuratorCache cache = findTreeCache(key);
if (null == cache) {
return getDirectly(key);
}
- ChildData resultInCache = cache.getCurrentData(key);
- if (null != resultInCache) {
- return null == resultInCache.getData() ? null : new
String(resultInCache.getData(), Charsets.UTF_8);
+ Optional<ChildData> resultInCache = cache.get(key);
+ if (resultInCache.isPresent()) {
+ return null == resultInCache.get().getData() ? null : new
String(resultInCache.get().getData(), Charsets.UTF_8);
}
return getDirectly(key);
}
- private TreeCache findTreeCache(final String key) {
+ private CuratorCache findTreeCache(final String key) {
return caches.entrySet().stream().filter(entry ->
key.startsWith(entry.getKey())).findFirst().map(Entry::getValue).orElse(null);
}
@@ -166,7 +169,8 @@ public final class CuratorZookeeperRepository implements
ConfigurationRepository
private void update(final String key, final String value) {
try {
-
client.inTransaction().check().forPath(key).and().setData().forPath(key,
value.getBytes(Charsets.UTF_8)).and().commit();
+ TransactionOp transactionOp = client.transactionOp();
+
client.transaction().forOperations(transactionOp.check().forPath(key),
transactionOp.setData().forPath(key, value.getBytes(StandardCharsets.UTF_8)));
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
@@ -229,21 +233,19 @@ public final class CuratorZookeeperRepository implements
ConfigurationRepository
if (!caches.containsKey(path)) {
addCacheData(key);
}
- TreeCache cache = caches.get(path);
- cache.getListenable().addListener((client, event) -> {
- ChildData data = event.getData();
- if (null == data || null == data.getPath()) {
- return;
- }
- DataChangedEvent.ChangedType changedType = getChangedType(event);
+ CuratorCache cache = caches.get(path);
+ cache.listenable().addListener((type, oldData, data) -> {
+ String eventPath = CuratorCacheListener.Type.NODE_DELETED == type
? oldData.getPath() : data.getPath();
+ byte[] eventDataByte = CuratorCacheListener.Type.NODE_DELETED ==
type ? oldData.getData() : data.getData();
+ DataChangedEvent.ChangedType changedType = getChangedType(type);
if (ChangedType.IGNORED != changedType) {
- listener.onChange(new DataChangedEvent(data.getPath(), null ==
data.getData() ? null : new String(data.getData(), Charsets.UTF_8),
changedType));
+ listener.onChange(new DataChangedEvent(eventPath, null ==
eventDataByte ? null : new String(eventDataByte, Charsets.UTF_8), changedType));
}
});
}
private void addCacheData(final String cachePath) {
- TreeCache cache = new TreeCache(client, cachePath);
+ CuratorCache cache = CuratorCache.build(client, cachePath);
try {
cache.start();
// CHECKSTYLE:OFF
@@ -254,13 +256,13 @@ public final class CuratorZookeeperRepository implements
ConfigurationRepository
caches.put(cachePath + "/", cache);
}
- private ChangedType getChangedType(final TreeCacheEvent event) {
- switch (event.getType()) {
- case NODE_ADDED:
+ private ChangedType getChangedType(final CuratorCacheListener.Type type) {
+ switch (type) {
+ case NODE_CREATED:
return ChangedType.ADDED;
- case NODE_UPDATED:
+ case NODE_CHANGED:
return ChangedType.UPDATED;
- case NODE_REMOVED:
+ case NODE_DELETED:
return ChangedType.DELETED;
default:
return ChangedType.IGNORED;
@@ -269,7 +271,7 @@ public final class CuratorZookeeperRepository implements
ConfigurationRepository
@Override
public void close() {
- caches.values().forEach(TreeCache::close);
+ caches.values().forEach(CuratorCache::close);
waitForCacheClose();
CloseableUtils.closeQuietly(client);
}
diff --git
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepositoryTest.java
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-
[...]
index 52cb3b9..49b1d07 100644
---
a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepositoryTest.java
+++
b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-repository/shardingsphere-orchestration-repository-provider/shardingsphere-orchestration-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/orchestration/repository/zookeeper/CuratorZookeeperRepositoryTest.java
@@ -81,7 +81,7 @@ public final class CuratorZookeeperRepositoryTest {
public void assertWatchUpdatedChangedType() throws InterruptedException {
REPOSITORY.persist("/test/children_updated/1", "value1");
AtomicReference<DataChangedEvent> dataChangedEventActual = new
AtomicReference<>();
- REPOSITORY.watch("/test/children_updated",
dataChangedEventActual::set);
+ REPOSITORY.watch("/test/children_updated/1",
dataChangedEventActual::set);
REPOSITORY.persist("/test/children_updated/1", "value2");
Thread.sleep(50L);
DataChangedEvent dataChangedEvent = dataChangedEventActual.get();
@@ -94,13 +94,13 @@ public final class CuratorZookeeperRepositoryTest {
@Test
public void assertWatchDeletedChangedType() throws Exception {
+ AtomicReference<DataChangedEvent> dataChangedEventActual = new
AtomicReference<>();
+ REPOSITORY.watch("/test/children_deleted",
dataChangedEventActual::set);
REPOSITORY.persist("/test/children_deleted/5", "value5");
Field field =
CuratorZookeeperRepository.class.getDeclaredField("client");
field.setAccessible(true);
CuratorFramework client = (CuratorFramework) field.get(REPOSITORY);
- AtomicReference<DataChangedEvent> dataChangedEventActual = new
AtomicReference<>();
- REPOSITORY.watch("/test/children_deleted/5",
dataChangedEventActual::set);
- client.delete().forPath("/test/children_deleted/5");
+
client.delete().deletingChildrenIfNeeded().forPath("/test/children_deleted/5");
Thread.sleep(50L);
DataChangedEvent dataChangedEvent = dataChangedEventActual.get();
assertNotNull(dataChangedEvent);
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/engine/ShardingScalingExecuteEngine.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/engine/ShardingScalingExecuteEngine.java
index 39a1e05..261aba7 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/engine/ShardingScalingExecuteEngine.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/engine/ShardingScalingExecuteEngine.java
@@ -61,7 +61,7 @@ public final class ShardingScalingExecuteEngine {
*/
public Future<?> submit(final ShardingScalingExecutor
shardingScalingExecutor, final ExecuteCallback executeCallback) {
ListenableFuture<?> result =
executorService.submit(shardingScalingExecutor);
- Futures.addCallback(result, new
ExecuteFutureCallback<>(executeCallback));
+ Futures.addCallback(result, new
ExecuteFutureCallback<>(executeCallback), executorService);
return result;
}
@@ -79,7 +79,7 @@ public final class ShardingScalingExecuteEngine {
listenableFutures.add(listenableFuture);
}
ListenableFuture result = Futures.allAsList(listenableFutures);
- Futures.addCallback(result, new
ExecuteFutureCallback<Collection<Object>>(executeCallback));
+ Futures.addCallback(result, new
ExecuteFutureCallback<Collection<Object>>(executeCallback), executorService);
return result;
}