mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
improved chunking in putAll()
This commit is contained in:
@@ -277,6 +277,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
Set<? extends Map.Entry<? extends K, ? extends V>> entries = map.entrySet();
|
||||
Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator = entries.iterator();
|
||||
|
||||
OUTER:
|
||||
while (iterator.hasNext()) {
|
||||
hub.outBytesLock().lock();
|
||||
try {
|
||||
@@ -295,17 +296,26 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
wire.write(Fields.CHANNEL_ID).int16(channelID);
|
||||
writeField(Fields.METHOD_NAME, "PUT_ALL");
|
||||
|
||||
Map.Entry<? extends K, ? extends V> e = iterator.next();
|
||||
|
||||
hub.outWire().write(Fields.HAS_NEXT).bool(iterator.hasNext());
|
||||
|
||||
writeField(Fields.ARG_1, e.getKey());
|
||||
writeField(Fields.ARG_2, e.getValue());
|
||||
|
||||
|
||||
hub.writeSocket(hub.outWire());
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
Map.Entry<? extends K, ? extends V> e = iterator.next();
|
||||
|
||||
|
||||
hub.outWire().write(Fields.HAS_NEXT).bool(iterator.hasNext());
|
||||
writeField(Fields.ARG_1, e.getKey());
|
||||
writeField(Fields.ARG_2, e.getValue());
|
||||
|
||||
if (wire.bytes().remaining() < wire.bytes().capacity() * 0.5)
|
||||
break OUTER;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} finally {
|
||||
hub.writeSocket(hub.outWire());
|
||||
hub.outBytesLock().unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -448,12 +448,18 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boolean hasNext = inWire.read(HAS_NEXT).bool();
|
||||
collectData.put(toBytes(ARG_1), toBytes(ARG_2));
|
||||
if (!hasNext) {
|
||||
// the old code assumed that all the data would fit into a single buffer
|
||||
// this assumption is invalid
|
||||
if (!collectData.isEmpty()) {
|
||||
|
||||
|
||||
// the old code assumed that ALL of the entries would fit into a single buffer
|
||||
// this assumption is invalid
|
||||
boolean hasNext;
|
||||
for(;;) {
|
||||
|
||||
hasNext = inWire.read(HAS_NEXT).bool();
|
||||
|
||||
collectData.put(toBytes(ARG_1), toBytes(ARG_2));
|
||||
|
||||
if (!hasNext) {
|
||||
|
||||
incompleteWork.remove(transactionId);
|
||||
|
||||
@@ -463,8 +469,10 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
bytesMap.delegate.putAll((Map) collectData);
|
||||
return null;
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
if (inWire.bytes().remaining() == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user