-
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?
Changes from all commits
709026e
5d3d229
b535028
f433901
97c0519
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,37 +17,32 @@ | |
|
|
||
| package org.apache.ignite.internal.processors.cache.distributed.dht; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import org.apache.ignite.internal.GridDirectTransient; | ||
| import org.apache.ignite.internal.IgniteCodeGeneratingFail; | ||
| import org.apache.ignite.internal.Order; | ||
| import org.apache.ignite.internal.util.GridUnsafe; | ||
| import org.apache.ignite.internal.util.typedef.internal.U; | ||
| import org.apache.ignite.plugin.extensions.communication.Message; | ||
| import org.apache.ignite.plugin.extensions.communication.MessageReader; | ||
| import org.apache.ignite.plugin.extensions.communication.MessageWriter; | ||
|
|
||
| /** | ||
| * Partition update counters message. | ||
| */ | ||
| @IgniteCodeGeneratingFail | ||
| public class PartitionUpdateCountersMessage implements Message { | ||
| /** */ | ||
| private static final int ITEM_SIZE = 4 /* partition */ + 8 /* initial counter */ + 8 /* updates count */; | ||
|
|
||
| /** */ | ||
| private byte data[]; | ||
| /** Byte representation of partition counters. */ | ||
| @Order(0) | ||
| private byte[] data; | ||
|
|
||
| /** */ | ||
| @Order(1) | ||
| private int cacheId; | ||
|
|
||
| /** */ | ||
| @GridDirectTransient | ||
| private int size; | ||
|
|
||
| /** Used for assigning counters to cache entries during tx finish. */ | ||
| @GridDirectTransient | ||
| private Map<Integer, Long> counters; | ||
|
|
||
| /** */ | ||
|
|
@@ -66,13 +61,35 @@ public PartitionUpdateCountersMessage(int cacheId, int initSize) { | |
| data = new byte[initSize * ITEM_SIZE]; | ||
| } | ||
|
|
||
| /** | ||
| * @return Data. | ||
| */ | ||
| public byte[] data() { | ||
| return Arrays.copyOf(data, size * ITEM_SIZE); | ||
shishkovilja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * @param data New data. | ||
| */ | ||
| public void data(byte[] data) { | ||
| this.data = data; | ||
| size = data == null ? 0 : data.length / ITEM_SIZE; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IgniteCachePutGetRestartAbstractTest#testTxPutGetRestart fails without null check
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Previously, we were setting the size after successfully reading the whole byte array using the reader. In my opinion, the current logic seems fine. |
||
| } | ||
|
|
||
| /** | ||
| * @return Cache id. | ||
| */ | ||
| public int cacheId() { | ||
| return cacheId; | ||
| } | ||
|
|
||
| /** | ||
| * @param cacheId New cache id. | ||
| */ | ||
| public void cacheId(int cacheId) { | ||
| this.cacheId = cacheId; | ||
| } | ||
|
|
||
| /** | ||
| * @return Size. | ||
| */ | ||
|
|
@@ -152,13 +169,6 @@ public Long nextCounter(int partId) { | |
| return counters.computeIfPresent(partId, (key, cntr) -> cntr + 1); | ||
| } | ||
|
|
||
| /** | ||
| * Clears message. | ||
| */ | ||
| public void clear() { | ||
| size = 0; | ||
| } | ||
|
|
||
| /** | ||
| * Check if there is enough space is allocated. | ||
| * | ||
|
|
@@ -171,63 +181,6 @@ private void ensureSpace(int newSize) { | |
| data = Arrays.copyOf(data, data.length << 1); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) { | ||
| writer.setBuffer(buf); | ||
|
|
||
| if (!writer.isHeaderWritten()) { | ||
| if (!writer.writeHeader(directType())) | ||
| return false; | ||
|
|
||
| writer.onHeaderWritten(); | ||
| } | ||
|
|
||
| switch (writer.state()) { | ||
| case 0: | ||
| if (!writer.writeInt(cacheId)) | ||
| return false; | ||
|
|
||
| writer.incrementState(); | ||
|
|
||
| case 1: | ||
| if (!writer.writeByteArray(data, 0, size * ITEM_SIZE)) | ||
| return false; | ||
|
|
||
| writer.incrementState(); | ||
|
|
||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) { | ||
| reader.setBuffer(buf); | ||
|
|
||
| switch (reader.state()) { | ||
| case 0: | ||
| cacheId = reader.readInt(); | ||
|
|
||
| if (!reader.isLastRead()) | ||
| return false; | ||
|
|
||
| reader.incrementState(); | ||
|
|
||
| case 1: | ||
| data = reader.readByteArray(); | ||
|
|
||
| if (!reader.isLastRead()) | ||
| return false; | ||
|
|
||
| size = data.length / ITEM_SIZE; | ||
|
|
||
| reader.incrementState(); | ||
|
|
||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public short directType() { | ||
| return 157; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.