geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [01/27] incubator-geode git commit: GEODE-1803 Inefficient code in ClientMetadataService.getServerToFilterMap()
Date Tue, 30 Aug 2016 02:57:45 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-420 5d0cd4304 -> a3a5a04cd


GEODE-1803 Inefficient code in ClientMetadataService.getServerToFilterMap()

Created a Random to use in methods needing it.  Replaced Collections.shuffle()
with random selection from an ArrayList.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/9184b593
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9184b593
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9184b593

Branch: refs/heads/feature/GEODE-420
Commit: 9184b593ffca411e03b3c438d93e04225ef038df
Parents: 7f4992c
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
Authored: Fri Aug 26 10:02:13 2016 -0700
Committer: Bruce Schuchardt <bschuchardt@pivotal.io>
Committed: Fri Aug 26 10:17:42 2016 -0700

----------------------------------------------------------------------
 .../client/internal/ClientPartitionAdvisor.java | 23 +++++++++-----------
 1 file changed, 10 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9184b593/geode-core/src/main/java/com/gemstone/gemfire/cache/client/internal/ClientPartitionAdvisor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/client/internal/ClientPartitionAdvisor.java
b/geode-core/src/main/java/com/gemstone/gemfire/cache/client/internal/ClientPartitionAdvisor.java
index d3b0cf3..c8a523d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/client/internal/ClientPartitionAdvisor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/client/internal/ClientPartitionAdvisor.java
@@ -26,20 +26,18 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import org.apache.logging.log4j.Logger;
+
 import com.gemstone.gemfire.InternalGemFireException;
 import com.gemstone.gemfire.cache.FixedPartitionAttributes;
-import com.gemstone.gemfire.internal.cache.BucketServerLocation66;
 import com.gemstone.gemfire.cache.PartitionResolver;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.distributed.internal.ServerLocation;
 import com.gemstone.gemfire.internal.ClassPathLoader;
-import com.gemstone.gemfire.internal.cache.BucketServerLocation;
-import com.gemstone.gemfire.internal.cache.FixedPartitionAttributesImpl;
 import com.gemstone.gemfire.internal.cache.BucketServerLocation66;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.FixedPartitionAttributesImpl;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import com.gemstone.gemfire.internal.logging.LogService;
-import org.apache.logging.log4j.Logger;
 
 /**
  * Stores the information such as partition attributes and meta data details
@@ -66,6 +64,8 @@ public class ClientPartitionAdvisor {
   private Map<String, List<Integer>> fixedPAMap = null;
 
   private boolean fpaAttrsCompletes = false;
+  
+  private Random random = new Random();
 
   @SuppressWarnings("unchecked")
   public ClientPartitionAdvisor(int totalNumBuckets, String colocatedWith,
@@ -115,21 +115,18 @@ public class ClientPartitionAdvisor {
       if (locationsCopy.size() == 1) {
         return locationsCopy.get(0);
       }
-      int index = new Random().nextInt(locationsCopy.size() - 1);
+      int index = random.nextInt(locationsCopy.size());
       return locationsCopy.get(index);
     }
     return null;
   }
 
   public ServerLocation adviseRandomServerLocation() {
-    ArrayList<Integer> bucketList = new ArrayList<Integer>(
-        this.bucketServerLocationsMap.keySet());
-
-    if (bucketList.size() > 0) {
-      Collections.shuffle(bucketList);
+    ArrayList<Integer> bucketList = new ArrayList<Integer>(this.bucketServerLocationsMap.keySet());
+    int size = bucketList.size();
+    if (size > 0) {
       List<BucketServerLocation66> locations = this.bucketServerLocationsMap
-          .get(bucketList.get(0));
-
+          .get(bucketList.get(random.nextInt(size)));
       if (locations != null) {
         List<BucketServerLocation66> serverList = new ArrayList<BucketServerLocation66>(
             locations);


Mime
View raw message