ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [02/50] ignite git commit: ignite-3261 Store information about AffinityKey class in metadata cache.
Date Mon, 20 Jun 2016 12:52:42 GMT
ignite-3261 Store information about AffinityKey class in metadata cache.


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

Branch: refs/heads/ignite-3341
Commit: 2b64e7c8b059f31e5ccd6a475b1ba0ad198d86fd
Parents: 1cb291c
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Jun 14 09:45:10 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Jun 14 09:45:10 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java   | 43 ++++++++++--
 .../ignite/internal/binary/AffinityKey.java     | 69 ++++++++++++++++++++
 .../binary/GridBinaryAffinityKeySelfTest.java   | 15 +++++
 ...aultBinaryMappersBinaryMetaDataSelfTest.java | 17 +++++
 4 files changed, 137 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2b64e7c8/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index daf34ad..d39f9c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -259,7 +259,7 @@ public class BinaryContext {
         registerPredefinedType(LinkedHashMap.class, 0);
 
         // Classes with overriden default serialization flag.
-        registerPredefinedType(AffinityKey.class, 0, affinityFieldName(AffinityKey.class));
+        registerPredefinedType(AffinityKey.class, 0, affinityFieldName(AffinityKey.class),
false);
 
         registerPredefinedType(GridMapEntry.class, 60);
         registerPredefinedType(IgniteBiTuple.class, 61);
@@ -562,9 +562,37 @@ public class BinaryContext {
         if (desc == null)
             desc = registerClassDescriptor(cls, deserialize);
         else if (!desc.registered()) {
-            assert desc.userType();
-
-            desc = registerUserClassDescriptor(desc);
+            if (!desc.userType()) {
+                BinaryClassDescriptor desc0 = new BinaryClassDescriptor(
+                    this,
+                    desc.describedClass(),
+                    false,
+                    desc.typeId(),
+                    desc.typeName(),
+                    desc.affFieldKeyName(),
+                    desc.mapper(),
+                    desc.initialSerializer(),
+                    false,
+                    true
+                );
+
+                if (descByCls.replace(cls, desc, desc0)) {
+                    Collection<BinarySchema> schemas =
+                        desc0.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+                    BinaryMetadata meta = new BinaryMetadata(desc0.typeId(),
+                        desc0.typeName(),
+                        desc0.fieldsMeta(),
+                        desc0.affFieldKeyName(),
+                        schemas, desc0.isEnum());
+
+                    metaHnd.addMeta(desc0.typeId(), meta.wrap(this));
+
+                    return desc0;
+                }
+            }
+            else
+                desc = registerUserClassDescriptor(desc);
         }
 
         return desc;
@@ -959,15 +987,16 @@ public class BinaryContext {
      * @return GridBinaryClassDescriptor.
      */
     public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id) {
-        return registerPredefinedType(cls, id, null);
+        return registerPredefinedType(cls, id, null, true);
     }
 
     /**
      * @param cls Class.
      * @param id Type ID.
+     * @param affFieldName Affinity field name.
      * @return GridBinaryClassDescriptor.
      */
-    public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id, String
affFieldName) {
+    public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id, String
affFieldName, boolean registered) {
         String simpleClsName = SIMPLE_NAME_LOWER_CASE_MAPPER.typeName(cls.getName());
 
         if (id == 0)
@@ -983,7 +1012,7 @@ public class BinaryContext {
             SIMPLE_NAME_LOWER_CASE_MAPPER,
             new BinaryReflectiveSerializer(),
             false,
-            true /* registered */
+            registered /* registered */
         );
 
         predefinedTypeNames.put(simpleClsName, id);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b64e7c8/modules/core/src/test/java/org/apache/ignite/internal/binary/AffinityKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/AffinityKey.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/AffinityKey.java
new file mode 100644
index 0000000..1b4daee
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/AffinityKey.java
@@ -0,0 +1,69 @@
+/*
+ * 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.internal.binary;
+
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ *
+ */
+public class AffinityKey {
+    /** Key. */
+    private int key;
+
+    /** Affinity key. */
+    @AffinityKeyMapped
+    private int aff;
+
+    /**
+     * @param key Key.
+     * @param aff Affinity key.
+     */
+    public AffinityKey(int key, int aff) {
+        this.key = key;
+        this.aff = aff;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        AffinityKey that = (AffinityKey) o;
+
+        return key == that.key && aff == that.aff;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = key;
+
+        res = 31 * res + aff;
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(AffinityKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b64e7c8/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
index 06406e0..2b54f6b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
@@ -139,6 +139,8 @@ public class GridBinaryAffinityKeySelfTest extends GridCommonAbstractTest
{
 
             assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
 
+            assertEquals(i, aff.affinityKey(new AffinityKey(0, i)));
+
             BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
 
             bldr.setField("affKey", i);
@@ -162,6 +164,8 @@ public class GridBinaryAffinityKeySelfTest extends GridCommonAbstractTest
{
             assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
 
             assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
+
+            assertEquals(affProc.mapKeyToNode(null, new AffinityKey(0, i)), affProc.mapKeyToNode(null,
i));
         }
     }
 
@@ -184,6 +188,17 @@ public class GridBinaryAffinityKeySelfTest extends GridCommonAbstractTest
{
             });
 
             assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+
+            grid(0).compute().affinityRun(null, new AffinityKey(0, i), new IgniteRunnable()
{
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                @Override public void run() {
+                    nodeId.set(ignite.configuration().getNodeId());
+                }
+            });
+
+            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2b64e7c8/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java
index 041238f..7010463 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridDefaultBinaryMappersBinaryMetaDataSelfTest.java
@@ -26,6 +26,7 @@ import org.apache.ignite.IgniteBinary;
 import org.apache.ignite.binary.BinaryBasicIdMapper;
 import org.apache.ignite.binary.BinaryNameMapper;
 import org.apache.ignite.binary.BinaryBasicNameMapper;
+import org.apache.ignite.cache.affinity.AffinityKey;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
@@ -149,6 +150,22 @@ public class GridDefaultBinaryMappersBinaryMetaDataSelfTest extends GridCommonAb
             else
                 assert false : meta.typeName();
         }
+
+        grid().cache(null).put(new AffinityKey<>(1, 1), 1);
+
+        metas = binaries().types();
+
+        assertEquals(3, metas.size());
+
+        for (BinaryType meta : metas) {
+            if (AffinityKey.class.getSimpleName().equals(meta.typeName())) {
+                assertEquals("affKey", meta.affinityKeyFieldName());
+
+                return;
+            }
+        }
+
+        fail("Failed to find metadata for AffinityKey");
     }
 
     /**


Mime
View raw message