ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject [02/50] [abbrv] ignite git commit: fixing cache iteration small refactoring
Date Mon, 30 Nov 2015 13:33:48 GMT
fixing cache iteration
small refactoring


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

Branch: refs/heads/master
Commit: a8edb1ed042b62fc160b497d2f4febb28abc686d
Parents: de08cd5
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Fri Nov 27 11:33:51 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Fri Nov 27 11:33:51 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      | 67 +++++---------------
 .../cache/GridCacheConcurrentMap.java           | 52 +++++----------
 .../distributed/dht/GridNoStorageCacheMap.java  |  4 +-
 .../distributed/near/GridNearCacheAdapter.java  |  4 +-
 .../cache/GridCacheConcurrentMapSelfTest.java   |  2 +-
 5 files changed, 37 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a8edb1ed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index c7467b2..00f65f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -296,7 +296,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
      */
     @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction")
     protected GridCacheAdapter(GridCacheContext<K, V> ctx, int startSize) {
-        this(ctx, new GridCacheConcurrentMap(ctx, startSize, 0.75F, null));
+        this(ctx, new GridCacheConcurrentMap(ctx, startSize, null));
     }
 
     /**
@@ -925,60 +925,25 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
      */
     @Nullable private GridCacheEntryEx entry0(KeyCacheObject key, AffinityTopologyVersion
topVer, boolean create,
         boolean touch) {
-        GridCacheMapEntry cur = map.getEntry(key);
+        GridTriple<GridCacheMapEntry> t = map.putEntryIfObsoleteOrAbsent(topVer, key,
null, create);
 
-        if (cur == null || cur.obsolete()) {
-            GridTriple<GridCacheMapEntry> t = map.putEntryIfObsoleteOrAbsent(
-                topVer,
-                key,
-                null,
-                create);
+        GridCacheEntryEx cur = t.get1();
+        GridCacheEntryEx created = t.get2();
+        GridCacheEntryEx doomed = t.get3();
 
-            cur = t.get1();
+        if (doomed != null && ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
+            // Event notification.
+            ctx.events().addEvent(doomed.partition(), doomed.key(), locNodeId, (IgniteUuid)null,
null,
+                EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, true);
 
-            GridCacheEntryEx created = t.get2();
-            GridCacheEntryEx doomed = t.get3();
+        if (created != null) {
+            // Event notification.
+            if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED))
+                ctx.events().addEvent(created.partition(), created.key(), locNodeId, (IgniteUuid)null,
null,
+                    EVT_CACHE_ENTRY_CREATED, null, false, null, false, null, null, null,
true);
 
-            if (doomed != null && ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
-                // Event notification.
-                ctx.events().addEvent(doomed.partition(),
-                    doomed.key(),
-                    locNodeId,
-                    (IgniteUuid)null,
-                    null,
-                    EVT_CACHE_ENTRY_DESTROYED,
-                    null,
-                    false,
-                    null,
-                    false,
-                    null,
-                    null,
-                    null,
-                    true);
-
-            if (created != null) {
-                // Event notification.
-                if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED))
-                    ctx.events().addEvent(created.partition(),
-                        created.key(),
-                        locNodeId,
-                        (IgniteUuid)null,
-                        null,
-                        EVT_CACHE_ENTRY_CREATED,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        null,
-                        true);
-
-                if (touch)
-                    ctx.evicts().touch(
-                        cur,
-                        topVer);
-            }
+            if (touch)
+                ctx.evicts().touch(cur, topVer);
         }
 
         return cur;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8edb1ed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
index 8293044..1c64387 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
@@ -237,6 +237,7 @@ public class GridCacheConcurrentMap {
      * @param ctx Cache context.
      * @param initCap the initial capacity. The implementation
      *      performs internal sizing to accommodate this many elements.
+     * @param factory Entry factory.
      * @param loadFactor  the load factor threshold, used to control resizing.
      *      Resizing may be performed when the average number of elements per
      *      bin exceeds this threshold.
@@ -248,8 +249,13 @@ public class GridCacheConcurrentMap {
      *      non-positive.
      */
     @SuppressWarnings({"unchecked"})
-    protected GridCacheConcurrentMap(GridCacheContext ctx, int initCap, float loadFactor,
-        int concurrencyLevel) {
+    protected GridCacheConcurrentMap(
+        GridCacheContext ctx,
+        int initCap,
+        GridCacheMapEntryFactory factory,
+        float loadFactor,
+        int concurrencyLevel
+    ) {
         this.ctx = ctx;
 
         if (!(loadFactor > 0) || initCap < 0 || concurrencyLevel <= 0)
@@ -289,6 +295,8 @@ public class GridCacheConcurrentMap {
 
         for (int i = 0; i < segs.length; ++i)
             segs[i] = new Segment(cap, loadFactor);
+
+        this.factory = factory;
     }
 
     /**
@@ -298,20 +306,16 @@ public class GridCacheConcurrentMap {
      * @param ctx Cache context.
      * @param initCap The implementation performs internal
      *      sizing to accommodate this many elements.
-     * @param loadFactor  the load factor threshold, used to control resizing.
-     *      Resizing may be performed when the average number of elements per
-     *      bin exceeds this threshold.
      * @param factory Entries factory.
      * @throws IllegalArgumentException if the initial capacity of
      *      elements is negative or the load factor is non-positive.
      */
-    public GridCacheConcurrentMap(GridCacheContext ctx,
+    public GridCacheConcurrentMap(
+        GridCacheContext ctx,
         int initCap,
-        float loadFactor,
-        @Nullable GridCacheMapEntryFactory factory) {
-        this(ctx, initCap, loadFactor, DFLT_CONCUR_LEVEL);
-
-        this.factory = factory;
+        @Nullable GridCacheMapEntryFactory factory
+    ) {
+        this(ctx, initCap, factory, DFLT_LOAD_FACTOR, DFLT_CONCUR_LEVEL);
     }
 
     /**
@@ -1425,13 +1429,6 @@ public class GridCacheConcurrentMap {
         }
 
         /**
-         * @return Number of reads.
-         */
-        long reads() {
-            return reads.sum();
-        }
-
-        /**
          * @return Header ID.
          */
         int id() {
@@ -1439,21 +1436,6 @@ public class GridCacheConcurrentMap {
         }
 
         /**
-         * @return {@code True} if {@code ID} is even.
-         */
-        boolean even() {
-            return id % 2 == 0;
-        }
-
-        /**
-         * @return {@code True} if {@code ID} is odd.
-         */
-        @SuppressWarnings("BadOddness")
-        boolean odd() {
-            return id % 2 == 1;
-        }
-
-        /**
          * @return Table.
          */
         GridCacheMapEntry[] table() {
@@ -2108,9 +2090,7 @@ public class GridCacheConcurrentMap {
             it.next();
 
             // Cached value.
-            V val = it.currentValue();
-
-            return val;
+            return it.currentValue();
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8edb1ed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
index ef6612b..c6b969d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridNoStorageCacheMap.java
@@ -41,7 +41,7 @@ public class GridNoStorageCacheMap extends GridCacheConcurrentMap {
      * @param ctx Cache context.
      */
     public GridNoStorageCacheMap(GridCacheContext ctx) {
-        super(ctx, 0, 0.75f, 1);
+        super(ctx, 0, null, 0.75f, 1);
     }
 
     /** {@inheritDoc} */
@@ -119,4 +119,4 @@ public class GridNoStorageCacheMap extends GridCacheConcurrentMap {
     @Override public String toString() {
         return S.toString(GridNoStorageCacheMap.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8edb1ed/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
index b471486..c92e4e8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
@@ -123,9 +123,9 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
 
     /** {@inheritDoc} */
     @Override public void onReconnected() {
-        map = new GridCacheConcurrentMap(ctx,
+        map = new GridCacheConcurrentMap(
+            ctx,
             ctx.config().getNearConfiguration().getNearStartSize(),
-            0.75F,
             map.getEntryFactory());
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8edb1ed/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
index 3381a34..1f494c0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java
@@ -362,4 +362,4 @@ public class GridCacheConcurrentMapSelfTest extends GridCommonAbstractTest
{
             assertEquals(0, local().map.iteratorMapSize());
         }
     }
-}
\ No newline at end of file
+}


Mime
View raw message