Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
petrov-mg committed Nov 29, 2023
1 parent 28d5a87 commit bc7b7f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bc7b7f3

Please sign in to comment.