You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "azexcy (via GitHub)" <gi...@apache.org> on 2023/04/12 12:00:06 UTC

[GitHub] [shardingsphere] azexcy opened a new pull request, #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

azexcy opened a new pull request, #25144:
URL: https://github.com/apache/shardingsphere/pull/25144

   refer https://dev.mysql.com/doc/refman/8.0/en/datetime.html
   MySQL may have the datetime value wiht '0000-00-00 00:00:00', but the value is illegal for `LocalDateTime` at java.
   
   Changes proposed in this pull request:
     - Fix the error of incremental tasks caused by datetime containing zero value in MySQL
     - Fix MySQLClient always print error log when decode binlog failed.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164899700


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   The official document can't find currently, but i found some relate source code from https://github.com/mysql/mysql-server/blob/5.7/sql-common/my_time.c#L1783
   
   <img width="652" alt="image" src="https://user-images.githubusercontent.com/101622833/231629876-ab01d0ec-b15d-44a5-9d85-329def80aeb9.png">
   
   the first bit sign seem not related to time 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164079234


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   How many values `long datetime` could be? Seems all of them will be `0` after `& (0x8000000000L - 1)`, and `0000-00-00 00:00:00` should be only one value, so I'm not sure whether it's correct or not.
   
   It's better to find related official document and put it here, then we could discuss about it.
   



##########
test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLTimeTypesMigrationE2EIT.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.data.pipeline.cases.migration.general;
+
+
+import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.PipelineContainerComposer;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.migration.AbstractMigrationE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ECondition;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+/**
+ * E2E IT for time types of MySQL, includes:
+ * 1) datetime.
+ * 2) timestamp.
+ * 3) date
+ */
+@PipelineE2ESettings(fetchSingle = true, database = @PipelineE2ESettings.PipelineE2EDatabaseSettings(type = "MySQL", scenarioFiles = "env/common/none.xml"))
+public class MySQLTimeTypesMigrationE2EIT extends AbstractMigrationE2EIT {
+    
+    @ParameterizedTest(name = "{0}")
+    @EnabledIf("isEnabled")
+    @ArgumentsSource(PipelineE2ETestCaseArgumentsProvider.class)
+    void assertIllegalTimeTypesValueMigrationSuccess(final PipelineTestParameter testParam) throws Exception {
+        try (PipelineContainerComposer containerComposer = new PipelineContainerComposer(testParam, new MigrationJobType())) {
+            String sql = "CREATE TABLE `time_e2e` ( `id` int NOT NULL, `t_timestamp` timestamp NULL DEFAULT NULL, `t_datetime` datetime DEFAULT NULL, `t_date` date DEFAULT NULL, `t_year` year DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;";
+            containerComposer.sourceExecuteWithLog(sql);
+            try (Connection connection = containerComposer.getSourceDataSource().getConnection()) {
+                PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `time_e2e`(id, t_timestamp, t_datetime, t_date, t_year) VALUES (?, ?, ?, ?, ?)");
+                preparedStatement.setObject(1, 1);
+                preparedStatement.setObject(2, "0000-00-00 00:00:00");
+                preparedStatement.setObject(3, "0000-00-00 00:00:00");
+                preparedStatement.setObject(4, "0000-00-00");
+                preparedStatement.setObject(5, "0000");
+                preparedStatement.execute();
+            }
+            addMigrationSourceResource(containerComposer);
+            addMigrationTargetResource(containerComposer);
+            startMigration(containerComposer, "time_e2e", "time_e2e");
+            String jobId = listJobId(containerComposer).get(0);

Review Comment:
   It's better to add incremental task in E2E to verify related modification



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164899700


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   The official document not find currently, but i found some relate source code from https://github.com/mysql/mysql-server/blob/5.7/sql-common/my_time.c#L1783
   
   <img width="652" alt="image" src="https://user-images.githubusercontent.com/101622833/231629876-ab01d0ec-b15d-44a5-9d85-329def80aeb9.png">
   
   the first bit sign seem not related to time 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz merged pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz merged PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164107760


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   https://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html is not available now, refer to https://stackoverflow.com/questions/36937211/how-datetime-values-are-stored-in-mysql for more details.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#discussion_r1164108309


##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -48,6 +48,9 @@ private long readDatetimeV2FromPayload(final MySQLPacketPayload payload) {
     
     private Serializable readDatetime(final MySQLBinlogColumnDef columnDef, final long datetime, final MySQLPacketPayload payload) {
         long datetimeWithoutSign = datetime & (0x8000000000L - 1);
+        if (0 == datetimeWithoutSign) {
+            return MySQLTimeValueUtils.DATETIME_OF_ZERO;
+        }

Review Comment:
   The sign bit might be needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on pull request #25144: Fix the error of incremental tasks caused by datetime containing zero value in MySQL

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on PR #25144:
URL: https://github.com/apache/shardingsphere/pull/25144#issuecomment-1506426476

   I find a problem when init ShardingSphereDataSource, the parameter at `jdbcUrl` maybe not equals with `dataSourceProperties`
   
   <img width="798" alt="image" src="https://user-images.githubusercontent.com/101622833/231673314-02f1e1fe-fd60-4c91-8ad5-12fdae27394a.png">
   
   This may lead to results that do not match expectations


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org