1717package org .apache .ignite .internal .processors .cache .binary ;
1818
1919import java .util .UUID ;
20+ import org .apache .ignite .IgniteCheckedException ;
2021import org .apache .ignite .binary .BinaryObjectException ;
22+ import org .apache .ignite .internal .Order ;
2123import org .apache .ignite .internal .binary .BinaryMetadata ;
2224import org .apache .ignite .internal .binary .BinaryMetadataHandler ;
25+ import org .apache .ignite .internal .managers .communication .ErrorMessage ;
2326import org .apache .ignite .internal .managers .discovery .DiscoveryCustomMessage ;
2427import org .apache .ignite .internal .util .typedef .internal .S ;
28+ import org .apache .ignite .internal .util .typedef .internal .U ;
2529import org .apache .ignite .lang .IgniteUuid ;
30+ import org .apache .ignite .marshaller .Marshaller ;
31+ import org .apache .ignite .plugin .extensions .communication .MarshallableMessage ;
2632import 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>
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} */
0 commit comments