mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-167 added support for larger entry sizes
This commit is contained in:
@@ -20,6 +20,7 @@ import java.nio.channels.SocketChannel;
|
||||
import java.util.*;
|
||||
|
||||
import static java.nio.ByteBuffer.allocateDirect;
|
||||
import static net.openhft.chronicle.map.AbstractChannelReplicator.SIZE_OF_SIZE;
|
||||
import static net.openhft.chronicle.map.StatelessChronicleMap.EventId.*;
|
||||
|
||||
/**
|
||||
@@ -80,8 +81,8 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
this.kClass = kClass;
|
||||
this.vClass = vClass;
|
||||
attemptConnect(builder.remoteAddress());
|
||||
headroom = 1024 + maxEntrySize;
|
||||
buffer = allocateDirect(headroom*1024).order(ByteOrder.nativeOrder());
|
||||
// headroom = 1024 + maxEntrySize;
|
||||
buffer = allocateDirect(maxEntrySize).order(ByteOrder.nativeOrder());
|
||||
|
||||
bytes = new ByteBufferBytes(buffer.slice());
|
||||
|
||||
@@ -281,7 +282,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) return true;
|
||||
if (object == null || object.getClass().isAssignableFrom(Map.class))
|
||||
if (object == null || object.getClass().isAssignableFrom(Map.class))
|
||||
return false;
|
||||
|
||||
final Map<? extends K, ? extends V> that = (Map<? extends K, ? extends V>) object;
|
||||
@@ -311,7 +312,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
long sizeLocation = writeEvent(HASH_CODE);
|
||||
@@ -400,8 +400,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void writeEntries(Map<? extends K, ? extends V> map) {
|
||||
final int numberOfEntries = map.size();
|
||||
int numberOfEntriesReadSoFar = 0;
|
||||
@@ -444,10 +442,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
|
||||
} catch (
|
||||
Exception e4) {
|
||||
Exception e4) {
|
||||
LOG.info("bytes position=" + bytes.position() + ",capacity=" + bytes.capacity() +
|
||||
", " +
|
||||
"limit=" + bytes.limit());
|
||||
"limit=" + bytes.limit());
|
||||
assert bytes.limit() == bytes.capacity();
|
||||
|
||||
writeValue(value);
|
||||
@@ -469,12 +467,12 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
long remaining = bytes.remaining();
|
||||
|
||||
/*LOG.info("bytes position=" + bytes.position() + ",capacity=" + bytes.capacity() + ", " +
|
||||
"limit=" + bytes.limit());
|
||||
*/
|
||||
|
||||
if (remaining < maxEntrySize) {
|
||||
|
||||
// todo check this again as I think it may have a bug
|
||||
long estimatedRequiredSize = estimateSize(numberOfEntries, numberOfEntriesReadSoFar);
|
||||
resizeBuffer(estimatedRequiredSize * 2);
|
||||
resizeBuffer(estimatedRequiredSize + maxEntrySize * 128);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,14 +499,14 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
assert size < Integer.MAX_VALUE;
|
||||
|
||||
LOG.info("bytes before position=" + bytes.position() +
|
||||
", " +
|
||||
"limit=" + bytes.limit()+ ",capacity=" + bytes.capacity() );
|
||||
|
||||
LOG.info("resizing to=" + size);
|
||||
|
||||
LOG.info("buffer before position=" + buffer.position() +
|
||||
LOG.info("bytes before position=" + bytes.position() +
|
||||
", " +
|
||||
"limit=" + buffer.limit()+ ",capacity=" + buffer.capacity() );
|
||||
"limit=" + bytes.limit() + ",capacity=" + bytes.capacity());
|
||||
|
||||
LOG.info("buffer before");
|
||||
|
||||
LOG.info("resize buffer to " + size + " bytes");
|
||||
final ByteBuffer result = ByteBuffer.allocateDirect((int) size).order(ByteOrder.nativeOrder());
|
||||
@@ -520,7 +518,10 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
bytes = new ByteBufferBytes(result.slice());
|
||||
|
||||
buffer.position(0);
|
||||
|
||||
buffer.limit((int) bytesPosition);
|
||||
LOG.info("bytesPosition to=" + bytesPosition + ", buffer.position=" + buffer.position() +
|
||||
", " +
|
||||
"limit=" + buffer.limit() + ",capacity=" + buffer.capacity());
|
||||
for (int i = 0; i < bytesPosition; i++) {
|
||||
result.put(buffer.get());
|
||||
}
|
||||
@@ -534,21 +535,19 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
bytes.limit(bytes.capacity());
|
||||
bytes.position(bytesPosition);
|
||||
|
||||
|
||||
|
||||
assert buffer.capacity() == size;
|
||||
assert buffer.capacity() == bytes.capacity();
|
||||
assert bytes.limit() == bytes.capacity();
|
||||
|
||||
|
||||
LOG.info("bytes after position=" + bytes.position() +
|
||||
LOG.info("bytes after position=" + bytes.position() +
|
||||
", " +
|
||||
"limit=" + bytes.limit()+ ",capacity=" + bytes.capacity() );
|
||||
"limit=" + bytes.limit() + ",capacity=" + bytes.capacity());
|
||||
|
||||
|
||||
LOG.info("buffer after position=" + buffer.position() +
|
||||
", " +
|
||||
"limit=" + buffer.limit()+ ",capacity=" + buffer.capacity() );
|
||||
"limit=" + buffer.limit() + ",capacity=" + buffer.capacity());
|
||||
|
||||
}
|
||||
|
||||
@@ -716,7 +715,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
bytes.buffer().clear();
|
||||
|
||||
// the number of bytes in the response
|
||||
int size = receive(2, timeoutTime).readUnsignedShort();
|
||||
int size = receive(SIZE_OF_SIZE, timeoutTime).readInt();
|
||||
|
||||
if (bytes.capacity() < size)
|
||||
bytes = new ByteBufferBytes(allocateDirect(size));
|
||||
@@ -778,12 +777,13 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
private void writeSizeAt(long locationOfSize) {
|
||||
long size = bytes.position() - locationOfSize;
|
||||
bytes.writeUnsignedShort(locationOfSize, (int) size - 2);
|
||||
LOG.info("writing size = " + size);
|
||||
bytes.writeInt(locationOfSize, (int) size - SIZE_OF_SIZE);
|
||||
}
|
||||
|
||||
private long markSizeLocation() {
|
||||
long position = bytes.position();
|
||||
bytes.skip(2);
|
||||
bytes.skip(SIZE_OF_SIZE);
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user