ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [04/20] ignite git commit: IGNITE-3154: Optimized BinaryField lookup within a BinaryType.
Date Fri, 01 Jul 2016 10:40:54 GMT
IGNITE-3154: Optimized BinaryField lookup within a BinaryType.


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

Branch: refs/heads/ignite-3410
Commit: 62c714340ef6c40de4dcdb6d9ecaf11ab30df834
Parents: ac092f4
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Tue Jun 28 11:37:21 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Tue Jun 28 11:37:21 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java   |   1 -
 .../internal/binary/BinaryEnumObjectImpl.java   |   2 +-
 .../internal/binary/BinaryObjectImpl.java       |   5 +-
 .../binary/BinaryObjectOffheapImpl.java         |   5 +-
 .../ignite/internal/binary/BinaryTypeProxy.java | 107 +++++++++++++++++++
 .../ignite/internal/binary/BinaryUtils.java     |  21 +++-
 6 files changed, 129 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/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 d39f9c6..3853841 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
@@ -83,7 +83,6 @@ import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileUnlockProcess
 import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdatePropertiesProcessor;
 import org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor;
 import org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
-import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.lang.GridMapEntry;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;

http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index 60642ab..eea85ef9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -131,7 +131,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable,
Cac
 
     /** {@inheritDoc} */
     @Override public BinaryType type() throws BinaryObjectException {
-        return ctx.metadata(typeId());
+        return BinaryUtils.typeProxy(ctx, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/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 173bb6e..9ebee0b 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
@@ -227,10 +227,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements
Extern
 
     /** {@inheritDoc} */
     @Nullable @Override public BinaryType type() throws BinaryObjectException {
-        if (ctx == null)
-            throw new BinaryObjectException("BinaryContext is not set for the object.");
-
-        return ctx.metadata(typeId());
+        return BinaryUtils.typeProxy(ctx, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 509247f..60527d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -142,10 +142,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements
Exter
 
     /** {@inheritDoc} */
     @Nullable @Override public BinaryType type() throws BinaryObjectException {
-        if (ctx == null)
-            throw new BinaryObjectException("BinaryContext is not set for the object.");
-
-        return ctx.metadata(typeId());
+        return BinaryUtils.typeProxy(ctx, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
new file mode 100644
index 0000000..e10f2f7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
@@ -0,0 +1,107 @@
+/*
+ * 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.binary.BinaryField;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.Collection;
+
+/**
+ * Binary type proxy. Is used to delay or completely avoid metadata lookup.
+ */
+public class BinaryTypeProxy implements BinaryType {
+    /** Binary context. */
+    @GridToStringExclude
+    private final BinaryContext ctx;
+
+    /** Type ID. */
+    private final int typeId;
+
+    /** Target type. */
+    @GridToStringExclude
+    private volatile BinaryType target;
+
+    /**
+     * Constrcutor.
+     *
+     * @param ctx Context.
+     * @param typeId Type ID.
+     */
+    public BinaryTypeProxy(BinaryContext ctx, int typeId) {
+        this.ctx = ctx;
+        this.typeId = typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryField field(String fieldName) {
+        return ctx.createField(typeId, fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String typeName() {
+        return target().typeName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<String> fieldNames() {
+        return target().fieldNames();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String fieldTypeName(String fieldName) {
+        return target().fieldTypeName(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String affinityKeyFieldName() {
+        return target().affinityKeyFieldName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isEnum() {
+        return target().isEnum();
+    }
+
+    /**
+     * @return Target ype.
+     */
+    private BinaryType target() {
+        if (target == null) {
+            synchronized (this) {
+                if (target == null) {
+                    target = ctx.metadata(typeId);
+                }
+            }
+        }
+
+        return target;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryTypeProxy.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/62c71434/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index 0250e3b..e986228 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -54,6 +54,7 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawReader;
 import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
@@ -602,6 +603,7 @@ public class BinaryUtils {
      * @param map Map.
      * @return New map of the same type or null.
      */
+    @SuppressWarnings("unchecked")
     public static <K, V> Map<K, V> newKnownMap(Object map) {
         Class<?> cls = map == null ? null : map.getClass();
 
@@ -676,6 +678,7 @@ public class BinaryUtils {
      * @param col Collection.
      * @return New empty collection.
      */
+    @SuppressWarnings("unchecked")
     public static <V> Collection<V> newKnownCollection(Object col) {
         Class<?> cls = col == null ? null : col.getClass();
 
@@ -1392,6 +1395,7 @@ public class BinaryUtils {
     /**
      * @return Value.
      */
+    @SuppressWarnings("ConstantConditions")
     public static Object doReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader
ldr,
         BinaryReaderHandlesHolder handles) {
         Class<?>[] intfs = new Class<?>[in.readInt()];
@@ -2123,8 +2127,7 @@ public class BinaryUtils {
                         throw new BinaryObjectException("Malformed input around byte: " +
(off - 1));
 
                     res[charArrCnt++] = (char)(((c & 0x0F) << 12) |
-                        ((c2 & 0x3F) << 6) |
-                        ((c3 & 0x3F) << 0));
+                        ((c2 & 0x3F) << 6) | (c3 & 0x3F));
 
                     break;
                 default:
@@ -2183,6 +2186,20 @@ public class BinaryUtils {
     }
 
     /**
+     * Create binary type proxy.
+     *
+     * @param ctx Context.
+     * @param obj Binary object.
+     * @return Binary type proxy.
+     */
+    public static BinaryType typeProxy(BinaryContext ctx, BinaryObjectEx obj) {
+        if (ctx == null)
+            throw new BinaryObjectException("BinaryContext is not set for the object.");
+
+        return new BinaryTypeProxy(ctx, obj.typeId());
+    }
+
+    /**
      * Enum type.
      */
     private static class EnumType {


Mime
View raw message