ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-3505: BinaryObject keys can't be reused because of partition caching.
Date Wed, 20 Jul 2016 13:42:48 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3505 7079c18a6 -> edd5ca50f


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/edd5ca50
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/edd5ca50
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/edd5ca50

Branch: refs/heads/ignite-3505
Commit: edd5ca50fc2e9c13773aa0de159d88284fd7ae57
Parents: 7079c18
Author: Denis Magda <dmagda@gridgain.com>
Authored: Wed Jul 20 16:42:40 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Wed Jul 20 16:42:40 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/edd5ca50/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/edd5ca50/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.
      */


Mime
View raw message