Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MySqlValidator implements Validator {
private static final String BINLOG_FORMAT_ROW = "ROW";
private static final String BINLOG_FORMAT_IMAGE_FULL = "FULL";
private static final String DEFAULT_BINLOG_ROW_VALUE_OPTIONS = "";
private static final int TIME_ZONE_TOLERANCE_SECONDS = 30 * 60;

private final Properties dbzProperties;
private final MySqlSourceConfig sourceConfig;
Expand Down Expand Up @@ -206,7 +207,10 @@ private void checkTimeZone(JdbcConnection connection) throws SQLException {
zoneId.getRules().getOffset(LocalDateTime.now()).getTotalSeconds();

if (!timeDiffMatchesZoneOffset(
timeDiffInSeconds, timeZoneOffsetInSeconds, inDayLightTime)) {
timeDiffInSeconds,
timeZoneOffsetInSeconds,
inDayLightTime,
TIME_ZONE_TOLERANCE_SECONDS)) {
throw new ValidationException(
String.format(
"The MySQL server has a timezone offset (%d seconds %s UTC) which does not match "
Expand All @@ -220,10 +224,14 @@ private void checkTimeZone(JdbcConnection connection) throws SQLException {
}

private boolean timeDiffMatchesZoneOffset(
int timeDiffInSeconds, int timeZoneOffsetInSeconds, boolean inDayLightTime) {
int timeDiffInSeconds,
int timeZoneOffsetInSeconds,
boolean inDayLightTime,
int toleranceInSeconds) {
// Trivial case for non-DST timezone
if (!inDayLightTime) {
return timeDiffInSeconds == timeZoneOffsetInSeconds;
return equalsWithTolerance(
timeDiffInSeconds, timeZoneOffsetInSeconds, toleranceInSeconds);
}

// There are two cases when Daylight Saving Time is in effect,
Expand All @@ -232,7 +240,14 @@ private boolean timeDiffMatchesZoneOffset(
// 2) MySQL timezone has been fixed to non-DST, like using 'Pacific Standard Time' all year
// long.
// thus we need to accept both.
return timeDiffInSeconds == timeZoneOffsetInSeconds
|| timeDiffInSeconds == timeZoneOffsetInSeconds - TimeUnit.HOURS.toSeconds(1);
return equalsWithTolerance(timeDiffInSeconds, timeZoneOffsetInSeconds, toleranceInSeconds)
|| equalsWithTolerance(
timeDiffInSeconds,
timeZoneOffsetInSeconds - TimeUnit.HOURS.toSeconds(1),
toleranceInSeconds);
}

private boolean equalsWithTolerance(long val1, long val2, long tolerance) {
return Math.abs(val1 - val2) <= tolerance;
}
}