DBD::Sybase 1.05_1 and Perl threads
- From: alattke@xxxxxxxxx
- Date: 20 Oct 2005 13:50:27 -0700
Hi,
I am using Perl 5.8.5 on Linux RedHat Enterprise, DBD::Sybase 1.05_1,
OpenClient 12.5.1, connecting to Sybase IQ 12.6.
In my Perl script, I spawn several threads, each making a single
connection to a separate database.
>>From time to time, I experience the following error:
thread failed to start: install_driver(Sybase) failed: DBD::Sybase
initialize: ct_callback(clientmsg) failed at
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/DynaLoader.pm line 249.
Compilation failed in require at (eval 14) line 3.
This will kill the current thread, and if I start another one, it will
be fine. Also, this tends to be on the first thread launched (about 80%
of the time). However, I am having trouble diagnosing the root cause of
this problem.
============== start snippet of code =================
use DBI;
use threads;
sub main
{
....
## Trigger a thread to execute SQL for each DB.
foreach $db_id (@db_ids)
{
$threads->{$db_id} =
threads->create(\&run_multiple_sql, $db_id, $sql);
} ## End of thread setup
## Now that we are done with the threads, make sure
## they're all done before moving on to next query
foreach $db_id (keys %{$threads})
{
## get results from the thread
eval{ $ok = $threads->{$db_id}->join() };
## Verify that return status was ok.
if ( ( $@ ) || ( !$ok ) )
{
## Log error and send email notification
&ln( "[error] Thread for $db_id when sql = '$sql': $@"
);
}
else
{
$processed_ds_counter++;
}
}
....
} ## end of main
##################################################################
## run_multiple_sql:
## Takes in a db_id and an sql query that has multiple
## statements (like a stored proc).
## All interactions are logged to the log file for this pid.
## Returns if there were no errors. Otherwise, dies. (this
## function should be executed as a thread so only that thread
## is affected).
##################################################################
sub run_multiple_sql
{
my ($db_id, $sql) = @_;
my ($dbh, $query, $results, $row) = ();
## 1. Open DB connection
$dbh =
DBI->connect("dbi:Sybase:server=".$::DB_GLOBAL_CONFIG{$db_id}{db_name}
.";timeout=".$::DB_TIMEOUT,
$::DB_GLOBAL_CONFIG{$db_id}{username},
$::DB_GLOBAL_CONFIG{$db_id}{password},
{PrintError => 1,RaiseError => 0, AutoCommit => 1 })
|| die("Cannot connect to datasource: $DBI::errstr");
$dbh->{syb_show_sql} = 1;
# $dbh->trace(3, "/tmp/dbi_trace.log");
## 2. Prepare and execute SQL
($query = $dbh->prepare($sql))
|| ($dbh->disconnect() && die("($db_id) Cannot prepare query:
$DBI::errstr\n$sql"));
($query->execute())
|| ($dbh->disconnect() && die("($db_id) Cannot execute query:
$DBI::errstr\n$sql"));
## 3. Get results
## syb_result_type indicates:
## 4040 CS_ROW_RESULT data incomplete, only 1 row
## 4043 CS_STATUS_RESULT successful exec of a storeddproc
## 4046 (no name) successful SQL select
## In other words, loop until we get the 4046 or 4043 code
while (! ($query->{syb_result_type} == 4046)
|| ($query->{syb_result_type} == 4043))
{
$results = $query->fetch();
## If error thrown by the database
if ($DBI::err)
{
$dbh->disconnect();
## Log, send email, and die
&lnd("($db_id) Cannot get results: $DBI::errstr\n$sql");
};
## If something was returned, let's see what it is
if ($results)
{
$row = join(" ", @{$results});
print ($query->{syb_result_type}, ": $row\n") if
($::DEBUG);
&log_to_file("($db_id) $row") if ($row);
## If line printed was an error: log, notify, die.
if ($row =~ /error/i) {
$dbh->disconnect();
&lnd("[error]: ($db_id) could not execute $sql.
$DBI::errstr\n\t$row");
}
## If line printed was a warning: log, notify.
if ($row =~ /(warning|\!\!\!)/i) {
&ln("[warning]: ($db_id) warning generated while
executing $sql.\n\t$row");
}
}
}
if ($DBI::err)
{
$dbh->disconnect();
die("($db_id) Cannot get results: $DBI::errstr\n$sql");
}
## 4. Finish query and disconnect from DB
$query->finish;
$dbh->disconnect();
## 5. Return results
return (1);
}
============== end snippet of code =================
Not sure if this is related. Not sure if this is a known problem in
DBD::Syabase. Not sure if it's been addressed in DBD::Sybase 1.06 or
1.07 (the Changes document has no reference to this).
Also, in the Sybase IQ log I don't see an attempt to connect (or any
activity at all) at the time the thread failed.
Please let me know what other information would be useful.
Thank you for your help,
-A Lattke
.
- Prev by Date: RE: Serializing Storable.pm objects via DBI to Oracle 10g
- Next by Date: MS Access, scripts clashing
- Previous by thread: Is it a bug in DBD::SQLite?
- Next by thread: MS Access, scripts clashing
- Index(es):
Relevant Pages
|
|