Skip to content

Commit 851caa7

Browse files
authored
IGNITE-28046 Use MessageSerializer for MetadataUpdateProposedMessage (#12855)
1 parent 56e1c57 commit 851caa7

3 files changed

Lines changed: 46 additions & 24 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage;
7171
import org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage;
7272
import org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage;
73+
import org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage;
7374
import org.apache.ignite.internal.processors.cache.distributed.GridCacheTtlUpdateRequest;
7475
import org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryRequest;
7576
import org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryResponse;
@@ -418,6 +419,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarhaller, Marshaller schemaLe
418419
withNoSchema(WalStateFinishMessage.class);
419420
withNoSchema(WalStateProposeMessage.class);
420421
withNoSchema(MetadataUpdateAcceptedMessage.class);
422+
withNoSchema(MetadataUpdateProposedMessage.class);
421423
withNoSchema(TxTimeoutOnPartitionMapExchangeChangeMessage.class);
422424
withNoSchema(UserAcceptedMessage.class);
423425
withNoSchema(UserProposedMessage.class);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/MetadataUpdateProposedMessage.java

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@
1717
package org.apache.ignite.internal.processors.cache.binary;
1818

1919
import java.util.UUID;
20+
import org.apache.ignite.IgniteCheckedException;
2021
import org.apache.ignite.binary.BinaryObjectException;
22+
import org.apache.ignite.internal.Order;
2123
import org.apache.ignite.internal.binary.BinaryMetadata;
2224
import org.apache.ignite.internal.binary.BinaryMetadataHandler;
25+
import org.apache.ignite.internal.managers.communication.ErrorMessage;
2326
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
2427
import org.apache.ignite.internal.util.typedef.internal.S;
28+
import org.apache.ignite.internal.util.typedef.internal.U;
2529
import org.apache.ignite.lang.IgniteUuid;
30+
import org.apache.ignite.marshaller.Marshaller;
31+
import org.apache.ignite.plugin.extensions.communication.MarshallableMessage;
2632
import org.jetbrains.annotations.Nullable;
2733

2834
/**
2935
* <b>MetadataUpdateProposedMessage</b> and {@link MetadataUpdateAcceptedMessage} messages make a basis for
3036
* discovery-based protocol for exchanging {@link BinaryMetadata metadata} describing objects in binary format stored in Ignite caches.
31-
*
37+
* <p>
3238
* All interactions with binary metadata are performed through {@link BinaryMetadataHandler}
3339
* interface implemented in {@link CacheObjectBinaryProcessorImpl} processor.
34-
*
40+
* <p>
3541
* Protocol works as follows:
3642
* <ol>
3743
* <li>
@@ -67,33 +73,45 @@
6773
* it gets blocked until {@link MetadataUpdateAcceptedMessage} arrives with <b>accepted version</b>
6874
* equals to <b>pending version</b> of this metadata to the moment when is was initially read by the thread.
6975
*/
70-
public final class MetadataUpdateProposedMessage implements DiscoveryCustomMessage {
76+
public final class MetadataUpdateProposedMessage implements DiscoveryCustomMessage, MarshallableMessage {
7177
/** */
7278
private static final long serialVersionUID = 0L;
7379

7480
/** */
75-
private final IgniteUuid id = IgniteUuid.randomUuid();
81+
@Order(0)
82+
IgniteUuid id;
7683

7784
/** Node UUID which initiated metadata update. */
78-
private final UUID origNodeId;
85+
@Order(1)
86+
UUID origNodeId;
7987

8088
/** */
8189
private BinaryMetadata metadata;
8290

91+
/** Serialized {@link #metadata}. */
92+
@Order(2)
93+
byte[] metadataBytes;
94+
8395
/** Metadata type id. */
84-
private final int typeId;
96+
@Order(3)
97+
int typeId;
8598

8699
/** Metadata version which is pending for update. */
87-
private int pendingVer;
100+
@Order(4)
101+
int pendingVer;
88102

89103
/** Metadata version which is already accepted by entire cluster. */
90-
private int acceptedVer;
91-
92-
/** Message acceptance status. */
93-
private ProposalStatus status = ProposalStatus.SUCCESSFUL;
104+
@Order(5)
105+
int acceptedVer;
94106

95107
/** */
96-
private BinaryObjectException err;
108+
@Order(6)
109+
@Nullable ErrorMessage errMsg;
110+
111+
/** Constructor. */
112+
public MetadataUpdateProposedMessage() {
113+
// No-op.
114+
}
97115

98116
/**
99117
* @param metadata {@link BinaryMetadata} requested to be updated.
@@ -103,6 +121,7 @@ public MetadataUpdateProposedMessage(BinaryMetadata metadata, UUID origNodeId) {
103121
assert origNodeId != null;
104122
assert metadata != null;
105123

124+
id = IgniteUuid.randomUuid();
106125
this.origNodeId = origNodeId;
107126

108127
this.metadata = metadata;
@@ -120,7 +139,7 @@ public MetadataUpdateProposedMessage(BinaryMetadata metadata, UUID origNodeId) {
120139
* {@inheritDoc}
121140
*/
122141
@Nullable @Override public DiscoveryCustomMessage ackMessage() {
123-
return (status == ProposalStatus.SUCCESSFUL) ? new MetadataUpdateAcceptedMessage(typeId, pendingVer) : null;
142+
return !rejected() ? new MetadataUpdateAcceptedMessage(typeId, pendingVer) : null;
124143
}
125144

126145
/**
@@ -134,22 +153,21 @@ public MetadataUpdateProposedMessage(BinaryMetadata metadata, UUID origNodeId) {
134153
* @param err Error caused this update to be rejected.
135154
*/
136155
void markRejected(BinaryObjectException err) {
137-
status = ProposalStatus.REJECTED;
138-
this.err = err;
156+
errMsg = new ErrorMessage(err);
139157
}
140158

141159
/**
142160
*
143161
*/
144162
boolean rejected() {
145-
return status == ProposalStatus.REJECTED;
163+
return errMsg != null;
146164
}
147165

148166
/**
149167
*
150168
*/
151169
BinaryObjectException rejectionError() {
152-
return err;
170+
return (BinaryObjectException)ErrorMessage.error(errMsg);
153171
}
154172

155173
/**
@@ -208,13 +226,16 @@ public int typeId() {
208226
return typeId;
209227
}
210228

211-
/** Message acceptance status. */
212-
private enum ProposalStatus {
213-
/** */
214-
SUCCESSFUL,
229+
/** {@inheritDoc} */
230+
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
231+
if (metadata != null)
232+
metadataBytes = U.marshal(marsh, metadata);
233+
}
215234

216-
/** */
217-
REJECTED
235+
/** {@inheritDoc} */
236+
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader ldr) throws IgniteCheckedException {
237+
if (metadataBytes != null)
238+
metadata = U.unmarshal(marsh, metadataBytes, ldr);
218239
}
219240

220241
/** {@inheritDoc} */

modules/core/src/main/resources/META-INF/classnames.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage
10301030
org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage
10311031
org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage
10321032
org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage
1033-
org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage$ProposalStatus
10341033
org.apache.ignite.internal.processors.cache.binary.MetadataUpdateResult$ResultType
10351034
org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$BlockSetCallable
10361035
org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager$QueueHeaderPredicate

0 commit comments

Comments
 (0)