Local updates couldn't be late

This commit is contained in:
leventov
2015-02-19 19:42:25 +07:00
parent 053284750d
commit 0a2726ac4a
5 changed files with 139 additions and 538 deletions
@@ -37,19 +37,21 @@ import java.io.Serializable;
* @see ChronicleHashBuilder#timeProvider(TimeProvider)
*/
public abstract class TimeProvider implements Serializable {
private static final long serialVersionUID = 0L;
/**
* Delegates {@link #currentTime()} to {@link System#currentTime()}.
*/
public static final TimeProvider SYSTEM = new System();
private static final long serialVersionUID = 0L;
public abstract long currentTime();
private static class System extends TimeProvider {
private static final long serialVersionUID = 0L;
private static final long serialVersionUID = 1L;
private static final long SCALE = 1000;
public long currentTime() {
return java.lang.System.currentTimeMillis();
return java.lang.System.currentTimeMillis() * SCALE;
}
@Override
@@ -541,22 +541,28 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
closeReplicationUpdate();
}
private boolean testTimeStampInSensibleRange() {
if (rm().timeProvider == TimeProvider.SYSTEM) {
long currentTime = TimeProvider.SYSTEM.currentTime();
assert Math.abs(currentTime - timestamp) <= 100000000 :
"unrealistic timestamp: " + timestamp;
assert Math.abs(currentTime - newTimestamp) <= 100000000 :
"unrealistic newTimestamp: " + newTimestamp;
}
return true;
}
boolean shouldIgnore() {
assert replicationStateInit() : "replication state not init";
assert replicationUpdateInit() : "replication update not init";
boolean shouldIgnore;
if (timestamp < newTimestamp) {
shouldIgnore = false;
} else if (timestamp > newTimestamp) {
shouldIgnore = true;
} else {
shouldIgnore = identifier > newIdentifier;
assert testTimeStampInSensibleRange();
if (!remoteUpdate()) {
newTimestamp = timestamp + 1L;
return false;
}
if (shouldIgnore && !remoteUpdate()) {
assert newIdentifier == rm().identifier();
throw new LateUpdateException(identifier, timestamp, newIdentifier, newTimestamp);
}
return shouldIgnore;
return timestamp > newTimestamp ||
(timestamp == newTimestamp && identifier > newIdentifier);
}
public void dirtyEntries(final long dirtyFromTimeStamp,