mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-277 HCOLL-278 HCOLL-289 Fixed two bugs in VanillaChronicleMap.putValue()
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
<dependency>
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>lang</artifactId>
|
||||
<version>6.4.21</version>
|
||||
<version>6.4.22-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -239,9 +239,12 @@ class Int24Int24MultiMap implements MultiMap {
|
||||
@Override
|
||||
public void replacePrevPos(SearchState searchState, long newValue) {
|
||||
checkValueForPut(newValue);
|
||||
long prevPos = stepBack(searchState.searchPos);
|
||||
long prevPos = searchState.searchPos;
|
||||
if (!searchState.putAfterFailedSearch)
|
||||
prevPos = stepBack(prevPos);
|
||||
long oldEntry = bytes.readInt48(prevPos);
|
||||
long oldValue = value(oldEntry);
|
||||
checkValueForRemove(oldValue);
|
||||
positions.clear(oldValue);
|
||||
positions.set(newValue);
|
||||
bytes.writeInt48(prevPos, entry(searchState.searchHash, newValue));
|
||||
|
||||
@@ -240,9 +240,12 @@ class IntIntMultiMap implements MultiMap {
|
||||
@Override
|
||||
public void replacePrevPos(SearchState searchState, long newValue) {
|
||||
checkValueForPut(newValue);
|
||||
long prevPos = stepBack(searchState.searchPos);
|
||||
long prevPos = searchState.searchPos;
|
||||
if (!searchState.putAfterFailedSearch)
|
||||
prevPos = stepBack(prevPos);
|
||||
long oldEntry = bytes.readLong(prevPos);
|
||||
long oldValue = value(oldEntry);
|
||||
checkValueForRemove(oldValue);
|
||||
positions.clear(oldValue);
|
||||
positions.set(newValue);
|
||||
bytes.writeLong(prevPos, entry(searchState.searchHash, newValue));
|
||||
|
||||
@@ -19,4 +19,5 @@ package net.openhft.chronicle.map;
|
||||
final class SearchState {
|
||||
long searchHash = -1L;
|
||||
long searchPos = -1L;
|
||||
boolean putAfterFailedSearch = false;
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ class ShortShortMultiMap implements MultiMap {
|
||||
key = maskUnsetKey(key);
|
||||
searchStateToReuse.searchPos = pos(key);
|
||||
searchStateToReuse.searchHash = key;
|
||||
searchStateToReuse.putAfterFailedSearch = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,9 +238,12 @@ class ShortShortMultiMap implements MultiMap {
|
||||
@Override
|
||||
public void replacePrevPos(SearchState searchState, long newValue) {
|
||||
checkValueForPut(newValue);
|
||||
long prevPos = stepBack(searchState.searchPos);
|
||||
long prevPos = searchState.searchPos;
|
||||
if (!searchState.putAfterFailedSearch)
|
||||
prevPos = stepBack(prevPos);
|
||||
int oldEntry = bytes.readInt(prevPos);
|
||||
long oldValue = value(oldEntry);
|
||||
checkValueForRemove(oldValue);
|
||||
positions.clear(oldValue);
|
||||
positions.set(newValue);
|
||||
bytes.writeInt(prevPos, entry(searchState.searchHash, newValue));
|
||||
@@ -250,6 +254,7 @@ class ShortShortMultiMap implements MultiMap {
|
||||
checkValueForPut(value);
|
||||
positions.set(value);
|
||||
bytes.writeInt(searchState.searchPos, entry(searchState.searchHash, value));
|
||||
searchState.putAfterFailedSearch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2348,26 +2348,26 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
onRelocation(this, pos);
|
||||
int allocatedChunks =
|
||||
inChunks(innerEntrySize(sizeOfEverythingBeforeValue, newElemSize));
|
||||
pos = alloc(allocatedChunks);
|
||||
long newPos = alloc(allocatedChunks);
|
||||
// putValue() is called from put() and replace()
|
||||
// after successful search by key
|
||||
searchedHashLookup.replacePrevPos(segmentState.searchState, pos);
|
||||
offset = offsetFromPos(pos);
|
||||
searchedHashLookup.replacePrevPos(segmentState.searchState, newPos);
|
||||
long newOffset = offsetFromPos(newPos);
|
||||
reuse(entry, newOffset);
|
||||
// Moving metadata, key size and key.
|
||||
// Don't want to fiddle with pseudo-buffers for this,
|
||||
// since we already have all absolute addresses.
|
||||
long newEntryStartAddr = entry.address();
|
||||
NativeBytes.UNSAFE.copyMemory(entryStartAddr,
|
||||
newEntryStartAddr, valueSizeAddr - entryStartAddr);
|
||||
entry = reuse(entry, offset);
|
||||
entry.position(valueSizePos);
|
||||
valueSizeMarshaller.writeSize(entry, newElemSize);
|
||||
alignment.alignPositionAddr(entry);
|
||||
metaElemWriter.write(elemWriter, entry, newElem);
|
||||
|
||||
freeExtraAllocatedChunks(pos, allocatedChunks, entry);
|
||||
freeExtraAllocatedChunks(newPos, allocatedChunks, entry);
|
||||
|
||||
segmentState.pos = pos;
|
||||
segmentState.pos = newPos;
|
||||
return offset;
|
||||
// END OF RELOCATION
|
||||
} else if (newSizeInChunks < oldSizeInChunks) {
|
||||
|
||||
@@ -664,7 +664,7 @@ public class ChronicleMapTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("HCOLL-277")
|
||||
@Ignore("Performance test")
|
||||
public void testAcquirePerf256()
|
||||
throws IOException, ClassNotFoundException, IllegalAccessException,
|
||||
InstantiationException, InterruptedException, ExecutionException {
|
||||
@@ -690,7 +690,8 @@ public class ChronicleMapTest {
|
||||
|
||||
// File tmpFile = File.createTempFile("testAcquirePerf", ".deleteme");
|
||||
// tmpFile.deleteOnExit();
|
||||
final ChronicleMap<CharSequence, CharSequence> map = builder.create(); //createPersistedTo(tmpFile);
|
||||
//createPersistedTo(tmpFile);
|
||||
final ChronicleMap<CharSequence, CharSequence> map = builder.create();
|
||||
|
||||
int count = runs > 500 ? 2 : 3;
|
||||
System.out.println("\nKey size: " + runs + " Million entries. " + builder);
|
||||
@@ -734,7 +735,8 @@ public class ChronicleMapTest {
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis() - start;
|
||||
System.out.printf("EntrySize: %,d Entries: %,d M Segments: %,d Throughput %.1f M ops/sec%n",
|
||||
System.out.printf("EntrySize: %,d Entries: %,d M Segments: " +
|
||||
"%,d Throughput %.1f M ops/sec%n",
|
||||
entrySize, runs, segments,
|
||||
threads * entries / 1000.0 / time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user