Skip to content

Commit 71cf250

Browse files
committed
Add stop-signal handling to arbiter.
1 parent 6231700 commit 71cf250

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

contrib/mmts/arbiter.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ MtmResolveHostByName(const char *hostname, unsigned* addrs, unsigned* n_addrs)
164164
return 1;
165165
}
166166

167+
static int stop = 0;
168+
static void SetStop(int sig)
169+
{
170+
stop = 1;
171+
}
172+
167173
#if USE_EPOLL
168174
static int epollfd;
169175
#else
@@ -530,17 +536,24 @@ static void MtmBroadcastMessage(MtmBuffer* txBuffer, MtmTransState* ts)
530536

531537
static void MtmTransSender(Datum arg)
532538
{
539+
sigset_t sset;
533540
int nNodes = MtmNodes;
534541
int i;
535542
MtmBuffer* txBuffer = (MtmBuffer*)palloc(sizeof(MtmBuffer)*nNodes);
536-
543+
544+
signal(SIGINT, SetStop);
545+
signal(SIGQUIT, SetStop);
546+
signal(SIGTERM, SetStop);
547+
sigfillset(&sset);
548+
sigprocmask(SIG_UNBLOCK, &sset, NULL);
549+
537550
MtmOpenConnections();
538551

539552
for (i = 0; i < nNodes; i++) {
540553
txBuffer[i].used = 0;
541554
}
542555

543-
while (true) {
556+
while (!stop) {
544557
MtmTransState* ts;
545558
PGSemaphoreLock(&Mtm->votingSemaphore);
546559
CHECK_FOR_INTERRUPTS();
@@ -605,6 +618,7 @@ static bool MtmRecovery()
605618

606619
static void MtmTransReceiver(Datum arg)
607620
{
621+
sigset_t sset;
608622
int nNodes = MtmNodes;
609623
int nResponses;
610624
int i, j, n, rc;
@@ -617,14 +631,20 @@ static void MtmTransReceiver(Datum arg)
617631
FD_ZERO(&inset);
618632
max_fd = 0;
619633
#endif
634+
635+
signal(SIGINT, SetStop);
636+
signal(SIGQUIT, SetStop);
637+
signal(SIGTERM, SetStop);
638+
sigfillset(&sset);
639+
sigprocmask(SIG_UNBLOCK, &sset, NULL);
620640

621641
MtmAcceptIncomingConnections();
622642

623643
for (i = 0; i < nNodes; i++) {
624644
rxBuffer[i].used = 0;
625645
}
626646

627-
while (true) {
647+
while (!stop) {
628648
#if USE_EPOLL
629649
n = epoll_wait(epollfd, events, nNodes, MtmKeepaliveTimeout/1000);
630650
if (n < 0) {

contrib/mmts/t/000_deadlock.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sub allocate_ports
5656
return @allocated_now;
5757
}
5858

59-
my $nnodes = 3;
59+
my $nnodes = 2;
6060
my @nodes = ();
6161

6262
# Create nodes and allocate ports

contrib/mmts/t/001_basic_recovery.pl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,27 @@ sub PostgresNode::inet_connstr {
9696

9797
$nodes[2]->teardown_node;
9898

99+
diag("sleeping");
100+
sleep(15);
101+
102+
diag("inserting 2");
99103
$nodes[0]->psql('postgres', "insert into t values(2, 20);");
104+
diag("selecting");
100105
$nodes[1]->psql('postgres', "select v from t where k=2;", stdout => \$psql_out);
106+
diag("selected");
101107
is($psql_out, '20', "Check replication after node failure.");
102108

103109
###############################################################################
104110
# Work after node start
105111
###############################################################################
106112

107113
$nodes[2]->start;
108-
sleep(5); # XXX: here we can poll
114+
sleep(15); # XXX: here we can poll
115+
diag("inserting 3");
109116
$nodes[0]->psql('postgres', "insert into t values(3, 30);");
117+
diag("selecting");
110118
$nodes[2]->psql('postgres', "select v from t where k=3;", stdout => \$psql_out);
119+
diag("selected");
111120
is($psql_out, '30', "Check replication after failed node recovery.");
112121

113122

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy