From bc7b7f37ced88b7415984d7fce2217c580cab2ea Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Wed, 29 Nov 2023 18:36:14 +0300 Subject: [PATCH] wip --- .../internal/binary/BinaryObjectImpl.java | 2 +- .../builder/BinaryObjectBuilderImpl.java | 50 ++++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) 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 0d6d2ebfdd433e..cdde588582dfc2 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 @@ -300,7 +300,7 @@ public BinaryObjectImpl detach(boolean resolveReferences) { return this; if (resolveReferences) { - BinaryObjectBuilderImpl builder = new BinaryObjectBuilderImpl(this); + BinaryObjectBuilderImpl builder = new BinaryObjectBuilderImpl(this, true); return (BinaryObjectImpl)builder.build(); } 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 378f06c2f9b683..6c96ffbd4f39b8 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 @@ -93,6 +93,9 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder { /** Affinity key field name. */ private String affFieldName; + /** Affinity key field name. */ + private boolean skipMetadataUpdate; + /** * @param clsName Class name. * @param ctx Binary context. @@ -123,8 +126,17 @@ public BinaryObjectBuilderImpl(BinaryContext ctx, int typeId, String typeName) { * @param obj Object to wrap. */ public BinaryObjectBuilderImpl(BinaryObjectImpl obj) { + this(obj, false); + } + + /** + * @param obj Object to wrap. + */ + public BinaryObjectBuilderImpl(BinaryObjectImpl obj, boolean skipMetadataUpdate) { this(new BinaryBuilderReader(obj), obj.start()); reader.registerObject(this); + + this.skipMetadataUpdate = skipMetadataUpdate; } /** @@ -145,7 +157,7 @@ public BinaryObjectBuilderImpl(BinaryObjectImpl obj) { int typeId = reader.readIntPositioned(start + GridBinaryMarshaller.TYPE_ID_POS); ctx = reader.binaryContext(); - if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { + if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID && !skipMetadataUpdate) { int mark = reader.position(); reader.position(start + GridBinaryMarshaller.DFLT_HDR_LEN); @@ -343,33 +355,35 @@ else if (readCache == null) { writer.postWrite(BinaryUtils.isCompactFooter(flags), true, registeredType); - // Update metadata if needed. - int schemaId = writer.schemaId(); + if (!skipMetadataUpdate) { + // Update metadata if needed. + int schemaId = writer.schemaId(); - BinarySchemaRegistry schemaReg = ctx.schemaRegistry(typeId); + BinarySchemaRegistry schemaReg = ctx.schemaRegistry(typeId); - if (schemaReg.schema(schemaId) == null) { - String typeName = this.typeName; + if (schemaReg.schema(schemaId) == null) { + String typeName = this.typeName; - if (typeName == null) { - assert meta != null; + if (typeName == null) { + assert meta != null; - typeName = meta.typeName(); - } + typeName = meta.typeName(); + } - BinarySchema curSchema = writer.currentSchema(); + BinarySchema curSchema = writer.currentSchema(); - String affFieldName0 = affFieldName; + String affFieldName0 = affFieldName; - if (affFieldName0 == null) - affFieldName0 = ctx.affinityKeyFieldName(typeId); + if (affFieldName0 == null) + affFieldName0 = ctx.affinityKeyFieldName(typeId); - ctx.registerUserClassName(typeId, typeName, writer.failIfUnregistered(), false, JAVA_ID); + 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()); + ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta, affFieldName0, + Collections.singleton(curSchema), false, null), writer.failIfUnregistered()); - schemaReg.addSchema(curSchema.schemaId(), curSchema); + schemaReg.addSchema(curSchema.schemaId(), curSchema); + } } // Update hash code after schema is written.