为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:
【操作系统】:
【CPU】:
【问题描述】*:
使用XA事务时,单个XA事务执行没问题,当开启两个资源时,就会报如下错误
下方测试用例,将关于2的东西注释掉,运行没问题,但是就是放开就报-3的错误
public class XATestForDm {
public static void main(String[] args) throws Exception {
new XATestForDm().obOracleXAOne();
}
public void obOracleXAOne() throws Exception {
String url = "jdbc:dm://10.10.81.214:5236/test";
String user = "test";
String password = "test123";
Class.forName("dm.jdbc.driver.DmDriver");
Connection conn = DriverManager.getConnection(url, user, password);
Connection conn2 = DriverManager.getConnection(url, user, password);
DmdbXAConnection mysqlXAConnection = new DmdbXAConnection(conn);
DmdbXAConnection mysqlXAConnection2 = new DmdbXAConnection(conn2);
XAResource xaResource = mysqlXAConnection.getXAResource();
XAResource xaResource2 = mysqlXAConnection2.getXAResource();
conn.setAutoCommit(false);
conn2.setAutoCommit(false);
String gtridStr = "gtrid_test_wgs_ob_oracle_xa_one";
String bqualStr = "bqual_test_wgs_ob_oracle_xa_one";
String bqualStr2 = "bqual_test_wgs_ob_oracle_xa_one_2";
MysqlXid xaBranchXid = new MysqlXid(gtridStr.getBytes(), bqualStr.getBytes(),123);
MysqlXid xaBranchXid2 = new MysqlXid(gtridStr.getBytes(), bqualStr2.getBytes(),123);
try {
xaResource.start(xaBranchXid, XAResource.TMNOFLAGS);
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = conn.prepareStatement("select count from stock_tbl");
rs = pstmt.executeQuery();
int anInt = 0;
while (rs.next()) {
anInt = rs.getInt(1);
System.out.println(anInt);
}
pstmt.close();
pstmt = conn.prepareStatement("update stock_tbl set count = count - 30 where commodity_code = 'C100000';");
pstmt.executeUpdate();
xaResource.end(xaBranchXid, XAResource.TMSUCCESS);
xaResource.prepare(xaBranchXid);
// if (anInt > 0) {
// throw new Exception("回滚");
// }
xaResource2.start(xaBranchXid2, XAResource.TMNOFLAGS);
PreparedStatement pstmt2 = null;
pstmt2 = conn2.prepareStatement("insert into order_tbl(user_id,commodity_code,count,money) values('U100000','C100000',30,3000);");
pstmt2.executeUpdate();
xaResource2.end(xaBranchXid2, XAResource.TMSUCCESS);
xaResource2.prepare(xaBranchXid2);
xaResource.commit(xaBranchXid, false);
xaResource2.commit(xaBranchXid2, false);
} catch (Exception e) {
e.printStackTrace();
xaResource.rollback(xaBranchXid);
xaResource2.rollback(xaBranchXid2);
throw e;
}
}
}
sql表语句:
CREATE TABLE stock_tbl
(
id int NOT NULL IDENTITY(1,1),
commodity_code varchar(255) DEFAULT NULL,
count int DEFAULT 0,
CLUSTER PRIMARY KEY(id),
CONSTRAINT stock_tbl_commodity_code UNIQUE(commodity_code)
) STORAGE(ON MAIN, CLUSTERBTR);
CREATE TABLE order_tbl
(
id int NOT NULL IDENTITY(1,1),
user_id varchar(255) DEFAULT NULL,
commodity_code varchar(255) DEFAULT NULL,
count int DEFAULT 0,
money int DEFAULT 0,
CLUSTER PRIMARY KEY(id)
) STORAGE(ON MAIN, CLUSTERBTR) ;
您的问题正在处理,请您保持电话畅通。