[ 
https://issues.apache.org/jira/browse/IGNITE-24698?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pavel Pereslegin updated IGNITE-24698:
--------------------------------------
    Description: 
In IGNITE-24564, dynamic creation of serializer registry has been added (using 
the `CatalogSerializer` annotation).

The target serialization format (v2) should be as follows:
||Field description||type||
|PROTOCOL VERSION|short|
|Object type|short|
|Object serialization format version|varint|
|Object payload|...|

In order to migrate to the new serialization data format, we need to do the 
following:

1. Introduce new decorators for input/output which allow to write/read objects.

{code:Java}
interface CatalogObjectDataInput extends IgniteDataInput {
    // Reads an object.
    <T> T readObject() throws IOException;
}

interface CatalogObjectDataOutput extends IgniteDataOutput {
    // Writes an object.
    void writeObject(MarshallableEntry object) throws IOException;
}
{code}

2. Change CatalogObjectSerializer to use them instead of 
IgniteDataInput/IgniteDataOutput

3. In each serializer container class we need to add a new serializer and 
annotate it with CtalogSerializer(version = 2, since = "3.1.0")

4. Update unmarshal in UpdateLogMarshallerImpl
{code:java}
        try (CatalogObjectDataInput input = new CatalogObjectDataInputImpl(new 
IgniteUnsafeDataInput(bytes), serializers)) {
            short protoVersion = input.readShort();

            switch (protoVersion) {
                case 1:
                    int typeId = input.readShort();

                    return (UpdateLogEvent) serializers.get(1, 
typeId).readFrom(input);

                case 2:
                    return input.readObject();

                default:
                    throw new IllegalStateException(format("An object could not 
be deserialized because it was using a newer"
                            + " version of the serialization protocol 
[supported={}, actual={}].", PROTOCOL_VERSION, protoVersion));
            }
        } catch (Throwable t) {
            throw new CatalogMarshallerException(t);
        }
{code}

5. Simplify marshal in UpdateLogMarshallerImpl

{code:java}
        try (CatalogObjectDataOutputImpl output = new 
CatalogObjectDataOutputImpl(PROTOCOL_VERSION, INITIAL_BUFFER_CAPACITY, 
serializers)) {
            output.writeObject(update);

            return output.array();
        } catch (Throwable t) {
            throw new CatalogMarshallerException(t);
        }
{code}

This way we will read data depending on the protocol version, but write in 
version 2 format and thus ensure a transparent transition from version 1 to 
version 2.

  was:
In IGNITE-24564, dynamic creation of serializer registry has been added (using 
the `CatalogSerializer` annotation).

The target serialization format (v2) should be as follows:
||Field description||type||
|PROTOCOL VERSION|short|
|Object type|short|
|Object serialization format version|varint|
|Object payload|...|

In order to migrate to the new serialization data format, we need to do the 
following:

1. Introduce new decorators for input/output which allow to write/read objects.

{code:Java}
interface CatalogObjectDataInput extends IgniteDataInput {
    // Reads an object.
    <T> T readObject() throws IOException;
}

interface CatalogObjectDataOutput extends IgniteDataOutput {
    // Writes an object.
    void writeObject(MarshallableEntry object) throws IOException;
}
{code}

2. Change CatalogObjectSerializer to use them instead of 
IgniteDataInput/IgniteDataOutput

3. In each serializer container class we need to add a new serializer and 
annotate it with CtalogSerializer(version = 2, since = "3.1.0")

4. Update unmarshal in UpdateLogMarshallerImpl
{code:java}
        try (CatalogObjectDataInput input = new CatalogObjectDataInputImpl(new 
IgniteUnsafeDataInput(bytes), serializers)) {
            short protoVersion = input.readShort();

            switch (protoVersion) {
                case 1:
                    int typeId = input.readShort();

                    return (UpdateLogEvent) serializers.get(1, 
typeId).readFrom(input);

                case 2:
                    return input.readObject();

                default:
                    throw new IllegalStateException(format("An object could not 
be deserialized because it was using "
                            + "a newer version of the serialization protocol 
[objectVersion={}, supported={}]", protoVersion, PROTOCOL_VERSION));
            }
        } catch (Throwable t) {
            throw new CatalogMarshallerException(t);
        }
{code}

5. Simplify marshal in UpdateLogMarshallerImpl

{code:java}
        try (CatalogObjectDataOutputImpl output = new 
CatalogObjectDataOutputImpl(PROTOCOL_VERSION, INITIAL_BUFFER_CAPACITY, 
serializers)) {
            output.writeObject(update);

            return output.array();
        } catch (Throwable t) {
            throw new CatalogMarshallerException(t);
        }
{code}

This way we will read data depending on the protocol version, but write in 
version 2 format and thus ensure a transparent transition from version 1 to 
version 2.


> Sql. Add new serializers that comply with the new serialization protocol.
> -------------------------------------------------------------------------
>
>                 Key: IGNITE-24698
>                 URL: https://issues.apache.org/jira/browse/IGNITE-24698
>             Project: Ignite
>          Issue Type: Improvement
>          Components: sql
>            Reporter: Pavel Pereslegin
>            Priority: Major
>              Labels: ignite-3
>
> In IGNITE-24564, dynamic creation of serializer registry has been added 
> (using the `CatalogSerializer` annotation).
> The target serialization format (v2) should be as follows:
> ||Field description||type||
> |PROTOCOL VERSION|short|
> |Object type|short|
> |Object serialization format version|varint|
> |Object payload|...|
> In order to migrate to the new serialization data format, we need to do the 
> following:
> 1. Introduce new decorators for input/output which allow to write/read 
> objects.
> {code:Java}
> interface CatalogObjectDataInput extends IgniteDataInput {
>     // Reads an object.
>     <T> T readObject() throws IOException;
> }
> interface CatalogObjectDataOutput extends IgniteDataOutput {
>     // Writes an object.
>     void writeObject(MarshallableEntry object) throws IOException;
> }
> {code}
> 2. Change CatalogObjectSerializer to use them instead of 
> IgniteDataInput/IgniteDataOutput
> 3. In each serializer container class we need to add a new serializer and 
> annotate it with CtalogSerializer(version = 2, since = "3.1.0")
> 4. Update unmarshal in UpdateLogMarshallerImpl
> {code:java}
>         try (CatalogObjectDataInput input = new 
> CatalogObjectDataInputImpl(new IgniteUnsafeDataInput(bytes), serializers)) {
>             short protoVersion = input.readShort();
>             switch (protoVersion) {
>                 case 1:
>                     int typeId = input.readShort();
>                     return (UpdateLogEvent) serializers.get(1, 
> typeId).readFrom(input);
>                 case 2:
>                     return input.readObject();
>                 default:
>                     throw new IllegalStateException(format("An object could 
> not be deserialized because it was using a newer"
>                             + " version of the serialization protocol 
> [supported={}, actual={}].", PROTOCOL_VERSION, protoVersion));
>             }
>         } catch (Throwable t) {
>             throw new CatalogMarshallerException(t);
>         }
> {code}
> 5. Simplify marshal in UpdateLogMarshallerImpl
> {code:java}
>         try (CatalogObjectDataOutputImpl output = new 
> CatalogObjectDataOutputImpl(PROTOCOL_VERSION, INITIAL_BUFFER_CAPACITY, 
> serializers)) {
>             output.writeObject(update);
>             return output.array();
>         } catch (Throwable t) {
>             throw new CatalogMarshallerException(t);
>         }
> {code}
> This way we will read data depending on the protocol version, but write in 
> version 2 format and thus ensure a transparent transition from version 1 to 
> version 2.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to