ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [18/19] incubator-ignite git commit: IGNITE-49 Fixed extra read events.
Date Tue, 20 Jan 2015 09:16:13 GMT
IGNITE-49 Fixed extra read events.


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

Branch: refs/heads/ignite-49
Commit: d699216521219e72c7a1dc0b7ab58d13d0569259
Parents: 3ea7ea0
Author: nikolay_tikhonov <ntikhonov@gridgain.com>
Authored: Tue Jan 20 12:13:35 2015 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Tue Jan 20 12:13:35 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      | 39 ++++++++++++--------
 .../cache/GridCacheMetricsAdapter.java          | 12 +++++-
 .../dht/GridPartitionedGetFuture.java           |  2 +-
 .../dht/atomic/GridDhtAtomicCache.java          |  4 +-
 .../dht/colocated/GridDhtColocatedCache.java    |  4 +-
 .../local/atomic/GridLocalAtomicCache.java      | 27 +++++++++-----
 .../cache/GridCacheAbstractMetricsSelfTest.java | 26 +++++--------
 7 files changed, 69 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
index 84cd94c..4e0cb9e 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheAdapter.java
@@ -2088,9 +2088,9 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Nullable @Override public V put(final K key, final V val, @Nullable final GridCacheEntryEx<K,
V> cached,
         final long ttl, @Nullable final IgnitePredicate<GridCacheEntry<K, V>>[]
filter) throws IgniteCheckedException {
-        boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
-        long start = statisticsEnabled ? System.nanoTime() : 0L;
+        long start = statsEnabled ? System.nanoTime() : 0L;
 
         A.notNull(key, "key", val, "val");
 
@@ -2113,10 +2113,8 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
             }
         }));
 
-        if (statisticsEnabled) {
-            ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
-            ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);
-        }
+        if (statsEnabled)
+            ctx.cache().metrics0().addPutAndGetTimeNanos(System.nanoTime() - start);
 
         return prevValue;
     }
@@ -2540,9 +2538,9 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public boolean putxIfAbsent(final K key, final V val) throws IgniteCheckedException
{
-        boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
-        long start = statisticsEnabled ? System.nanoTime() : 0L;
+        long start = statsEnabled ? System.nanoTime() : 0L;
 
         A.notNull(key, "key", val, "val");
 
@@ -2565,7 +2563,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
             }
         });
 
-        if (statisticsEnabled && stored)
+        if (statsEnabled && stored)
             ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
 
         return stored;
@@ -2938,15 +2936,24 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
     /** {@inheritDoc} */
     @Override public boolean removex(final K key, final IgnitePredicate<GridCacheEntry<K,
V>>... filter)
         throws IgniteCheckedException {
-        return removex(key, null, filter);
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        long start = statsEnabled ? System.nanoTime() : 0L;
+
+        boolean removed = removex(key, null, filter);
+
+        if (statsEnabled && removed)
+            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);
+
+        return removed;
     }
 
     /** {@inheritDoc} */
     @Override public boolean removex(final K key, @Nullable final GridCacheEntryEx<K,
V> entry,
         @Nullable final IgnitePredicate<GridCacheEntry<K, V>>... filter) throws
IgniteCheckedException {
-        boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
-        long start = statisticsEnabled ? System.nanoTime() : 0L;
+        long start = statsEnabled ? System.nanoTime() : 0L;
 
         ctx.denyOnLocalRead();
 
@@ -2967,7 +2974,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
             }
         });
 
-        if (statisticsEnabled && removed)
+        if (statsEnabled && removed)
             ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);
 
         return removed;
@@ -3151,9 +3158,9 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
 
     /** {@inheritDoc} */
     @Override public boolean remove(final K key, final V val) throws IgniteCheckedException
{
-        boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
-        long start = statisticsEnabled ? System.nanoTime() : 0L;
+        long start = statsEnabled ? System.nanoTime() : 0L;
 
         ctx.denyOnLocalRead();
 
@@ -3184,7 +3191,7 @@ public abstract class GridCacheAdapter<K, V> extends GridMetadataAwareAdapter
im
             }
         });
 
-        if (statisticsEnabled && removed)
+        if (statsEnabled && removed)
             ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);
 
         return removed;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
index e30b38b..2c22aee 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/GridCacheMetricsAdapter.java
@@ -270,7 +270,7 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
     }
 
     /**
-     * Increments the remove and get time accumulators.
+     * Increments remove and get time accumulators.
      *
      * @param duration the time taken in nanoseconds.
      */
@@ -279,6 +279,16 @@ public class GridCacheMetricsAdapter implements GridCacheMetrics, Externalizable
         getTimeNanos += duration;
     }
 
