Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
39f11fa
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 22, 2026
3f15eb9
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 22, 2026
ab1ff1a
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 22, 2026
45720ab
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 23, 2026
3770237
Merge branch 'master' into IGNITE-27641
nizhikov Jan 23, 2026
bc0e9f0
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 23, 2026
6959ecc
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 23, 2026
308ddd6
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 23, 2026
baa6d7b
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 23, 2026
d58705f
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 24, 2026
2f51d3d
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 24, 2026
bea02ab
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 24, 2026
1913eca
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 25, 2026
9d9e5b8
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 26, 2026
c78d3ec
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 26, 2026
bcb334f
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 26, 2026
14338c1
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 27, 2026
5bc0e15
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 27, 2026
3945a26
Merge branch 'IGNITE-27641' into IGNITE-27641-2
nizhikov Jan 27, 2026
2f65874
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 27, 2026
6d9b2d2
Merge branch 'master' into IGNITE-27641-2
nizhikov Jan 29, 2026
336babe
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 29, 2026
2f615b4
Merge branch 'master' into IGNITE-27641-2
nizhikov Jan 30, 2026
0fa3a41
IGNITE-27641 Generate serdes code for IgniteDataTransferObject
nizhikov Jan 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -56,6 +57,7 @@
import static org.apache.ignite.internal.MessageSerializerGenerator.TAB;
import static org.apache.ignite.internal.MessageSerializerGenerator.enumType;
import static org.apache.ignite.internal.MessageSerializerGenerator.identicalFileIsAlreadyGenerated;
import static org.apache.ignite.internal.idto.IgniteDataTransferObjectProcessor.DTO_CLASS;

/**
* Generates serializer class for given {@code IgniteDataTransferObject} extension.
Expand All @@ -73,6 +75,10 @@ public class IDTOSerializerGenerator {
" * @see org.apache.ignite.internal.dto.IgniteDataTransferObject" + NL +
" */";

/** */
private static final IgniteBiTuple<String, String> OBJECT_SERDES =
F.t("out.writeObject(obj.${f});", "obj.${f} = (${c})in.readObject();");

/** Type name to write/read code for the type. */
private static final Map<String, IgniteBiTuple<String, String>> TYPE_SERDES = new HashMap<>();

Expand All @@ -85,22 +91,30 @@ public class IDTOSerializerGenerator {
TYPE_SERDES.put(float.class.getName(), F.t("out.writeFloat(obj.${f});", "obj.${f} = in.readFloat();"));
TYPE_SERDES.put(double.class.getName(), F.t("out.writeDouble(obj.${f});", "obj.${f} = in.readDouble();"));

IgniteBiTuple<String, String> objSerdes = F.t("out.writeObject(obj.${f});", "obj.${f} = (${c})in.readObject();");

TYPE_SERDES.put(Boolean.class.getName(), objSerdes);
TYPE_SERDES.put(Byte.class.getName(), objSerdes);
TYPE_SERDES.put(Short.class.getName(), objSerdes);
TYPE_SERDES.put(Integer.class.getName(), objSerdes);
TYPE_SERDES.put(Long.class.getName(), objSerdes);
TYPE_SERDES.put(Float.class.getName(), objSerdes);
TYPE_SERDES.put(Double.class.getName(), objSerdes);
TYPE_SERDES.put(Boolean.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Byte.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Short.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Integer.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Long.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Float.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Double.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Throwable.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Exception.class.getName(), OBJECT_SERDES);
TYPE_SERDES.put(Object.class.getName(), OBJECT_SERDES);

TYPE_SERDES.put(String.class.getName(), F.t("U.writeString(out, obj.${f});", "obj.${f} = U.readString(in);"));
TYPE_SERDES.put(UUID.class.getName(), F.t("U.writeUuid(out, obj.${f});", "obj.${f} = U.readUuid(in);"));
TYPE_SERDES.put("org.apache.ignite.lang.IgniteUuid", F.t("U.writeIgniteUuid(out, obj.${f});", "obj.${f} = U.readIgniteUuid(in);"));
TYPE_SERDES.put("org.apache.ignite.internal.processors.cache.version.GridCacheVersion", objSerdes);
TYPE_SERDES.put("org.apache.ignite.internal.processors.cache.version.GridCacheVersion", OBJECT_SERDES);
TYPE_SERDES.put("org.apache.ignite.lang.IgniteProductVersion", OBJECT_SERDES);
TYPE_SERDES.put("org.apache.ignite.internal.binary.BinaryMetadata", OBJECT_SERDES);
TYPE_SERDES.put("org.apache.ignite.internal.management.cache.PartitionKey", OBJECT_SERDES);
TYPE_SERDES.put("org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion", OBJECT_SERDES);

TYPE_SERDES.put(Map.class.getName(), F.t("U.writeMap(out, obj.${f});", "obj.${f} = U.readMap(in);"));
TYPE_SERDES.put(Collection.class.getName(), F.t("U.writeCollection(out, obj.${f});", "obj.${f} = U.readCollection(in);"));
TYPE_SERDES.put(List.class.getName(), F.t("U.writeCollection(out, obj.${f});", "obj.${f} = U.readList(in);"));
TYPE_SERDES.put(Set.class.getName(), F.t("U.writeCollection(out, obj.${f});", "obj.${f} = U.readSet(in);"));
}

