Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA40E1744A for ; Tue, 7 Apr 2015 11:44:21 +0000 (UTC) Received: (qmail 78411 invoked by uid 500); 7 Apr 2015 11:44:06 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 78383 invoked by uid 500); 7 Apr 2015 11:44:06 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 78374 invoked by uid 99); 7 Apr 2015 11:44:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2015 11:44:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 07 Apr 2015 11:43:40 +0000 Received: (qmail 73634 invoked by uid 99); 7 Apr 2015 11:42:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2015 11:42:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2E4E8E0990; Tue, 7 Apr 2015 11:42:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 07 Apr 2015 11:42:59 -0000 Message-Id: <0998388a0a464889b9fbf101e576cae4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/16] incubator-ignite git commit: # ignite-684 X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Mon Apr 6 17:05:20 2015 +0300 Committer: sboikov 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 extends MutableConfiguration { * 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}. - *

- * 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> IMMUTABLE_CLS = new HashSet<>(); - /** */ - private final GridBoundedConcurrentLinkedHashMap, 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). - *

- * 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}. - *

- * Copies are not created for types marked with {@link IgniteImmutable} annotation and for known - * immutable types: - *

    - *
  • Boxed primitives ({@link Integer}, {@link Long}, ...)
  • - *
  • {@link String}
  • - *
  • {@link java.util.UUID}
  • - *
  • {@link java.math.BigDecimal}
  • - *
  • {@link org.apache.ignite.lang.IgniteUuid}
  • - *
- */ -@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 cache = grid(0).cache(null); - - Map 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 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 cache = grid(0).cache(null); Affinity 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 cache = grid(0).cache(null); + + Affinity 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() { + @Override public Object process(MutableEntry 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 streamer = grid(0).dataStreamer(null)) { + streamer.addData(key, val); + } + + checkHasValue(aff, key); + + cache.remove(key); + + atomicClockModeDelay(cache); + + try (IgniteDataStreamer 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 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 {