Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0b0b1d

Browse files
committed
Tighten TAP tests' tracking of postmaster state some more.
Commits6c4a890 et al. had a couple of deficiencies:* The logic I added to Cluster::start to see if a PID file is presentcould be fooled by a stale PID file left over from a previouspostmaster. To fix, if we're not sure whether we expect to find arunning postmaster or not, validate the PID using "kill 0".* 017_shm.pl has a loop in which it just issues repeated Cluster::startcalls; this will fail if some invocation fails but leaves self->_pidset. Per buildfarm results, the above fix is not enough to make thissafe: we might have "validated" a PID for a postmaster that exitsimmediately after we look. Hence, match each failed start call witha stop call that will get us back to the self->_pid == undef state.Add a fail_ok option to Cluster::stop to make this work.Discussion:https://postgr.es/m/CA+hUKGKV6fOHvfiPt8=dOKzvswjAyLoFoJF1iQXMNpi7+hD1JQ@mail.gmail.com
1 parent22d8c25 commitf0b0b1d

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,20 +826,37 @@ Note: if the node is already known stopped, this does nothing.
826826
However, if we think it's running and it's not, it's important for
827827
this to fail. Otherwise, tests might fail to detect server crashes.
828828
829+
With optional extra param fail_ok => 1, returns 0 for failure
830+
instead of bailing out.
831+
829832
=cut
830833

831834
substop
832835
{
833-
my ($self,$mode) =@_;
834-
my$port =$self->port;
836+
my ($self,$mode,%params) =@_;
835837
my$pgdata =$self->data_dir;
836838
my$name =$self->name;
839+
my$ret;
837840
$mode ='fast'unlessdefined$mode;
838-
returnunlessdefined$self->{_pid};
841+
return 1unlessdefined$self->{_pid};
842+
839843
print"### Stopping node\"$name\" using mode$mode\n";
840-
TestLib::system_or_bail('pg_ctl','-D',$pgdata,'-m',$mode,'stop');
844+
$ret = TestLib::system_log('pg_ctl','-D',$pgdata,
845+
'-m',$mode,'stop');
846+
847+
if ($ret != 0)
848+
{
849+
print"# pg_ctl stop failed:$ret\n";
850+
851+
# Check to see if we still have a postmaster or not.
852+
$self->_update_pid(-1);
853+
854+
BAIL_OUT("pg_ctl stop failed")unless$params{fail_ok};
855+
return 0;
856+
}
857+
841858
$self->_update_pid(0);
842-
return;
859+
return 1;
843860
}
844861

845862
=pod
@@ -1038,9 +1055,20 @@ sub _update_pid
10381055
if (openmy$pidfile,'<',$self->data_dir ."/postmaster.pid")
10391056
{
10401057
chomp($self->{_pid} = <$pidfile>);
1041-
print"# Postmaster PID for node\"$name\" is$self->{_pid}\n";
10421058
close$pidfile;
10431059

1060+
# If we aren't sure what to expect, validate the PID using kill().
1061+
# This protects against stale PID files left by crashed postmasters.
1062+
if ($is_running == -1 &&kill(0,$self->{_pid}) == 0)
1063+
{
1064+
print
1065+
"# Stale postmaster.pid file for node\"$name\": PID$self->{_pid} no longer exists\n";
1066+
$self->{_pid} =undef;
1067+
return;
1068+
}
1069+
1070+
print"# Postmaster PID for node\"$name\" is$self->{_pid}\n";
1071+
10441072
# If we found a pidfile when there shouldn't be one, complain.
10451073
BAIL_OUT("postmaster.pid unexpectedly present")if$is_running == 0;
10461074
return;

‎src/test/recovery/t/017_shm.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ sub poll_start
196196
# Wait 0.1 second before retrying.
197197
usleep(100_000);
198198

199+
# Clean up in case the start attempt just timed out or some such.
200+
$node->stop('fast',fail_ok=> 1);
201+
199202
$attempts++;
200203
}
201204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp