Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.CoreMessagesProvider;
import org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner;
import org.apache.ignite.internal.direct.DirectMessageReader;
Expand All @@ -30,6 +31,8 @@
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GroupPartitionIdPair;
import org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext;
import org.apache.ignite.logger.NullLogger;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
Expand Down Expand Up @@ -73,7 +76,7 @@ public static void main(String[] args) throws Exception {

/** */
@Setup
public void setup() {
public void setup() throws IgniteCheckedException {
MessageFactory msgFactory = msgFactory();

reader = new DirectMessageReader(msgFactory, null);
Expand Down Expand Up @@ -120,8 +123,8 @@ public Message compressedMessage() {
}

/** */
private static MessageFactory msgFactory() {
return new IgniteMessageFactoryImpl(new MessageFactoryProvider[]{
new CoreMessagesProvider()});
private static MessageFactory msgFactory() throws IgniteCheckedException {
return new IgniteMessageFactoryImpl(new MessageFactoryProvider[] {
new CoreMessagesProvider(new StandaloneGridKernalContext(new NullLogger(), null))});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ public class MessageProcessor extends AbstractProcessor {
/** */
public static final Set<String> NO_PUBLIC_CTOR_MSGS = Set.of(GRID_H2_NULL, ZK_NO_SERVERS_MESSAGE);

/** Messages with no fields. A serializer generation intentionally skipped. */
/** */
static final String OP_CTX_SNAPSHOT_MESSAGE_CLASS = "org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage";

/** Messages with no fields, or with a hand-written serializer. A serializer generation intentionally skipped. */
static final String[] SKIP_MESSAGES = {
"org.apache.ignite.internal.processors.odbc.ClientMessage",
COMPRESSED_MESSAGE_CLASS,
OP_CTX_SNAPSHOT_MESSAGE_CLASS,
"org.apache.ignite.loadtests.communication.GridTestMessage",
"org.apache.ignite.spi.communication.tcp.TestDelayMessage"
};
Expand Down Expand Up @@ -194,7 +198,7 @@ public static boolean isSkippedMessage(String clsName) {
clazz);
}

if (!checkConstructors(clazz) || !checkFeatureGatedFields(clazz, fields))
if (!checkConstructors(clazz) || !checkFeatureGatedFields(processingEnv, clazz, fields))
continue;

msgFields.put(clazz, fields);
Expand Down Expand Up @@ -227,8 +231,12 @@ public static boolean isSkippedMessage(String clsName) {
}

/** */
private boolean checkFeatureGatedFields(TypeElement clazz, List<VariableElement> fields) {
boolean isSchemaImmutable = isSchemaImmutable(processingEnv, clazz);
public static boolean checkFeatureGatedFields(
ProcessingEnvironment env,
TypeElement clazz,
Collection<VariableElement> fields
) {
boolean isSchemaImmutable = isSchemaImmutable(env, clazz);
String reg = null;
Map<String, VariableElement> gatedFields = new HashMap<>();

Expand All @@ -242,7 +250,7 @@ private boolean checkFeatureGatedFields(TypeElement clazz, List<VariableElement>

if (isSchemaImmutable) {
printError(
processingEnv,
env,
field,
"A message with an immutable schema must not have fields gated by features [cls=" + clazz + ", field=" + field + ']');

Expand All @@ -255,7 +263,7 @@ private boolean checkFeatureGatedFields(TypeElement clazz, List<VariableElement>
reg = fieldReg;
else if (!reg.equals(fieldReg)) {
printError(
processingEnv,
env,
field,
"All fields gated by features in one message hierarchy must resolve to the same feature registry" +
" [expected=" + reg + ", actual=" + fieldReg + ']');
Expand All @@ -265,7 +273,7 @@ else if (!reg.equals(fieldReg)) {

if (!order.introducedBy().isEmpty() && !order.deprecatedBy().isEmpty()) {
printError(
processingEnv,
env,
field,
"A field must not be introduced and deprecated at once, deprecate it after the feature that introduced it" +
" is retired" +
Expand All @@ -281,7 +289,7 @@ else if (!reg.equals(fieldReg)) {

if (otherField != null) {
printError(
processingEnv,
env,
field,
"A feature can gate only one field of a message class hierarchy" +
" [cls=" + clazz +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.processing.FilerException;
import javax.annotation.processing.ProcessingEnvironment;
Expand All @@ -48,6 +47,7 @@
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.apache.ignite.internal.MessageProcessor.FieldFeatureGate;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.NotNull;
Expand All @@ -56,6 +56,8 @@
import static org.apache.ignite.internal.MessageCompanionGenerator.TAB;
import static org.apache.ignite.internal.MessageCompanionGenerator.identicalFileIsAlreadyGenerated;
import static org.apache.ignite.internal.MessageCompanionGenerator.writeLicense;
import static org.apache.ignite.internal.MessageProcessor.buildFieldFeatureGate;
import static org.apache.ignite.internal.MessageProcessor.checkFeatureGatedFields;
import static org.apache.ignite.internal.MessageSerializerGenerator.enumType;
import static org.apache.ignite.internal.MessageSerializerGenerator.qualifiedClassName;
import static org.apache.ignite.internal.idto.IgniteDataTransferObjectProcessor.DTO_CLASS;
Expand Down Expand Up @@ -214,6 +216,9 @@ public String serializerFQN() {
* @throws Exception in case of error.
*/
public boolean generate() throws Exception {
if (!checkFeatureGatedFields(env, type, orderedFlds))
return false;

String fqnClsName = serializerFQN();
String serCode = generateSerializerCode();

Expand Down Expand Up @@ -253,6 +258,7 @@ private String generateSerializerCode() throws IOException {
imports.add(ObjectInput.class.getName());
imports.add(IOException.class.getName());
imports.add("org.apache.ignite.internal.util.typedef.internal.U");
imports.add("org.apache.ignite.internal.MessageSerializationContext");

if (type.getNestingKind() != NestingKind.TOP_LEVEL)
imports.add(type.getQualifiedName().toString());
Expand Down Expand Up @@ -310,7 +316,10 @@ private List<String> generateWrite(Collection<VariableElement> flds) {
List<String> code = new ArrayList<>();

code.add("/** {@inheritDoc} */");
code.add("@Override public void writeExternal(" + typeWithGeneric(type.asType()) + " obj, ObjectOutput out) throws IOException {");
code.add("@Override public void writeExternal(" +
typeWithGeneric(type.asType()) + " obj," +
" ObjectOutput out," +
" MessageSerializationContext ctx) throws IOException {");

fieldsSerdes(flds).forEach(line -> code.add(TAB + line));

Expand All @@ -326,8 +335,10 @@ private List<String> generateRead(Collection<VariableElement> flds) {
List<String> code = new ArrayList<>();

code.add("/** {@inheritDoc} */");
code.add("@Override public void readExternal(" + typeWithGeneric(type.asType()) + " obj, ObjectInput in) " +
"throws IOException, ClassNotFoundException {");
code.add("@Override public void readExternal(" +
typeWithGeneric(type.asType()) + " obj," +
" ObjectInput in," +
" MessageSerializationContext ctx) throws IOException, ClassNotFoundException {");

fieldsSerdes(flds).forEach(line -> code.add(TAB + line));

Expand All @@ -341,9 +352,27 @@ private List<String> generateRead(Collection<VariableElement> flds) {
* @return Lines to serdes fields.
*/
private List<String> fieldsSerdes(Collection<VariableElement> flds) {
return flds.stream()
.flatMap(fld -> variableCode(fld.asType(), "obj." + fld.getSimpleName().toString()))
.collect(Collectors.toList());
List<String> res = new ArrayList<>();

for (VariableElement fld : flds) {
List<String> lines = variableCode(fld.asType(), "obj." + fld.getSimpleName()).toList();

FieldFeatureGate gate = buildFieldFeatureGate(env, fld);

if (gate == null)
res.addAll(lines);
else {
imports.add(gate.registry());

res.add("if (" + gate.expression() + ") {");

lines.forEach(line -> res.add(TAB + line));

res.add("}");
}
}

return res;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.internal.MessageSerializationContext;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.dto.IgniteDataTransferObjectSerializer;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -36,12 +37,20 @@
*/
public class OfflineTestCommandArgSerializer implements IgniteDataTransferObjectSerializer<TestOfflineTestCommandArg> {
/** {@inheritDoc} */
@Override public void writeExternal(TestOfflineTestCommandArg obj, ObjectOutput out) throws IOException {
@Override public void writeExternal(
TestOfflineTestCommandArg obj,
ObjectOutput out,
MessageSerializationContext ctx
) throws IOException {
U.writeString(out, obj.input);
}

/** {@inheritDoc} */
@Override public void readExternal(TestOfflineTestCommandArg obj, ObjectInput in) throws IOException, ClassNotFoundException {
@Override public void readExternal(
TestOfflineTestCommandArg obj,
ObjectInput in,
MessageSerializationContext ctx
) throws IOException, ClassNotFoundException {
obj.input = U.readString(in);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
import org.apache.ignite.internal.processors.service.ServiceTopology;
import org.apache.ignite.internal.processors.service.ServiceUndeploymentRequest;
import org.apache.ignite.internal.thread.context.OperationContextSnapshotMessage;
import org.apache.ignite.internal.thread.context.OperationContextSnapshotMessageSerializer;
import org.apache.ignite.internal.util.ErrorMessage;
import org.apache.ignite.internal.util.GridByteArrayList;
import org.apache.ignite.internal.util.GridIntList;
Expand All @@ -291,6 +292,7 @@
import org.apache.ignite.internal.util.distributed.InitMessage;
import org.apache.ignite.internal.util.distributed.SingleNodeMessage;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
import org.apache.ignite.plugin.security.SecurityBasicPermissionSet;
import org.apache.ignite.spi.collision.jobstealing.JobStealingRequest;
import org.apache.ignite.spi.communication.tcp.internal.TcpConnectionRequestDiscoveryMessage;
Expand Down Expand Up @@ -351,12 +353,12 @@ public class CoreMessagesProvider extends AbstractMessageFactoryProvider {
/** */
private @Nullable IgniteMessageFactory factory;

/**
* Default plugin-purposes constructor.
*
*/
public CoreMessagesProvider() {
// No-op.
/** */
private final GridKernalContext ctx;

/** */
public CoreMessagesProvider(GridKernalContext ctx) {
this.ctx = ctx;
}

/**
Expand Down Expand Up @@ -751,7 +753,7 @@ public CoreMessagesProvider() {

// [13400 - 13500]: Operation context messages.
msgIdx = 13400;
register(OperationContextSnapshotMessage.class);
register(OperationContextSnapshotMessage.class, new OperationContextSnapshotMessageSerializer(ctx));
register(SecurityContextWrapper.class);

// [13600 - 13700]: Rolling Upgrade messages.
Expand All @@ -769,4 +771,9 @@ public CoreMessagesProvider() {
private <T extends Message> void register(Class<T> cls) {
register(factory, cls, msgIdx++);
}

/** */
private <T extends Message> void register(Class<T> cls, MessageSerializer<T> serializer) {
register(factory, cls, msgIdx++, serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ private void initMessageFactory() throws IgniteCheckedException {

List<MessageFactoryProvider> compMsgs = new ArrayList<>();

compMsgs.add(new CoreMessagesProvider());
compMsgs.add(new CoreMessagesProvider(ctx));

for (IgniteComponentType compType : IgniteComponentType.values()) {
MessageFactoryProvider f = compType.messageFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ public static IgniteMessageSerializationContext buildForPeers(
return new IgniteMessageSerializationContext(ctxByComponent);
}

/** */
public static MessageSerializationContext buildForInitiator(@Nullable IgniteNodeFeatureSet initiatorFeatures) {
if (initiatorFeatures == null)
return IMMUTABLE_SCHEMA;

Map<String, ComponentMessageSerializationContext> ctxByComponent = new HashMap<>();

for (IgniteComponentFeatureSet cmpFeatures : initiatorFeatures.values()) {
ctxByComponent.put(
cmpFeatures.componentName(),
new ComponentMessageSerializationContext(cmpFeatures.features(), cmpFeatures.features()));
}

return new IgniteMessageSerializationContext(ctxByComponent);
}

/** */
private static ComponentMessageSerializationContext resolveComponentSerializationContext(
String cmpName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
import java.util.Collection;
import java.util.List;
import org.apache.ignite.internal.codegen.idto.IDTOSerializerFactory;
import org.apache.ignite.internal.thread.context.OperationContext;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.direct.IgniteMessageSerializationContext.buildForInitiator;
import static org.apache.ignite.internal.processors.rollingupgrade.RollingUpgradeProcessor.OP_FEATURES_ATTR;

/**
* Base class for data transfer objects.
*/
Expand Down Expand Up @@ -72,7 +76,7 @@ protected void writeIgniteDataTransferObject(ObjectOutput out) throws IOExceptio
try (IgniteDataTransferObjectOutput dtout = new IgniteDataTransferObjectOutput(out)) {
IgniteDataTransferObjectSerializer serializer = IDTOSerializerFactory.getInstance().serializer(getClass());

serializer.writeExternal(this, dtout);
serializer.writeExternal(this, dtout, buildForInitiator(OperationContext.get(OP_FEATURES_ATTR)));
}
}

Expand All @@ -81,7 +85,7 @@ protected void readIgniteDataTransferObject(ObjectInput in) throws IOException,
try (IgniteDataTransferObjectInput dtin = new IgniteDataTransferObjectInput(in)) {
IgniteDataTransferObjectSerializer serializer = IDTOSerializerFactory.getInstance().serializer(getClass());

serializer.readExternal(this, dtin);
serializer.readExternal(this, dtin, buildForInitiator(OperationContext.get(OP_FEATURES_ATTR)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.internal.MessageSerializationContext;

/**
* @param <T> Type of specific IgniteDataTransferObject this serializer works with.
Expand All @@ -29,17 +30,19 @@ public interface IgniteDataTransferObjectSerializer<T> {
*
* @param instance Instance of IgniteDataTransferObject to serialize.
* @param out Output stream to write object to.
* @param ctx Serialization context.
* @throws IOException If write operation failed.
*/
void writeExternal(T instance, ObjectOutput out) throws IOException;
void writeExternal(T instance, ObjectOutput out, MessageSerializationContext ctx) throws IOException;

/**
*
* @param instance Instance of an IgniteDataTransferObject to read data to.
* @param in Input stream to read object from.
* @param ctx Serialization context.
* @return
* @throws IOException If read operation failed.
* @throws ClassNotFoundException If class not found.
*/
void readExternal(T instance, ObjectInput in) throws IOException, ClassNotFoundException;
void readExternal(T instance, ObjectInput in, MessageSerializationContext ctx) throws IOException, ClassNotFoundException;
}
Loading
Loading