Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hey, all.

The setup: I'm working on some code that involves forking in a process with potentially several open DBI database handles (dbhs) to Oracle database handles. Oracle dbhs will encounter problems when the child processes terminate unless they have the InactiveDestroy attribute set on them in the child processes. Otherwise, essentially, when the child process terminates, during its global destruction phase, every dbh reports back to its respective database that the connection has terminated, which means that Oracle will not accept any further activity on that connection (from other processes). Even if that connection was never used in the child process, the mere act of the child process coming into existence and then exiting will foul the parent process's database handle... unless of course this InactiveDestroy attribute is set. The whole purpose of the InactiveDestroy attribute is, basically, to make the DESTROY on the dbh "inactive", i.e. it doesn't send a message to Oracle to the effect of "I'm dead, ignore any future communications from me".

So, anyway, because I may be performing a fork deep down inside of a function call, I may not be able to easily pull a list of all the dbhs that are hanging around in the process, waiting to get passively disrupted by the fork. At least, I hadn't been able to do so in the past. However, DBI has somewhat recently (I don't know when exactly) introduced an attribute called ChildHandles which returns an array of weak-referrences to all the child handles of a given handle object. This allows me to something like this:

sub MakeAllDBHsForkSafe { my %drivers = DBI->installed_drivers; foreach my $drh (values %drivers) { map { $_->{InactiveDestroy} = 1 } @{$_->{ChildHandles}}; } }
Which, if called as the first thing in the child process, will prevent the child's global destruction from fouling all of the dbhs in the parent. This seems like a complete answer to my problems.

The real question though, is if this is a safe action to take. The DBI docs on the ChildHandles attributes state explicitly that "The referenced array returned should be treated as read-only." I'm a little concerned (perhaps overly concerned) over the specific semantics of this. Does it mean that the array, itself should not be altered (like adding or removing elements to the array), or does it mean that the array contents should not be altered? Is anybody here familiar enough with the DBI internals to know? Am I just being paranoid for even asking? :-)

I have tested this, and it seems to work fine, but I don't know if there are any gremlins hiding in their that will bite me over this. It seemed like a good idea to at least ask.

Thanks in advance.

------------ :Wq Not an editor command: Wq

In reply to Fork-safe DBI handles via ChildHandles and InactiveDestroy by etcshadow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found