ARTEMIS-2274 Fix on Journal buffer overflow with almost large messages

This commit is contained in:
Clebert Suconic 2019-03-13 14:55:22 -04:00
parent b672cc3ad9
commit 828a4856da
2 changed files with 6 additions and 2 deletions

View File

@ -244,7 +244,7 @@ public final class TimedBuffer extends CriticalComponentImpl {
}
if (sizeChecked > bufferSize) {
throw new IllegalStateException("Can't write records bigger than the bufferSize(" + bufferSize + ") on the journal");
throw new IllegalStateException("Can't write records (size=" + sizeChecked + ") bigger than the bufferSize(" + bufferSize + ") on the journal");
}
if (bufferLimit == 0 || buffer.writerIndex() + sizeChecked > bufferLimit) {

View File

@ -42,13 +42,17 @@ import io.netty.buffer.Unpooled;
public final class LargeServerMessageImpl extends CoreMessage implements LargeServerMessage {
// When a message is stored on the journal, it will contain some header and trail on the journal
// we need to take that into consideration if that would fit the Journal TimedBuffer.
private static final int ESTIMATE_RECORD_TRAIL = 512;
/** This will check if a regular message needs to be converted as large message */
public static Message checkLargeMessage(Message message, StorageManager storageManager) throws Exception {
if (message.isLargeMessage()) {
return message; // nothing to be done on this case
}
if (message.getEncodeSize() > storageManager.getMaxRecordSize()) {
if (message.getEncodeSize() + ESTIMATE_RECORD_TRAIL > storageManager.getMaxRecordSize()) {
return asLargeMessage(message, storageManager);
} else {
return message;