Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy can't support multiple transaction #2061

Closed
koalas1105 opened this issue Mar 20, 2019 · 3 comments
Closed

proxy can't support multiple transaction #2061

koalas1105 opened this issue Mar 20, 2019 · 3 comments

Comments

@koalas1105
Copy link

koalas1105 commented Mar 20, 2019

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

3.1.0

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-Proxy

Expected behavior

			Connection con = getConnection1();
			con.setAutoCommit(false);
			Statement statement = con.createStatement();
			String orderNo = System.currentTimeMillis() + "A";
			String sql = "insert into t_order(order_no,merc_no,merch_order_no,tx_dt,tx_tm,tx_amt) values('" + orderNo + "', 'B123456789012345', '" + orderNo + "', '20181117', '161411', '123.33')";
			statement.executeUpdate(sql);
			con.rollback();

			orderNo = System.currentTimeMillis() + "B";
			sql = "insert into t_order(order_no,merc_no,merch_order_no,tx_dt,tx_tm,tx_amt) values('" + orderNo + "', 'B123456789012345', '" + orderNo + "', '20181117', '161411', '123.33')";
			statement.executeUpdate(sql);


			orderNo = System.currentTimeMillis() + "C";
			sql = "insert into t_order(order_no,merc_no,merch_order_no,tx_dt,tx_tm,tx_amt) values('" + orderNo + "', 'B123456789012345', '" + orderNo + "', '20181117', '161411', '123.33')";
			statement.executeUpdate(sql);
			con.commit();

			ResultSet rs = statement.executeQuery("select * from t_order where order_no ='" + orderNo + "'");
			while( rs.next() ) {
				System.out.println("order_no:" + rs.getString("order_no"));
			}
//			con.commit();
//			sql = "insert into t_order(order_no,merc_no,merch_order_no,tx_dt,tx_tm,tx_amt) values('526431086763446276', 'B123456789012345', '526431083269591046', '20181117', '161411', '123.33')";
//			statement.executeUpdate(sql);
			con.rollback();

			con.close();

Actual behavior

ACTIONS: You can try one of the following: 
1. Make sure you started a transaction for the thread.
2. Make sure you didn't terminate it yet.
3. Increase the transaction timeout to avoid automatic rollback of long transactions;
   check http://www.atomikos.com/Documentation/JtaProperties for how to do this.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
	at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1739)
	at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:752)
	at TestMySql.main(TestMySql.java:32)

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

@cherrylzhao
Copy link
Member

@tonnixu I'm sorry for the lately reply, it seems that you have using a XA transaction in proxy?

@cherrylzhao
Copy link
Member

we have fixed this error in current dev branch(4.0.0-RC1-SNAPSHOT).
and I want to tell you XA transaction only support transaction between begin and commit/rollback. it looks like this:

  XATransaction.begin
    statement1.execute("sq1");           -- sq1 and sql2 will use XA transaction
    statement2.execute("sql2");
  XATransaction.commit
     stemet1.execute("sql3");            --  "sql3" will use local auto commit transaction

@cherrylzhao
Copy link
Member

cherrylzhao commented Mar 21, 2019

fixed at #1805 #1808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants