This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 2796ada0637 Fix sonar issue (#25952)
2796ada0637 is described below
commit 2796ada0637ba2077d648947c31212042436409c
Author: zhaojinchao <[email protected]>
AuthorDate: Tue May 30 22:07:34 2023 +0800
Fix sonar issue (#25952)
---
.../cluster/lock/impl/DefaultDistributedLock.java | 10 ++----
.../cluster/consul/lock/ConsulDistributedLock.java | 37 ++++++++--------------
.../cluster/zookeeper/ZookeeperRepository.java | 12 +------
3 files changed, 17 insertions(+), 42 deletions(-)
diff --git
a/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/DefaultDistributedLock.java
b/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/DefaultDistributedLock.java
index 7e4d65b7f4d..fb7b3d68c8f 100644
---
a/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/DefaultDistributedLock.java
+++
b/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/DefaultDistributedLock.java
@@ -63,14 +63,8 @@ public final class DefaultDistributedLock implements
DistributedLock {
}
private boolean persist(final String value) {
- try {
- client.persistExclusiveEphemeral(lockKey, value);
- return true;
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
- return false;
- }
+ client.persistExclusiveEphemeral(lockKey, value);
+ return true;
}
@Override
diff --git
a/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/lock/ConsulDistributedLock.java
b/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/lock/ConsulDistributedLock.java
index 2cf04d8d09e..1b96692cf5f 100644
---
a/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/lock/ConsulDistributedLock.java
+++
b/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/lock/ConsulDistributedLock.java
@@ -75,27 +75,21 @@ public final class ConsulDistributedLock implements
DistributedLock {
}
PutParams putParams = new PutParams();
long remainingMillis = timeoutMillis;
- try {
- while (true) {
- String sessionId = createSessionId();
- putParams.setAcquireSession(sessionId);
- Response<Boolean> response = client.setKVValue(lockPath,
LOCK_VALUE, putParams);
- if (response.getValue()) {
- lockSessionId.set(sessionId);
- SESSION_FLUSH_EXECUTOR.scheduleAtFixedRate(() ->
client.renewSession(sessionId, QueryParams.DEFAULT), 5L, 10L, TimeUnit.SECONDS);
- return true;
- }
- client.sessionDestroy(sessionId, null);
- long waitingMillis =
waitUntilRelease(response.getConsulIndex(), remainingMillis);
- if (waitingMillis >= remainingMillis) {
- return false;
- }
- remainingMillis -= waitingMillis;
+ while (true) {
+ String sessionId = createSessionId();
+ putParams.setAcquireSession(sessionId);
+ Response<Boolean> response = client.setKVValue(lockPath,
LOCK_VALUE, putParams);
+ if (response.getValue()) {
+ lockSessionId.set(sessionId);
+ SESSION_FLUSH_EXECUTOR.scheduleAtFixedRate(() ->
client.renewSession(sessionId, QueryParams.DEFAULT), 5L, 10L, TimeUnit.SECONDS);
+ return true;
+ }
+ client.sessionDestroy(sessionId, null);
+ long waitingMillis = waitUntilRelease(response.getConsulIndex(),
remainingMillis);
+ if (waitingMillis >= remainingMillis) {
+ return false;
}
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
- return false;
+ remainingMillis -= waitingMillis;
}
}
@@ -164,9 +158,6 @@ public final class ConsulDistributedLock implements
DistributedLock {
try {
client.setKVValue(lockPath, UNLOCK_VALUE, putParams);
client.sessionDestroy(sessionId, null);
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
} finally {
lockSessionId.remove();
}
diff --git
a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java
b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java
index 57dbb3a3fa0..1dfb75663dc 100644
---
a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java
+++
b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java
@@ -247,17 +247,7 @@ public final class ZookeeperRepository implements
ClusterPersistRepository, Inst
}
}).build();
cache.listenable().addListener(curatorCacheListener);
- start(cache);
- }
-
- private void start(final CuratorCache cache) {
- try {
- cache.start();
- // CHECKSTYLE:OFF
- } catch (final Exception ex) {
- // CHECKSTYLE:ON
- ZookeeperExceptionHandler.handleException(ex);
- }
+ cache.start();
}
private Type getChangedType(final TreeCacheEvent.Type type) {