Index: src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceMetrics.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceMetrics.java (revision 1099152) +++ src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceMetrics.java (working copy) @@ -66,6 +66,11 @@ public final MetricsIntValue sizeOfLogQueue = new MetricsIntValue("sizeOfLogQueue", registry); + // It's a little dirty to preset the age to now since if we fail + // to replicate the very first time then it will show that age instead + // of nothing (although that might not be good either). + private long lastTimestampForAge = System.currentTimeMillis(); + /** * Constructor used to register the metrics * @param id Name of the source this class is monitoring @@ -90,9 +95,19 @@ * @param timestamp write time of the edit */ public void setAgeOfLastShippedOp(long timestamp) { - ageOfLastShippedOp.set(System.currentTimeMillis() - timestamp); + lastTimestampForAge = timestamp; + ageOfLastShippedOp.set(System.currentTimeMillis() - lastTimestampForAge); } + /** + * Convenience method to use the last given timestamp to refresh the age + * of the last edit. Used when replication fails and need to keep that + * metric accurate. + */ + public void refreshAgeOfLastShippedOp() { + setAgeOfLastShippedOp(lastTimestampForAge); + } + @Override public void doUpdates(MetricsContext metricsContext) { synchronized (this) { Index: src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java (revision 1099152) +++ src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java (working copy) @@ -569,6 +569,8 @@ break; } catch (IOException ioe) { + // Didn't ship anything, but must still age the last time we did + this.metrics.refreshAgeOfLastShippedOp(); if (ioe instanceof RemoteException) { ioe = ((RemoteException) ioe).unwrapRemoteException(); LOG.warn("Can't replicate because of an error on the remote cluster: ", ioe);