On Sep 23, 2005, at 3:19 PM, Tim Bunce wrote:

I'm interested to hear stories of people who have subclassed the DBI,
or used modules that subclass the DBI.

Was subclassing the DBI a good approach?

Where there any problems?

Could it have been done well/better some other way?

Thanks!

Tim.



I subclassed DBI for DBIx::HA, a high-availability module.
I subclassed connect(), prepare() and execute().

The new connect() takes as input a stack of DSNs with its associated meta info (timeouts, type of failover, etc...) and determines which DSN to connect to based on availability and inter-process communication.

The prepare() and execute() are subclassed to trap errors and kick back to reconnect, then reprepare and reexecute into another DSN.

Who is using it:
We're internally using it very heavily. I know of one other external person/group using the module.

What went well:
It solved many problems, one of which was to be able to use Sybase OpenSwitch (a load balancer/failover proxy for Sybase ASE) with DBI. Other problems solved were the ability to automatically failover in case of hard database failure, and an easy failback mechanism that doesn't necessitate an Apache restart under mod_perl. Subclassing the DBI looked like an easy approach at first, and I was able to get most needed functionality quickly and easily.

Problems:
There were many painful issues to deal with: signal handling, trapping of errors, making sure the database behaves properly, remembering the state of the query, etc... At this point I can't guarantee even that I've nailed all possible race conditions. It's extremely difficult to debug all the use cases.

Could it have been done a better way?
Absolutely. I think that this whole high availability layer should be at the driver level as a proxy driver, ultimately part of DBD::Multiplex. In fact DBIx::HA couldn't have worked at all without the added functionality in DBI of swap_inner_handle(), but even with that I ran into a wall where I didn't have enough control over the row-level info that a proper DBD driver would have.

Reply via email to