Make checksum computation delayed, on lock release

This commit is contained in:
leventov
2015-12-05 05:37:17 +03:00
parent 6045d017e6
commit d5ee1f9aae
19 changed files with 58 additions and 73 deletions
@@ -92,6 +92,7 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
}
public void writeValue(Data<?> value) {
initDelayedUpdateChecksum(true);
// In acquireContext(), replaceValue() is called for
// 1) executing custom replaceValue() logic, if defined, from configured MapEntryOperations
// 2) Update replication status (bits, timestamp)
@@ -43,6 +43,7 @@ public abstract class ReplicatedMapEntryStages<K, V> extends MapEntryStages<K, V
}
void updateReplicationState(long timestamp, byte identifier) {
initDelayedUpdateChecksum(true);
Bytes segmentBytes = s.segmentBytesForWrite();
segmentBytes.writePosition(replicationBytesOffset);
segmentBytes.writeLong(timestamp);
@@ -95,32 +95,11 @@ public abstract class ReplicatedInput<K, V, R>
mh.m().setLastModificationTime(riId, bootstrapTimestamp);
q.initInputKey(replicatedInputKeyBytesValue);
boolean debugEnabled = lh.LOG.isDebugEnabled();
s.innerUpdateLock.lock();
if (isDeleted) {
if (debugEnabled) {
lh.LOG.debug("READING FROM SOURCE - into local-id={}, remote={}, remove(key={})",
mh.m().identifier(), riId, ks.inputKey);
}
mh.m().remoteOperations.remove(this);
return;
}
String message = null;
if (debugEnabled) {
message = String.format(
"READING FROM SOURCE - into local-id=%d, remote-id=%d, put(key=%s,",
mh.m().identifier(), riId, ks.inputKey);
}
mh.m().remoteOperations.put(this, replicatedInputValueBytesValue);
if (debugEnabled) {
lh.LOG.debug(message + "value=" + replicatedInputValueBytesValue + ")");
} else {
mh.m().remoteOperations.put(this, replicatedInputValueBytesValue);
}
}
}
@@ -39,7 +39,6 @@ public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<
checkOnEachPublicOperation.checkOnEachPublicOperation();
try {
entry.innerDefaultReplaceValue(newValue);
entry.checksumStrategy.computeAndStoreChecksum();
} finally {
s.innerWriteLock.unlock();
}
@@ -59,7 +59,6 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
entry.innerDefaultReplaceValue(newValue);
ru.updateChange();
e.updatedReplicationStateOnPresentEntry();
e.checksumStrategy.computeAndStoreChecksum();
} finally {
s.innerWriteLock.unlock();
}
@@ -121,7 +120,6 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
e.updatedReplicationStateOnPresentEntry();
e.writeEntryDeleted();
ru.updateChange();
e.checksumStrategy.computeAndStoreChecksum();
s.deleted(s.deleted() + 1);
} finally {
s.innerWriteLock.unlock();
@@ -148,7 +146,6 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
e.writeEntryPresent();
ru.updateChange();
e.updatedReplicationStateOnPresentEntry();
e.checksumStrategy.computeAndStoreChecksum();
} finally {
s.innerWriteLock.unlock();
}
@@ -79,7 +79,6 @@ public abstract class MapAbsent<K, V> implements Absent<K, V> {
s.incrementModCount();
ks.setSearchState(PRESENT);
q.initPresenceOfEntry(EntryPresence.PRESENT);
e.checksumStrategy.computeAndStoreChecksum();
} else {
throw new IllegalStateException(
"Entry is present in the map when doInsert() is called");
@@ -99,11 +99,6 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
@Override
public void doReplaceValue(Data<V> newValue) {
doReplaceValueWithoutChecksum(newValue);
e.checksumStrategy.computeAndStoreChecksum();
}
public void doReplaceValueWithoutChecksum(Data<V> newValue) {
putPrefix();
if (entryPresent()) {
e.innerDefaultReplaceValue(newValue);
@@ -51,7 +51,6 @@ public abstract class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
s.incrementModCount();
e.writeEntryPresent();
ru.updateChange();
e.checksumStrategy.computeAndStoreChecksum();
} else {
throw new IllegalStateException(
"Entry is present in the map when doInsert() is called");
@@ -78,7 +78,6 @@ public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
e.updatedReplicationStateOnPresentEntry();
e.writeEntryDeleted();
ru.updateChange();
e.checksumStrategy.computeAndStoreChecksum();
s.deleted(s.deleted() + 1);
} else {
throw new IllegalStateException("Entry is absent in the map when doRemove() is called");
@@ -95,9 +94,8 @@ public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
@Override
public void doReplaceValue(Data<V> newValue) {
doReplaceValueWithoutChecksum(newValue);
super.doReplaceValue(newValue);
ru.updateChange();
e.updatedReplicationStateOnPresentEntry();
e.checksumStrategy.computeAndStoreChecksum();
}
}