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

nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new 42c6644  KYLIN-4168 fix sonar bug
42c6644 is described below

commit 42c66446f881e97fcacfd33be1b11af5df964d72
Author: yaqian.zhang <598593...@qq.com>
AuthorDate: Tue Oct 29 20:08:42 2019 +0800

    KYLIN-4168 fix sonar bug
---
 .../spy/memcached/RefinedKetamaNodeLocator.java    | 25 +++++++++++-----------
 .../java/org/apache/kylin/common/QueryContext.java |  7 +++---
 .../java/org/apache/kylin/common/StorageURL.java   |  2 +-
 .../apache/kylin/common/livy/LivyRestExecutor.java |  2 +-
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git 
a/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java 
b/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
index 43f31bc..0ee9732 100644
--- a/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
+++ b/cache/src/main/java/net/spy/memcached/RefinedKetamaNodeLocator.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicReference;
 
 import net.spy.memcached.compat.SpyObject;
 import net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration;
@@ -54,8 +55,8 @@ public final class RefinedKetamaNodeLocator extends SpyObject 
implements NodeLoc
     private final Map<InetSocketAddress, Integer> weights;
     private final boolean isWeightedKetama;
     private final KetamaNodeLocatorConfiguration config;
-    private volatile TreeMap<Long, MemcachedNode> ketamaNodes;
-    private volatile Collection<MemcachedNode> allNodes;
+    private AtomicReference<TreeMap<Long, MemcachedNode>> ketamaNodes = new 
AtomicReference<>();
+    private AtomicReference<Collection<MemcachedNode>> allNodes = new 
AtomicReference<>();
 
     /**
      * Create a new KetamaNodeLocator using specified nodes and the specifed 
hash
@@ -117,7 +118,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
     public RefinedKetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm 
alg,
             Map<InetSocketAddress, Integer> nodeWeights, 
KetamaNodeLocatorConfiguration configuration) {
         super();
-        allNodes = nodes;
+        allNodes.set(nodes);
         hashAlg = alg;
         config = configuration;
         weights = nodeWeights;
@@ -128,8 +129,8 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
     private RefinedKetamaNodeLocator(TreeMap<Long, MemcachedNode> smn, 
Collection<MemcachedNode> an, HashAlgorithm alg,
             Map<InetSocketAddress, Integer> nodeWeights, 
KetamaNodeLocatorConfiguration conf) {
         super();
-        ketamaNodes = smn;
-        allNodes = an;
+        ketamaNodes.set(smn);
+        allNodes.set(an);
         hashAlg = alg;
         config = conf;
         weights = nodeWeights;
@@ -137,7 +138,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
     }
 
     public Collection<MemcachedNode> getAll() {
-        return allNodes;
+        return allNodes.get();
     }
 
     public MemcachedNode getPrimary(final String k) {
@@ -152,7 +153,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
 
     MemcachedNode getNodeForKey(long hash) {
         final MemcachedNode rv;
-        if (!ketamaNodes.containsKey(hash)) {
+        if (!ketamaNodes.get().containsKey(hash)) {
             // Java 1.6 adds a ceilingKey method, but I'm still stuck in 1.5
             // in a lot of places, so I'm doing this myself.
             SortedMap<Long, MemcachedNode> tailMap = 
getKetamaNodes().tailMap(hash);
@@ -183,7 +184,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
 
     public NodeLocator getReadonlyCopy() {
         TreeMap<Long, MemcachedNode> smn = new TreeMap<Long, 
MemcachedNode>(getKetamaNodes());
-        Collection<MemcachedNode> an = new 
ArrayList<MemcachedNode>(allNodes.size());
+        Collection<MemcachedNode> an = new 
ArrayList<MemcachedNode>(allNodes.get().size());
 
         // Rewrite the values a copy of the map.
         for (Map.Entry<Long, MemcachedNode> me : smn.entrySet()) {
@@ -191,7 +192,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
         }
 
         // Copy the allNodes collection.
-        for (MemcachedNode n : allNodes) {
+        for (MemcachedNode n : allNodes.get()) {
             an.add(new MemcachedNodeROImpl(n));
         }
 
@@ -200,7 +201,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
 
     @Override
     public void updateLocator(List<MemcachedNode> nodes) {
-        allNodes = nodes;
+        allNodes.set(nodes);
         setKetamaNodes(nodes);
     }
 
@@ -208,7 +209,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
      * @return the ketamaNodes
      */
     protected TreeMap<Long, MemcachedNode> getKetamaNodes() {
-        return ketamaNodes;
+        return ketamaNodes.get();
     }
 
     /**
@@ -263,7 +264,7 @@ public final class RefinedKetamaNodeLocator extends 
SpyObject implements NodeLoc
             }
         }
         assert newNodeMap.size() == numReps * nodes.size();
-        ketamaNodes = newNodeMap;
+        ketamaNodes.set(newNodeMap);
     }
 
     private List<Long> ketamaNodePositionsAtIteration(MemcachedNode node, int 
iteration) {
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/QueryContext.java 
b/core-common/src/main/java/org/apache/kylin/common/QueryContext.java
index 000f7bf..88caa7d 100644
--- a/core-common/src/main/java/org/apache/kylin/common/QueryContext.java
+++ b/core-common/src/main/java/org/apache/kylin/common/QueryContext.java
@@ -25,6 +25,7 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.kylin.common.exceptions.KylinTimeoutException;
 import org.apache.kylin.common.util.RandomUtil;
@@ -59,7 +60,7 @@ public class QueryContext {
     private Object calcitePlan;
 
     private AtomicBoolean isRunning = new AtomicBoolean(true);
-    private volatile Throwable throwable;
+    private AtomicReference<Throwable> throwable = new AtomicReference<>();
     private String stopReason;
     private List<QueryStopListener> stopListeners = 
Lists.newCopyOnWriteArrayList();
 
@@ -171,7 +172,7 @@ public class QueryContext {
         if (!isRunning.compareAndSet(true, false)) {
             return;
         }
-        this.throwable = t;
+        this.throwable.set(t);
         this.stopReason = reason;
         for (QueryStopListener stopListener : stopListeners) {
             stopListener.stop(this);
@@ -179,7 +180,7 @@ public class QueryContext {
     }
 
     public Throwable getThrowable() {
-        return throwable;
+        return throwable.get();
     }
 
     public void addContext(int ctxId, String type, boolean ifCube) {
diff --git a/core-common/src/main/java/org/apache/kylin/common/StorageURL.java 
b/core-common/src/main/java/org/apache/kylin/common/StorageURL.java
index 2d3e04c..f4c810f 100644
--- a/core-common/src/main/java/org/apache/kylin/common/StorageURL.java
+++ b/core-common/src/main/java/org/apache/kylin/common/StorageURL.java
@@ -94,7 +94,7 @@ public class StorageURL {
             }
         }
 
-        this.identifier = n.isEmpty() ? "kylin_metadata" : n;
+        this.identifier = n.isEmpty() || n==null ? "kylin_metadata" : n;
         this.scheme = s;
         this.params = ImmutableMap.copyOf(m);
     }
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/livy/LivyRestExecutor.java 
b/core-common/src/main/java/org/apache/kylin/common/livy/LivyRestExecutor.java
index 03d66aa..449c0ab 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/livy/LivyRestExecutor.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/livy/LivyRestExecutor.java
@@ -63,7 +63,7 @@ public class LivyRestExecutor {
                     livyLog(stateJson, logAppender);
                 }
                 state = stateJson.getString("state");
-                Thread.sleep(10*1000);
+                Thread.sleep(10*1000L);
             }
             if (!LivyStateEnum.success.toString().equalsIgnoreCase(state)) {
                 logAppender.log("livy start execute failed. state is " + 
state);

Reply via email to