Commit 4bfe8a78 authored by Leo Gordon's avatar Leo Gordon
Browse files

bugfix: two instances of REPLACE INTO substituted by DELETE+INSERT

parents 5e3d2cd2 07a02deb
......@@ -320,14 +320,16 @@ sub check_in_job {
sub store_out_files {
my ($self, $job) = @_;
# FIXME: An UPSERT would be better here, but it is only promised in PostgreSQL starting from 9.5, which is not officially out yet.
my $delete_sql = 'DELETE from job_file WHERE role_id=' . $job->role_id . ' AND job_id=' . $job->dbID . ' AND retry='.$job->retry_count;
$self->dbc->do( $delete_sql );
if($job->stdout_file or $job->stderr_file) {
my $insert_sql = 'REPLACE INTO job_file (job_id, retry, role_id, stdout_file, stderr_file) VALUES (?,?,?,?,?)';
my $sth = $self->dbc()->prepare($insert_sql);
$sth->execute($job->dbID(), $job->retry_count(), $job->role_id(), $job->stdout_file(), $job->stderr_file());
$sth->finish();
} else {
my $sql = 'DELETE from job_file WHERE role_id='.$job->role_id.' AND job_id='.$job->dbID;
$self->dbc->do($sql);
my $insert_sql = 'INSERT INTO job_file (job_id, retry, role_id, stdout_file, stderr_file) VALUES (?,?,?,?,?)';
my $insert_sth = $self->dbc->prepare($insert_sql);
$insert_sth->execute( $job->dbID, $job->retry_count, $job->role_id, $job->stdout_file, $job->stderr_file );
$insert_sth->finish();
}
}
......
......@@ -719,21 +719,28 @@ sub interval_workers_with_unknown_usage {
sub store_resource_usage {
my ($self, $report_entries, $processid_2_workerid) = @_;
my $sql_replace = 'REPLACE INTO worker_resource_usage (worker_id, exit_status, mem_megs, swap_megs, pending_sec, cpu_sec, lifespan_sec, exception_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
my $sth_replace = $self->prepare( $sql_replace );
# FIXME: An UPSERT would be better here, but it is only promised in PostgreSQL starting from 9.5, which is not officially out yet.
my $sql_delete = 'DELETE FROM worker_resource_usage WHERE worker_id=?';
my $sth_delete = $self->prepare( $sql_delete );
my $sql_insert = 'INSERT INTO worker_resource_usage (worker_id, exit_status, mem_megs, swap_megs, pending_sec, cpu_sec, lifespan_sec, exception_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
my $sth_insert = $self->prepare( $sql_insert );
my @not_ours = ();
while( my ($process_id, $report_entry) = each %$report_entries ) {
if( my $worker_id = $processid_2_workerid->{$process_id} ) {
$sth_replace->execute( $worker_id, @$report_entry{'exit_status', 'mem_megs', 'swap_megs', 'pending_sec', 'cpu_sec', 'lifespan_sec', 'exception_status'} ); # slicing hashref
$sth_delete->execute( $worker_id );
$sth_insert->execute( $worker_id, @$report_entry{'exit_status', 'mem_megs', 'swap_megs', 'pending_sec', 'cpu_sec', 'lifespan_sec', 'exception_status'} ); # slicing hashref
} else {
push @not_ours, $process_id;
#warn "\tDiscarding process_id=$process_id as probably not ours because it could not be mapped to a Worker\n";
}
}
$sth_replace->finish();
$sth_delete->finish();
$sth_insert->finish();
}
......
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