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 58157a882ac IGNITE-26049 Remove BinaryConfiguration dependency from BinaryContext (#12229) 58157a882ac is described below commit 58157a882acc21ec1c98b5775400ce8eae0f02a3 Author: Nikolay <nizhi...@apache.org> AuthorDate: Tue Jul 29 12:01:50 2025 +0300 IGNITE-26049 Remove BinaryConfiguration dependency from BinaryContext (#12229) --- .../ignite/internal/binary/BinaryContext.java | 121 +++++++++------------ .../binary/CacheObjectBinaryProcessorImpl.java | 83 -------------- .../apache/ignite/internal/util/IgniteUtils.java | 108 +++++++++++++++++- .../ignite/testframework/junits/IgniteMock.java | 15 ++- ...aryMetadataConcurrentUpdateWithIndexesTest.java | 8 +- 5 files changed, 172 insertions(+), 163 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 3d016fc9b99..7cd5864b8c1 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 @@ -43,6 +43,7 @@ import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.apache.ignite.IgniteCheckedException; @@ -62,7 +63,6 @@ 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.configuration.BinaryConfiguration; import org.apache.ignite.internal.DuplicateTypeIdException; import org.apache.ignite.internal.UnregisteredBinaryTypeException; import org.apache.ignite.internal.UnregisteredClassException; @@ -77,6 +77,7 @@ import org.apache.ignite.internal.processors.platform.websession.PlatformDotNetS import org.apache.ignite.internal.processors.query.QueryUtils; 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; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; @@ -104,29 +105,22 @@ public class BinaryContext { 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; - - /* Binarylizable system classes set initialization. */ - static { - Set<String> sysClss = new HashSet<>(); - + private static final Set<String> BINARYLIZABLE_SYS_CLSS = Set.of( // Closure processor classes. - sysClss.add(GridClosureProcessor.C1.class.getName()); - sysClss.add(GridClosureProcessor.C1MLA.class.getName()); - sysClss.add(GridClosureProcessor.C2.class.getName()); - sysClss.add(GridClosureProcessor.C2MLA.class.getName()); - sysClss.add(GridClosureProcessor.C4.class.getName()); - sysClss.add(GridClosureProcessor.C4MLA.class.getName()); + GridClosureProcessor.C1.class.getName(), + GridClosureProcessor.C1MLA.class.getName(), + GridClosureProcessor.C2.class.getName(), + GridClosureProcessor.C2MLA.class.getName(), + GridClosureProcessor.C4.class.getName(), + GridClosureProcessor.C4MLA.class.getName(), - sysClss.add(IgniteUuid.class.getName()); + IgniteUuid.class.getName(), // BinaryUtils.FIELDS_SORTED_ORDER support, since it uses TreeMap at BinaryMetadata. - sysClss.add(BinaryTreeMap.class.getName()); - sysClss.add(TreeMap.class.getName()); - sysClss.add(TreeSet.class.getName()); - - BINARYLIZABLE_SYS_CLSS = Collections.unmodifiableSet(sysClss); - } + BinaryTreeMap.class.getName(), + TreeMap.class.getName(), + TreeSet.class.getName() + ); /** */ private final ConcurrentMap<Class<?>, BinaryClassDescriptor> descByCls = new ConcurrentHashMap<>(); @@ -170,8 +164,11 @@ public class BinaryContext { /** */ private MarshallerContext marshCtx; - /** Binary configuration. */ - private final @Nullable BinaryConfiguration bcfg; + /** */ + private final @Nullable BinarySerializer dfltSerializer; + + /** */ + private final Function<String, BinaryInternalMapper> mapperProvider; /** Logger. */ private final IgniteLogger log; @@ -180,7 +177,7 @@ public class BinaryContext { private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller(false); /** Compact footer flag. */ - private boolean compactFooter; + private final boolean compactFooter; /** Object schemas. */ private volatile Map<Integer, BinarySchemaRegistry> schemas; @@ -190,8 +187,11 @@ public class BinaryContext { * @param marsh Binary marshaller. * @param igniteInstanceName Ignite instance name. * @param clsLdr Class loader. - * @param bcfg Binary configuration. + * @param dfltSerializer Binary serializer. + * @param idMapper Binary id mapper. + * @param nameMapper Binary name mapper. * @param affFlds Affinity fields. + * @param compactFooter Compact footer flag. * @param log Logger. */ public BinaryContext( @@ -199,8 +199,12 @@ public class BinaryContext { @Nullable BinaryMarshaller marsh, @Nullable String igniteInstanceName, @Nullable ClassLoader clsLdr, - @Nullable BinaryConfiguration bcfg, + @Nullable BinarySerializer dfltSerializer, + @Nullable BinaryIdMapper idMapper, + @Nullable BinaryNameMapper nameMapper, + @Nullable Collection<BinaryTypeConfiguration> typeCfgs, Map<String, String> affFlds, + boolean compactFooter, IgniteLogger log ) { assert metaHnd != null; @@ -210,7 +214,15 @@ public class BinaryContext { this.metaHnd = metaHnd; this.igniteInstanceName = igniteInstanceName; this.clsLdr = clsLdr; - this.bcfg = bcfg; + this.dfltSerializer = dfltSerializer; + + if (idMapper != null || nameMapper != null || !F.isEmpty(typeCfgs)) + mapperProvider = clsName -> resolveMapper(clsName, idMapper, nameMapper, typeCfgs); + else + mapperProvider = clsName -> DFLT_MAPPER; + + this.compactFooter = compactFooter; + this.log = log; colTypes.put(ArrayList.class, GridBinaryMarshaller.ARR_LIST); @@ -296,7 +308,17 @@ public class BinaryContext { "default constructor is not possible"); } - configure(marsh, bcfg, affFlds); + if (marsh != null) { + this.marsh = marsh; + + marshCtx = marsh.getContext(); + + assert marshCtx != null; + + optmMarsh.setContext(marshCtx); + + configure(nameMapper, idMapper, dfltSerializer, typeCfgs, affFlds); + } } /** @@ -348,42 +370,6 @@ public class BinaryContext { return clsLdr; } - /** - * @param marsh Binary marshaller. - * @param binaryCfg Binary configuration. - * @param affFlds Type name to affinity key field name mapping. - * @throws BinaryObjectException In case of error. - */ - private void configure( - BinaryMarshaller marsh, - BinaryConfiguration binaryCfg, - Map<String, String> affFlds - ) throws BinaryObjectException { - if (marsh == null) - return; - - this.marsh = marsh; - - marshCtx = marsh.getContext(); - - if (binaryCfg == null) - binaryCfg = new BinaryConfiguration(); - - assert marshCtx != null; - - optmMarsh.setContext(marshCtx); - - configure( - binaryCfg.getNameMapper(), - binaryCfg.getIdMapper(), - binaryCfg.getSerializer(), - binaryCfg.getTypeConfigurations(), - affFlds - ); - - compactFooter = binaryCfg.isCompactFooter(); - } - /** * @param globalNameMapper Name mapper. * @param globalIdMapper ID mapper. @@ -932,7 +918,7 @@ public class BinaryContext { * @return Default serializer. */ private BinarySerializer defaultSerializer() { - return bcfg != null ? bcfg.getSerializer() : null; + return dfltSerializer; } /** @@ -1011,12 +997,7 @@ public class BinaryContext { if (mapper != null) return mapper; - mapper = bcfg == null ? DFLT_MAPPER : resolveMapper( - clsName, - bcfg.getIdMapper(), - bcfg.getNameMapper(), - bcfg.getTypeConfigurations() - ); + mapper = mapperProvider.apply(clsName); BinaryInternalMapper prevMap = cls2Mappers.putIfAbsent(clsName, mapper); 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 3eec434fbe1..b6295d5cd9c 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 @@ -21,12 +21,10 @@ import java.io.File; import java.io.Serializable; import java.math.BigDecimal; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -38,7 +36,6 @@ import org.apache.ignite.IgniteBinary; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteClientDisconnectedException; import org.apache.ignite.IgniteException; -import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.binary.BinaryField; import org.apache.ignite.binary.BinaryObject; @@ -50,7 +47,6 @@ import org.apache.ignite.cache.affinity.AffinityKeyMapper; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; @@ -1618,83 +1614,4 @@ public class CacheObjectBinaryProcessorImpl extends GridProcessorAdapter impleme return metadata(typeId); } - - /** */ - @SuppressWarnings("PublicInnerClass") - public static class TestBinaryContext extends BinaryContext { - /** */ - private List<TestBinaryContextListener> listeners; - - /** - * @param metaHnd Meta handler. - * @param cfg Ignite configuration. - * @param log Logger. - */ - public TestBinaryContext(BinaryMetadataHandler metaHnd, BinaryMarshaller marsh, IgniteConfiguration cfg, IgniteLogger log) { - super( - metaHnd, - marsh, - cfg.getIgniteInstanceName(), - cfg.getClassLoader(), - cfg.getBinaryConfiguration(), - CU.affinityFields(cfg), - log - ); - } - - /** {@inheritDoc} */ - @Nullable @Override public BinaryType metadata(int typeId) throws BinaryObjectException { - BinaryType metadata = super.metadata(typeId); - - if (listeners != null) { - for (TestBinaryContextListener listener : listeners) - listener.onAfterMetadataRequest(typeId, metadata); - } - - return metadata; - } - - /** {@inheritDoc} */ - @Override public void updateMetadata(int typeId, BinaryMetadata meta, - boolean failIfUnregistered) throws BinaryObjectException { - if (listeners != null) { - for (TestBinaryContextListener listener : listeners) - listener.onBeforeMetadataUpdate(typeId, meta); - } - - super.updateMetadata(typeId, meta, failIfUnregistered); - } - - /** */ - public interface TestBinaryContextListener { - /** - * @param typeId Type id. - * @param type Type. - */ - void onAfterMetadataRequest(int typeId, BinaryType type); - - /** - * @param typeId Type id. - * @param metadata Metadata. - */ - void onBeforeMetadataUpdate(int typeId, BinaryMetadata metadata); - } - - /** - * @param lsnr Listener. - */ - public void addListener(TestBinaryContextListener lsnr) { - if (listeners == null) - listeners = new ArrayList<>(); - - if (!listeners.contains(lsnr)) - listeners.add(lsnr); - } - - /** */ - public void clearAllListener() { - if (listeners != null) - listeners.clear(); - } - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 01fe353bd0b..359e59416d7 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -155,6 +155,12 @@ import org.apache.ignite.IgniteIllegalStateException; import org.apache.ignite.IgniteInterruptedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.binary.BinaryIdMapper; +import org.apache.ignite.binary.BinaryNameMapper; +import org.apache.ignite.binary.BinaryObjectException; +import org.apache.ignite.binary.BinarySerializer; +import org.apache.ignite.binary.BinaryType; +import org.apache.ignite.binary.BinaryTypeConfiguration; import org.apache.ignite.cluster.ClusterGroupEmptyException; import org.apache.ignite.cluster.ClusterMetrics; import org.apache.ignite.cluster.ClusterNode; @@ -164,6 +170,7 @@ import org.apache.ignite.compute.ComputeTaskCancelledException; import org.apache.ignite.compute.ComputeTaskName; import org.apache.ignite.compute.ComputeTaskTimeoutException; import org.apache.ignite.configuration.AddressResolver; +import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.DataRegionConfiguration; import org.apache.ignite.configuration.DataStorageConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -177,6 +184,7 @@ import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.IgniteNodeAttributes; import org.apache.ignite.internal.binary.BinaryContext; import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.binary.BinaryMetadata; import org.apache.ignite.internal.binary.BinaryMetadataHandler; import org.apache.ignite.internal.binary.BinaryUtils; import org.apache.ignite.internal.binary.GridBinaryMarshaller; @@ -194,7 +202,6 @@ import org.apache.ignite.internal.mxbean.IgniteStandardMXBean; import org.apache.ignite.internal.processors.cache.CacheClassLoaderMarker; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.IgnitePeerToPeerClassLoadingException; -import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.TestBinaryContext; import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException; import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException; import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException; @@ -9852,15 +9859,33 @@ public abstract class IgniteUtils extends CommonUtils { IgniteConfiguration cfg, IgniteLogger log ) { + BinaryConfiguration bcfg = cfg.getBinaryConfiguration() == null ? new BinaryConfiguration() : cfg.getBinaryConfiguration(); + return useTestBinaryCtx - ? new TestBinaryContext(metaHnd, marsh, cfg, log) + ? new TestBinaryContext( + metaHnd, + marsh, + cfg.getIgniteInstanceName(), + cfg.getClassLoader(), + bcfg.getSerializer(), + bcfg.getIdMapper(), + bcfg.getNameMapper(), + bcfg.getTypeConfigurations(), + CU.affinityFields(cfg), + bcfg.isCompactFooter(), + log + ) : new BinaryContext( metaHnd, marsh, cfg.getIgniteInstanceName(), cfg.getClassLoader(), - cfg.getBinaryConfiguration(), + bcfg.getSerializer(), + bcfg.getIdMapper(), + bcfg.getNameMapper(), + bcfg.getTypeConfigurations(), CU.affinityFields(cfg), + bcfg.isCompactFooter(), log ); } @@ -9912,4 +9937,81 @@ public abstract class IgniteUtils extends CommonUtils { return null; } + + /** */ + @SuppressWarnings("PublicInnerClass") + public static class TestBinaryContext extends BinaryContext { + /** */ + private List<TestBinaryContextListener> listeners; + + /** */ + public TestBinaryContext( + BinaryMetadataHandler metaHnd, + @Nullable BinaryMarshaller marsh, + @Nullable String igniteInstanceName, + @Nullable ClassLoader clsLdr, + @Nullable BinarySerializer dfltSerializer, + @Nullable BinaryIdMapper idMapper, + @Nullable BinaryNameMapper nameMapper, + @Nullable Collection<BinaryTypeConfiguration> typeCfgs, + Map<String, String> affFlds, + boolean compactFooter, + IgniteLogger log + ) { + super(metaHnd, marsh, igniteInstanceName, clsLdr, dfltSerializer, idMapper, nameMapper, typeCfgs, affFlds, compactFooter, log); + } + + + /** {@inheritDoc} */ + @Nullable @Override public BinaryType metadata(int typeId) throws BinaryObjectException { + BinaryType metadata = super.metadata(typeId); + + if (listeners != null) { + for (TestBinaryContextListener listener : listeners) + listener.onAfterMetadataRequest(typeId, metadata); + } + + return metadata; + } + + /** {@inheritDoc} */ + @Override public void updateMetadata(int typeId, BinaryMetadata meta, boolean failIfUnregistered) throws BinaryObjectException { + if (listeners != null) { + for (TestBinaryContextListener listener : listeners) + listener.onBeforeMetadataUpdate(typeId, meta); + } + + super.updateMetadata(typeId, meta, failIfUnregistered); + } + + /** */ + public interface TestBinaryContextListener { + /** + * @param typeId Type id. + * @param type Type. + */ + void onAfterMetadataRequest(int typeId, BinaryType type); + + /** + * @param typeId Type id. + * @param metadata Metadata. + */ + void onBeforeMetadataUpdate(int typeId, BinaryMetadata metadata); + } + + /** @param lsnr Listener. */ + public void addListener(TestBinaryContextListener lsnr) { + if (listeners == null) + listeners = new ArrayList<>(); + + if (!listeners.contains(lsnr)) + listeners.add(lsnr); + } + + /** */ + public void clearAllListener() { + if (listeners != null) + listeners.clear(); + } + } } diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java index b3cff2119d4..c26d84b1710 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java @@ -56,6 +56,7 @@ import org.apache.ignite.cache.affinity.Affinity; import org.apache.ignite.cluster.ClusterGroup; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.configuration.AtomicConfiguration; +import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.CollectionConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -442,14 +443,22 @@ public class IgniteMock implements IgniteEx { return binaryMock; if (ctx == null) { + IgniteConfiguration cfg = configuration(); + + BinaryConfiguration bcfg = cfg.getBinaryConfiguration() == null ? new BinaryConfiguration() : cfg.getBinaryConfiguration(); + /** {@inheritDoc} */ ctx = new BinaryContext( BinaryUtils.cachingMetadataHandler(), (BinaryMarshaller)marshaller, - configuration().getIgniteInstanceName(), - configuration().getClassLoader(), - configuration().getBinaryConfiguration(), + cfg.getIgniteInstanceName(), + cfg.getClassLoader(), + bcfg.getSerializer(), + bcfg.getIdMapper(), + bcfg.getNameMapper(), + bcfg.getTypeConfigurations(), CU.affinityFields(configuration()), + bcfg.isCompactFooter(), NullLogger.INSTANCE ) { @Override public int typeId(String typeName) { diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/BinaryMetadataConcurrentUpdateWithIndexesTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/BinaryMetadataConcurrentUpdateWithIndexesTest.java index f0b2844e754..1a4403a307a 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/BinaryMetadataConcurrentUpdateWithIndexesTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/BinaryMetadataConcurrentUpdateWithIndexesTest.java @@ -46,6 +46,8 @@ import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.binary.BinaryMetadata; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage; +import org.apache.ignite.internal.util.IgniteUtils.TestBinaryContext; +import org.apache.ignite.internal.util.IgniteUtils.TestBinaryContext.TestBinaryContextListener; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.BlockTcpDiscoverySpi; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -146,11 +148,9 @@ public class BinaryMetadataConcurrentUpdateWithIndexesTest extends GridCommonAbs IgniteEx client0 = startClientGrid("client0"); - CacheObjectBinaryProcessorImpl.TestBinaryContext clientCtx = - (CacheObjectBinaryProcessorImpl.TestBinaryContext)((CacheObjectBinaryProcessorImpl)client0.context(). - cacheObjects()).binaryContext(); + TestBinaryContext clientCtx = (TestBinaryContext)((CacheObjectBinaryProcessorImpl)client0.context().cacheObjects()).binaryContext(); - clientCtx.addListener(new CacheObjectBinaryProcessorImpl.TestBinaryContext.TestBinaryContextListener() { + clientCtx.addListener(new TestBinaryContextListener() { @Override public void onAfterMetadataRequest(int typeId, BinaryType type) { if (syncMeta) { try {