Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 32A66189B5 for ; Thu, 26 Nov 2015 09:30:12 +0000 (UTC) Received: (qmail 6130 invoked by uid 500); 26 Nov 2015 09:30:11 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 5996 invoked by uid 500); 26 Nov 2015 09:30:11 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 5585 invoked by uid 99); 26 Nov 2015 09:30:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Nov 2015 09:30:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CCBE4DFC3C; Thu, 26 Nov 2015 09:30:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Thu, 26 Nov 2015 09:30:12 -0000 Message-Id: <1f506fed1f0b45ccb9074e43407eb37d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/24] ignite git commit: Make binary marshaller default. Make binary marshaller default. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3ca58d7b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3ca58d7b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3ca58d7b Branch: refs/heads/ignite-1.5 Commit: 3ca58d7b5edd0354c73450ff9fff3acf8a2da2cd Parents: 7ea000a Author: Alexey Goncharuk Authored: Mon Nov 23 16:49:53 2015 +0300 Committer: Alexey Goncharuk Committed: Mon Nov 23 16:49:53 2015 +0300 ---------------------------------------------------------------------- examples/config/example-ignite.xml | 10 +-- .../ignite/examples/binary/EmployeeKey.java | 3 + .../configuration/CacheConfiguration.java | 26 -------- .../org/apache/ignite/internal/IgnitionEx.java | 6 +- .../internal/portable/BinaryMarshaller.java | 68 ++++++++++---------- .../internal/portable/PortableContext.java | 23 ++++++- 6 files changed, 62 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/examples/config/example-ignite.xml ---------------------------------------------------------------------- diff --git a/examples/config/example-ignite.xml b/examples/config/example-ignite.xml index d842a6d..a3e7e22 100644 --- a/examples/config/example-ignite.xml +++ b/examples/config/example-ignite.xml @@ -27,13 +27,5 @@ - - - - - - - - - + http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java index 2794230..7614f2c 100644 --- a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java +++ b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java @@ -17,6 +17,8 @@ package org.apache.ignite.examples.binary; +import org.apache.ignite.cache.affinity.AffinityKeyMapped; + /** * This class represents key for employee object. *

@@ -28,6 +30,7 @@ public class EmployeeKey { private int id; /** Organization ID. */ + @AffinityKeyMapped private int organizationId; /** http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java index e7dd9c3..8c3ea19 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java @@ -389,9 +389,6 @@ public class CacheConfiguration extends MutableConfiguration { /** Query entities. */ private Collection qryEntities; - /** Cache */ - private Collection cacheKeyCfgs; - /** Empty constructor (all values are initialized to their defaults). */ public CacheConfiguration() { /* No-op. */ @@ -426,7 +423,6 @@ public class CacheConfiguration extends MutableConfiguration { atomicityMode = cc.getAtomicityMode(); atomicWriteOrderMode = cc.getAtomicWriteOrderMode(); backups = cc.getBackups(); - cacheKeyCfgs = cc.getCacheKeyConfiguration(); cacheLoaderFactory = cc.getCacheLoaderFactory(); cacheMode = cc.getCacheMode(); cacheWriterFactory = cc.getCacheWriterFactory(); @@ -997,28 +993,6 @@ public class CacheConfiguration extends MutableConfiguration { } /** - * Gets cache key configuration. Cache key configuration allows to override default cache key affinity - * by specifying affinity field name. - * - * @return Cache key configuration. - */ - public Collection getCacheKeyConfiguration() { - return cacheKeyCfgs; - } - - /** - * Sets cache key configuration. - * - * @param cacheKeyCfgs Collection of cache key configurations. - */ - public void setCacheKeyConfiguration(Collection cacheKeyCfgs) { - if (this.cacheKeyCfgs != null) - this.cacheKeyCfgs.addAll(cacheKeyCfgs); - else - this.cacheKeyCfgs = cacheKeyCfgs; - } - - /** * Gets cache atomicity mode. *

* Default value is defined by {@link #DFLT_CACHE_ATOMICITY_MODE}. http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 7d2b2dc..a83ddcc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -61,6 +61,7 @@ import org.apache.ignite.configuration.DeploymentMode; import org.apache.ignite.configuration.FileSystemConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.portable.BinaryMarshaller; import org.apache.ignite.internal.processors.resource.GridSpringResourceContext; import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.IgniteUtils; @@ -76,7 +77,6 @@ import org.apache.ignite.logger.LoggerNodeIdAware; import org.apache.ignite.logger.java.JavaLogger; import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.marshaller.jdk.JdkMarshaller; -import org.apache.ignite.marshaller.optimized.OptimizedMarshaller; import org.apache.ignite.mxbean.IgnitionMXBean; import org.apache.ignite.plugin.segmentation.SegmentationPolicy; import org.apache.ignite.resources.SpringApplicationContextResource; @@ -1793,7 +1793,7 @@ public class IgnitionEx { Marshaller marsh = myCfg.getMarshaller(); if (marsh == null) { - if (!OptimizedMarshaller.available()) { + if (!BinaryMarshaller.available()) { U.warn(log, "OptimizedMarshaller is not supported on this JVM " + "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " + "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release. " + @@ -1804,7 +1804,7 @@ public class IgnitionEx { marsh = new JdkMarshaller(); } else - marsh = new OptimizedMarshaller(); + marsh = new BinaryMarshaller(); } myCfg.setMarshaller(marsh); http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java index 4f8c83c..759d802 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java @@ -24,54 +24,54 @@ import java.io.OutputStream; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.binary.BinaryObjectException; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.GridUnsafe; import org.apache.ignite.marshaller.AbstractMarshaller; import org.apache.ignite.marshaller.MarshallerContext; import org.jetbrains.annotations.Nullable; +import sun.misc.Unsafe; /** * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects - * in the portable format. + * in the binary format. *

* {@code PortableMarshaller} is tested only on Java HotSpot VM on other VMs it could yield unexpected results. - *

- *

Configuration

- *

Mandatory

- * This marshaller has no mandatory configuration parameters. - *

Java Example

- *
- * PortableMarshaller marshaller = new PortableMarshaller();
- *
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * // Override marshaller.
- * cfg.setMarshaller(marshaller);
- *
- * // Starts grid.
- * G.start(cfg);
- * 
- *

Spring Example

- * PortableMarshaller can be configured from Spring XML configuration file: - *
- * <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
- *     ...
- *     <property name="marshaller">
- *         <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
- *            ...
- *         </bean>
- *     </property>
- *     ...
- * </bean>
- * 
- *

- * - *
- * For information about Spring framework visit www.springframework.org */ public class BinaryMarshaller extends AbstractMarshaller { /** */ private GridPortableMarshaller impl; /** + * Checks whether {@code BinaryMarshaller} is able to work on the current JVM. + *

+ * As long as {@code BinaryMarshaller} uses JVM-private API, which is not guaranteed + * to be available on all JVM, this method should be called to ensure marshaller could work properly. + *

+ * Result of this method is automatically checked in constructor. + * + * @return {@code true} if {@code BinaryMarshaller} can work on the current JVM or + * {@code false} if it can't. + */ + @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"}) + public static boolean available() { + try { + Unsafe unsafe = GridUnsafe.unsafe(); + + Class unsafeCls = unsafe.getClass(); + + unsafeCls.getMethod("allocateInstance", Class.class); + unsafeCls.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class); + + return true; + } + catch (Exception ignored) { + return false; + } + catch (NoClassDefFoundError ignored) { + return false; + } + } + + /** * Returns currently set {@link MarshallerContext}. * * @return Marshaller context. http://git-wip-us.apache.org/repos/asf/ignite/blob/3ca58d7b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java index 8f37517..1ff459e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java @@ -24,6 +24,7 @@ import java.io.InvalidObjectException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.ObjectStreamException; +import java.lang.reflect.Field; import java.math.BigDecimal; import java.net.URISyntaxException; import java.net.URL; @@ -52,6 +53,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheKeyConfiguration; +import org.apache.ignite.cache.affinity.AffinityKeyMapped; import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.binary.BinaryTypeConfiguration; @@ -503,12 +505,14 @@ public class PortableContext implements Externalizable { throw new BinaryObjectException("Failed to register class.", e); } + String affFieldName = affinityFieldName(cls); + PortableClassDescriptor desc = new PortableClassDescriptor(this, cls, true, typeId, typeName, - null, + affFieldName, idMapper, null, true, @@ -518,7 +522,7 @@ public class PortableContext implements Externalizable { Collection schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null; - metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), null, schemas).wrap(this)); + metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas).wrap(this)); // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader // might have reloaded described class. @@ -606,6 +610,21 @@ public class PortableContext implements Externalizable { return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance(); } + /** + * @param cls Class to get affinity field for. + * @return Affinity field name or {@code null} if field name was not found. + */ + private String affinityFieldName(Class cls) { + for (; cls != Object.class; cls = cls.getSuperclass()) { + for (Field f : cls.getDeclaredFields()) { + if (f.getAnnotation(AffinityKeyMapped.class) != null) + return f.getName(); + } + } + + return null; + } + /** {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { U.writeString(out, igniteCfg.getGridName());