ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [01/16] incubator-ignite git commit: # ignite-684
Date Tue, 07 Apr 2015 11:42:59 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-665 dfd748ba1 -> 34e30046b


# ignite-684


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

Branch: refs/heads/ignite-665
Commit: 360a41f258fa405d33045d3dc90fb78767b75677
Parents: 60aaaaa
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Apr 6 17:05:20 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Apr 6 17:21:28 2015 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       |   3 -
 .../cacheobject/IgniteCacheObjectProcessor.java |   3 +-
 .../IgniteCacheObjectProcessorImpl.java         |  20 +--
 .../org/apache/ignite/lang/IgniteImmutable.java |  49 ------
 .../GridCacheOnCopyFlagAbstractSelfTest.java    |  85 ----------
 .../GridCacheReturnValueTransferSelfTest.java   |   1 -
 .../IgniteCacheStoreValueAbstractTest.java      | 168 ++++++++++++++++++-
 7 files changed, 169 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index f7f8e26..c90de92 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -1415,11 +1415,8 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K,
V> {
      * Gets flag indicating whether copy of of the value stored in cache should be created
      * for cache operation implying return value. Also if this flag is set copies are created
for values
      * passed to {@link CacheInterceptor} and to {@link CacheEntryProcessor}.
-     * <p>
-     * Copies are not created for immutable types, see {@link IgniteImmutable}.
      *
      * @return Copy on get flag.
-     * @see IgniteImmutable
      */
     public boolean isCopyOnRead() {
         return cpOnRead;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index fff6dd1..358ef1a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -160,8 +160,7 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
 
     /**
      * @param obj Value.
-     * @return {@code True} if object is of known immutable type of it is marked
-     *          with {@link IgniteImmutable} annotation.
+     * @return {@code True} if object is of known immutable type.
      */
     public boolean immutable(Object obj);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index 7b3f270..bd79d0c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -45,10 +45,6 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter
impleme
     /** Immutable classes. */
     private static final Collection<Class<?>> IMMUTABLE_CLS = new HashSet<>();
 
-    /** */
-    private final GridBoundedConcurrentLinkedHashMap<Class<?>, Boolean> reflectionCache
=
-            new GridBoundedConcurrentLinkedHashMap<>(1024, 1024);
-
     /**
      *
      */
@@ -216,21 +212,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter
impleme
     @Override public boolean immutable(Object obj) {
         assert obj != null;
 
-        Class<?> cls = obj.getClass();
-
-        if (IMMUTABLE_CLS.contains(cls))
-            return true;
-
-        Boolean immutable = reflectionCache.get(cls);
-
-        if (immutable != null)
-            return immutable;
-
-        immutable = IgniteUtils.hasAnnotation(cls, IgniteImmutable.class);
-
-        reflectionCache.putIfAbsent(cls, immutable);
-
-        return immutable;
+        return IMMUTABLE_CLS.contains(obj.getClass());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/main/java/org/apache/ignite/lang/IgniteImmutable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteImmutable.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteImmutable.java
deleted file mode 100644
index bcecd7d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteImmutable.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.lang;
-
-import org.apache.ignite.cache.*;
-import org.apache.ignite.configuration.*;
-
-import java.lang.annotation.*;
-
-/**
- * Immutable types should be annotated with this annotation to avoid unnecessary
- * copying (e.g. in case of stateless compute closures or cache values).
- * <p>
- * If cache configuration flag {@link CacheConfiguration#isCopyOnRead()} is set
- * then for each operation implying return value copy of the value stored in cache is created.
- * Also if this flag is set copies are created for values passed to {@link CacheInterceptor}
and
- * to {@link CacheEntryProcessor}.
- * <p>
- * Copies are not created for types marked with {@link IgniteImmutable} annotation and for
known
- * immutable types:
- * <ul>
- *     <li>Boxed primitives ({@link Integer}, {@link Long}, ...)</li>
- *     <li>{@link String}</li>
- *     <li>{@link java.util.UUID}</li>
- *     <li>{@link java.math.BigDecimal}</li>
- *     <li>{@link org.apache.ignite.lang.IgniteUuid}</li>
- * </ul>
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface IgniteImmutable {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java
index 538567c..c1ad283 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOnCopyFlagAbstractSelfTest.java
@@ -355,54 +355,6 @@ public abstract class GridCacheOnCopyFlagAbstractSelfTest extends GridCacheAbstr
     /**
      * @throws Exception If failed.
      */
-    public void testPutGetImmutable() throws Exception {
-        noInterceptor = true;
-
-        IgniteCache<TestImmutableKey, TestImmutableValue> cache = grid(0).cache(null);
-
-        Map<TestImmutableKey, TestImmutableValue> map = new HashMap<>();
-
-        for (int i = 0; i < ITER_CNT; i++) {
-            TestImmutableKey key = new TestImmutableKey(i, i);
-            TestImmutableValue val = new TestImmutableValue(i);
-
-            cache.put(key, val);
-
-            map.put(key, val);
-        }
-
-        GridCacheAdapter cache0 = internalCache(cache);
-
-        GridCacheContext cctx = cache0.context();
-
-        for (Map.Entry<TestImmutableKey, TestImmutableValue> e : map.entrySet()) {
-            GridCacheEntryEx entry = cache0.peekEx(e.getKey());
-
-            assertNotNull("No entry for key: " + e.getKey(), entry);
-
-            TestKey key0 = entry.key().value(cctx.cacheObjectContext(), false);
-
-            assertSame(key0, e.getKey());
-
-            TestKey key1 = entry.key().value(cctx.cacheObjectContext(), true);
-
-            assertSame(key0, key1);
-
-            TestImmutableValue val0 = entry.rawGet().value(cctx.cacheObjectContext(), false);
-
-            assertNotSame(val0, e.getValue());
-
-            TestImmutableValue val1 = entry.rawGet().value(cctx.cacheObjectContext(), true);
-
-            assertNotSame(val0, val1);
-
-            assertNotSame(e.getValue(), cache.get(e.getKey()));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
     public void testPutGetKnownImmutable() throws Exception {
         noInterceptor = true;
 
@@ -648,41 +600,4 @@ public abstract class GridCacheOnCopyFlagAbstractSelfTest extends GridCacheAbstr
             this.delegate = delegate;
         }
     }
-
-    /**
-     *
-     */
-    @IgniteImmutable
-    public static class TestImmutableKey extends TestKey {
-        /**
-         *
-         */
-        public TestImmutableKey() {
-            // No-op.
-        }
-
-        /**
-         * @param key Key.
-         * @param field Field.
-         */
-        public TestImmutableKey(int key, int field) {
-            super(key, field);
-        }
-    }
-
-    /**
-     *
-     */
-    @IgniteImmutable
-    public static class TestImmutableValue {
-        /** */
-        public int val;
-
-        /**
-         * @param val Value.
-         */
-        public TestImmutableValue(int val) {
-            this.val = val;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
index 0dd23a7..9446486 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
@@ -155,7 +155,6 @@ public class GridCacheReturnValueTransferSelfTest extends GridCommonAbstractTest
     /**
      *
      */
-    @IgniteImmutable
     private static class TestObject implements Externalizable {
         /**
          *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/360a41f2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
index 9552258..3835c8e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
@@ -40,6 +40,9 @@ import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
  *
  */
 public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstractTest {
+    /** */
+    private boolean cpyOnRead;
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -58,6 +61,8 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
 
         assertTrue(ccfg.isCopyOnRead());
 
+        ccfg.setCopyOnRead(cpyOnRead);
+
         assertEquals(FULL_SYNC, ccfg.getWriteSynchronizationMode());
 
         ccfg.setCacheStoreFactory(singletonFactory(new CacheStoreAdapter() {
@@ -93,10 +98,26 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
         return 2 * 60_000;
     }
 
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
     /**
      * @throws Exception If failed.
      */
     public void testValueNotStored() throws Exception {
+        cpyOnRead = true;
+
+        startGrids();
+
         IgniteCache<TestKey, TestValue> cache = grid(0).cache(null);
 
         Affinity<Object> aff = grid(0).affinity(null);
@@ -221,10 +242,18 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
                 e = ((GridNearCacheAdapter)cache0).dht().peekEx(key);
 
             if (e != null) {
+                KeyCacheObject keyObj = e.key();
+
+                assertNotNull(keyObj);
+
+                assertEquals(KeyCacheObjectImpl.class, keyObj.getClass());
+
+                assertNotNull("Unexpected value, node: " + g,
+                    GridTestUtils.getFieldValue(keyObj, CacheObjectAdapter.class, "val"));
+
                 CacheObject obj = e.rawGet();
 
                 if (obj != null) {
-                    assertNotNull(obj);
                     assertEquals(CacheObjectImpl.class, obj.getClass());
 
                     assertNull("Unexpected value, node: " + g,
@@ -249,6 +278,143 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testValueStored() throws Exception {
+        cpyOnRead = false;
+
+        startGrids();
+
+        IgniteCache<TestKey, TestValue> cache = grid(0).cache(null);
+
+        Affinity<Object> aff = grid(0).affinity(null);
+
+        for (int i = 0; i < 100; i++) {
+            TestKey key = new TestKey(i);
+            TestValue val = new TestValue(i);
+
+            cache.put(key, val);
+
+            checkHasValue(aff, key);
+
+            for (int g = 0; g < gridCount(); g++)
+                assertNotNull(grid(g).cache(null).get(key));
+
+            checkHasValue(aff, key);
+
+            cache.invoke(key, new CacheEntryProcessor<TestKey, TestValue, Object>()
{
+                @Override public Object process(MutableEntry<TestKey, TestValue> entry,
Object... args) {
+                    assertNotNull(entry.getValue());
+
+                    entry.setValue(new TestValue(10_000));
+
+                    return new TestValue(20_000);
+                }
+            });
+
+            checkHasValue(aff, key);
+
+            for (int g = 0; g < gridCount(); g++)
+                assertNotNull(grid(g).cache(null).get(key));
+
+            checkHasValue(aff, key);
+
+            cache.remove(key);
+
+            for (int g = 0; g < gridCount(); g++)
+                assertNull(grid(g).cache(null).get(key));
+
+            try (IgniteDataStreamer<TestKey, TestValue> streamer  = grid(0).dataStreamer(null))
{
+                streamer.addData(key, val);
+            }
+
+            checkHasValue(aff, key);
+
+            cache.remove(key);
+
+            atomicClockModeDelay(cache);
+
+            try (IgniteDataStreamer<TestKey, TestValue> streamer  = grid(0).dataStreamer(null))
{
+                streamer.allowOverwrite(true);
+
+                streamer.addData(key, val);
+            }
+
+            checkHasValue(aff, key);
+
+            if (aff.isPrimaryOrBackup(grid(0).localNode(), key)) {
+                cache.localEvict(Collections.singleton(key));
+
+                assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+
+                cache.localPromote(Collections.singleton(key));
+
+                assertNotNull(cache.localPeek(key, CachePeekMode.ONHEAP));
+
+                checkHasValue(aff, key);
+            }
+        }
+    }
+
+    /**
+     * @param aff Affinity.
+     * @param key Key.
+     */
+    private void checkHasValue(Affinity<Object> aff, Object key) {
+        for (int g = 0; g < gridCount(); g++) {
+            GridCacheAdapter cache0 = internalCache(grid(g), null);
+
+            GridCacheEntryEx e = cache0.peekEx(key);
+
+            if (e == null && cache0.isNear())
+                e = ((GridNearCacheAdapter)cache0).dht().peekEx(key);
+
+            if (e != null) {
+                KeyCacheObject keyObj = e.key();
+
+                assertNotNull(keyObj);
+
+                assertEquals(KeyCacheObjectImpl.class, keyObj.getClass());
+
+                assertNotNull("Unexpected value, node: " + g,
+                    GridTestUtils.getFieldValue(keyObj, CacheObjectAdapter.class, "val"));
+
+                CacheObject obj = e.rawGet();
+
+                if (obj != null) {
+                    assertEquals(CacheObjectImpl.class, obj.getClass());
+
+                    assertNotNull("Unexpected value, node: " + g,
+                        GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val"));
+
+                    Object val0 = obj.value(cache0.context().cacheObjectContext(), true);
+
+                    assertNotNull("Unexpected value after value() requested1: " + g,
+                        GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val"));
+
+                    Object val1 = obj.value(cache0.context().cacheObjectContext(), true);
+
+                    assertNotNull("Unexpected value after value() requested2: " + g,
+                        GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val"));
+
+                    assertSame(val0, val1);
+
+                    Object val2 = obj.value(cache0.context().cacheObjectContext(), false);
+
+                    assertNotNull("Unexpected value after value() requested3: " + g,
+                        GridTestUtils.getFieldValue(obj, CacheObjectAdapter.class, "val"));
+
+                    assertSame(val1, val2);
+                }
+                else
+                    assertFalse(aff.isPrimaryOrBackup(grid(g).localNode(), key));
+            }
+            else
+                assertFalse("Entry not found, node: " + g, aff.isPrimaryOrBackup(grid(g).localNode(),
key));
+        }
+    }
+
+    /**
      *
      */
     static class TestKey implements Serializable {


Mime
View raw message