ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [31/50] [abbrv] ignite git commit: IGNITE-3154: More efficient BinaryObject.type() implmentation.
Date Thu, 07 Jul 2016 06:01:56 GMT
IGNITE-3154: More efficient BinaryObject.type() implmentation.


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

Branch: refs/heads/ignite-1232
Commit: 955a5f84f1b2e8c99c5a3ad6c4f27ba068b7e5fc
Parents: 34798d3
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Tue Jul 5 14:58:25 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Jul 6 09:57:57 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java   |  50 ++++-----
 .../internal/binary/BinaryEnumObjectImpl.java   |   9 +-
 .../ignite/internal/binary/BinaryObjectEx.java  |  11 ++
 .../internal/binary/BinaryObjectExImpl.java     |   4 +-
 .../internal/binary/BinaryObjectImpl.java       |   8 +-
 .../binary/BinaryObjectOffheapImpl.java         |   8 +-
 .../ignite/internal/binary/BinaryTypeProxy.java | 111 +++++++++++++++++++
 .../ignite/internal/binary/BinaryUtils.java     |  35 +++++-
 .../binary/CacheObjectBinaryProcessorImpl.java  |   3 +-
 .../processors/query/GridQueryProcessor.java    |   3 +-
 10 files changed, 202 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 593e8af..27e9440 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
@@ -17,30 +17,6 @@
 
 package org.apache.ignite.internal.binary;
 
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
@@ -99,7 +75,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;
@@ -110,6 +85,31 @@ import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
 /**
  * Binary context.
  */

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 e58edd2..c9874ed 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
@@ -130,7 +130,12 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable,
Cac
 
     /** {@inheritDoc} */
     @Override public BinaryType type() throws BinaryObjectException {
-        return ctx.metadata(typeId());
+        return BinaryUtils.typeProxy(ctx, this);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType rawType() throws BinaryObjectException {
+        return BinaryUtils.type(ctx, this);
     }
 
     /** {@inheritDoc} */
@@ -198,7 +203,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable,
Cac
         BinaryType type;
 
         try {
-            type = type();
+            type = rawType();
         }
         catch (Exception e) {
             type = null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
index ba15d13..e3566bc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -18,6 +18,9 @@
 package org.apache.ignite.internal.binary;
 
 import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Extended binary object interface.
@@ -27,4 +30,12 @@ public interface BinaryObjectEx extends BinaryObject {
      * @return Type ID.
      */
     public int typeId();
+
+    /**
+     * Get raw type.
+     *
+     * @return Raw type
+     * @throws BinaryObjectException If failed.
+     */
+    @Nullable public BinaryType rawType() throws BinaryObjectException;
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
index ddf17f0..b4e909e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
@@ -176,7 +176,7 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx {
         BinaryType meta;
 
         try {
-            meta = type();
+            meta = rawType();
         }
         catch (BinaryObjectException ignore) {
             meta = null;
@@ -222,7 +222,7 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx {
                         Integer idHash0 = handles.get(val);
 
                         if (idHash0 != null) {  // Circular reference.
-                            BinaryType meta0 = po.type();
+                            BinaryType meta0 = po.rawType();
 
                             assert meta0 != null;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 fa10de3..7998ee3 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
@@ -257,10 +257,12 @@ 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 BinaryUtils.typeProxy(ctx, this);
+    }
 
-        return ctx.metadata(typeId());
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType rawType() throws BinaryObjectException {
+        return BinaryUtils.type(ctx, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 c687192..2225b7a 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
@@ -146,10 +146,12 @@ 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 BinaryUtils.typeProxy(ctx, this);
+    }
 
-        return ctx.metadata(typeId());
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType rawType() throws BinaryObjectException {
+        return BinaryUtils.type(ctx, this);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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..17b0bc6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java
@@ -0,0 +1,111 @@
+/*
+ * 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.BinaryObjectException;
+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 type.
+     */
+    private BinaryType target() {
+        if (target == null) {
+            synchronized (this) {
+                if (target == null) {
+                    target = ctx.metadata(typeId);
+
+                    if (target == null)
+                        throw new BinaryObjectException("Failed to get binary type details
[typeId=" + typeId + ']');
+                }
+            }
+        }
+
+        return target;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryTypeProxy.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 a9ae64e..76e5b31 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,34 @@ 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());
+    }
+
+    /**
+     * Create binary type which is used by users.
+     *
+     * @param ctx Context.
+     * @param obj Binary object.
+     * @return Binary type.
+     */
+    public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj) {
+        if (ctx == null)
+            throw new BinaryObjectException("BinaryContext is not set for the object.");
+
+        return ctx.metadata(obj.typeId());
+    }
+
+    /**
      * Enum type.
      */
     private static class EnumType {

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/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 139a8a2..8079a0c 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
@@ -26,7 +26,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import javax.cache.Cache;
@@ -667,7 +666,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
      */
     public Object affinityKey(BinaryObject po) {
         try {
-            BinaryType meta = po.type();
+            BinaryType meta = po instanceof BinaryObjectEx ? ((BinaryObjectEx)po).rawType()
: po.type();
 
             if (meta != null) {
                 String affKeyFieldName = meta.affinityKeyFieldName();

http://git-wip-us.apache.org/repos/asf/ignite/blob/955a5f84/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 074e7e5..a42eb98 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -36,6 +36,7 @@ import org.apache.ignite.events.CacheQueryExecutedEvent;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.cache.CacheEntryImpl;
 import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -2021,7 +2022,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             BinaryField field0 = field;
 
             if (field0 == null && !fieldTaken) {
-                BinaryType type = obj.type();
+                BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx)obj).rawType()
: obj.type();
 
                 if (type != null) {
                     field0 = type.field(propName);


Mime
View raw message