This is an automated email from the ASF dual-hosted git repository.
sergeychugunov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 12f78c410d2 IGNITE-25963 Use MessageSerializer for GridCacheMessage
(#12202)
12f78c410d2 is described below
commit 12f78c410d2edf880162a05229bcd058165b8a6b
Author: Maksim Davydov <[email protected]>
AuthorDate: Wed Aug 13 12:36:27 2025 +0300
IGNITE-25963 Use MessageSerializer for GridCacheMessage (#12202)
---
.../communication/GridIoMessageFactory.java | 6 +-
.../processors/cache/GridCacheMessage.java | 23 +++-
.../cache/transactions/TxLocksRequest.java | 91 ++++---------
.../cache/transactions/TxLocksResponse.java | 143 +++++++--------------
4 files changed, 91 insertions(+), 172 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index 0488df96c17..fa145c802d4 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -48,6 +48,8 @@ import
org.apache.ignite.internal.codegen.NearCacheUpdatesSerializer;
import org.apache.ignite.internal.codegen.SessionChannelMessageSerializer;
import
org.apache.ignite.internal.codegen.TcpInverseConnectionResponseMessageSerializer;
import org.apache.ignite.internal.codegen.TxLockSerializer;
+import org.apache.ignite.internal.codegen.TxLocksRequestSerializer;
+import org.apache.ignite.internal.codegen.TxLocksResponseSerializer;
import
org.apache.ignite.internal.codegen.UserAuthenticateRequestMessageSerializer;
import
org.apache.ignite.internal.codegen.UserAuthenticateResponseMessageSerializer;
import
org.apache.ignite.internal.codegen.UserManagementOperationFinishedMessageSerializer;
@@ -216,8 +218,8 @@ public class GridIoMessageFactory implements
MessageFactoryProvider {
factory.register((short)-27, GridDhtTxOnePhaseCommitAckRequest::new);
factory.register((short)-26, TxLockList::new);
factory.register((short)-25, TxLock::new, new TxLockSerializer());
- factory.register((short)-24, TxLocksRequest::new);
- factory.register((short)-23, TxLocksResponse::new);
+ factory.register((short)-24, TxLocksRequest::new, new
TxLocksRequestSerializer());
+ factory.register((short)-23, TxLocksResponse::new, new
TxLocksResponseSerializer());
factory.register(TcpCommunicationSpi.NODE_ID_MSG_TYPE,
NodeIdMessage::new);
factory.register(TcpCommunicationSpi.RECOVERY_LAST_ID_MSG_TYPE,
RecoveryLastReceivedMessage::new);
factory.register(TcpCommunicationSpi.HANDSHAKE_MSG_TYPE,
HandshakeMessage::new);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
index 79e0f0caad1..f17fbd1ba4b 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
@@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.cache.processor.EntryProcessor;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.managers.deployment.GridDeployment;
import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo;
import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
@@ -59,30 +59,29 @@ public abstract class GridCacheMessage implements Message {
private static final long NULL_MSG_ID = -1;
/** ID of this message. */
+ @Order(value = 0, method = "messageId")
private long msgId = NULL_MSG_ID;
/** */
@GridToStringInclude
+ @Order(value = 1, method = "deployInfo")
private GridDeploymentInfoBean depInfo;
/** */
@GridToStringInclude
+ @Order(value = 2, method = "lastAffinityChangedTopologyVersion")
private @Nullable AffinityTopologyVersion lastAffChangedTopVer;
/** */
- @GridDirectTransient
protected boolean addDepInfo;
/** Force addition of deployment info regardless of {@code addDepInfo}
flag value.*/
- @GridDirectTransient
protected boolean forceAddDepInfo;
/** */
- @GridDirectTransient
private IgniteCheckedException err;
/** */
- @GridDirectTransient
private boolean skipPrepare;
/**
@@ -172,7 +171,7 @@ public abstract class GridCacheMessage implements Message {
*
* @param msgId New message ID.
*/
- void messageId(long msgId) {
+ public void messageId(long msgId) {
this.msgId = msgId;
}
@@ -272,10 +271,18 @@ public abstract class GridCacheMessage implements Message
{
* @return Preset deployment info.
* @see GridCacheDeployable#deployInfo()
*/
- public GridDeploymentInfo deployInfo() {
+ public GridDeploymentInfoBean deployInfo() {
return depInfo;
}
+ /**
+ * @param depInfo Preset deployment info.
+ * @see GridCacheDeployable#deployInfo()
+ */
+ public void deployInfo(GridDeploymentInfoBean depInfo) {
+ this.depInfo = depInfo;
+ }
+
/**
* This method is called before the whole message is serialized
* and is responsible for pre-marshalling state.
@@ -659,6 +666,7 @@ public abstract class GridCacheMessage implements Message {
/** {@inheritDoc} */
@Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+ // TODO: Safe to remove only after all inheritors have migrated to the
new ser/der scheme (IGNITE-25490).
writer.setBuffer(buf);
if (!writer.isHeaderWritten()) {
@@ -694,6 +702,7 @@ public abstract class GridCacheMessage implements Message {
/** {@inheritDoc} */
@Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+ // TODO: Safe to remove only after all inheritors have migrated to the
new ser/der scheme (IGNITE-25490).
reader.setBuffer(buf);
switch (reader.state()) {
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java
index 1d9fbb5bb8e..a5198d78c25 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java
@@ -17,11 +17,10 @@
package org.apache.ignite.internal.processors.cache.transactions;
-import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Set;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.processors.cache.GridCacheMessage;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
@@ -29,24 +28,22 @@ import
org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
-import
org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
/**
* Transactions lock list request.
*/
public class TxLocksRequest extends GridCacheMessage {
/** Future ID. */
+ @Order(value = 3, method = "futureId")
private long futId;
/** Tx keys. */
@GridToStringInclude
- @GridDirectTransient
private Set<IgniteTxKey> txKeys;
/** Array of txKeys from {@link #txKeys}. Used during marshalling and
unmarshalling. */
@GridToStringExclude
+ @Order(value = 4, method = "txKeysArray")
private IgniteTxKey[] txKeysArr;
/**
@@ -84,6 +81,27 @@ public class TxLocksRequest extends GridCacheMessage {
return futId;
}
+ /**
+ * @param futId Future ID.
+ */
+ public void futureId(long futId) {
+ this.futId = futId;
+ }
+
+ /**
+ * @return Array of txKeys from {@link #txKeys}. Used during marshalling
and unmarshalling.
+ */
+ public IgniteTxKey[] txKeysArray() {
+ return txKeysArr;
+ }
+
+ /**
+ * @param txKeysArr Array of txKeys from {@link #txKeys}. Used during
marshalling and unmarshalling.
+ */
+ public void txKeysArray(IgniteTxKey[] txKeysArr) {
+ this.txKeysArr = txKeysArr;
+ }
+
/**
* @return Tx keys.
*/
@@ -131,67 +149,6 @@ public class TxLocksRequest extends GridCacheMessage {
txKeysArr = null;
}
- /** {@inheritDoc} */
- @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
- writer.setBuffer(buf);
-
- if (!super.writeTo(buf, writer))
- return false;
-
- if (!writer.isHeaderWritten()) {
- if (!writer.writeHeader(directType()))
- return false;
-
- writer.onHeaderWritten();
- }
-
- switch (writer.state()) {
- case 3:
- if (!writer.writeLong(futId))
- return false;
-
- writer.incrementState();
-
- case 4:
- if (!writer.writeObjectArray(txKeysArr,
MessageCollectionItemType.MSG))
- return false;
-
- writer.incrementState();
-
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
- reader.setBuffer(buf);
-
- if (!super.readFrom(buf, reader))
- return false;
-
- switch (reader.state()) {
- case 3:
- futId = reader.readLong();
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 4:
- txKeysArr =
reader.readObjectArray(MessageCollectionItemType.MSG, IgniteTxKey.class);
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- }
-
- return true;
- }
-
/** {@inheritDoc} */
@Override public short directType() {
return -24;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java
index 4c7c3421acb..bf471c0532b 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java
@@ -17,50 +17,48 @@
package org.apache.ignite.internal.processors.cache.transactions;
-import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.processors.cache.GridCacheMessage;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
-import
org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
/**
* Transactions lock list response.
*/
public class TxLocksResponse extends GridCacheMessage {
/** Future ID. */
+ @Order(value = 3, method = "futureId")
private long futId;
/** Locks for near txKeys of near transactions. */
@GridToStringInclude
- @GridDirectTransient
private final Map<IgniteTxKey, TxLockList> nearTxKeyLocks = new
HashMap<>();
/** Remote keys involved into transactions. Doesn't include near keys. */
@GridToStringInclude
- @GridDirectTransient
private Set<IgniteTxKey> txKeys;
/** Array of txKeys from {@link #nearTxKeyLocks}. Used during marshalling
and unmarshalling. */
@GridToStringExclude
+ @Order(value = 4, method = "nearTxKeysArray")
private IgniteTxKey[] nearTxKeysArr;
/** Array of txKeys from {@link #txKeys}. Used during marshalling and
unmarshalling. */
@GridToStringExclude
+ @Order(value = 5, method = "txKeysArray")
private IgniteTxKey[] txKeysArr;
/** Array of locksArr from {@link #nearTxKeyLocks}. Used during
marshalling and unmarshalling. */
@GridToStringExclude
+ @Order(value = 6, method = "locksArray")
private TxLockList[] locksArr;
/**
@@ -94,6 +92,48 @@ public class TxLocksResponse extends GridCacheMessage {
this.futId = futId;
}
+ /**
+ * @return Array of txKeys from {@link #nearTxKeyLocks}. Used during
marshalling and unmarshalling.
+ */
+ public IgniteTxKey[] nearTxKeysArray() {
+ return nearTxKeysArr;
+ }
+
+ /**
+ * @param nearTxKeysArr Array of txKeys from {@link #nearTxKeyLocks}. Used
during marshalling and unmarshalling.
+ */
+ public void nearTxKeysArray(IgniteTxKey[] nearTxKeysArr) {
+ this.nearTxKeysArr = nearTxKeysArr;
+ }
+
+ /**
+ * @return Array of txKeys from {@link #txKeys}. Used during marshalling
and unmarshalling.
+ */
+ public IgniteTxKey[] txKeysArray() {
+ return txKeysArr;
+ }
+
+ /**
+ * @param txKeysArr Array of txKeys from {@link #txKeys}. Used during
marshalling and unmarshalling.
+ */
+ public void txKeysArray(IgniteTxKey[] txKeysArr) {
+ this.txKeysArr = txKeysArr;
+ }
+
+ /**
+ * @return Array of locksArr from {@link #nearTxKeyLocks}. Used during
marshalling and unmarshalling.
+ */
+ public TxLockList[] locksArray() {
+ return locksArr;
+ }
+
+ /**
+ * @param locksArr Array of locksArr from {@link #nearTxKeyLocks}. Used
during marshalling and unmarshalling.
+ */
+ public void locksArray(TxLockList[] locksArr) {
+ this.locksArr = locksArr;
+ }
+
/**
* @return Lock lists for all tx nearTxKeysArr.
*/
@@ -221,95 +261,6 @@ public class TxLocksResponse extends GridCacheMessage {
}
}
- /** {@inheritDoc} */
- @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
- writer.setBuffer(buf);
-
- if (!super.writeTo(buf, writer))
- return false;
-
- if (!writer.isHeaderWritten()) {
- if (!writer.writeHeader(directType()))
- return false;
-
- writer.onHeaderWritten();
- }
-
- switch (writer.state()) {
- case 3:
- if (!writer.writeLong(futId))
- return false;
-
- writer.incrementState();
-
- case 4:
- if (!writer.writeObjectArray(locksArr,
MessageCollectionItemType.MSG))
- return false;
-
- writer.incrementState();
-
- case 5:
- if (!writer.writeObjectArray(nearTxKeysArr,
MessageCollectionItemType.MSG))
- return false;
-
- writer.incrementState();
-
- case 6:
- if (!writer.writeObjectArray(txKeysArr,
MessageCollectionItemType.MSG))
- return false;
-
- writer.incrementState();
-
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
- reader.setBuffer(buf);
-
- if (!super.readFrom(buf, reader))
- return false;
-
- switch (reader.state()) {
- case 3:
- futId = reader.readLong();
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 4:
- locksArr =
reader.readObjectArray(MessageCollectionItemType.MSG, TxLockList.class);
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 5:
- nearTxKeysArr =
reader.readObjectArray(MessageCollectionItemType.MSG, IgniteTxKey.class);
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 6:
- txKeysArr =
reader.readObjectArray(MessageCollectionItemType.MSG, IgniteTxKey.class);
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- }
-
- return true;
- }
-
/** {@inheritDoc} */
@Override public short directType() {
return -23;