connection pooling: retrieve lost DB connection

做~自己de王妃 提交于 2019-12-25 05:12:04

问题


I am implementing 2-phase commit for a distributed transaction(using 2 Databases). I simulate a DB server connection loss by pulling the network cable to my desk Computer and then plugging it back. However, this causes the transaction to fail in executing a "rollback" as the DB connection object is lost. Is there a way that i can retrieve the lost DB connection object or enforce the application to try reconnect to the same connection after a certain timeperiod. I am using DB2 and Websphere 6.1 as the app server. DB connection is thru a jndi lookup. Using Atomikos as the Transaction Manager.

In general, how does an application implementing 2-phase commit recover(rollback) in the scenario of a DB crash? Is the recovery the application's responsibility or should the Transaction Manager do that?


回答1:


I don't think that your problem has anything to do with recovery because it likely occurs before the 2 phase transaction is prepared.

If you simulate a failure by unplugging the network cable, then the app server will quickly notice that the connection is broken, namely when the application attempts to execute another database operation. However, on the DB2 side, the connection simply looks idle, and it may take a long time for DB2 or the host system where DB2 runs to notice that the connection is broken. The rollback will only occur once the connection has been identified as broken. In the meantime you may have issues because of the locks held by the connection.

If you want to reduce the time it takes before DB2 initiates rollback on the connection, then you may want to tune the TCP keep-alive setting on the server.




回答2:


I don't have any idea of Atomikos.

In general, the Transaction Manager is responsible for the recovery. Usually the application server in this case WAS acts as the transaction manager and is responsible for performing this activity.

Once the DB connection is lost, a StaleConnectionException would be received and the WAS runtime would purge this connection or all the DB connection in the connection pool for that database (depending on what you have configured).

A new connection is available to the application upon the next request from ds.getConnection.

The application does not need to perform any recovery activity (as far as the database is concerned).

HTH

Manglu



来源:https://stackoverflow.com/questions/9812327/connection-pooling-retrieve-lost-db-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!