+    /**
+     * Increments put and get time accumulators.
+     *
+     * @param duration the time taken in nanoseconds.
+     */
+    public void addPutAndGetTimeNanos(long duration) {
+        putTimeNanos += duration;
+        getTimeNanos += duration;
+    }
+
     /** {@inheritDoc} */
     @Override public float getAverageGetTime() {
         long timeNanos = getTimeNanos;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index a5ddaf7..3e3d8d4 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -425,7 +425,7 @@ public class GridPartitionedGetFuture<K, V> extends GridCompoundIdentityFuture<M
                                 /*read-through*/false,
                                 /*fail-fast*/true,
                                 /*unmarshal*/true,
-                                /**update-metrics*/true,
+                                /**update-metrics*/false,
                                 /*event*/true,
                                 /*temporary*/false,
                                 subjId,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index c3f1bf5..d27323b 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -886,7 +886,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K,
V> {
                                 /*read-through*/false,
                                 /*fail-fast*/true,
                                 /*unmarshal*/true,
-                                /**update-metrics*/true,
+                                /**update-metrics*/false,
                                 /*event*/true,
                                 /*temporary*/false,
                                 subjId,
@@ -941,6 +941,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K,
V> {
 
                 if (!success)
                     break;
+                else
+                    ctx.cache().metrics0().onRead(true);
             }
 
             if (success) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index 62c12f9..5d9226c 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -276,7 +276,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
                                 /*read-through*/false,
                                 /*fail-fast*/true,
                                 /*unmarshal*/true,
-                                /**update-metrics*/true,
+                                /**update-metrics*/false,
                                 /*event*/true,
                                 /*temporary*/false,
                                 subjId,
@@ -329,6 +329,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
 
                 if (!success)
                     break;
+                else
+                    ctx.cache().metrics0().onRead(true);
             }
 
             if (success) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
index fca2dd5..7f495ce 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -403,19 +403,28 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K,
V> {
     @Override public boolean removex(K key,
         @Nullable GridCacheEntryEx<K, V> entry,
         @Nullable IgnitePredicate<GridCacheEntry<K, V>>... filter) throws IgniteCheckedException
{
+        boolean statsEnabled = ctx.config().isStatisticsEnabled();
+
+        long start = statsEnabled ? System.nanoTime() : 0L;
+
         A.notNull(key, "key");
 
         ctx.denyOnLocalRead();
 
-        return (Boolean)updateAllInternal(DELETE,
-            Collections.singleton(key),
-            null,
-            null,
-            expiryPerCall(),
-            false,
-            false,
-            filter,
-            ctx.isStoreEnabled());
+        Boolean removed = (Boolean)updateAllInternal(DELETE,
+                Collections.singleton(key),
+                null,
+                null,
+                expiryPerCall(),
+                false,
+                false,
+                filter,
+                ctx.isStoreEnabled());
+
+        if (statsEnabled && removed)
+            ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);
+
+        return  removed;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d6992165/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
index 59b70b3..5767494 100644
--- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractMetricsSelfTest.java
@@ -35,9 +35,6 @@ import static java.util.concurrent.TimeUnit.*;
  */
 public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstractSelfTest
{
     /** */
-    public static final String CACHE_NAME = "metric_test";
-
-    /** */
     private static final int KEY_CNT = 50;
 
     /** {@inheritDoc} */
@@ -158,21 +155,16 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         jcache.put(1, 1);
 
         assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
-        assertEquals(0, cache.metrics().reads());
-
-        long start = System.nanoTime();
 
         jcache.get(1);
 
         float averageGetTime = cache.metrics().getAverageGetTime();
 
-        assert averageGetTime >= 0;
-
-        assertEquals(1, cache.metrics().reads());
+        assert averageGetTime > 0;
 
         jcache.get(2);
 
-        assert cache.metrics().getAverageGetTime() >= 0;
+        assert cache.metrics().getAverageGetTime() > 0;
     }
 
     /**
@@ -182,12 +174,13 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         IgniteCache<Integer, Integer> jcache = grid(0).jcache(null);
         GridCache<Object, Object> cache = grid(0).cache(null);
 
+        assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
+
         jcache.put(1, 1);
         jcache.put(2, 2);
         jcache.put(3, 3);
 
         assertEquals(0.0, cache.metrics().getAverageGetTime(), 0.0);
-        assertEquals(0, cache.metrics().reads());
 
         Set<Integer> keys = new HashSet<>();
         keys.add(1);
@@ -196,10 +189,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
 
         jcache.getAll(keys);
 
-        float averageGetTime = cache.metrics().getAverageGetTime();
-
-        assert averageGetTime >= 0;
-        assertEquals(3, cache.metrics().reads());
+        assert cache.metrics().getAverageGetTime() > 0;
     }
 
     /**
@@ -357,7 +347,8 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
         for (int i = 0; i < keyCnt; i++) {
             assertNull("Value is not null for key: " + i, cache.get(i));
 
-            if (cache.affinity().isPrimary(grid(0).localNode(), i))
+            if (cache.configuration().getCacheMode() == GridCacheMode.REPLICATED ||
+                cache.affinity().isPrimary(grid(0).localNode(), i))
                 expReads++;
             else
                 expReads += 2;
@@ -390,6 +381,9 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract
     public void testMissesOnEmptyCache() throws Exception {
         GridCache<Integer, Integer> cache = grid(0).cache(null);
 
+        assertEquals("Expected 0 read", 0, cache.metrics().reads());
+        assertEquals("Expected 0 miss", 0, cache.metrics().misses());
+
         Integer key =  null;
 
         for (int i = 0; i < 1000; i++) {


Mime
View raw message