This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 06a557b2e4d IGNITE-26061 Register predefined types in corresponding
processors (#12230)
06a557b2e4d is described below
commit 06a557b2e4d89905d17111f82884df398f8be21a
Author: Nikolay <[email protected]>
AuthorDate: Thu Jul 31 10:54:45 2025 +0300
IGNITE-26061 Register predefined types in corresponding processors (#12230)
---
.../ignite/internal/binary/BinaryContext.java | 107 ++++++++-------------
.../processors/cache/binary/BinaryMetadataKey.java | 82 ----------------
.../binary/CacheObjectBinaryProcessorImpl.java | 18 ++++
.../processors/closure/GridClosureProcessor.java | 11 +++
.../processors/platform/PlatformProcessorImpl.java | 10 ++
5 files changed, 79 insertions(+), 149 deletions(-)
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 33133a9d434..795c6ec36a3 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
@@ -61,19 +61,11 @@ import org.apache.ignite.binary.BinaryReflectiveSerializer;
import org.apache.ignite.binary.BinarySerializer;
import org.apache.ignite.binary.BinaryType;
import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.cache.affinity.AffinityKey;
import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import org.apache.ignite.internal.DuplicateTypeIdException;
import org.apache.ignite.internal.UnregisteredBinaryTypeException;
import org.apache.ignite.internal.UnregisteredClassException;
import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.internal.processors.cache.binary.BinaryMetadataKey;
-import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
-import
org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
-import
org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
-import
org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
-import
org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionData;
-import
org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.lang.GridMapEntry;
import org.apache.ignite.internal.util.typedef.F;
@@ -103,24 +95,6 @@ public class BinaryContext {
static final BinaryInternalMapper SIMPLE_NAME_LOWER_CASE_MAPPER =
new BinaryInternalMapper(new BinaryBasicNameMapper(true), new
BinaryBasicIdMapper(true), false);
- /** Set of system classes that should be marshalled with BinaryMarshaller.
*/
- private static final Set<String> BINARYLIZABLE_SYS_CLSS = Set.of(
- // Closure processor classes.
- GridClosureProcessor.C1.class.getName(),
- GridClosureProcessor.C1MLA.class.getName(),
- GridClosureProcessor.C2.class.getName(),
- GridClosureProcessor.C2MLA.class.getName(),
- GridClosureProcessor.C4.class.getName(),
- GridClosureProcessor.C4MLA.class.getName(),
-
- IgniteUuid.class.getName(),
-
- // BinaryUtils.FIELDS_SORTED_ORDER support, since it uses TreeMap at
BinaryMetadata.
- BinaryTreeMap.class.getName(),
- TreeMap.class.getName(),
- TreeSet.class.getName()
- );
-
/** */
private final ConcurrentMap<Class<?>, BinaryClassDescriptor> descByCls =
new ConcurrentHashMap<>();
@@ -275,30 +249,23 @@ public class BinaryContext {
registerPredefinedType(HashMap.class, 0);
registerPredefinedType(LinkedHashMap.class, 0);
- // Classes with overriden default serialization flag.
- registerPredefinedType(AffinityKey.class, 0,
affinityFieldName(AffinityKey.class), true);
- registerPredefinedType(CollocatedSetItemKey.class, 0,
affinityFieldName(CollocatedSetItemKey.class), true);
- registerPredefinedType(CollocatedQueueItemKey.class, 0,
affinityFieldName(CollocatedQueueItemKey.class), true);
-
registerPredefinedType(GridMapEntry.class, 60);
registerPredefinedType(IgniteBiTuple.class, 61);
registerPredefinedType(T2.class, 62);
registerPredefinedType(IgniteUuid.class, 63);
- registerPredefinedType(PlatformJavaObjectFactoryProxy.class,
- GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY);
-
registerPredefinedType(BinaryObjectImpl.class, 0);
registerPredefinedType(BinaryObjectOffheapImpl.class, 0);
- registerPredefinedType(BinaryMetadataKey.class, 0);
registerPredefinedType(BinaryMetadata.class, 0);
registerPredefinedType(BinaryEnumObjectImpl.class, 0);
registerPredefinedType(BinaryTreeMap.class, 0);
registerPredefinedType(BinaryArray.class, 0);
registerPredefinedType(BinaryEnumArray.class, 0);
- registerPredefinedType(PlatformDotNetSessionData.class, 0);
- registerPredefinedType(PlatformDotNetSessionLockResult.class, 0);
+ // BinaryUtils.FIELDS_SORTED_ORDER support, since it uses TreeMap at
BinaryMetadata.
+ registerBinarilizableSystemClass(BinaryTreeMap.class);
+ registerBinarilizableSystemClass(TreeMap.class);
+ registerBinarilizableSystemClass(TreeSet.class);
// IDs range [200..1000] is used by Ignite internal APIs.
@@ -344,12 +311,8 @@ public class BinaryContext {
public boolean mustDeserialize(Class cls) {
BinaryClassDescriptor desc = descByCls.get(cls);
- if (desc == null) {
- if (cls == TreeMap.class || cls == TreeSet.class)
- return false;
-
+ if (desc == null)
return marshCtx.isSystemType(cls.getName()) ||
serializerForClass(cls) == null;
- }
else
return desc.useOptimizedMarshaller();
}
@@ -640,6 +603,16 @@ public class BinaryContext {
return desc;
}
+ /**
+ * Register system class that should be marshalled with BinaryMarshaller.
+ * @param cls Class to register.
+ */
+ public void registerBinarilizableSystemClass(Class<?> cls) {
+ String clsName = cls.getName();
+
+ descByCls.put(cls, systemClassDescriptor(cls, clsName, new
BinaryReflectiveSerializer()));
+ }
+
/**
* Registers binary type locally.
*
@@ -675,24 +648,8 @@ public class BinaryContext {
@NotNull private BinaryClassDescriptor createDescriptorForClass(Class<?>
cls) {
String clsName = cls.getName();
- if (marshCtx.isSystemType(clsName)) {
- BinarySerializer serializer = null;
-
- if (BINARYLIZABLE_SYS_CLSS.contains(clsName))
- serializer = new BinaryReflectiveSerializer();
-
- return new BinaryClassDescriptor(this,
- cls,
- false,
- clsName.hashCode(),
- clsName,
- null,
- SIMPLE_NAME_LOWER_CASE_MAPPER,
- serializer,
- false,
- false
- );
- }
+ if (marshCtx.isSystemType(clsName))
+ return systemClassDescriptor(cls, clsName, null);
else {
BinaryInternalMapper mapper = userTypeMapper(clsName);
@@ -721,6 +678,26 @@ public class BinaryContext {
}
}
+ /**
+ * @param cls Class.
+ * @param clsName Class name.
+ * @param serializer Serializer.
+ * @return Binary class descriptor
+ */
+ private BinaryClassDescriptor systemClassDescriptor(Class<?> cls, String
clsName, @Nullable BinarySerializer serializer) {
+ return new BinaryClassDescriptor(this,
+ cls,
+ false,
+ clsName.hashCode(),
+ clsName,
+ null,
+ SIMPLE_NAME_LOWER_CASE_MAPPER,
+ serializer,
+ false,
+ false
+ );
+ }
+
/**
* @param userType User type or not.
* @param typeId Type ID.
@@ -1090,19 +1067,17 @@ public class BinaryContext {
/**
* @param cls Class.
* @param id Type ID.
- * @return GridBinaryClassDescriptor.
*/
- BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id) {
- return registerPredefinedType(cls, id, null, true);
+ public void registerPredefinedType(Class<?> cls, int id) {
+ registerPredefinedType(cls, id, null, true);
}
/**
* @param cls Class.
* @param id Type ID.
* @param affFieldName Affinity field name.
- * @return GridBinaryClassDescriptor.
*/
- BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id, String
affFieldName, boolean registered) {
+ public void registerPredefinedType(Class<?> cls, int id, String
affFieldName, boolean registered) {
String simpleClsName =
SIMPLE_NAME_LOWER_CASE_MAPPER.typeName(cls.getName());
if (id == 0)
@@ -1128,8 +1103,6 @@ public class BinaryContext {
if (affFieldName != null)
affKeyFieldNames.putIfAbsent(id, affFieldName);
-
- return desc;
}
/**
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
deleted file mode 100644
index 35275406992..00000000000
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Key for binary metadata.
- */
-public class BinaryMetadataKey extends GridCacheUtilityKey<BinaryMetadataKey>
implements Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** */
- private int typeId;
-
- /**
- * For {@link Externalizable}.
- */
- public BinaryMetadataKey() {
- // No-op.
- }
-
- /**
- * @param typeId Type ID.
- */
- BinaryMetadataKey(int typeId) {
- this.typeId = typeId;
- }
-
- /**
- * @return Type id.
- */
- public int typeId() {
- return typeId;
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(typeId);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
- typeId = in.readInt();
- }
-
- /** {@inheritDoc} */
- @Override protected boolean equalsx(BinaryMetadataKey key) {
- return typeId == key.typeId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return typeId;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(BinaryMetadataKey.class, this);
- }
-}
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 b6295d5cd9c..c6c121b3cdc 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
@@ -43,6 +43,7 @@ import org.apache.ignite.binary.BinaryObjectBuilder;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryType;
import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.affinity.AffinityKey;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.BinaryConfiguration;
@@ -86,6 +87,8 @@ import
org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProces
import
org.apache.ignite.internal.processors.cacheobject.UserCacheObjectByteArrayImpl;
import org.apache.ignite.internal.processors.cacheobject.UserCacheObjectImpl;
import
org.apache.ignite.internal.processors.cacheobject.UserKeyCacheObjectImpl;
+import
org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
+import
org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
import org.apache.ignite.internal.processors.query.QueryUtils;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.MutableSingletonList;
@@ -116,6 +119,7 @@ import static
org.apache.ignite.IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION
import static
org.apache.ignite.IgniteSystemProperties.IGNITE_WAIT_SCHEMA_UPDATE;
import static org.apache.ignite.IgniteSystemProperties.getBoolean;
import static
org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.BINARY_PROC;
+import static
org.apache.ignite.internal.binary.BinaryContext.affinityFieldName;
import static org.apache.ignite.internal.binary.BinaryUtils.mergeMetadata;
import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
@@ -274,6 +278,12 @@ public class CacheObjectBinaryProcessorImpl extends
GridProcessorAdapter impleme
marsh.setBinaryContext(binaryCtx);
+ // Will be null in case of StandaloneGridKernalContext.
+ if (ctx.closure() != null)
+ ctx.closure().onBinaryContextCreated(binaryCtx);
+
+ onBinaryContextCreated(binaryCtx);
+
transport = new BinaryMetadataTransport(metadataLocCache,
metadataFileStore, binaryCtx, ctx, log);
binaryMarsh = new GridBinaryMarshaller(binaryCtx);
@@ -1614,4 +1624,12 @@ public class CacheObjectBinaryProcessorImpl extends
GridProcessorAdapter impleme
return metadata(typeId);
}
+
+ /** */
+ private void onBinaryContextCreated(BinaryContext ctx) {
+ // Classes with overriden default serialization flag.
+ ctx.registerPredefinedType(AffinityKey.class, 0,
affinityFieldName(AffinityKey.class), true);
+ ctx.registerPredefinedType(CollocatedSetItemKey.class, 0,
affinityFieldName(CollocatedSetItemKey.class), true);
+ ctx.registerPredefinedType(CollocatedQueueItemKey.class, 0,
affinityFieldName(CollocatedQueueItemKey.class), true);
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java
index 03d1dd144ad..5596a0553c7 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/closure/GridClosureProcessor.java
@@ -45,6 +45,7 @@ import org.apache.ignite.internal.GridClosureCallMode;
import org.apache.ignite.internal.GridInternalWrapper;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.managers.communication.GridIoPolicy;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -954,6 +955,16 @@ public class GridClosureProcessor extends
GridProcessorAdapter {
return partId;
}
+ /** @param ctx Binary context. */
+ public void onBinaryContextCreated(BinaryContext ctx) {
+ ctx.registerBinarilizableSystemClass(C1.class);
+ ctx.registerBinarilizableSystemClass(C1MLA.class);
+ ctx.registerBinarilizableSystemClass(C2.class);
+ ctx.registerBinarilizableSystemClass(C2MLA.class);
+ ctx.registerBinarilizableSystemClass(C4.class);
+ ctx.registerBinarilizableSystemClass(C4MLA.class);
+ }
+
/**
*
*/
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
index e34ae85de11..54b623da99a 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
@@ -39,8 +39,10 @@ import
org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.configuration.PlatformConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.binary.BinaryReaderEx;
import org.apache.ignite.internal.binary.BinaryWriterEx;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
import org.apache.ignite.internal.cluster.DetachedClusterNode;
import org.apache.ignite.internal.logger.platform.PlatformLogger;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
@@ -65,6 +67,8 @@ import
org.apache.ignite.internal.processors.platform.memory.PlatformOutputStrea
import
org.apache.ignite.internal.processors.platform.transactions.PlatformTransactions;
import
org.apache.ignite.internal.processors.platform.utils.PlatformConfigurationUtils;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
+import
org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionData;
+import
org.apache.ignite.internal.processors.platform.websession.PlatformDotNetSessionLockResult;
import org.apache.ignite.internal.util.typedef.CI1;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -243,6 +247,12 @@ public class PlatformProcessorImpl extends
GridProcessorAdapter implements Platf
public PlatformProcessorImpl(GridKernalContext ctx) {
super(ctx);
+ BinaryContext bctx = ctx.marshaller().binaryMarshaller().context();
+
+ bctx.registerPredefinedType(PlatformJavaObjectFactoryProxy.class,
GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY);
+ bctx.registerPredefinedType(PlatformDotNetSessionData.class, 0);
+ bctx.registerPredefinedType(PlatformDotNetSessionLockResult.class, 0);
+
log = ctx.log(PlatformProcessorImpl.class);
PlatformConfiguration interopCfg0 =
ctx.config().getPlatformConfiguration();