mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-213 - improved the stateless clients handling of large values
This commit is contained in:
@@ -48,6 +48,7 @@ import static net.openhft.chronicle.map.StatelessChronicleMap.EventId.*;
|
||||
*/
|
||||
class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
public static final String START_OF = "Attempt to write ";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StatelessChronicleMap.class);
|
||||
public static final byte STATELESS_CLIENT_IDENTIFIER = (byte) -127;
|
||||
|
||||
@@ -1112,12 +1113,23 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
long start = bytes.position();
|
||||
for (; ; ) {
|
||||
try {
|
||||
|
||||
bytes.limit(bytes.capacity());
|
||||
keyValueSerializer.writeValue(value, bytes, null);
|
||||
|
||||
return;
|
||||
} catch (IllegalArgumentException e) {
|
||||
resizeBuffer((int) (bytes.capacity() + maxEntrySize), start);
|
||||
String message = e.getMessage();
|
||||
if (message.startsWith(START_OF)) {
|
||||
String substring = message.substring("Attempt to write ".length(), message.length());
|
||||
int i = substring.indexOf(' ');
|
||||
if (i != -1) {
|
||||
int size = Integer.parseInt(substring.substring(0, i));
|
||||
resizeBuffer(size+ maxEntrySize, start);
|
||||
} else
|
||||
resizeBuffer((int) (bytes.capacity() + maxEntrySize), start);
|
||||
}
|
||||
|
||||
|
||||
} catch (IllegalStateException e) {
|
||||
if (e.getMessage().contains("Not enough available space"))
|
||||
resizeBuffer((int) (bytes.capacity() + maxEntrySize), start);
|
||||
|
||||
@@ -2019,6 +2019,7 @@ class KeyValueSerializer<K, V> {
|
||||
}
|
||||
|
||||
void writeValue(V value, Bytes writer, ThreadLocalCopies threadLocal) {
|
||||
|
||||
assert writer.limit() == writer.capacity();
|
||||
writer.writeBoolean(value == null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user