geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject incubator-geode git commit: GEODE-1587: Replaced AtomicInteger with AtomicIntegerFieldUpdater
Date Wed, 13 Jul 2016 19:04:39 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 31336f15a -> c4cf82101


GEODE-1587: Replaced AtomicInteger with AtomicIntegerFieldUpdater

        * Use of AtomicIntegerFieldUpdater decereased the memory overhead per entry during
index creation

	This closes #191


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

Branch: refs/heads/develop
Commit: c4cf821018e5727323f7819b783677f4dd8da21f
Parents: 31336f1
Author: nabarun <nnag@pivotal.io>
Authored: Mon Jun 27 10:25:20 2016 -0700
Committer: nabarun <nnag@pivotal.io>
Committed: Wed Jul 13 12:03:37 2016 -0700

----------------------------------------------------------------------
 .../query/internal/index/AbstractIndex.java     | 29 +++++++++++---------
 1 file changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c4cf8210/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
b/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
index 393428b..6c0d509 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
@@ -24,7 +24,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -96,7 +96,10 @@ import com.gemstone.gemfire.pdx.internal.PdxString;
 public abstract class AbstractIndex implements IndexProtocol
 {
   private static final Logger logger = LogService.getLogger();
-  
+
+  private static final AtomicIntegerFieldUpdater<RegionEntryToValuesMap> atomicUpdater
=  AtomicIntegerFieldUpdater
+    .newUpdater(RegionEntryToValuesMap.class, "numValues");
+
   final String indexName;
 
   final Region region;
@@ -1421,7 +1424,7 @@ public abstract class AbstractIndex implements IndexProtocol
    * @return true if limit is satisfied.
    */
   protected boolean verifyLimit(Collection result, int limit,
-      ExecutionContext context) {   
+      ExecutionContext context) {
     if (limit > 0) {
      /* if (!context.isDistinct()) {
         return ((Bag)result).size() == limit;
@@ -1737,7 +1740,7 @@ public abstract class AbstractIndex implements IndexProtocol
   {
     protected Map map;
     private boolean useList;
-    private AtomicInteger numValues = new AtomicInteger(0);
+    volatile int numValues;
 
     RegionEntryToValuesMap(boolean useList) {
       this.map = new ConcurrentHashMap(2, 0.75f, 1);
@@ -1786,7 +1789,7 @@ public abstract class AbstractIndex implements IndexProtocol
         coll.add(value);
         map.put(entry, coll);
       }
-      numValues.incrementAndGet();
+      atomicUpdater.incrementAndGet(this);
     }
 
     public void addAll(RegionEntry entry, Collection values)
@@ -1796,7 +1799,7 @@ public abstract class AbstractIndex implements IndexProtocol
         Collection coll = useList?new ArrayList(values.size()):new IndexConcurrentHashSet(values.size(),
0.75f, 1);
         coll.addAll(values);
         map.put(entry, coll);
-        numValues.addAndGet(values.size());
+        atomicUpdater.addAndGet(this,values.size());
       } else if (object instanceof Collection) {
         Collection coll = (Collection) object;
         // If its a list query might get ConcurrentModificationException.
@@ -1815,7 +1818,7 @@ public abstract class AbstractIndex implements IndexProtocol
         coll.add(object);
         map.put(entry, coll);
       }
-      numValues.addAndGet(values.size());
+      atomicUpdater.addAndGet(this,values.size());
     }
 
     public Object get(RegionEntry entry)
@@ -1853,14 +1856,14 @@ public abstract class AbstractIndex implements IndexProtocol
           if (coll.size() == 0) {
             map.remove(entry);
           }
-          numValues.decrementAndGet();
+          atomicUpdater.decrementAndGet(this);
         }
       }
       else {
         if (object.equals(value)) {
           map.remove(entry);
         }
-        this.numValues.decrementAndGet();
+        atomicUpdater.decrementAndGet(this);
       }
     }
 
@@ -1868,7 +1871,7 @@ public abstract class AbstractIndex implements IndexProtocol
     {
       Object retVal = map.remove(entry);
       if (retVal != null) {
-            numValues.addAndGet((retVal instanceof Collection) ?
+        atomicUpdater.addAndGet(this,(retVal instanceof Collection) ?
               - ((Collection) retVal).size() : -1 );
       }
       return retVal;
@@ -1889,7 +1892,7 @@ public abstract class AbstractIndex implements IndexProtocol
 
     public int getNumValues()
     {
-      return this.numValues.get();
+      return atomicUpdater.get(this);
     }
 
     public int getNumEntries()
@@ -2151,7 +2154,7 @@ public abstract class AbstractIndex implements IndexProtocol
     public void clear()
     {
       map.clear();
-      this.numValues.set(0);
+      atomicUpdater.set(this,0);
     }
 
     public Set entrySet()
@@ -2168,7 +2171,7 @@ public abstract class AbstractIndex implements IndexProtocol
     public void replace(RegionEntry entry, Object values) {
       int numOldValues = getNumValues(entry);
       this.map.put(entry, values);
-      this.numValues.addAndGet(((values instanceof Collection) ? ((Collection) values)
+      atomicUpdater.addAndGet(this,((values instanceof Collection) ? ((Collection) values)
           .size() : 1) - numOldValues);
     }
   }


Mime
View raw message