mysql-binlog-connector-java
mysql-binlog-connector-java copied to clipboard
getSecondsBehindMaster sometimes returns epoch instead of seconds
It seems that getSecondsBehindMaster
in BinaryLogClientStatistics
sometimes return the epoch value of timestamp
instead of the difference timestamp - eventHeader.getTimestamp()
, most likely because eventHeader.getTimestamp()=0
. Maybe this happen when getSecondsBehindMaster
is called right before a new event is seen/fully deserde, in which case an extra test for a zero value would fix it, something like:
@Override
public long getSecondsBehindMaster() {
// because lastEventHeader and timestampOfLastEvent are not guarded by the common lock
// we may get some "distorted" results, though shouldn't be a problem given the nature of the final value
long timestamp = timestampOfLastEvent.get();
EventHeader eventHeader = lastEventHeader.get();
if (timestamp == 0 || eventHeader == null || eventHeader.getTimestamp() == 0) {
return -1;
}
return (timestamp - eventHeader.getTimestamp()) / 1000;
}