Skip to content

IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage v2#12821

Open
Vladsz83 wants to merge 40 commits intoapache:masterfrom
Vladsz83:IGNITE-27414-TcpDiscoveryClientReconnectMessage_v2
Open

IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage v2#12821
Vladsz83 wants to merge 40 commits intoapache:masterfrom
Vladsz83:IGNITE-27414-TcpDiscoveryClientReconnectMessage_v2

Conversation

@Vladsz83
Copy link
Contributor

Thank you for submitting the pull request to the Apache Ignite.

In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:

The Contribution Checklist

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    the green visa attached to the JIRA ticket (see TC.Bot: Check PR)

Notes

If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com #ignite channel.

This reverts commit 4adf01a.
# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoveryMessageFactory.java
#	modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java
…ssage

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/DiscoveryMessageFactory.java
…ssage

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryNodeAddFinishedMessage.java
…nectMessage_v2' into IGNITE-27414-TcpDiscoveryClientReconnectMessage_v2

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java
@Vladsz83 Vladsz83 changed the title IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage IGNITE-27414 : Use MessageSerializer for TcpDiscoveryClientReconnectMessage v2 Feb 25, 2026
Copy link
Contributor

@shishkovilja shishkovilja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I suggest to revert unnecessary replacements of getters and setters. It can be done (if necessary) in a separate pull request.
  2. I suggest alternate approach of invoking marshalling methods. Let's add wrappers to DiscoveryMessageFactory. Code sample:
public class DiscoveryMessageFactory implements MessageFactoryProvider {
    private final Marshaller marsh;

    private final ClassLoader clsLdr;

    /**
     * @param marsh Marshaller.
     * @param clsLdr Class loader.
     */
    public DiscoveryMessageFactory(Marshaller marsh, ClassLoader clsLdr) {
        this.marsh = marsh;
        this.clsLdr = clsLdr;
    }

    /** {@inheritDoc} */
    @Override public void registerAll(MessageFactory factory) {
        factory.register((short)-108, TcpDiscoveryCollectionMessage::new, wrap(new TcpDiscoveryCollectionMessageSerializer()));

         ...

    }

    /** */
    private MarshallingSerializer wrap(MessageSerializer delegate) {
        return new MarshallingSerializer(delegate, marsh, clsLdr);
    }

    /** */
    private static class MarshallingSerializer implements MessageSerializer {
        /** */
        private final MessageSerializer delegate;

        /** */
        private final Marshaller marsh;

        /** */
        private final ClassLoader clsLdr;

        /** */
        private MarshallingSerializer(MessageSerializer delegate, Marshaller marsh, ClassLoader clsLdr) {
            this.delegate = delegate;
            this.marsh = marsh;
            this.clsLdr = clsLdr;
        }

        /** {@inheritDoc} */
        @Override public boolean writeTo(Message msg, MessageWriter writer) {
            boolean res = delegate.writeTo(msg, writer);

            if (res)
                ((TcpDiscoveryMarshallableMessage)msg).prepareMarshal(marsh);

            return res;
        }

        /** {@inheritDoc} */
        @Override public boolean readFrom(Message msg, MessageReader reader) {
            boolean res = delegate.readFrom(msg, reader);

            if (res)
                ((TcpDiscoveryMarshallableMessage)msg).finishUnmarshal(marsh, clsLdr);

            return res;
        }
    }

In such case we call marshalling only for those messages for which wrappers was registered in the factory.

Unfortunately, such leads to propagation of context to factory. Also, failures of IgniteDiscoveryMessageSerializationTest caused by calls of marshliing methods should be fixed (see IgniteIoCommunicationMessageSerializationTest.TestIoMessageReader#readByteArray in order to solve problem).

@Override public MessageSerializer serializer(short type) {
MessageSerializer serializer = mf.serializer(type);

return new MessageSerializer() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such approach leads to situation, that we create new serializer each time, when we writing and reading message. I suggest to use seralizers from MessageFactory, but for marshallable message we can add a wrapper.

…ssage_v2

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
#	modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
@Vladsz83
Copy link
Contributor Author

IgniteIoCommunicationMessageSerializationTest

Didn't catch you. This test seems to work in current PR.

@Vladsz83
Copy link
Contributor Author

  1. I suggest to revert unnecessary replacements of getters and setters. It can be done (if necessary) in a separate pull request.

This interferes with the new clear-message-methods strategy indroduced by @anton-vinogradov in the previous tickets. @anton-vinogradov asked me not to use get/set methods in new messages refactored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants