* Clock: Synchronization, log large shifts to event log

This commit is contained in:
zzz
2012-09-09 15:45:29 +00:00
parent 74e753934c
commit 2f98d05e7c
3 changed files with 5 additions and 4 deletions

View File

@ -43,7 +43,7 @@ public class Clock implements Timestamper.UpdateListener {
/** we fetch it on demand to avoid circular dependencies (logging uses the clock) */ /** we fetch it on demand to avoid circular dependencies (logging uses the clock) */
protected Log getLog() { return _context.logManager().getLog(Clock.class); } protected Log getLog() { return _context.logManager().getLog(Clock.class); }
/** if the clock is skewed by 3+ days, fuck 'em */ /** if the clock is skewed by 3+ days, forget it */
public final static long MAX_OFFSET = 3 * 24 * 60 * 60 * 1000; public final static long MAX_OFFSET = 3 * 24 * 60 * 60 * 1000;
/** after we've started up and shifted the clock, don't allow shifts of more than 10 minutes */ /** after we've started up and shifted the clock, don't allow shifts of more than 10 minutes */
public final static long MAX_LIVE_OFFSET = 10 * 60 * 1000; public final static long MAX_LIVE_OFFSET = 10 * 60 * 1000;
@ -67,7 +67,7 @@ public class Clock implements Timestamper.UpdateListener {
* *
* @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now())
*/ */
public void setOffset(long offsetMs, boolean force) { public synchronized void setOffset(long offsetMs, boolean force) {
if (false) return; if (false) return;
long delta = offsetMs - _offset; long delta = offsetMs - _offset;
if (!force) { if (!force) {

View File

@ -1056,6 +1056,7 @@ public class Router implements RouterClock.ClockShiftListener {
return; return;
if (delta > -60*1000 && delta < 60*1000) if (delta > -60*1000 && delta < 60*1000)
return; return;
_eventLog.addEvent(EventLog.CLOCK_SHIFT, Long.toString(delta));
// update the routing key modifier // update the routing key modifier
_context.routingKeyGenerator().generateDateBasedModData(); _context.routingKeyGenerator().generateDateBasedModData();
if (_context.commSystem().countActivePeers() <= 0) if (_context.commSystem().countActivePeers() <= 0)

View File

@ -91,7 +91,7 @@ public class RouterClock extends Clock {
* @since 0.7.12 * @since 0.7.12
* @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now())
*/ */
private void setOffset(long offsetMs, boolean force, int stratum) { private synchronized void setOffset(long offsetMs, boolean force, int stratum) {
long delta = offsetMs - _offset; long delta = offsetMs - _offset;
if (!force) { if (!force) {
if ((offsetMs > MAX_OFFSET) || (offsetMs < 0 - MAX_OFFSET)) { if ((offsetMs > MAX_OFFSET) || (offsetMs < 0 - MAX_OFFSET)) {
@ -236,7 +236,7 @@ public class RouterClock extends Clock {
* *
* @since 0.8.8 * @since 0.8.8
*/ */
private void notifyMassive(long shift) { private synchronized void notifyMassive(long shift) {
long nowNanos = System.nanoTime(); long nowNanos = System.nanoTime();
// try to prevent dups, not guaranteed // try to prevent dups, not guaranteed
// nanoTime() isn't guaranteed to be monotonic either :( // nanoTime() isn't guaranteed to be monotonic either :(