Commit 9f777871 authored by Leigh Stoller's avatar Leigh Stoller

Minor change to locking. When locking an experiment (object), add

option to also unlock tables at the same time, but before the callout
to the event system. This should hopefully reduce the incidence of
complete system lockup cause a process is holding the experiments
table locked while the event system is wedged up.
parent 8ea72401
......@@ -1248,9 +1248,9 @@ sub Unlock($;$)
return 0;
}
sub Lock(;$)
sub Lock(;$$)
{
my ($self, $newstate) = @_;
my ($self, $newstate, $unlocktables) = @_;
# Must be a real reference.
return -1
......@@ -1260,14 +1260,27 @@ sub Lock(;$)
my $eid = $self->eid();
my $sclause = (defined($newstate) ? ",state='$newstate' " : "");
# flag to indicate tables should be unlocked.
$unlocktables = 0
if (!defined($unlocktables));
my $query_result =
DBQueryWarn("update experiments set expt_locked=now() $sclause ".
"where eid='$eid' and pid='$pid'");
if (! $query_result ||
$query_result->numrows == 0) {
$self->UnLockTables()
if ($unlocktables);
return -1;
}
#
# We do this before calling out to the event system to avoid livelock
# in case the event system goes down.
#
$self->UnLockTables()
if ($unlocktables);
if (defined($newstate)) {
$self->{'EXPT'}->{'state'} = $newstate;
......
......@@ -2373,14 +2373,10 @@ sub MarkPhysNodeDown($)
return -1;
}
DBQueryFatal("lock tables reserved write");
DBQueryFatal("update reserved set " .
" exptidx=$exptidx, pid='$pid',eid='$eid',rsrv_time=now() ".
"where node_id='$pnode'");
DBQueryFatal("unlock tables");
TBSetNodeHistory($pnode, TB_NODEHISTORY_OP_MOVE, $UID, $pid, $eid);
}
......
......@@ -182,7 +182,7 @@ if ($waitmode) {
# terminating consists of a couple of different experiment states down inside
# the tb scripts.
#
$experiment->LockTables("experiments write") == 0
$experiment->LockTables() == 0
or die("*** $0:\n".
" Could not lock experiment tables for $pid/$eid!\n");
......@@ -335,8 +335,8 @@ else {
die("*** $0:\n".
" Experiment $pid/$eid appears to be in the wrong state: $estate\n");
}
$experiment->Lock($nextstate);
$experiment->UnLockTables();
# Unlock tables at same time.
$experiment->Lock($nextstate, 1);
#
# XXX - At this point a failure is going to leave things in an
......
......@@ -162,11 +162,10 @@ else {
}
#
# Change experiment state and lock it.
# Change experiment state and lock it. Unlock tables at same time.
#
$experiment->Lock(($reset ? EXPTSTATE_ACTIVE : EXPTSTATE_PANICED)) == 0
$experiment->Lock(($reset ? EXPTSTATE_ACTIVE : EXPTSTATE_PANICED), 1) == 0
or fatal("Could not lock $experiment");
$experiment->UnLockTables();
#
# XXX - At this point a failure is going to leave things in an
......
......@@ -379,7 +379,7 @@ $robotexp =
# terminating consists of a couple of different experiment states down inside
# the tb scripts.
#
$experiment->LockTables("experiments write") == 0
$experiment->LockTables() == 0
or die("*** $0:\n".
" Could not lock experiment tables for $pid/$eid!\n");
......@@ -715,8 +715,9 @@ if ($inout ne "out") {
#
$termswapstate = $estate;
# Lock the record, set the nextstate, and unlock the table.
$experiment->Lock($nextswapstate) == 0
# Lock the record, set the nextstate, and unlock the table. Unlock
# tables at same time.
$experiment->Lock($nextswapstate, 1) == 0
or tbdie({type => 'secondary', severity => SEV_SECONDARY,
error => ['set_experiment_state_failed', $nextswapstate]},
"Failed to set experiment state to $nextswapstate");
......@@ -727,8 +728,6 @@ $experiment->Lock($nextswapstate) == 0
#
$justexit = 0;
$experiment->UnLockTables();
# Need the previous swapper for rollback below. Safe now that tables unlocked.
my $last_swapper = User->Lookup($experiment->swapper_idx());
if (! defined($last_swapper)) {
......
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