/** Write/Read code for enum. */
Expand Down Expand Up @@ -295,6 +309,8 @@ private List<String> fieldsSerdes(
List<VariableElement> flds,
Function<IgniteBiTuple<String, String>, String> lineProvider
) {
TypeMirror dtoCls = env.getElementUtils().getTypeElement(DTO_CLASS).asType();

List<String> code = new ArrayList<>();

for (VariableElement fld : flds) {
Expand All @@ -303,7 +319,11 @@ private List<String> fieldsSerdes(

IgniteBiTuple<String, String> serDes;

if (type.getKind() == TypeKind.ARRAY) {
if (env.getTypeUtils().isAssignable(type, dtoCls))
serDes = OBJECT_SERDES;
else if (type.getKind() == TypeKind.TYPEVAR)
serDes = F.t("out.writeObject(obj.${f});", "obj.${f} = in.readObject();");
else if (type.getKind() == TypeKind.ARRAY) {
comp = ((ArrayType)type).getComponentType();

serDes = enumType(env, comp) ? OBJ_ARRAY_SERDES : ARRAY_TYPE_SERDES.get(className(comp));
Expand All @@ -319,7 +339,8 @@ private List<String> fieldsSerdes(
.replaceAll("\\$\\{c}", simpleClassName(comp == null ? type : comp)));
}
else
throw new IllegalStateException("Unsupported type: " + type);
code.add("// Unsupported type: " + type + ", kind = " + type.getKind());
//throw new IllegalStateException("Unsupported type: " + type);
}

return code;
Expand Down Expand Up @@ -351,6 +372,12 @@ private List<VariableElement> fields(TypeElement type) {
/** @return FQN of {@code comp}. */
private static String className(TypeMirror comp) {
String n = comp.toString();

int spaceIdx = n.indexOf(' ');

if (spaceIdx != -1)
n = n.substring(spaceIdx + 1);

int genIdx = n.indexOf('<');

return genIdx == -1 ? n : n.substring(0, genIdx);
Expand All @@ -372,7 +399,7 @@ private String simpleClassName(TypeMirror type) {

String fqn = className(type);

if (!fqn.startsWith("java.lang"))
if (!fqn.startsWith("java.lang") && type.getKind() != TypeKind.TYPEVAR)
imports.add(fqn);

return simpleName(fqn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,21 @@ public class IgniteDataTransferObjectProcessor extends AbstractProcessor {
/** Package for serializers. */
private static final String FACTORY_PKG_NAME = "org.apache.ignite.internal.codegen.idto";

/** Base class that every dto must extend. */
private static final String DTO_CLASS = "org.apache.ignite.internal.dto.IgniteDataTransferObject";

/**
* Annotation used in management commands.
* For now, we restrict set of generated serdes to all management commands argument classes.
* Because, they strictly follows Ignite codestyle convention.
* Providing support of all other inheritor of {@code IgniteDataTransferObject} is matter of following improvements.
*/
private static final String ARG_ANNOTATION = "org.apache.ignite.internal.management.api.Argument";
/** Base class that every dto must extends. */
static final String DTO_CLASS = "org.apache.ignite.internal.dto.IgniteDataTransferObject";

/** Factory class name. */
public static final String FACTORY_CLASS = "IDTOSerializerFactory";

/** Generated classes. */
private final Map<TypeElement, String> genSerDes = new HashMap<>();

/** Currently unsupported classes. */
private final Set<String> unsupported = Set.of(
"org.apache.ignite.internal.management.cache.ContentionJobResult",
"org.apache.ignite.internal.processors.cache.CacheMetricsSnapshot"
);

/**
* Processes all classes extending the {@code IgniteDataTransferObject} and generates corresponding serializer code.
*/
Expand Down Expand Up @@ -107,13 +105,15 @@ private void generateSingle(Element el) {
return;

TypeMirror dtoCls = processingEnv.getElementUtils().getTypeElement(DTO_CLASS).asType();
TypeMirror argAnnotation = processingEnv.getElementUtils().getTypeElement(ARG_ANNOTATION).asType();

TypeElement clazz = (TypeElement)el;

// Generate code for inner classes.
clazz.getEnclosedElements().forEach(this::generateSingle);

if (unsupported.contains(clazz.getQualifiedName().toString()))
return;

if (!processingEnv.getTypeUtils().isAssignable(clazz.asType(), dtoCls))
return;

Expand All @@ -126,9 +126,6 @@ private void generateSingle(Element el) {
if (clazz.getNestingKind() != NestingKind.TOP_LEVEL && clazz.getNestingKind() != NestingKind.MEMBER)
return;

if (!hasArgumentFields(clazz, argAnnotation))
return;

try {
IDTOSerializerGenerator gen = new IDTOSerializerGenerator(processingEnv, clazz);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package org.apache.ignite.internal.cache.query.index.sorted;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -76,25 +73,25 @@ public class DurableBackgroundCleanupIndexTreeTaskV2 extends IgniteDataTransferO
@Nullable private transient volatile IgniteLogger log;

/** Unique id. */
private String uid;
String uid;

/** Cache group name. */
@Nullable private String grpName;
@Nullable String grpName;

/** Cache name. */
private String cacheName;
String cacheName;

/** Index name. */
private String idxName;
String idxName;

/** Old name of underlying index tree name. */
private String oldTreeName;
String oldTreeName;

/** New name of underlying index tree name. */
private String newTreeName;
String newTreeName;

/** Number of segments. */
private int segments;
int segments;

/** Need to rename index root pages. */
private transient volatile boolean needToRen;
Expand Down Expand Up @@ -153,28 +150,6 @@ public DurableBackgroundCleanupIndexTreeTaskV2() {
// No-op.
}

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeLongString(out, uid);
U.writeLongString(out, grpName);
U.writeLongString(out, cacheName);
U.writeLongString(out, idxName);
U.writeLongString(out, oldTreeName);
U.writeLongString(out, newTreeName);
out.writeInt(segments);
}

/** {@inheritDoc} */
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
uid = U.readLongString(in);
grpName = U.readLongString(in);
cacheName = U.readLongString(in);
idxName = U.readLongString(in);
oldTreeName = U.readLongString(in);
newTreeName = U.readLongString(in);
segments = in.readInt();
}

/** {@inheritDoc} */
@Override public String name() {
return "drop-sql-index-" + cacheName + "-" + idxName + "-" + uid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CheckIndexInlineSizesResult extends IgniteDataTransferObject {
private static final long serialVersionUID = 0L;

/** Index info (index name, inline size) per node. */
private Map<UUID, Map<String, Integer>> nodeToIndexes = new HashMap<>();
Map<UUID, Map<String, Integer>> nodeToIndexes = new HashMap<>();

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
*/
package org.apache.ignite.internal.commandline.cache.distribution;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.util.typedef.internal.U;

/**
* DTO for CacheDistributionTask, contains information about group
Expand All @@ -31,13 +27,13 @@ public class CacheDistributionGroup extends IgniteDataTransferObject {
private static final long serialVersionUID = 0L;

/** Group identifier. */
private int grpId;
int grpId;

/** Group name. */
private String grpName;
String grpName;

/** List of partitions. */
private List<CacheDistributionPartition> partitions;
List<CacheDistributionPartition> partitions;

/** Default constructor. */
public CacheDistributionGroup() {
Expand Down Expand Up @@ -84,18 +80,4 @@ public void setPartitions(
List<CacheDistributionPartition> partitions) {
this.partitions = partitions;
}

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
out.writeInt(grpId);
U.writeString(out, grpName);
U.writeCollection(out, partitions);
}

/** {@inheritDoc} */
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
grpId = in.readInt();
grpName = U.readString(in);
partitions = U.readList(in);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
*/
package org.apache.ignite.internal.commandline.cache.distribution;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.util.typedef.internal.U;

/**
* DTO for CacheDistributionTask, contains information about node
Expand All @@ -33,16 +29,16 @@ public class CacheDistributionNode extends IgniteDataTransferObject {
private static final long serialVersionUID = 0L;

/** Node identifier. */
private UUID nodeId;
UUID nodeId;

/** Network addresses. */
private String addrs;
String addrs;

/** User attribute in result. */
private Map<String, String> userAttrs;
Map<String, String> userAttrs;

/** Information about groups. */
private List<CacheDistributionGroup> groups;
List<CacheDistributionGroup> groups;

/** Default constructor. */
public CacheDistributionNode() {
Expand Down Expand Up @@ -106,21 +102,4 @@ public List<CacheDistributionGroup> getGroups() {
public void setGroups(List<CacheDistributionGroup> groups) {
this.groups = groups;
}

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeUuid(out, nodeId);
U.writeString(out, addrs);
U.writeMap(out, userAttrs);
U.writeCollection(out, groups);
}

/** {@inheritDoc} */
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
nodeId = U.readUuid(in);
addrs = U.readString(in);
userAttrs = U.readMap(in);
groups = U.readList(in);
}

}
Loading
Loading