You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/27 10:37:31 UTC

[GitHub] [shardingsphere] dragonorant opened a new issue, #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

dragonorant opened a new issue, #18008:
URL: https://github.com/apache/shardingsphere/issues/18008

   
   当我使用 shardingSphere 5.1.1 版本时, 事务失败回滚失效。而使用 5.0.0 版本以及不使用的时候,事务失败回滚是成功的
   
   When I use shardingsphere version 5.1.1, transaction rollback fails. When using version 5.0.0 or not, the transaction failure rollback is successful
   
   ```pom
   <properties>    
   <spring-boot.version>2.6.3</spring-boot.version>    
        <spring-cloud.version>2021.0.2</spring-cloud.version>
           <spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>
   
   <!--<sharding-sphere.version>5.0.0</sharding-sphere.version>-->
   <sharding-sphere.version>5.0.0</sharding-sphere.version>
   </>
    <dependencyManagement>
           <dependencies>
               <!-- spring boot 依赖 -->
               <dependency>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-dependencies</artifactId>
                   <version>${spring-boot.version}</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
   
   
               <!-- spring cloud 依赖 -->
               <dependency>
                   <groupId>org.springframework.cloud</groupId>
                   <artifactId>spring-cloud-dependencies</artifactId>
                   <version>${spring-cloud.version}</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
               <!-- spring cloud alibaba 依赖 -->
               <dependency>
                   <groupId>com.alibaba.cloud</groupId>
                   <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                   <version>${spring-cloud-alibaba.version}</version>
                   <type>pom</type>
                   <scope>import</scope>
               </dependency>
               <dependency>
                   <groupId>org.apache.shardingsphere</groupId>
                   <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
                   <version>${sharding-sphere.version}</version>
               </dependency>
           </dependencies>
       </dependencyManagement>
   
   ```
   
   ```app.yml
   server:
     tomcat:
       uri-encoding: UTF-8
       threads:
         max: 1000
         min-spare: 30
       connection-timeout: 5000ms
     port: 8090
     servlet:
       context-path: /sanyi/manager
   spring:
     transaction:
       rollback-on-commit-failure: true
     jackson:
       default-property-inclusion: non_null
     # 不使用 shardingSphere
     datasource:
       type: com.zaxxer.hikari.HikariDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver
       username: root
       password: root
       url: jdbc:mysql://192.168.2.254:3307/sanyi_manager?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
   
   # 5.0.0 版本配置
     #shardingsphere:
     #  datasource:
     #    names: master
     #    master:
     #      type: com.zaxxer.hikari.HikariDataSource
     #      driver-class-name: com.mysql.cj.jdbc.Driver
     #      username: root
     #      password: root
     #      jdbc-url: jdbc:mysql://192.168.2.254:3307/sanyi_manager?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
     #  props:
     #    sql-show: true
     #  enabled: true
     #  rules:
     #    # 读写分离
     #    readwrite_splitting:
     #      data-sources:
     #        sanyi_manager:
     #          write-data-source-name: master
     #          read-data-source-names: master
     #          load-balancers-name: round-robin
     #      load-balancers:
     #        round-robin:
     #          type: ROUND_ROBIN
     #          props:
     #            workId: 1
   
     # 5.1.1 版本配置 数据源
     #shardingsphere:
     #  datasource:
     #    names: master
     #    master:
     #      type: com.zaxxer.hikari.HikariDataSource
     #      driver-class-name: com.mysql.cj.jdbc.Driver
     #      username: root
     #      password: root
     #      jdbc-url: jdbc:mysql://192.168.2.254:3307/sanyi_manager?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
     #  props:
     #    sql-show: true
     #  enabled: true
     #  rules:
     #    # 读写分离
     #    readwrite-splitting:
     #      data-sources:
     #        onn_auth:
     #          type: DYNAMIC
     #          props:
     #            auto-aware-data-source-name: master
     #            write-data-source-name: master
     #            read-data-source-names: master
     #          load-balancers-name: round-robin
     #      load-balancers:
     #        round-robin:
     #          type: ROUND_ROBIN
     #          props:
     #            workId: 1
   
   
   # Spring 相关
   # mybaits-plus配置
   mybatis-plus:
     mapper-locations: classpath:/mapper/**/*.xml
     global-config:
       db-config:
         id-type: auto
         table-underline: true
         logic-delete-value: 1
         logic-not-delete-value: 0
         db-column-underline: true
         refresh-mapper: true
     configuration:
       map-underscore-to-camel-case: true
       cache-enabled: false
       call-setters-on-nulls: true
       jdbc-type-for-null: 'null'
       default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
       log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
     type-enums-package: com.demo.**.enums
   
   ```
   
   ```java
   
   @Data
   @AllArgsConstructor
   @NoArgsConstructor
   @TableName(value = "status_record")
   @Builder
   public class StatusRecord implements Serializable {
       private static final long serialVersionUID = 1L;
       @TableId(value = "id", type = IdType.AUTO)
       private Long id;
   
       @TableField(value = "project_id")
       private Integer projectId;
   }
   
   /**
    * by zhaowenyuan create 2022/5/27 17:45
    */
   public interface StatusRecordMapper extends BaseMapper<StatusRecord> {
   }
   
   
   
   /**
    * by zhaowenyuan create 2022/5/27 17:45
    */
   public interface StatusRecordService extends IService<StatusRecord> {
   
       void saveTest();
   
   }
   
   
   @Slf4j
   @Service
   public class StatusRecordServiceImpl extends ServiceImpl<StatusRecordMapper, StatusRecord> implements StatusRecordService {
   
       @Override
       @Transactional
       public void saveTest() {
   
           save(StatusRecord.builder()
                   .projectId(11)
                   .build());
   
           int s = 1 / 0;
       }
   }
   
   ```
   
   ```test
   
   @Slf4j
   @SpringBootTest(classes = DemoApplication.class)
   @RunWith(SpringRunner.class)
   public class DemoTest {
   
       @Autowired
       StatusRecordService statusRecordService;
   
       /**
        * success
        * shardingsphere version 5.0.0 and do not use shardingsphere
        * error
        * shardingsphere version 5.1.1
        *
        */
       @Test
       public void transactionalTest(){
           statusRecordService.saveTest();
       }
   
   }
   
   ```


