mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-203 fixed a bug -- MultiMap's search state was shared between non-exclusive read threads
This commit is contained in:
@@ -47,9 +47,6 @@ class IntIntMultiMap implements MultiMap {
|
||||
private final long capacityMask2;
|
||||
private final Bytes bytes;
|
||||
|
||||
private long searchHash = -1L;
|
||||
private long searchPos = -1L;
|
||||
|
||||
public IntIntMultiMap(long minCapacity) {
|
||||
capacity = multiMapCapacity(minCapacity);
|
||||
capacityMask = capacity - 1L;
|
||||
@@ -208,57 +205,53 @@ class IntIntMultiMap implements MultiMap {
|
||||
// Stateful methods
|
||||
|
||||
@Override
|
||||
public void startSearch(long key) {
|
||||
public void startSearch(long key, SearchState searchStateToReuse) {
|
||||
key = maskUnsetKey(key);
|
||||
searchPos = pos(key);
|
||||
searchHash = key;
|
||||
searchStateToReuse.searchPos = pos(key);
|
||||
searchStateToReuse.searchHash = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextPos() {
|
||||
long pos = searchPos;
|
||||
public long nextPos(SearchState searchState) {
|
||||
long pos = searchState.searchPos;
|
||||
while (true) {
|
||||
long entry = bytes.readLong(pos);
|
||||
if (entry == UNSET_ENTRY) {
|
||||
searchPos = pos;
|
||||
searchState.searchPos = pos;
|
||||
return -1L;
|
||||
}
|
||||
pos = step(pos);
|
||||
if (key(entry) == searchHash) {
|
||||
searchPos = pos;
|
||||
if (key(entry) == searchState.searchHash) {
|
||||
searchState.searchPos = pos;
|
||||
return value(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePrevPos() {
|
||||
long prevPos = stepBack(searchPos);
|
||||
public void removePrevPos(SearchState searchState) {
|
||||
long prevPos = stepBack(searchState.searchPos);
|
||||
long entry = bytes.readLong(prevPos);
|
||||
positions.clear(value(entry));
|
||||
removePos(prevPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replacePrevPos(long newValue) {
|
||||
public void replacePrevPos(SearchState searchState, long newValue) {
|
||||
checkValueForPut(newValue);
|
||||
long prevPos = stepBack(searchPos);
|
||||
long prevPos = stepBack(searchState.searchPos);
|
||||
long oldEntry = bytes.readLong(prevPos);
|
||||
long oldValue = value(oldEntry);
|
||||
positions.clear(oldValue);
|
||||
positions.set(newValue);
|
||||
bytes.writeLong(prevPos, entry(searchHash, newValue));
|
||||
bytes.writeLong(prevPos, entry(searchState.searchHash, newValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAfterFailedSearch(long value) {
|
||||
public void putAfterFailedSearch(SearchState searchState, long value) {
|
||||
checkValueForPut(value);
|
||||
positions.set(value);
|
||||
bytes.writeLong(searchPos, entry(searchHash, value));
|
||||
}
|
||||
|
||||
public long getSearchHash() {
|
||||
return searchHash;
|
||||
bytes.writeLong(searchState.searchPos, entry(searchState.searchHash, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user