mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Safer unlocking on eventListener calls
This commit is contained in:
@@ -957,6 +957,8 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
if (eventListener != null) {
|
||||
V valueInstance = toValue.toInstance(copies, v, valueSize);
|
||||
writeUnlock();
|
||||
// TODO unlocking is dangerous, because this method is a part of
|
||||
// acquireUsingLocked()
|
||||
try {
|
||||
eventListener.onPut(keyInstance, valueInstance, null, false, true,
|
||||
true, localIdentifier, replacedIdentifier, timestamp,
|
||||
@@ -1159,6 +1161,8 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
updateResult = isDeleted ? UpdateResult.INSERT : UpdateResult.UPDATE;
|
||||
}
|
||||
|
||||
replaceValueDeletedCallback(segmentState, hashLookup, pos, isDeleted);
|
||||
|
||||
// put callbacks
|
||||
boolean hasValueChanged = updateResult != UpdateResult.UNCHANGED;
|
||||
onPutMaybeRemote(segmentState.pos, false);
|
||||
@@ -1184,21 +1188,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
}
|
||||
}
|
||||
|
||||
// for DRY (reusing replaceValueAndNotifyPut() method),
|
||||
// size is updated AFTER callbacks are called.
|
||||
// however this shouldn't be an issue because exclusive segment lock
|
||||
// is still held
|
||||
if (isDeleted) {
|
||||
incrementSize();
|
||||
// if they are NOT equal, it means the entry was relocated in putValue(),
|
||||
// hence position is already set
|
||||
if (pos == segmentState.pos) {
|
||||
hashLookup.putPosition(segmentState.pos);
|
||||
} else {
|
||||
assert hashLookup.getPositions().isSet(segmentState.pos);
|
||||
}
|
||||
}
|
||||
|
||||
return updateResult;
|
||||
}
|
||||
// key is not found
|
||||
@@ -1315,20 +1304,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
entry, pos, hashLookup, readValue,
|
||||
resultUnused, isDeleted, remote,
|
||||
replacedIdentifier, replacedTimestamp);
|
||||
// for DRY (reusing replaceValueAndNotifyPut() method),
|
||||
// size is updated AFTER callbacks are called.
|
||||
// however this shouldn't be an issue because exclusive segment lock
|
||||
// is still held
|
||||
if (isDeleted) {
|
||||
incrementSize();
|
||||
// if they are NOT equal, it means the entry was relocated in putValue(),
|
||||
// hence position is already set
|
||||
if (pos == segmentState.pos) {
|
||||
hashLookup.putPosition(segmentState.pos);
|
||||
} else {
|
||||
assert hashLookup.getPositions().isSet(segmentState.pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (resultUnused)
|
||||
return null;
|
||||
return isDeleted ? readValue.readNull() : prevValue;
|
||||
@@ -1379,6 +1355,21 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
return resultUnused ? null : readValue.readNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
void replaceValueDeletedCallback(
|
||||
SegmentState segmentState, MultiMap hashLookup, long pos, boolean isDeleted) {
|
||||
if (isDeleted) {
|
||||
incrementSize();
|
||||
// if they are NOT equal, it means the entry was relocated in putValue(),
|
||||
// hence position is already set
|
||||
if (pos == segmentState.pos) {
|
||||
hashLookup.putPosition(segmentState.pos);
|
||||
} else {
|
||||
assert hashLookup.getPositions().isSet(segmentState.pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used only with replication, its sometimes possible to receive an old ( or stale update )
|
||||
* from a remote map. This method is used to determine if we should ignore such updates.
|
||||
@@ -1643,11 +1634,6 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
getExpectedValueInterops, expectedValue, getNewValueInterops, newValue,
|
||||
readValue, toValue, pos, entry, hashLookup,
|
||||
replacedIdentifier, replacedTimestamp);
|
||||
if (result != Boolean.FALSE) {
|
||||
entry.position(timestampPos);
|
||||
entry.writeLong(timestamp);
|
||||
entry.writeByte(identifier);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// key is not found
|
||||
@@ -1658,6 +1644,13 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void updateReplicationBytesOnKeyPresentOnReplace(
|
||||
Bytes entry, long timestampPos, long timestamp, byte identifier) {
|
||||
entry.position(timestampPos);
|
||||
entry.writeLong(timestamp);
|
||||
entry.writeByte(identifier);
|
||||
}
|
||||
|
||||
public void dirtyEntries(final long timeStamp,
|
||||
final EntryModifiableCallback callback,
|
||||
|
||||
Reference in New Issue
Block a user