-- 
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.apache.org

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


[GitHub] [shardingsphere] dragonorant commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
dragonorant commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1140609369

   @strongduanmu How should I solve it?  


-- 
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


Re: [I] springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #18008:  springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back
URL: https://github.com/apache/shardingsphere/issues/18008


-- 
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] dragonorant commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
dragonorant commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1144737313

   > 我也有同样的问题。我使用的版本如下:
   > 
   > ```
   > <parent>
   >   <groupId>org.springframework.boot</groupId>
   >   <artifactId>spring-boot-starter-parent</artifactId>
   >   <version>2.6.7</version>
   >   <relativePath/> <!-- lookup parent from repository -->
   > </parent>
   > ```
   > 
   > ```
   > <dependency>
   >   <groupId>org.apache.shardingsphere</groupId>
   >   <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
   >   <version>5.1.1</version>
   > </dependency>
   > <dependency>
   >   <groupId>mysql</groupId>
   >   <artifactId>mysql-connector-java</artifactId>
   >   <version>8.0.28</version>
   >   <scope>runtime</scope>
   > </dependency>
   > ```
   > 
   > 通过调试mysql驱动源码,发现这与一个useLocalSessionState参数有关。我注意到mysql官方文档中这个参数的默认值为false。但是在shardingsphere 5.1.1版本中,有这么一段代码来设置这个参数值。
   > 
   > ![图片](https://user-images.githubusercontent.com/35357351/171575191-47992a53-b77f-45ac-94eb-ea791838e245.png)
   > 
   > 两个类中都存在类似的代码。 ![图片](https://user-images.githubusercontent.com/35357351/171575405-cbe6146b-6f1f-42c4-b432-f72bbd1fabd4.png)
   > 
   > shardingsphere 5.0.0 中没有这些修改数据库驱动参数值的行为。这有什么原因吗?
   > 
   > 我尝试如下修改参数值,然后Spring的事务回滚行为正常生效。
   > 
   > ![图片](https://user-images.githubusercontent.com/35357351/171577102-79323e40-4a73-4b29-86fb-8f38f70ba359.png)
   > 
   > 那么设置这个参数值的代码能不能改成false呢?
   
   Thank you for your advice


-- 
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] yanghao888 commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
yanghao888 commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1144541061

   I also had the same problem. The version I am using is as follows:
   ```
   <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.6.7</version>
     <relativePath/> <!-- lookup parent from repository -->
   </parent>
   ```
   ```
   <dependency>
     <groupId>org.apache.shardingsphere</groupId>
     <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
     <version>5.1.1</version>
   </dependency>
   <dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>8.0.28</version>
     <scope>runtime</scope>
   </dependency>
   ```
   Through the debug mysql driver source code, it is found that this is related to a useLocalSessionState parameter. I noticed that the default value of this parameter is false in the mysql official document. However, in the shardingsphere 5.1.1 version, there is such a piece of code to set this parameter value.
   
   ![image](https://user-images.githubusercontent.com/35357351/171575191-47992a53-b77f-45ac-94eb-ea791838e245.png)
   
   Similar code exists in both classes.
   ![image](https://user-images.githubusercontent.com/35357351/171575405-cbe6146b-6f1f-42c4-b432-f72bbd1fabd4.png)
   
   These behaviors of modifying database-driven parameter values are not found in shardingsphere 5.0.0. Is there any reason for this?
   
   I tried to modify the parameter value like below, and then Spring's transaction rollback behavior took effect normally.
   
   ![image](https://user-images.githubusercontent.com/35357351/171577102-79323e40-4a73-4b29-86fb-8f38f70ba359.png)
   
   So can the code that sets this parameter value be changed to false?
   
   
   


-- 
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] github-actions[bot] commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1272349721

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
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] github-actions[bot] closed issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #18008:  springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back
URL: https://github.com/apache/shardingsphere/issues/18008


-- 
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] dragonorant commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by GitBox <gi...@apache.org>.
dragonorant commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1140604012

   mybatis-plus  3.5.1


-- 
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] RaigorJiang commented on issue #18008: springboot 2.6.3 and shardingsphere 5.1.1 , transaction do not roll back

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #18008:
URL: https://github.com/apache/shardingsphere/issues/18008#issuecomment-1407573530

   This issue has been inactive for a long time, and ShardingSphere has released several new versions.
   Anyone want to try version 5.3.1?


-- 
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