Skip to content

Commit 6e65dfd

Browse files
IGNITE-27724 Use MessageSerializer for GridDhtAffinityAssignmentResponse (#12715)
1 parent ed01f2b commit 6e65dfd

File tree

2 files changed

+59
-126
lines changed

2 files changed

+59
-126
lines changed

modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.apache.ignite.internal.codegen.GridCheckpointRequestSerializer;
6666
import org.apache.ignite.internal.codegen.GridDeploymentResponseSerializer;
6767
import org.apache.ignite.internal.codegen.GridDhtAffinityAssignmentRequestSerializer;
68+
import org.apache.ignite.internal.codegen.GridDhtAffinityAssignmentResponseSerializer;
6869
import org.apache.ignite.internal.codegen.GridDhtAtomicDeferredUpdateResponseSerializer;
6970
import org.apache.ignite.internal.codegen.GridDhtAtomicNearResponseSerializer;
7071
import org.apache.ignite.internal.codegen.GridDhtAtomicSingleUpdateRequestSerializer;
@@ -385,7 +386,7 @@ public class GridIoMessageFactory implements MessageFactoryProvider {
385386
factory.register((short)26, GridDistributedTxPrepareResponse::new, new GridDistributedTxPrepareResponseSerializer());
386387
// Type 27 is former GridDistributedUnlockRequest
387388
factory.register((short)28, GridDhtAffinityAssignmentRequest::new, new GridDhtAffinityAssignmentRequestSerializer());
388-
factory.register((short)29, GridDhtAffinityAssignmentResponse::new);
389+
factory.register((short)29, GridDhtAffinityAssignmentResponse::new, new GridDhtAffinityAssignmentResponseSerializer());
389390
factory.register((short)30, GridDhtLockRequest::new, new GridDhtLockRequestSerializer());
390391
factory.register((short)31, GridDhtLockResponse::new, new GridDhtLockResponseSerializer());
391392
factory.register((short)32, GridDhtTxFinishRequest::new, new GridDhtTxFinishRequestSerializer());

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtAffinityAssignmentResponse.java

Lines changed: 57 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,19 @@
1717

1818
package org.apache.ignite.internal.processors.cache.distributed.dht;
1919

20-
import java.nio.ByteBuffer;
2120
import java.util.ArrayList;
2221
import java.util.List;
2322
import java.util.UUID;
2423
import org.apache.ignite.IgniteCheckedException;
2524
import org.apache.ignite.cluster.ClusterNode;
26-
import org.apache.ignite.internal.GridDirectTransient;
25+
import org.apache.ignite.internal.Order;
2726
import org.apache.ignite.internal.managers.discovery.DiscoCache;
2827
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
2928
import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage;
3029
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
3130
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
3231
import org.apache.ignite.internal.util.typedef.internal.S;
3332
import org.apache.ignite.internal.util.typedef.internal.U;
34-
import org.apache.ignite.plugin.extensions.communication.MessageReader;
35-
import org.apache.ignite.plugin.extensions.communication.MessageWriter;
3633
import org.jetbrains.annotations.NotNull;
3734
import org.jetbrains.annotations.Nullable;
3835

@@ -41,37 +38,39 @@
4138
*/
4239
public class GridDhtAffinityAssignmentResponse extends GridCacheGroupIdMessage {
4340
/** */
41+
@Order(value = 4, method = "futureId")
4442
private long futId;
4543

4644
/** Topology version. */
45+
@Order(value = 5, method = "topologyVersion")
4746
private AffinityTopologyVersion topVer;
4847

4948
/** */
50-
@GridDirectTransient
5149
private List<List<UUID>> affAssignmentIds;
5250

5351
/** */
52+
@Order(value = 6, method = "affinityAssignmentIdsBytes")
5453
private byte[] affAssignmentIdsBytes;
5554

5655
/** */
57-
@GridDirectTransient
5856
private List<List<UUID>> idealAffAssignment;
5957

6058
/** Affinity assignment bytes. */
59+
@Order(value = 7, method = "idealAffinityAssignmentsBytes")
6160
private byte[] idealAffAssignmentBytes;
6261

6362
/** */
64-
@GridDirectTransient
6563
private GridDhtPartitionFullMap partMap;
6664

6765
/** */
66+
@Order(value = 8, method = "partitionBytes")
6867
private byte[] partBytes;
6968

7069
/** Indicates that getting required affinity assignments has been failed. */
71-
@GridDirectTransient
7270
private IgniteCheckedException affAssignmentErr;
7371

7472
/** Serialized error. */
73+
@Order(value = 9, method = "affinityAssignmentsErrorBytes")
7574
private byte[] affAssignmentErrBytes;
7675

7776
/**
@@ -99,6 +98,11 @@ public GridDhtAffinityAssignmentResponse(
9998
affAssignmentIds = ids(affAssignment);
10099
}
101100

101+
/** */
102+
public void futureId(long futId) {
103+
this.futId = futId;
104+
}
105+
102106
/**
103107
* @return Future ID.
104108
*/
@@ -111,6 +115,11 @@ public long futureId() {
111115
return true;
112116
}
113117

118+
/** */
119+
public void topologyVersion(AffinityTopologyVersion topVer) {
120+
this.topVer = topVer;
121+
}
122+
114123
/**
115124
* @return Topology version.
116125
*/
@@ -188,6 +197,46 @@ public void partitionMap(GridDhtPartitionFullMap partMap) {
188197
return partMap;
189198
}
190199

200+
/** */
201+
public byte[] affinityAssignmentIdsBytes() {
202+
return affAssignmentIdsBytes;
203+
}
204+
205+
/** */
206+
public void affinityAssignmentIdsBytes(byte[] affAssignmentIdsBytes) {
207+
this.affAssignmentIdsBytes = affAssignmentIdsBytes;
208+
}
209+
210+
/** */
211+
public byte[] idealAffinityAssignmentsBytes() {
212+
return idealAffAssignmentBytes;
213+
}
214+
215+
/** */
216+
public void idealAffinityAssignmentsBytes(byte[] idealAffAssignmentBytes) {
217+
this.idealAffAssignmentBytes = idealAffAssignmentBytes;
218+
}
219+
220+
/** */
221+
public byte[] partitionBytes() {
222+
return partBytes;
223+
}
224+
225+
/** */
226+
public void partitionBytes(byte[] partBytes) {
227+
this.partBytes = partBytes;
228+
}
229+
230+
/** */
231+
public byte[] affinityAssignmentsErrorBytes() {
232+
return affAssignmentErrBytes;
233+
}
234+
235+
/** */
236+
public void affinityAssignmentsErrorBytes(byte[] affAssignmentErrBytes) {
237+
this.affAssignmentErrBytes = affAssignmentErrBytes;
238+
}
239+
191240
/**
192241
* @param assignments Assignment.
193242
* @return Assignment where cluster nodes are converted to their ids.
@@ -280,123 +329,6 @@ public IgniteCheckedException affinityAssignmentsError() {
280329
return false;
281330
}
282331

283-
/** {@inheritDoc} */
284-
@Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
285-
writer.setBuffer(buf);
286-
287-
if (!super.writeTo(buf, writer))
288-
return false;
289-
290-
if (!writer.isHeaderWritten()) {
291-
if (!writer.writeHeader(directType()))
292-
return false;
293-
294-
writer.onHeaderWritten();
295-
}
296-
297-
switch (writer.state()) {
298-
case 4:
299-
if (!writer.writeByteArray(affAssignmentErrBytes))
300-
return false;
301-
302-
writer.incrementState();
303-
304-
case 5:
305-
if (!writer.writeByteArray(affAssignmentIdsBytes))
306-
return false;
307-
308-
writer.incrementState();
309-
310-
case 6:
311-
if (!writer.writeLong(futId))
312-
return false;
313-
314-
writer.incrementState();
315-
316-
case 7:
317-
if (!writer.writeByteArray(idealAffAssignmentBytes))
318-
return false;
319-
320-
writer.incrementState();
321-
322-
case 8:
323-
if (!writer.writeByteArray(partBytes))
324-
return false;
325-
326-
writer.incrementState();
327-
328-
case 9:
329-
if (!writer.writeAffinityTopologyVersion(topVer))
330-
return false;
331-
332-
writer.incrementState();
333-
334-
}
335-
336-
return true;
337-
}
338-
339-
/** {@inheritDoc} */
340-
@Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
341-
reader.setBuffer(buf);
342-
343-
if (!super.readFrom(buf, reader))
344-
return false;
345-
346-
switch (reader.state()) {
347-
case 4:
348-
affAssignmentErrBytes = reader.readByteArray();
349-
350-
if (!reader.isLastRead())
351-
return false;
352-
353-
reader.incrementState();
354-
355-
case 5:
356-
affAssignmentIdsBytes = reader.readByteArray();
357-
358-
if (!reader.isLastRead())
359-
return false;
360-
361-
reader.incrementState();
362-
363-
case 6:
364-
futId = reader.readLong();
365-
366-
if (!reader.isLastRead())
367-
return false;
368-
369-
reader.incrementState();
370-
371-
case 7:
372-
idealAffAssignmentBytes = reader.readByteArray();
373-
374-
if (!reader.isLastRead())
375-
return false;
376-
377-
reader.incrementState();
378-
379-
case 8:
380-
partBytes = reader.readByteArray();
381-
382-
if (!reader.isLastRead())
383-
return false;
384-
385-
reader.incrementState();
386-
387-
case 9:
388-
topVer = reader.readAffinityTopologyVersion();
389-
390-
if (!reader.isLastRead())
391-
return false;
392-
393-
reader.incrementState();
394-
395-
}
396-
397-
return true;
398-
}
399-
400332
/** {@inheritDoc} */
401333
@Override public String toString() {
402334
return S.toString(GridDhtAffinityAssignmentResponse.class, this);

0 commit comments

Comments
 (0)