Using postgresql connection in distributed environment
Using postgresql connection in distributed environment
От:
"Zoltan Fulop" <zfulop@csi.ca>
Дата:
Hello, I am using openorb, openorb transaction service, openorb implementation of JTA, and the XA classes provided by postgresql to execute distributed transactions. When i use only one resource, the transaction commits properly (since the prepare() method does not get invoked), but when i use more then one resources in a global transaction, it seems that the prepare() call of the org.postgresql.xa.XAConnectionImpl throws an XAException indicating that it was invoked in an improper context (XAException.XAER_PROTO), which is caused by having the TxConnection.count > 0 condition. Here is a breief discription on the sequence of calls: processA: Create transaction (getting CosTransactions::Control) cache it with some id. processB: (different control of thread than processA created Control in) get Control from processA for a specific ID. resume CosTransactions::Current with that control. Get XAConnection from org.postgressql.PostgresqlDataSource register XAResource (from XAConnection) with JTA (the JTA implementation uses CosTransaction::Current to talk to the distributed transaction) exercute some sql command using the connetion aquired from XAConnection processC: do the same as processB processA: (after receiving notification from processB and processC about the completion of the task) get the CosTransaction::Control for the id. call commit. When i call commit, it calls prepare() on the registered XAResources, but since the TxConnection.count is 1 it throws the exception (described above) However if i change the code (org.postgresql.xa.XAConnectionImpl.java: around line 670) that the comparison is "txConn.count > 1" (instead of "txConn.count > 0") the transaction commits properly... Any help is greatly apprechiated, Thank you, Zoltan Fulop
Re: Using postgresql connection in distributed environment
От:
Kovács Péter <peter.kovacs@sysdata.siemens.hu>
Дата:
You cannot use PostgreSQL in a truely global transaction. PostgreSQL does not support distributed transactions in general and it does not support 2pc in particular. The XA interface is only a fake 2pc interface. You can use it safely only for transactions, in which one single DataSource is involved. Last time I checked, this fake 2pc interface did not correctly work even for single DataSource transactions without some small modification. I think that my modification was something similar to what you mention in your mail, but I do not remember any more. If you're interested I can dig out what modification I needed back then to get it work properly. Peter > -----Original Message----- > From: Zoltan Fulop [mailto:zfulop@csi.ca] > Sent: Friday, April 12, 2002 10:13 PM > To: pgsql-jdbc@postgresql.org > Subject: [JDBC] Using postgresql connection in distributed environment > > > Hello, > > I am using openorb, openorb transaction service, openorb > implementation of JTA, and the XA classes provided by > postgresql to execute distributed transactions. > When i use only one resource, the transaction commits > properly (since the prepare() method does not get invoked), > but when i use more then one resources in a global > transaction, it seems that the prepare() call of the > org.postgresql.xa.XAConnectionImpl throws an XAException > indicating that it was invoked in an improper context > (XAException.XAER_PROTO), which is caused by having the > TxConnection.count > 0 condition. Here is a breief > discription on the sequence of calls: > > processA: > Create transaction (getting CosTransactions::Control) > cache it with some id. > > processB: (different control of thread than processA created > Control in) > get Control from processA for a specific ID. > resume CosTransactions::Current with that control. > Get XAConnection from org.postgressql.PostgresqlDataSource > register XAResource (from XAConnection) with JTA (the JTA > implementation uses CosTransaction::Current to talk to the > distributed transaction) > exercute some sql command using the connetion aquired from > XAConnection > > processC: > do the same as processB > > processA: (after receiving notification from processB and > processC about the completion of the task) > get the CosTransaction::Control for the id. > call commit. > > When i call commit, it calls prepare() on the registered > XAResources, but since the TxConnection.count is 1 it throws > the exception (described above) > However if i change the code > (org.postgresql.xa.XAConnectionImpl.java: around line 670) > that the comparison is "txConn.count > 1" (instead of > "txConn.count > 0") the transaction commits properly... > > > Any help is greatly apprechiated, > Thank you, > Zoltan Fulop > > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) >