Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. MessageWriter, MessageReader logic is depends on a remote IgniteProductVersion.
  2. Message#writeTo, Message#readFrom is auto-generated and stored separately from Message DTO classes.
  3. Add Message#writeObject - for serializing Objects (java functions, and user objects):
    1. MessageWriter for communication protocol use BinaryMarshaller
    2. MessageWriter for discovery protocol use JdkMarshaller
  4. Message fields contain:
    1. primitive classes.
    2. known collections.
    3. POJO - that are other Message.
    4. Users classes and java functions (e.g. ComputeJob).
    5. byte[] fields (objects serialized externally) must be avoided as much as possible, because their compatibility can't be guaranteed.
  5. Order of fields in Message is fixed with @Order annotation.
  6. Add  @Since, @Until  annotations for Message classes and fields.

Code checks

  1. Ignite CI must notify notifies for IF-clauses with condition based on IgniteVersion older than (curVer - 1).
  2. Ignite CI must forbid forbids code changes if Message DTO changed without corresponding @Since, @Until annotations.
  3. Ignite CI must forbid forbids code changes if Message DTO contains byte[] fields.
  4. Ignite CI checks @Order annotation of fields - starts with 0, no lags.

Nice to have (for later research)

...

  1. Message#writeTo consumes MessageWriter that stores IgniteProduceVersion IgniteProductVersion of destination node and use it for serializing data for this version (mostly, for ignoring some fields).
  2. Message#readFrom consumes MessageReader that stores IgniteProductVersion of source node and use it for deserializing data (mostly, for setting default values of new fields).

    Code Block
    languagejava
    titleMessage
    public interface MessageMessageWriter {   
     
        public booleanIgniteProductVersion writeTo(ByteBuffer buf, MessageWriter writerdestinationVersion();
    }
    
     public  interface publicMessageReader boolean{
     readFrom(ByteBuffer buf, MessageReader reader);
    
        public shortIgniteProductVersion directTypesourceVersion();
    }


  3. Introduce annotations @Since and @Until for Message classes and Message fields, to use it for generating code for Message#writeTo and Message#readFrom:

Code Block
languagejava
titleMyMessage
// Package where thatthe storeMessage allis schemasdefined.
package org.apache.ignite.internal.messagesmy.schemamessage;

// package private class.
@Since(version = "2.19.0")
public class MyMessage implements Message {
    @Order(0)
    private int id;
    
 	/** Remove field. */
    @Until(version = "2.20.0")
	
    private String rmFld;

    /** New field. */
    @Since(version = "2.20.0")
 	@Order(2)
    private String newFld;
}

	// GeneratedDelegates code#writeTo frommethod thecall schemato ^generated forserializer.
 Ignite  version 2.20.0.
package org.apache.ignite.internal.messages;

// public class.
public class MyMessage {
    private int id @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
        return MyMessageSerializer.writeTo(this, buf, writer);
    }

 	//**
 Delegates #readFrom method call *to Removegenerated fieldserializer.
 
   @Override public boolean * @deprecated since 2.20.0. readFrom(ByteBuffer buf, MessageReader reader) {
     */
    @Deprecated
    private String rmFld;

return MyMessageSerializer.readFrom(this, buf, reader);
    /** 
     * New field.
     * @since }
}

// Generated code from the message ^ for Ignite version 2.20.0.
// Use the same package */
as corresponding message.
package  private String newFld;
org.apache.ignite.internal.my.message;

class MyMessage {
    @Override public publicstatic boolean writeTo(ByteBufferMyMessage msg, MByteBuffer buf, MessageWriter writer) {
        IgniteProductVersion destVer = writer.version();

        if (destVer.lessThan(2, 19, 0))
            throw new IgniteException("Must not send the message to destination node");

        writer.writeString(msg.id());

        if (destVer.lessThan(2, 20, 0))
            writer.writeString(msg.rmFld());

        if (destVer.greaterThanEqual(2, 20, 0))
            writer.writeString(msg.newFld());
    
        return true;
    }

    @Overridepublic publicstatic boolean readFrom(MyMessage msg, ByteBuffer buf, MessageReader reader) {
        IgniteProductVersion srcVer = reader.version();

        msg.id = (reader.readString());

		if (srcVer.lessThan(2, 20, 0))
			msg.rmFld = (reader.readString());
		else 
			rmFld = null;

        if (srcVer.greaterThanEqual(2, 20, 0))
            msg.newFld = (reader.readString();
        else
            newFld = null));

        return true;
    }
}


Rules to describe Message (must be automated and validated):

  1. Do not remove Message class or Message fields, but annotate it with @Until
  2. Do not change types or order @Order of fields.
  3. New fields must be annotated with @Since. All such fields must be optional, default value is null. Handling the nulls is care of Message consumer on the reader side.
  4. Setters and getters must follow name of the field.

Removing annotated entities is allowed after current version is greater than (@Until + 1) or (@Since + 1).

...