shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

SQL will be broadcasted when Seata rollback transaction

Open hnxphnxp opened this issue 6 years ago • 3 comments

enviroment: springboot:2.0.4, shardingsphere:4.1.1, seata 1.3.0,using hint for sharding DB and table one micro service call other service.

below is the code and configuration: hintManager.addDatabaseShardingValue("t_user_route", Long.parseLong(userId)); hintManager.addTableShardingValue("t_user_route", Long.parseLong(userId));

         <dependency>
		<groupId>com.alibaba.cloud</groupId>
		<artifactId>spring-cloud-alibaba-seata</artifactId>
		<version>2.1.0.RELEASE</version>
		<exclusions>
			<exclusion>
				<artifactId>seata-all</artifactId>
				<groupId>io.seata</groupId>
			</exclusion>
		</exclusions>
	</dependency>
	<dependency>
		<groupId>io.seata</groupId>
		<artifactId>seata-all</artifactId>
		<version>1.3.0</version>
	</dependency>

logs: 2020-09-28 17:29:01.042 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : Actual SQL: ds-1 ::: insert into t_user_route(user_id,db_name,table_name) values(?, ?, ?) ::: [123, -0, _0] 2020-09-28 17:29:01.046 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : Logic SQL: SELECT * FROM t_user_route WHERE (id ) in ( (?) ) 2020-09-28 17:29:01.046 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@44e8f3c2, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@37773c17), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@37773c17, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=id, alias=Optional.empty), ColumnProjection(owner=null, name=user_id, alias=Optional.empty), ColumnProjection(owner=null, name=db_name, alias=Optional.empty), ColumnProjection(owner=null, name=table_name, alias=Optional.empty), ColumnProjection(owner=null, name=create_time, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@5ec4d122, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@3f1c7004, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@551cc520, containsSubquery=false) 2020-09-28 17:29:01.046 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : Actual SQL: ds-1 ::: SELECT * FROM t_user_route WHERE (id ) in ( (?) ) ::: [75] 2020-09-28 17:29:01.067 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : Logic SQL: INSERT INTO undo_log (branch_id, xid, context, rollback_info, log_status, log_created, log_modified) VALUES (?, ?, ?, ?, ?, now(6), now(6)) 2020-09-28 17:29:01.067 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : SQLStatement: InsertStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement@7fd71a6, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@18abf414), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@18abf414, columnNames=[branch_id, xid, context, rollback_info, log_status, log_created, log_modified], insertValueContexts=[InsertValueContext(parametersCount=5, valueExpressions=[ParameterMarkerExpressionSegment(startIndex=109, stopIndex=109, parameterMarkerIndex=0), ParameterMarkerExpressionSegment(startIndex=112, stopIndex=112, parameterMarkerIndex=1), ParameterMarkerExpressionSegment(startIndex=115, stopIndex=115, parameterMarkerIndex=2), ParameterMarkerExpressionSegment(startIndex=118, stopIndex=118, parameterMarkerIndex=3), ParameterMarkerExpressionSegment(startIndex=121, stopIndex=121, parameterMarkerIndex=4), org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ExpressionProjectionSegment@2efcec05, org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ExpressionProjectionSegment@3bbf03e4], parameters=[53897398016999425, 10.32.173.240:8091:53897397782118400, serializer=jackson, javax.sql.rowset.serial.SerialBlob@eb4eaf6e, 0])], generatedKeyContext=Optional.empty) 2020-09-28 17:29:01.067 INFO [service-feign,,,] 11984 --- [nio-8765-exec-2] ShardingSphere-SQL : Actual SQL: default-data-source ::: INSERT INTO undo_log (branch_id, xid, context, rollback_info, log_status, log_created, log_modified) VALUES (?, ?, ?, ?, ?, now(6), now(6)) ::: [53897398016999425, 10.32.173.240:8091:53897397782118400, serializer=jackson, javax.sql.rowset.serial.SerialBlob@eb4eaf6e, 0] 2020-09-28 17:29:01.087 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] i.s.c.r.p.c.RmBranchRollbackProcessor : rm handle branch rollback process:xid=10.32.173.240:8091:53897397782118400,branchId=53897398016999425,branchType=AT,resourceId=jdbc:mysql://localhost:3306/default-db,applicationData=null 2020-09-28 17:29:01.088 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] io.seata.rm.AbstractRMHandler : Branch Rollbacking: 10.32.173.240:8091:53897397782118400 53897398016999425 jdbc:mysql://localhost:3306/default-db 2020-09-28 17:29:01.103 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Logic SQL: SELECT * FROM undo_log WHERE branch_id = ? AND xid = ? FOR UPDATE 2020-09-28 17:29:01.103 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@72e5cad0, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@464a3031), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@464a3031, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=id, alias=Optional.empty), ColumnProjection(owner=null, name=branch_id, alias=Optional.empty), ColumnProjection(owner=null, name=xid, alias=Optional.empty), ColumnProjection(owner=null, name=context, alias=Optional.empty), ColumnProjection(owner=null, name=rollback_info, alias=Optional.empty), ColumnProjection(owner=null, name=log_status, alias=Optional.empty), ColumnProjection(owner=null, name=log_created, alias=Optional.empty), ColumnProjection(owner=null, name=log_modified, alias=Optional.empty), ColumnProjection(owner=null, name=ext, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@6bfd9acf, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@718b18f9, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@2de4ff52, containsSubquery=false) 2020-09-28 17:29:01.103 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Actual SQL: default-data-source ::: SELECT * FROM undo_log WHERE branch_id = ? AND xid = ? FOR UPDATE ::: [53897398016999425, 10.32.173.240:8091:53897397782118400] 2020-09-28 17:29:01.156 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Logic SQL: SELECT * FROM t_user_route WHERE (id ) in ( (?) ) 2020-09-28 17:29:01.156 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@44e8f3c2, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@dd0207), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@dd0207, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=id, alias=Optional.empty), ColumnProjection(owner=null, name=user_id, alias=Optional.empty), ColumnProjection(owner=null, name=db_name, alias=Optional.empty), ColumnProjection(owner=null, name=table_name, alias=Optional.empty), ColumnProjection(owner=null, name=create_time, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@74dde788, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@123f959c, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@2e1e51b, containsSubquery=false) 2020-09-28 17:29:01.156 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Actual SQL: ds-0 ::: SELECT * FROM t_user_route WHERE (id ) in ( (?) ) ::: [75] 2020-09-28 17:29:01.156 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Actual SQL: ds-1 ::: SELECT * FROM t_user_route WHERE (id ) in ( (?) ) ::: [75] 2020-09-28 17:29:01.169 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Logic SQL: DELETE FROM t_user_route WHERE id = ?
2020-09-28 17:29:01.169 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : SQLStatement: DeleteStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement@7395c792, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@1d7192b3), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@1d7192b3) 2020-09-28 17:29:01.169 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Actual SQL: ds-0 ::: DELETE FROM t_user_route WHERE id = ? ::: [75] 2020-09-28 17:29:01.169 INFO [service-feign,,,] 11984 --- [ch_RMROLE_1_2_8] ShardingSphere-SQL : Actual SQL: ds-1 ::: DELETE FROM t_user_route WHERE id = ? ::: [75]

transaction can be rollbacked while occured exception,but it seems hint is invalid since seata used new thread for rollback. anyone who can help me?thanks a lot.

hnxphnxp avatar Sep 28 '20 09:09 hnxphnxp

yes, seata rollback-phase will be invoked in a new thread asynchronous, so hint context will be invalided. if seata support to register user defined hook in rollback-phase, this problem will be resolved.

cherrylzhao avatar Sep 30 '20 13:09 cherrylzhao

so commit issue to seata team would be a better way?

hnxphnxp avatar Oct 28 '20 09:10 hnxphnxp

The seata version of ShardingSphere is 1.0.0, it is better to upgrade the version, please see #12739.

terrymanu avatar Sep 26 '21 08:09 terrymanu