[
https://issues.apache.org/jira/browse/ARTEMIS-1220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16058498#comment-16058498
]
ASF GitHub Bot commented on ARTEMIS-1220:
-----------------------------------------
Github user gaohoward commented on the issue:
https://github.com/apache/activemq-artemis/pull/1351
@clebertsuconic do you mean change the cited code piece to this:
`
for (;;) {
byte[] bufferBytes = new byte[100 * 1024];
ByteBuffer buffer = ByteBuffer.wrap(bufferBytes);
// The buffer is reused...
// We need to make sure we clear the limits and the buffer
before reusing it
buffer.clear();
int bytesRead = file.read(buffer);
byte[] bufferToWrite;
if (bytesRead <= 0) {
break;
} else {
//here, always make a copy
bufferToWrite = new byte[bytesRead];
System.arraycopy(bufferBytes, 0, bufferToWrite, 0,
bytesRead);
}
newMessage.addBytes(bufferToWrite);
if (bytesRead < bufferBytes.length) {
break;
}
}
`
I can see this is less efficient because if there is no replication
(standalone broker without a backup) the copy is not necessary. The good about
this is that it is simple and with largemessages the cost of copying seems not
important (largemessages are slower than normal messages anyway).
If the above understanding is right, I've no objection to making the
changes.
> Diverted LargeMessage file corrupted during replication
> -------------------------------------------------------
>
> Key: ARTEMIS-1220
> URL: https://issues.apache.org/jira/browse/ARTEMIS-1220
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Components: Broker
> Affects Versions: 1.5.5, 2.1.0
> Reporter: Howard Gao
> Assignee: Howard Gao
> Fix For: 1.5.6, 2.2.0
>
>
> When a large message is being diverted, a new copy of the original message is
> created and replicated (if there is a backup) to the backup.
> In LargeServerMessageImpl.copy(long) it reuse a byte array to copy message
> body. It is possible that one block of date is read into the byte array
> before the previous read has been replicated, causing the replicated bytes to
> corrupt.
> If we make a copy of the byte array before replication, the corruption of
> data will be avoided.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)