dbTalk Databases Forums  

MySQL's XA problem

mailing.database.mysql-java mailing.database.mysql-java


Discuss MySQL's XA problem in the mailing.database.mysql-java forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jack Wang
 
Posts: n/a

Default MySQL's XA problem - 02-12-2006 , 03:10 AM







I hava done a test to use the MySQL XADataSource. For MySQL has no MYSQLXADataSourceFactory
class, so I coded one to produce MysqlXADataSource. MysqlXADataSource is configured in tomcat 5.5
server.xml. I can get the MysqlXADataSource instance xaDs by which I can get XAConnection and
XAResource. I also configured a UserTransaction which was produced by
org.objectweb.jotm.UserTransactionFactory. The following is the action's code in a test web
application. This action runs correctly the first time, but in the second time, it runs very slow,
then reports "Lock wait timeout exceeded; try restarting transaction" error.

The first question is that it seems the action did not update the table testdata's data. Did the
UserTransaction ut have some error not participate in the database transaction?

The second question is that I have searched this error, but don't know how to solve it. Please
give me some tips. Must I not use MySQL's XA in Kandula ? Thanks.


The java code (JOTM example):
================================================== ======
UserTransaction ut = null;
try{
Context ctx = new InitialContext();
MysqlXADataSource xaDs = (MysqlXADataSource)ctx.lookup("java:comp/env/jdbc/myXADB");
ut = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");

XAConnection xCon = xaDs.getXAConnection();
java.sql.Connection conn = xCon.getConnection();

System.out.println("<<< beginning the transaction >>> xa con = " + conn);
ut.begin();

// JDBC statements
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select id, foo from testdata");
if(rst.next()) {
foo=rst.getInt(2);
}
System.out.println("foo = "+ foo +" (before completion)");

String sql = "update testdata set foo=" + (++foo) + " where id=1";
stmt.executeUpdate(sql);// <=== The program will wait here, and then report the error message
!

ut.commit();
System.out.println("<<< committing the transaction >>>");

conn.close();
System.out.println("<<< done >>>");
}catch(Exception e) {
System.out.print("DBTest >> ");
e.printStackTrace();
System.out.println("<<< rolling back the transaction >>>");
try {
ut.rollback();
System.out.println("rollback ok.");
}catch(Exception e1){
System.out.println("rollback Error " + e1);
}
System.out.println("rollback end");
}
}
================================================== ======


The error message:
================================================== ======
==> xaDataSource = com.mysql.jdbc.jdbc2.optional.MysqlXADataSource@e2 fbeb <==
<<< beginning the transaction >>> xa con = com.mysql.jdbc.jdbc2.optional.ConnectionWrapper@17 0984c
foo = 29 (before completion)
<<< committing the transaction >>>
<<< done >>>
<<< beginning the transaction >>> xa con = com.mysql.jdbc.jdbc2.optional.ConnectionWrapper@4d 5575
foo = 29 (before completion)
- set rollback only (tx=bb14:38:0:01777d30dfc9556034...986c02
DBTest >> java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2822)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:15 36)
at com.mysql.jdbc.ServerPreparedStatement.serverExecu te(ServerPreparedStatement.java:1159)
at
com.mysql.jdbc.ServerPreparedStatement.executeInte rnal(ServerPreparedStatement.java:684)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1184)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1101)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1086)
at
com.mysql.jdbc.jdbc2.optional.PreparedStatementWra pper.executeUpdate(PreparedStatementWrapper.java:8 40)
at foo.XADBTest.init(XADBTest.java:92)
at org.apache.jsp.testJotm_jsp._jspService(org.apache .jsp.testJotm_jsp:55)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:868)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
<<< rolling back the transaction >>>
rollback ok.
rollback end




Wang Jun






__________________________________________________ _________
雅虎1G免费邮箱百分百防垃圾信
http://cn.mail.yahoo.com/

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Christopher G. Stach II
 
Posts: n/a

Default Re: MySQL's XA problem - 02-12-2006 , 09:02 AM






Jack Wang wrote:
Quote:
I hava done a test to use the MySQL XADataSource. For MySQL has no MYSQLXADataSourceFactory
class, so I coded one to produce MysqlXADataSource. MysqlXADataSource is configured in tomcat 5.5
server.xml. I can get the MysqlXADataSource instance xaDs by which I can get XAConnection and
XAResource. I also configured a UserTransaction which was produced by
org.objectweb.jotm.UserTransactionFactory. The following is the action's code in a test web
application. This action runs correctly the first time, but in the second time, it runs very slow,
then reports "Lock wait timeout exceeded; try restarting transaction" error.

Is the XAConnection enlisted in the transaction? What does your innodb
status say?

--
Christopher G. Stach II

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Jack Wang
 
Posts: n/a

Default Re: MySQL's XA problem - 02-13-2006 , 03:28 AM



--- "Christopher G. Stach II" <cgs (AT) ldsys (DOT) net>写道:
Quote:
Jack Wang wrote:
I hava done a test to use the MySQL XADataSource. For MySQL has no MYSQLXADataSourceFactory
class, so I coded one to produce MysqlXADataSource. MysqlXADataSource is configured in tomcat
5.5
server.xml. I can get the MysqlXADataSource instance xaDs by which I can get XAConnection and
XAResource. I also configured a UserTransaction which was produced by
org.objectweb.jotm.UserTransactionFactory. The following is the action's code in a test web
application. This action runs correctly the first time, but in the second time, it runs very
slow,
then reports "Lock wait timeout exceeded; try restarting transaction" error.


Is the XAConnection enlisted in the transaction? What does your innodb
status say?
Thanks Christopher G. Stach II

Please ask how to enlist XAConnection in the transaction ? I did not enlist the XAConnection.
Maybe this is the reason. If so, how should I do ? The Innodb status is:

=========== begin ==================

mysql> show innodb status;
Quote:
Type | Name | Status
InnoDB | |
=====================================
060213 17:06:56 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 3 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 3, signal count 3
Mutex spin waits 1, rounds 20, OS waits 0
RW-shared spins 6, OS waits 3; RW-excl spins 0, OS waits 0
------------
TRANSACTIONS
------------
Trx id counter 0 3843
Purge done for trx's n < 0 3333 undo n < 0 0
History list length 4
Total number of lock structs in row lock hash table 2
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 3841, not started, OS thread id 1436
MySQL thread id 2, query id 16 localhost 127.0.0.1 root
show innodb status
---TRANSACTION 0 3842, ACTIVE 145 sec, OS thread id 1004 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 320
MySQL thread id 3, query id 15 localhost 127.0.0.1 root Updating
update testdata set foo=888 where id=1
------- TRX HAS BEEN WAITING 145 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 50 n bits 72 index `PRIMARY` of table `test/test
data` trx id 0 3842 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
0: len 4; hex 80000001; asc ;; 1: len 6; hex 000000000f00; asc ;; 2:
len 7; hex 00000000340bf6; asc 4 ;; 3: len 4; hex 80000378; asc x;;

