You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2025/04/22 12:56:47 UTC

(ignite) branch master updated: IGNITE-25156 Make BinarySchemaRegistry package private (#12007)

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 fd140911247 IGNITE-25156 Make BinarySchemaRegistry package private (#12007)
fd140911247 is described below

commit fd1409112473f82080b45c356239b7c79c8800fd
Author: Maksim Davydov <70...@users.noreply.github.com>
AuthorDate: Tue Apr 22 15:56:41 2025 +0300

    IGNITE-25156 Make BinarySchemaRegistry package private (#12007)
---
 .../ignite/internal/binary/BinaryContext.java      | 37 +++++++++++++++++++++-
 .../internal/binary/BinarySchemaRegistry.java      |  2 +-
 .../apache/ignite/internal/binary/BinaryUtils.java | 33 +++++++++++++++++++
 .../binary/builder/BinaryObjectBuilderImpl.java    | 33 +------------------
 .../processors/platform/PlatformContextImpl.java   |  3 +-
 .../processors/platform/utils/PlatformUtils.java   | 36 ---------------------
 6 files changed, 73 insertions(+), 71 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 d287cee733e..8f901aee76a 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
@@ -1373,13 +1373,48 @@ public class BinaryContext {
         return compactFooter;
     }
 
+    /** */
+    public void updateMetaIfNeeded(
+        BinaryWriterExImpl writer,
+        BinaryType meta,
+        int typeId,
+        String typeName,
+        String affFieldName,
+        Map<String, BinaryFieldMetadata> fieldsMeta
+    ) {
+        BinarySchemaRegistry schemaReg = schemaRegistry(typeId);
+
+        // Update metadata if needed.
+        int schemaId = writer.schemaId();
+
+        if (schemaReg.schema(schemaId) == null) {
+            if (typeName == null) {
+                assert meta != null;
+
+                typeName = meta.typeName();
+            }
+
+            BinarySchema curSchema = writer.currentSchema();
+
+            if (affFieldName == null)
+                affFieldName = affinityKeyFieldName(typeId);
+
+            registerUserClassName(typeId, typeName, writer.failIfUnregistered(), false, JAVA_ID);
+
+            updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, affFieldName,
+                Collections.singleton(curSchema), false, null), writer.failIfUnregistered());
+
+            schemaReg.addSchema(curSchema.schemaId(), curSchema);
+        }
+    }
+
     /**
      * Get schema registry for type ID.
      *
      * @param typeId Type ID.
      * @return Schema registry for type ID.
      */
-    public BinarySchemaRegistry schemaRegistry(int typeId) {
+    BinarySchemaRegistry schemaRegistry(int typeId) {
         Map<Integer, BinarySchemaRegistry> schemas0 = schemas;
 
         if (schemas0 == null) {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
index 028aa53f32f..bbfb14851f1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
  * of them with optional fallback to normal hash map lookup.
  *
  */
-public class BinarySchemaRegistry {
+class BinarySchemaRegistry {
     /** Empty schema ID. */
     private static final int EMPTY = 0;
 
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 f1019cc585c..ead54b1c093 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
@@ -71,6 +71,7 @@ import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.MutableSingletonList;
 import org.apache.ignite.internal.util.typedef.F;
@@ -2711,6 +2712,38 @@ public class BinaryUtils {
         BinaryEnumCache.clear();
     }
 
+    /**
+     * Gets the schema.
+     *
+     * @param cacheObjProc Cache object processor.
+     * @param typeId Type id.
+     * @param schemaId Schema id.
+     */
+    public static int[] getSchema(CacheObjectBinaryProcessorImpl cacheObjProc, int typeId, int schemaId) {
+        assert cacheObjProc != null;
+
+        BinarySchemaRegistry schemaReg = cacheObjProc.binaryContext().schemaRegistry(typeId);
+        BinarySchema schema = schemaReg.schema(schemaId);
+
+        if (schema == null) {
+            BinaryTypeImpl meta = (BinaryTypeImpl)cacheObjProc.metadata(typeId);
+
+            if (meta != null) {
+                for (BinarySchema typeSchema : meta.metadata().schemas()) {
+                    if (schemaId == typeSchema.schemaId()) {
+                        schema = typeSchema;
+                        break;
+                    }
+                }
+            }
+
+            if (schema != null)
+                schemaReg.addSchema(schemaId, schema);
+        }
+
+        return schema == null ? null : schema.fieldIds();
+    }
+
     /**
      * @return Unwrap function for object size calculation.
      */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 1df14e25496..74b8a3d12fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -34,10 +34,8 @@ import org.apache.ignite.internal.binary.BinaryArray;
 import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.binary.BinaryEnumObjectImpl;
 import org.apache.ignite.internal.binary.BinaryFieldMetadata;
-import org.apache.ignite.internal.binary.BinaryMetadata;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinarySchema;
-import org.apache.ignite.internal.binary.BinarySchemaRegistry;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
@@ -47,8 +45,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.thread.IgniteThread;
 import org.jetbrains.annotations.Nullable;
 
-import static org.apache.ignite.internal.MarshallerPlatformIds.JAVA_ID;
-
 /**
  *
  */
@@ -342,34 +338,7 @@ class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
             writer.postWrite(true, registeredType);
 
-            // Update metadata if needed.
-            int schemaId = writer.schemaId();
-
-            BinarySchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
-
-            if (schemaReg.schema(schemaId) == null) {
-                String typeName = this.typeName;
-
-                if (typeName == null) {
-                    assert meta != null;
-
-                    typeName = meta.typeName();
-                }
-
-                BinarySchema curSchema = writer.currentSchema();
-
-                String affFieldName0 = affFieldName;
-
-                if (affFieldName0 == null)
-                    affFieldName0 = ctx.affinityKeyFieldName(typeId);
-
-                ctx.registerUserClassName(typeId, typeName, writer.failIfUnregistered(), false, JAVA_ID);
-
-                ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, affFieldName0,
-                    Collections.singleton(curSchema), false, null), writer.failIfUnregistered());
-
-                schemaReg.addSchema(curSchema.schemaId(), curSchema);
-            }
+            ctx.updateMetaIfNeeded(writer, meta, typeId, typeName, affFieldName, fieldsMeta);
 
             // Update hash code after schema is written.
             writer.postWriteHashCode(registeredType ? null : clsNameToWrite);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index 6e8272803f9..4f1b70f0d5d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.binary.BinaryReaderExImpl;
 import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
@@ -361,7 +362,7 @@ public class PlatformContextImpl implements PlatformContext, PartitionsExchangeA
 
     /** {@inheritDoc} */
     @Override public void writeSchema(BinaryRawWriterEx writer, int typeId, int schemaId) {
-        writer.writeIntArray(PlatformUtils.getSchema(cacheObjProc, typeId, schemaId));
+        writer.writeIntArray(BinaryUtils.getSchema(cacheObjProc, typeId, schemaId));
     }
 
     /**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
index b9435feefcb..6bd459273c5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
@@ -54,14 +54,11 @@ import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.binary.BinaryReaderExImpl;
 import org.apache.ignite.internal.binary.BinarySchema;
-import org.apache.ignite.internal.binary.BinarySchemaRegistry;
-import org.apache.ignite.internal.binary.BinaryTypeImpl;
 import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.cacheobject.PlatformCacheObjectImpl;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformExtendedException;
@@ -1104,39 +1101,6 @@ public class PlatformUtils {
         return X.getFullStackTrace(throwable);
     }
 
-    /**
-     * Gets the schema.
-     *
-     * @param cacheObjProc Cache object processor.
-     * @param typeId Type id.
-     * @param schemaId Schema id.
-     */
-    public static int[] getSchema(CacheObjectBinaryProcessorImpl cacheObjProc, int typeId, int schemaId) {
-        assert cacheObjProc != null;
-
-        BinarySchemaRegistry schemaReg = cacheObjProc.binaryContext().schemaRegistry(typeId);
-        BinarySchema schema = schemaReg.schema(schemaId);
-
-        if (schema == null) {
-            BinaryTypeImpl meta = (BinaryTypeImpl)cacheObjProc.metadata(typeId);
-
-            if (meta != null) {
-                for (BinarySchema typeSchema : meta.metadata().schemas()) {
-                    if (schemaId == typeSchema.schemaId()) {
-                        schema = typeSchema;
-                        break;
-                    }
-                }
-            }
-
-            if (schema != null) {
-                schemaReg.addSchema(schemaId, schema);
-            }
-        }
-
-        return schema == null ? null : schema.fieldIds();
-    }
-
     /**
      * Writes the binary metadata to a writer.
      *