ws-kandula-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dasarath Weeratunge <dweer...@purdue.edu>
Subject Re: MySQL's XA problem
Date Sun, 12 Feb 2006 19:33:43 GMT
Quoting Jack Wang <pipashu@yahoo.com>:

Hello Jack,

Have you had a look at the following stuff in Tomcat docs?

http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html

What is missing in your work is you when you create the connection in you 
DataSource object's getConnection method, you need to also create an 
XAConnection and then enlist the XAResource in the local tx associated with the 
thread. This you can get from the TM and must be done BEFORE you return the 
connection object to your application.

When you invoke a ws with a coordination ctx, Kandula will create a local tx 
and attach that to the thread that runs your service implementation. This is 
why you do not and SHOULD NOT call begin() in your code. Then when the global 
ws-at tx is terminated, the Kandula will terminate that local tx as 
appropriate. This why you SHOULD not commit the tx. You can however rollback 
the local tx. Then Kandula will rollback the global tx. If you mark your local 
tx is RollbackOnly this will happen when the global ws-at tx is terminated. If 
rollback the local tx, the global ws-at tx will also be rollbacked immediately. 
If you try to commit the local tx, then AGAIN the global ws-at tx will be 
immediately rollbacked by Kandula since what you are tring to do is illegal.

--dasarath

> 
>   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@e2fbeb
> <==
> <<< beginning the transaction >>> xa con =
> com.mysql.jdbc.jdbc2.optional.ConnectionWrapper@170984c
> foo = 29 (before completion)
> <<< committing the transaction >>>
> <<< done >>>
> <<< beginning the transaction >>> xa con =
> com.mysql.jdbc.jdbc2.optional.ConnectionWrapper@4d5575
> 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(SQLError.java:946)
>         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2822)
>         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1536)
>         at
> com.mysql.jdbc.ServerPreparedStatement.serverExecute
(ServerPreparedStatement.java:1159)
>         at
> com.mysql.jdbc.ServerPreparedStatement.executeInternal
(ServerPreparedStatement.java:684)
>         at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1184)
>         at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1101)
>         at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1086)
>         at
> com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate
(PreparedStatementWrapper.java:840)
>         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(HttpJspBase.java:97)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at
> org.apache.jasper.servlet.JspServletWrapper.service
(JspServletWrapper.java:322)
>         at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:252)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:173)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:213)
>         at
> org.apache.catalina.core.StandardContextValve.invoke
(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.invoke
(StandardEngineValve.java:107)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
>         at
> 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConne
ction(Http11BaseProtocol.java:663)
>         at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket
(PoolTcpEndpoint.java:527)
>         at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt
(LeaderFollowerWorkerThread.java:80)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
(ThreadPool.java:684)
>         at java.lang.Thread.run(Thread.java:595)
> <<< rolling back the transaction >>>
> rollback ok.
> rollback end
> 
> 
> 
> 
> Wang Jun
> 
> 
> 		
> ___________________________________________________________
>  
> ÇéÈ˽ڣ¬ÓÃÑÅ»¢ÓÊÏäËÍõ¹å£¡ 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: kandula-dev-help@ws.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Mime
View raw message