You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dm...@apache.org on 2016/07/22 11:21:13 UTC

[4/5] ignite git commit: IGNITE-3505: BinaryObject keys can't be reused because of partition caching.

IGNITE-3505: BinaryObject keys can't be reused because of partition caching.


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

Branch: refs/heads/master
Commit: 0f1a0ccdbfc44658ee76024fc06ca39d81efc0a8
Parents: 6c5218f
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Jul 22 14:19:03 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Jul 22 14:19:03 2016 +0300

----------------------------------------------------------------------
 .../binary/CacheObjectBinaryProcessorImpl.java  |  6 ++++
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 38 ++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0f1a0ccd/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 8079a0c..8400594 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -775,6 +775,12 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
             return super.toCacheKeyObject(ctx, obj, userObj, partition);
 
         if (obj instanceof KeyCacheObject) {
+            if (obj instanceof BinaryObjectImpl) {
+                // Need to create a copy because the key can be reused at the application layer after that (IGNITE-3505).
+                BinaryObjectImpl bObj = (BinaryObjectImpl)obj;
+                obj = new BinaryObjectImpl(bObj.context(), bObj.array(), bObj.start());
+            }
+
             ((KeyCacheObject)obj).partition(partition);
 
             return (KeyCacheObject)obj;

http://git-wip-us.apache.org/repos/asf/ignite/blob/0f1a0ccd/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index e3e538b..be2ce9b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -23,11 +23,15 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import junit.framework.TestCase;
 import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
@@ -63,6 +67,7 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
 import static org.apache.ignite.cache.CacheMode.REPLICATED;
 
 /**
@@ -74,10 +79,12 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
         CacheConfiguration cacheCfg = new CacheConfiguration();
-
         cacheCfg.setCacheMode(REPLICATED);
 
-        cfg.setCacheConfiguration(cacheCfg);
+        CacheConfiguration cacheCfg2 = new CacheConfiguration("partitioned");
+        cacheCfg2.setCacheMode(PARTITIONED);
+
+        cfg.setCacheConfiguration(cacheCfg, cacheCfg2);
 
         BinaryConfiguration bCfg = new BinaryConfiguration();
 
@@ -1359,6 +1366,33 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testSameBinaryKey() throws Exception {
+        IgniteCache<BinaryObject, BinaryObject> replicatedCache =
+            jcache(0).withKeepBinary();
+
+        IgniteCache<BinaryObject, BinaryObject> partitionedCache =
+            jcache(0, "partitioned").withKeepBinary();
+
+        BinaryObjectBuilder keyBuilder = ignite(0).binary().builder("keyType")
+            .setField("F1", "V1").hashCode("V1".hashCode());
+
+        BinaryObjectBuilder valBuilder = ignite(0).binary().builder("valueType")
+            .setField("F2", "V2")
+            .setField("F3", "V3");
+
+        BinaryObject key = keyBuilder.build();
+        BinaryObject val = valBuilder.build();
+
+        replicatedCache.put(key, val);
+        partitionedCache.put(key, val);
+
+        assertNotNull(replicatedCache.get(key));
+        assertNotNull(partitionedCache.get(key));
+    }
+
+    /**
      * @param obj Object.
      * @return Object in binary format.
      */