You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by le...@apache.org on 2024/05/27 10:56:52 UTC

(flink-cdc) branch master updated: [FLINK-35408][mysql] Introduce 30 minutes tolerance when validate the time-zone setting

This is an automated email from the ASF dual-hosted git repository.

leonard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-cdc.git


The following commit(s) were added to refs/heads/master by this push:
     new b2cb30f24 [FLINK-35408][mysql] Introduce 30 minutes tolerance when validate the time-zone setting
b2cb30f24 is described below

commit b2cb30f2406502b5672f8ed8a3a8eaef1d6d6a07
Author: Shawn Huang <hx...@gmail.com>
AuthorDate: Mon May 27 18:56:48 2024 +0800

    [FLINK-35408][mysql] Introduce 30 minutes tolerance when validate the time-zone setting
    
    This closes  #3341.
---
 .../flink/cdc/connectors/mysql/MySqlValidator.java | 25 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/MySqlValidator.java b/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/MySqlValidator.java
index f97ef8ea7..3f5f18bef 100644
--- a/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/MySqlValidator.java
+++ b/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/MySqlValidator.java
@@ -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;
@@ -206,7 +207,10 @@ public class MySqlValidator implements Validator {
                 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 "
@@ -220,10 +224,14 @@ public class MySqlValidator implements Validator {
     }
 
     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,
@@ -232,7 +240,14 @@ public class MySqlValidator implements Validator {
         // 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;
     }
 }