-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-26646 Use MessageSerializer for PartitionUpdateCountersMessage #12402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
42034b2 to
3f54423
Compare
c0db299 to
2aac42e
Compare
2aac42e to
8bbcce0
Compare
…niteIoCommunicationMessageSerializationTest#testMessageSerializationAndDeserializationConsistency
| if (data == null) | ||
| return new byte[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IgniteIoCommunicationMessageSerializationTest#testMessageSerializationAndDeserializationConsistency fails without null check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the fact that data is initialized in the constructor and cannot be null, I suggest removing this check and adding to IgniteIoCommunicationMessageSerializationTest#initializeMessage:
if (msg instanceof PartitionUpdateCountersMessage)
FieldUtils.writeField(msg, "data", new byte[0], true);
| */ | ||
| public void payload(byte[] payload) { | ||
| data = payload; | ||
| size = data == null ? 0 : data.length / ITEM_SIZE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IgniteCachePutGetRestartAbstractTest#testTxPutGetRestart fails without null check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageReader#readByteArray returns null when it couldn't fully extract the entire payload from the buffer because the complete byte array didn't fit into the read buffer.
Previously, we were setting the size after successfully reading the whole byte array using the reader.
In my opinion, the current logic seems fine.
| /** */ | ||
| private byte data[]; | ||
| @Order(0) | ||
| private int cacheId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional change - usually we set Order according to the declaration order of fields in the class.
I would revert it, but it's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the field declaration order because writeTo/readFrom wrote the cacheId first and the data afterward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shishkovilja wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chesnokoff , I agree with @wernerdv . It is not necessary to refactor order of fieds.
…ssageSerializationAndDeserializationConsistency
| /** */ | ||
| private byte data[]; | ||
| @Order(0) | ||
| private int cacheId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chesnokoff , I agree with @wernerdv . It is not necessary to refactor order of fieds.
| * @return Payload. | ||
| */ | ||
| public byte[] payload() { | ||
| return Arrays.copyOf(data, size * ITEM_SIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possbile NPE here.
Also, we should ensure that it could not lead to a potential performance drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chesnokoff , see an example:
| return Arrays.copyOf(data, size * ITEM_SIZE); | |
| return F.isEmpty(data) ? null : Arrays.copyOf(data, size * ITEM_SIZE); |
| if (msg instanceof NodeIdMessage) | ||
| FieldUtils.writeField(msg, "nodeId", UUID.randomUUID(), true); | ||
|
|
||
| if (msg instanceof PartitionUpdateCountersMessage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this change? NPE should be properly fixed in a message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested removing the null check from the message and adding it to the test.
See #12402 (comment)
But the final decision is up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested removing the null check from the message and adding it to the test. See #12402 (comment) But the final decision is up to you.
We can safely send null for empty or null array. BUT, as I see now, message will be in incorrect state if data is null.
So, you are right. Let's keep it.
| /** | ||
| * @return Payload. | ||
| */ | ||
| public byte[] payload() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be just data?
| public byte[] payload() { | |
| public byte[] data() { |
|
|
||
| /** */ | ||
| private int cacheId; | ||
| @Order(value = 1, method = "payload") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @Order(value = 1, method = "payload") | |
| @Order(1) |
(rename getter and setter to data)
| @Order(0) | ||
| private int cacheId; | ||
|
|
||
| /** */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** */ | |
| /** Byte representation of partition counters. */ |
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
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summarywhereXXXX- number of JIRA issue.(see the Maintainers list)
the
green visaattached to the JIRA ticket (see TC.Bot: Check PR)Notes
If you need any help, please email [email protected] or ask anу advice on http://asf.slack.com #ignite channel.