ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-3300
Date Tue, 26 Jul 2016 06:29:10 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3300 6670ad62d -> 7ca0d8d59


ignite-3300


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

Branch: refs/heads/ignite-3300
Commit: 7ca0d8d591ea1a8c3e43b91312771f3d7ef4db6f
Parents: 6670ad6
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Jul 26 09:28:49 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Jul 26 09:28:49 2016 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryObjectImpl.java       | 11 +++++++++
 .../processors/cache/KeyCacheObject.java        |  7 ++++++
 .../processors/cache/KeyCacheObjectImpl.java    |  8 +++++++
 .../binary/CacheObjectBinaryProcessorImpl.java  | 23 ++++++++-----------
 .../IgniteCacheObjectProcessorImpl.java         | 24 +++++++++++++++++++-
 5 files changed, 58 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7ca0d8d5/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index ae110f1..7b42c03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -98,6 +98,17 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements
Extern
     }
 
     /** {@inheritDoc} */
+    @Override public KeyCacheObject copy(int part) {
+        if (this.part == part)
+            return this;
+
+        BinaryObjectImpl cp = new BinaryObjectImpl(ctx, arr, start);
+        cp.part = part;
+
+        return cp;
+    }
+
+    /** {@inheritDoc} */
     @Override public int partition() {
         return part;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ca0d8d5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
index ffb846c..21b1f89 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
@@ -38,7 +38,14 @@ public interface KeyCacheObject extends CacheObject {
 
     /**
      * Sets partition ID for this key.
+     *
      * @param part Partition ID.
      */
     public void partition(int part);
+
+    /**
+     * @param part Partition ID.
+     * @return Copy of this object with given partition set.
+     */
+    public KeyCacheObject copy(int part);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ca0d8d5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index 35e681c..146e554 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -61,6 +61,14 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
+    @Override public KeyCacheObject copy(int part) {
+        if (this.part == part)
+            return this;
+
+        return new KeyCacheObjectImpl(val, valBytes, part);
+    }
+
+    /** {@inheritDoc} */
     @Override public int partition() {
         return part;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ca0d8d5/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 141f0f8..3ab01e7 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
@@ -779,28 +779,23 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
             return super.toCacheKeyObject(ctx, cctx, obj, userObj);
 
         if (obj instanceof KeyCacheObject) {
-            if (obj instanceof BinaryObjectImpl) {
-                int part = partition(ctx, cctx, obj);
+            KeyCacheObject key = (KeyCacheObject)obj;
 
-                int part0 = ((KeyCacheObject)obj).partition();
-
-                if (part0 != part) {
-                    // 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());
-
-                    ((BinaryObjectImpl)obj).partition(part);
-                }
+            if (key instanceof BinaryObjectImpl) {
+                // Need to create a copy because the key can be reused at the application
layer after that (IGNITE-3505).
+                key = key.copy(partition(ctx, cctx, key));
             }
+            else if (key.partition() == -1)
+                // Assume others KeyCacheObjects can not be reused for another cache.
+                key.partition(partition(ctx, cctx, key));
 
-            return (KeyCacheObject)obj;
+            return key;
         }
 
         obj = toBinary(obj);
 
         if (obj instanceof BinaryObjectImpl) {
-            ((KeyCacheObject)obj).partition(partition(ctx, cctx, obj));
+            ((BinaryObjectImpl)obj).partition(partition(ctx, cctx, obj));
 
             return (KeyCacheObject)obj;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ca0d8d5/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 71c8f27..78a1838 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
@@ -117,8 +117,15 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter
impleme
         @Nullable GridCacheContext cctx,
         Object obj,
         boolean userObj) {
-        if (obj instanceof KeyCacheObject)
+        if (obj instanceof KeyCacheObject) {
+            KeyCacheObject key = (KeyCacheObject)obj;
+
+            if (key.partition() == -1)
+                // Assume all KeyCacheObjects except BinaryObject can not be reused for another
cache.
+                key.partition(partition(ctx, cctx, key));
+
             return (KeyCacheObject)obj;
+        }
 
         return toCacheKeyObject0(ctx, cctx, obj, userObj);
     }
@@ -334,6 +341,21 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter
impleme
             super(key, null, part);
         }
 
+        /**
+         * @param key Key.
+         */
+        UserKeyCacheObjectImpl(Object key, byte[] valBytes, int part) {
+            super(key, valBytes, part);
+        }
+
+        /** {@inheritDoc} */
+        @Override public KeyCacheObject copy(int part) {
+            if (this.partition() == part)
+                return this;
+
+            return new UserKeyCacheObjectImpl(val, valBytes, part);
+        }
+
         /** {@inheritDoc} */
         @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
             try {


Mime
View raw message