ARTEMIS-2785 io.netty.util.internal.OutOfDirectMemoryError during uncompress

This commit is contained in:
Francesco Nigro 2020-05-29 18:17:11 +02:00
parent 8921bd4bbb
commit c72b226bfb
3 changed files with 7 additions and 18 deletions

View File

@ -239,17 +239,6 @@ public class ByteUtil {
return sb.toString(); return sb.toString();
} }
public static byte[] getActiveArray(ByteBuffer buffer) {
byte[] ret = new byte[buffer.remaining()];
if (buffer.hasArray()) {
byte[] array = buffer.array();
System.arraycopy(array, buffer.arrayOffset() + buffer.position(), ret, 0, ret.length);
} else {
buffer.slice().get(ret);
}
return ret;
}
public static long convertTextBytes(final String text) { public static long convertTextBytes(final String text) {
try { try {
Matcher m = ONE.matcher(text); Matcher m = ONE.matcher(text);

View File

@ -39,7 +39,6 @@ import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle; import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
import org.apache.activemq.artemis.spi.core.remoting.ConsumerContext; import org.apache.activemq.artemis.spi.core.remoting.ConsumerContext;
import org.apache.activemq.artemis.spi.core.remoting.SessionContext; import org.apache.activemq.artemis.spi.core.remoting.SessionContext;
import org.apache.activemq.artemis.utils.ByteUtil;
import org.apache.activemq.artemis.utils.FutureLatch; import org.apache.activemq.artemis.utils.FutureLatch;
import org.apache.activemq.artemis.utils.ReusableLatch; import org.apache.activemq.artemis.utils.ReusableLatch;
import org.apache.activemq.artemis.utils.TokenBucketLimiter; import org.apache.activemq.artemis.utils.TokenBucketLimiter;
@ -655,9 +654,9 @@ public final class ClientConsumerImpl implements ClientConsumerInternal {
//sets the packet //sets the packet
ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer(); ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer();
int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex(); final int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
final byte[] body = ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer()); final byte[] body = new byte[bytesToRead];
qbuff.readBytes(body);
largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController)); largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
currentLargeMessageController.addPacket(body, body.length, false); currentLargeMessageController.addPacket(body, body.length, false);

View File

@ -44,7 +44,6 @@ import org.apache.activemq.artemis.core.persistence.CoreMessageObjectPools;
import org.apache.activemq.artemis.core.persistence.Persister; import org.apache.activemq.artemis.core.persistence.Persister;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl; import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import org.apache.activemq.artemis.reader.MessageUtil; import org.apache.activemq.artemis.reader.MessageUtil;
import org.apache.activemq.artemis.utils.ByteUtil;
import org.apache.activemq.artemis.utils.DataConstants; import org.apache.activemq.artemis.utils.DataConstants;
import org.apache.activemq.artemis.utils.UUID; import org.apache.activemq.artemis.utils.UUID;
import org.apache.activemq.artemis.utils.collections.TypedProperties; import org.apache.activemq.artemis.utils.collections.TypedProperties;
@ -251,9 +250,11 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage {
} }
private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws DataFormatException { private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws DataFormatException {
int bytesToRead = buffer.readableBytes(); final int bytesToRead = buffer.readableBytes();
Inflater inflater = new Inflater(); Inflater inflater = new Inflater();
inflater.setInput(ByteUtil.getActiveArray(buffer.readBytes(bytesToRead).toByteBuffer())); final byte[] input = new byte[bytesToRead];
buffer.readBytes(input);
inflater.setInput(input);
//get the real size of large message //get the real size of large message
long sizeBody = getLongProperty(Message.HDR_LARGE_BODY_SIZE); long sizeBody = getLongProperty(Message.HDR_LARGE_BODY_SIZE);