------------------
---TRANSACTION 0 3840, ACTIVE 295 sec, OS thread id 3452
2 lock struct(s), heap size 320, undo log entries 1
MySQL thread id 1, query id 7 localhost 127.0.0.1 root
--------
FILE I/O
--------
I/O thread 0 state: wait Windows aio (insert buffer thread)
I/O thread 1 state: wait Windows aio (log thread)
I/O thread 2 state: wait Windows aio (read thread)
I/O thread 3 state: wait Windows aio (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
74 OS file reads, 9 OS file writes, 7 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf for space 0: size 1, free list len 0, seg size 2, is empty
Ibuf for space 0: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 116329, used cells 0, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 0 65229
Log flushed up to 0 65229
Last checkpoint at 0 65229
0 pending log writes, 0 pending chkp writes
10 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 37345384; in additional pool allocated 194432
Buffer pool size 1792
Free buffers 1728
Database pages 64
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 64, created 0, written 3
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread id 188, state: waiting for server activity
Number of rows inserted 0, updated 1, deleted 0, read 3
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
-------------+
1 row in set, 1 warning (0.02 sec)
mysql>
============ end ===================

Quote:
--
Christopher G. Stach II

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=pi...ahoo (DOT) com


p.s.

My environment is: win XP, Tomcat 5.5, MySQL 5.0, Connector/J 5.0.0 beta, JOTM 2.0.10.

When I run the following jsp ,it runs the first time, but has not updated the database's table
which has one record (id=1,foo=29 not 888) . And when I run it the second time, it is very slow,
and then reports error:
"- set rollback only (tx=bb14:38:0:016c028f7ae82ed0a2...99bc02"

========= jsp begin =====================

<body bgcolor="#FFFFFF">
<%
UserTransaction ut = null;
try{
Context ctx = new InitialContext();
ut = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
ut.begin();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource xaDs =
(com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)c tx.lookup("java:comp/env/jdbc/myXADB");
XAConnection xCon = xaDs.getXAConnection();
javax.transaction.xa.XAResource xaRes = xCon.getXAResource();
Connection con = xCon.getConnection();
Statement stmt = con.createStatement();
String sql = "update testdata set foo=888 where id=1";
stmt.executeUpdate(sql);
ut.commit();
}catch(Exception e) {
e.printStackTrace();
try {
ut.rollback();
}catch(Exception e1){
System.out.println("[HelloWorldAction] rollback Error " + e1);
}
}
%>
</body>
========= jsp end========================


=========== resource begin =======================
<Resource name="jdbc/myXADB" auth="Container"
type="com.mysql.jdbc.jdbc2.optional.MysqlXADataSou rce"
factory="xa.MYSQLXADataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
databaseName="test"
serverName="localhost"
explicitUrl="true"
port="3306"
user="root"
password="password"
url="jdbc:mysql://localhost/test?useUnicode=true&amp;characterEncoding=utf-8"
/>
=========== resource end =======================















Wang Jun






__________________________________________________ _________
雅虎1G免费邮箱百分百防垃圾信
http://cn.mail.yahoo.com/

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Jack Wang
 
Posts: n/a

Default Re: MySQL's XA problem - 02-22-2006 , 10:24 PM




Hello, all. I have a experiment project, which will use MySQL's XA. The scenario is:

------------------------------------------
1) Get TransactionManager from Kandula Bridge

2) Get Transaction, tx = tm.getTransaction();

3) Get xCon and xRes with:
Context ctx = new InitialContext();
//ut = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
org.enhydra.jdbc.standard.StandardXADataSource xaDs =
ctx.lookup("java:comp/env/jdbc/myXADB20060222");
XAConnection xCon = xaDs.getXAConnection("root", "password");
java.sql.Connection conn = xCon.getConnection();
XAResource xRes = xCon.getXAResource();

4) Enlist the resource
try{
tx.enlistResource(xRes); <===== Error
}catch(Exception e){
System.out.println("HERE, Exception " + e);
}

5) Do the sql
//ut.begin();
Statement stmt = conn.createStatement();
stmt.executeUpdate("update testdata set foo=666 where id=1");
//ut.commit();
-------------------------------------------

In this test , I can get the tx and xRes, but when I enlist the resource to tx, it reports error:
"java.lang.ClassCastException: org.enhydra.jdbc.standard.StandardXAConnection". It seems
XADataSource and the tx are mismatched. Please ask how to solve this problem ? Thanks.




Wang Jun

__________________________________________________
赶快注册雅虎超大容量免费邮箱?
http://cn.mail.yahoo.com

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.