Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java (revision 1539518) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java (working copy) @@ -305,7 +305,7 @@ */ private void checkClockSkew(final ServerName serverName, final long serverCurrentTime) throws ClockOutOfSyncException { - long skew = System.currentTimeMillis() - serverCurrentTime; + long skew = Math.abs(System.currentTimeMillis() - serverCurrentTime); if (skew > maxSkew) { String message = "Server " + serverName + " has been " + "rejected; Reported time is too far out of sync with master. " + Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java (revision 1539518) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java (working copy) @@ -86,20 +86,39 @@ long warningSkew = c.getLong("hbase.master.warningclockskew", 1000); try { + //Master Time > Region Server Time + LOG.debug("Test: Master Time > Region Server Time"); LOG.debug("regionServerStartup 2"); InetAddress ia2 = InetAddress.getLocalHost(); sm.regionServerStartup(ia2, 1235, -1, System.currentTimeMillis() - maxSkew * 2); - fail("HMaster should have thrown an ClockOutOfSyncException but didn't."); + fail("HMaster should have thrown a ClockOutOfSyncException but didn't."); } catch(ClockOutOfSyncException e) { //we want an exception LOG.info("Recieved expected exception: "+e); } + try { + //Master Time < Region Server Time + LOG.debug("Test: Master Time < Region Server Time"); + LOG.debug("regionServerStartup 3"); + InetAddress ia3 = InetAddress.getLocalHost(); + sm.regionServerStartup(ia3, 1235, -1, System.currentTimeMillis() + maxSkew * 2); + fail("HMaster should have thrown a ClockOutOfSyncException but didn't."); + } catch(ClockOutOfSyncException e) { + //we want an exception + LOG.info("Recieved expected exception: "+e); + } + // make sure values above warning threshold but below max threshold don't kill - LOG.debug("regionServerStartup 3"); - InetAddress ia3 = InetAddress.getLocalHost(); - sm.regionServerStartup(ia3, 1236, -1, System.currentTimeMillis() - warningSkew * 2); + LOG.debug("regionServerStartup 4"); + InetAddress ia4 = InetAddress.getLocalHost(); + sm.regionServerStartup(ia4, 1236, -1, System.currentTimeMillis() - warningSkew * 2); + // make sure values above warning threshold but below max threshold don't kill + LOG.debug("regionServerStartup 5"); + InetAddress ia5 = InetAddress.getLocalHost(); + sm.regionServerStartup(ia5, 1236, -1, System.currentTimeMillis() + warningSkew * 2); + } }