Commit 1e402fa3 authored by Leo Gordon's avatar Leo Gordon
Browse files

interface_change: protected_prepare_execute() takes all sql-related parameters as first argument

parent 884da57e
......@@ -248,7 +248,7 @@ sub decrease_semaphore_count_for_jobid { # used in semaphore annihilation or
WHERE job_id=? AND status='SEMAPHORED'
};
$self->dbc->protected_prepare_execute( $sql, $dec, $jobid );
$self->dbc->protected_prepare_execute( [ $sql, $dec, $jobid ] );
}
sub increase_semaphore_count_for_jobid { # used in semaphore propagation
......@@ -262,7 +262,7 @@ sub increase_semaphore_count_for_jobid { # used in semaphore propagation
WHERE job_id=?
};
$self->dbc->protected_prepare_execute( $sql, $inc, $jobid );
$self->dbc->protected_prepare_execute( [ $sql, $inc, $jobid ] );
}
......@@ -294,7 +294,7 @@ sub check_in_job {
$sql .= " WHERE job_id='".$job->dbID."' ";
# This particular query is infamous for collisions and 'deadlock' situations; let's wait and retry:
$self->dbc->protected_prepare_execute( $sql );
$self->dbc->protected_prepare_execute( [ $sql ] );
}
......@@ -416,9 +416,9 @@ sub grab_jobs_for_role {
};
# we have to be explicitly numeric here because of '0E0' value returned by DBI if "no rows have been affected":
if( (my $claim_count = $self->dbc->protected_prepare_execute( $prefix_sql . $virgin_sql . $limit_sql . $offset_sql . $suffix_sql)) == 0 ) {
if( ($claim_count = $self->dbc->protected_prepare_execute( $prefix_sql . $limit_sql . $offset_sql . $suffix_sql)) == 0 ) {
$claim_count = $self->dbc->protected_prepare_execute( $prefix_sql . $limit_sql . $suffix_sql);
if( (my $claim_count = $self->dbc->protected_prepare_execute( [ $prefix_sql . $virgin_sql . $limit_sql . $offset_sql . $suffix_sql ] )) == 0 ) {
if( ($claim_count = $self->dbc->protected_prepare_execute( [ $prefix_sql . $limit_sql . $offset_sql . $suffix_sql ] )) == 0 ) {
$claim_count = $self->dbc->protected_prepare_execute( [ $prefix_sql . $limit_sql . $suffix_sql ] );
}
}
......
......@@ -115,7 +115,9 @@ sub url {
sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" by trying again (a useful workaround even in mysql 5.1.61)
my $self = shift @_;
my $sql = shift @_;
my $sql_params = shift @_;
my $sql_cmd = shift @$sql_params;
my $attempts = 4;
my $sleep_max_sec = 1;
......@@ -125,8 +127,8 @@ sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" b
foreach my $attempt (1..$attempts) {
eval {
my $sth = $self->prepare($sql);
$retval = $sth->execute( @_ );
my $sth = $self->prepare( $sql_cmd );
$retval = $sth->execute( @$sql_params );
$sth->finish;
1;
} or do {
......@@ -142,7 +144,7 @@ sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" b
}
my $this_sleep_sec = rand( $sleep_max_sec );
$log_message_adaptor->store_hive_message( "Caught a DEADLOCK when trying to execute '$sql' (attempt #$attempt), retrying in $this_sleep_sec sec", 0 );
$log_message_adaptor->store_hive_message( "Caught a DEADLOCK when trying to execute '$sql_cmd' (attempt #$attempt), retrying in $this_sleep_sec sec", 0 );
usleep( $this_sleep_sec*1000000 );
$sleep_max_sec *= 2;
......@@ -152,7 +154,7 @@ sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" b
};
last;
}
die "After $attempts attempts the query '$sql' is still in a deadlock: $@" if($@);
die "After $attempts attempts the query '$sql_cmd' is still in a deadlock: $@" if($@);
return $retval;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment