aboutsummaryrefslogtreecommitdiffstats
path: root/databases/pgcluster
diff options
context:
space:
mode:
authorkuriyama <kuriyama@FreeBSD.org>2004-02-25 21:47:27 +0800
committerkuriyama <kuriyama@FreeBSD.org>2004-02-25 21:47:27 +0800
commit46fea34a8a48b41710ca7e864ef5995d8539a3b1 (patch)
treeeba622cb658f8ba75f0992278e9f925cfdb23806 /databases/pgcluster
parent9c577ab816c354af0b398b63d54782d52d84ea01 (diff)
downloadfreebsd-ports-gnome-46fea34a8a48b41710ca7e864ef5995d8539a3b1.tar.gz
freebsd-ports-gnome-46fea34a8a48b41710ca7e864ef5995d8539a3b1.tar.zst
freebsd-ports-gnome-46fea34a8a48b41710ca7e864ef5995d8539a3b1.zip
o Fix some bugs reported on ML.
o Fix more style bugs in debug message. o Add internal function to postmaster which returns current replication server. o Add new packet handler to pgreplicate which returns cluster node status information. o Add check scripts for nagios. These scripts may be useful, but not intended to officially supported by me. I'll make them as another port when they become stable.
Diffstat (limited to 'databases/pgcluster')
-rw-r--r--databases/pgcluster/Makefile2
-rw-r--r--databases/pgcluster/files/check_pgcluster.pl66
-rw-r--r--databases/pgcluster/files/check_pgreplicate.pl84
-rw-r--r--databases/pgcluster/files/patch-libpq:recovery.c23
-rw-r--r--databases/pgcluster/files/patch-libpq:replicate.c69
-rw-r--r--databases/pgcluster/files/patch-main.c220
-rw-r--r--databases/pgcluster/files/patch-pg_proc.h12
-rw-r--r--databases/pgcluster/files/patch-postmaster.c19
-rw-r--r--databases/pgcluster/files/patch-recovery.c47
-rw-r--r--databases/pgcluster/files/patch-replicate.c160
10 files changed, 666 insertions, 36 deletions
diff --git a/databases/pgcluster/Makefile b/databases/pgcluster/Makefile
index fc4f985fb55f..010959628f25 100644
--- a/databases/pgcluster/Makefile
+++ b/databases/pgcluster/Makefile
@@ -6,7 +6,7 @@
PORTNAME= pgcluster
PORTVERSION= 1.0.6b
-PORTREVISION= 2
+PORTREVISION= 3
CATEGORIES= databases
MASTER_SITES= ${MASTER_SITE_PGSQL}
MASTER_SITE_SUBDIR= v${BASEPGSQL}
diff --git a/databases/pgcluster/files/check_pgcluster.pl b/databases/pgcluster/files/check_pgcluster.pl
new file mode 100644
index 000000000000..ac585852cf67
--- /dev/null
+++ b/databases/pgcluster/files/check_pgcluster.pl
@@ -0,0 +1,66 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2004 IMG SRC, Inc. All rights reserved.
+#
+# $Id: check_pgcluster.pl,v 1.2 2004/02/25 06:09:25 kuriyama Exp $
+#
+# Plugin for nagios.
+#
+# Prepare pgr_current_replicator() function before using.
+#
+# % psql -U pgsql -d template1
+# template1=# create function pgr_current_replicator () returns text as 'pgr_current_replicator' language internal with (isStrict);
+# CREATE FUNCTION
+# template1=#
+#
+# define command{
+# command_name check_pgcluster
+# command_line $USER1$/check_pgcluster -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$
+# }
+#
+# define service{
+# use generic-service
+# host_name cluster1.example.org
+# service_description PGCLUSTER
+# check_command check_pgcluster!5432!replicator.example.org:8777
+# }
+
+use strict;
+use Getopt::Std;
+use DBI;
+
+my %O;
+getopts('H:p:U:P:w:', \%O);
+
+$O{p} ||= 5432;
+$O{U} ||= "";
+$O{P} ||= "";
+usage() if (not $O{H} or not $O{w});
+
+my $dbh = DBI->connect("dbi:Pg:dbname=template1;host=$O{H};port=$O{p}", $O{U}, $O{P});
+
+die if (not $dbh);
+
+my $sth = $dbh->prepare("select pgr_current_replicator()") or die;
+$sth->execute or die;
+my @r = $sth->fetchrow_array;
+$sth->finish;
+
+$dbh->disconnect;
+
+my $ret = 0;
+if ($r[0] ne $O{w}) {
+ $ret = 1;
+ $ret = 2 if (length($r[0]) < 1);
+}
+
+my %STATUS = (2 => "CRITICAL", 1 => "WARNING", 0 => "OK");
+printf "PGCLUSTER %s: %s\n", $STATUS{$ret}, $r[0];
+exit $ret;
+
+# ============================================================
+sub usage {
+ print "Usage: check_pgcluster -H host [-p dbport] [-U dbuser] [-P dbpass] -w <primary replication server:port>\n";
+ exit(3);
+}
+
diff --git a/databases/pgcluster/files/check_pgreplicate.pl b/databases/pgcluster/files/check_pgreplicate.pl
new file mode 100644
index 000000000000..7451c3c27c8d
--- /dev/null
+++ b/databases/pgcluster/files/check_pgreplicate.pl
@@ -0,0 +1,84 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2004 IMG SRC, Inc. All rights reserved.
+#
+# $Id: check_pgreplicate.pl,v 1.1 2004/02/23 06:06:13 kuriyama Exp $
+#
+# Plugin for nagios.
+#
+# define command{
+# command_name check_pgreplicate
+# command_line $USER1$/check_pgreplicate -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$ -c $ARG3$
+# }
+#
+# # Declare cluster which has 2 pgcluster instances.
+# # Send a warning if usable pgcluster is under 2.
+# # Send a critical if usable pgcluster is under 1.
+# define service{
+# use generic-service
+# host_name replicator.example.org
+# service_description PGREPLICATE
+# check_command check_pgreplicate!8777!2!1
+# }
+
+use strict;
+use Getopt::Std;
+use IO::Socket::INET;
+
+my %O;
+getopts('H:p:w:c:v', \%O);
+
+my $w = $O{w};
+my $c = $O{c};
+usage() if (not $w or not $c);
+
+my $host = sprintf("%s:%d", $O{H} || "localhost", $O{p} || 8777);
+my $sock = IO::Socket::INET->new($host) or die "$!";
+
+my $HOSTNAME_MAX_LENGTH = 128;
+my $DBNAME_MAX_LENGTH = 128;
+my $USERNAME_MAX_LENGTH = 128;
+
+my $query = "dummy";
+my $packet = pack "CCCCllla128a128a128a128ll", 0, 0, 0, ord("o"),
+ 0, 0, 5, "except host", "from host", "db name", "user name",
+ time, 0;
+
+print $sock $packet;
+print $sock $query;
+
+my ($use, @Host, %tmp) = (0);
+while (<$sock>) {
+ chomp;
+ if ($_ eq "") {
+ push @Host, { %tmp };
+ $use++ if ($tmp{useFlag} == 2);
+ %tmp = ();
+ } else {
+ my ($var, $val) = split(/=/, $_, 2);
+ $tmp{$var} = $val;
+ }
+}
+close($sock);
+
+my $ret = 0;
+if ($use < $O{c}) {
+ $ret = 2;
+} elsif ($use < $O{w}) {
+ $ret = 1;
+}
+my %STATUS = (2 => "CRITICAL", 1 => "WARNING", 0 => "OK");
+printf "PGREPLICATE %s: %d hosts active\n", $STATUS{$ret}, $use;
+if ($O{v}) {
+ foreach (@Host) {
+ printf "%s:%d, useFlag=%d, recoveryPort=%d\n",
+ $_->{hostName}, $_->{port}, $_->{useFlag}, $_->{recoveryPort};
+ }
+}
+exit $ret;
+
+# ============================================================
+sub usage {
+ print "Usage: check_pgreplicate -H host -p port -w <warn> -c <crit> [-v]\n";
+ exit(3);
+}
diff --git a/databases/pgcluster/files/patch-libpq:recovery.c b/databases/pgcluster/files/patch-libpq:recovery.c
new file mode 100644
index 000000000000..74852c235408
--- /dev/null
+++ b/databases/pgcluster/files/patch-libpq:recovery.c
@@ -0,0 +1,23 @@
+--- src/backend/libpq/recovery.c.orig Fri Feb 20 11:38:39 2004
++++ src/backend/libpq/recovery.c Mon Feb 23 14:44:15 2004
+@@ -756,14 +756,14 @@
+
+ if (Debug_pretty_print)
+ {
+- elog(DEBUG1,"no = %d\n",packet->packet_no);
+- elog(DEBUG1,"max_connect = %d\n",packet->max_connect);
+- elog(DEBUG1,"port = %d\n",packet->port);
+- elog(DEBUG1,"recoveryPort = %d\n",packet->recoveryPort);
++ elog(DEBUG1,"no = %d",packet->packet_no);
++ elog(DEBUG1,"max_connect = %d",packet->max_connect);
++ elog(DEBUG1,"port = %d",packet->port);
++ elog(DEBUG1,"recoveryPort = %d",packet->recoveryPort);
+ if (packet->hostName != NULL)
+- elog(DEBUG1,"hostName = %s\n",packet->hostName);
++ elog(DEBUG1,"hostName = %s",packet->hostName);
+ if (packet->pg_data != NULL)
+- elog(DEBUG1,"pg_data = %s\n",packet->pg_data);
++ elog(DEBUG1,"pg_data = %s",packet->pg_data);
+ }
+ }
+
diff --git a/databases/pgcluster/files/patch-libpq:replicate.c b/databases/pgcluster/files/patch-libpq:replicate.c
new file mode 100644
index 000000000000..1c7d3fea1b43
--- /dev/null
+++ b/databases/pgcluster/files/patch-libpq:replicate.c
@@ -0,0 +1,69 @@
+--- src/backend/libpq/replicate.c.orig.1 Fri Feb 20 11:38:39 2004
++++ src/backend/libpq/replicate.c Wed Feb 25 09:28:07 2004
+@@ -645,6 +645,7 @@
+ return NULL;
+ }
+ sock = get_replicate_server_socket( sp , socket_type);
++ elog(DEBUG1, "get_replicate_server_socket() returns %d", sock);
+ if (sock == -1)
+ {
+ if (Debug_pretty_print)
+@@ -668,7 +669,7 @@
+ while (send_replicate_packet(sock,&header,query_string) != STATUS_OK)
+ {
+ if (Debug_pretty_print)
+- elog(DEBUG1,"replication server: %s may be down",sp->hostName);
++ elog(DEBUG1,"replication server: %s may be down (cnt=%d, sock=%d)", sp->hostName, cnt, sock);
+ close_replicate_server_socket ( sp , socket_type);
+ sp->useFlag = DATA_ERR;
+ sock = search_new_replication_server( sp,socket_type,&header);
+@@ -760,6 +761,11 @@
+ fd_set wmask;
+ struct timeval timeout;
+
++ /* check parameter */
++ if ((sock <= 0) || (header == NULL) || (query_string == NULL))
++ {
++ return STATUS_ERROR;
++ }
+ /*header->query_size +=1;*/
+ header_size = sizeof(ReplicateHeader);
+ buf_size = header_size + header->query_size + 4;
+@@ -776,6 +782,7 @@
+ /*
+ * Wait for something to happen.
+ */
++ elog(DEBUG1, "send_replicate_packet(%d, %p, %s)", sock, header, query_string);
+ FD_ZERO(&wmask);
+ FD_SET(sock,&wmask);
+ rtn = select(sock+1, (fd_set *)NULL, &wmask, (fd_set *)NULL, &timeout);
+@@ -1767,4 +1774,29 @@
+ return false;
+ }
+ }
++
++extern Datum pgr_current_replicator(PG_FUNCTION_ARGS);
++PG_FUNCTION_INFO_V1(pgr_current_replicator);
++
++Datum
++pgr_current_replicator(PG_FUNCTION_ARGS)
++{
++ int len;
++ char buf[HOSTNAME_MAX_LENGTH + 6];
++ text *result;
++ ReplicateServerInfo *sp;
++
++ sp = PGR_get_replicate_server_info();
++ if (sp == NULL) {
++ PG_RETURN_NULL();
++ }
++ len = snprintf(buf, sizeof(buf), "%s:%d",
++ sp->hostName, sp->portNumber);
++ result = palloc(VARHDRSZ + len);
++ VARATT_SIZEP(result) = VARHDRSZ + len;
++ memcpy(VARDATA(result), buf, len);
++
++ PG_RETURN_TEXT_P(result);
++}
++
+ #endif /* USE_REPLICATION */
diff --git a/databases/pgcluster/files/patch-main.c b/databases/pgcluster/files/patch-main.c
index fccd940d85d3..791b8d460168 100644
--- a/databases/pgcluster/files/patch-main.c
+++ b/databases/pgcluster/files/patch-main.c
@@ -1,5 +1,23 @@
---- src/pgcluster/pgrp/main.c.orig Tue Feb 3 23:34:22 2004
-+++ src/pgcluster/pgrp/main.c Tue Feb 3 23:36:10 2004
+--- src/pgcluster/pgrp/main.c.orig Fri Feb 20 11:38:40 2004
++++ src/pgcluster/pgrp/main.c Mon Feb 23 12:45:51 2004
+@@ -148,7 +148,7 @@
+ char * query;
+
+ /* set function name */
+- set_function("read_packet");
++ set_function("main::read_packet");
+
+ if (header == NULL)
+ {
+@@ -171,7 +171,7 @@
+ }
+ if (r == 0)
+ {
+- show_debug("connection closed");
++ show_debug("connection closed (sock=%d, header=%d, read=%d)", sock, header_size, read_size);
+ return NULL;
+ }
+ read_size += r;
@@ -258,18 +258,18 @@
/* set function name */
set_function("replicate_packet_send");
@@ -31,7 +49,17 @@
/*
* loop while registrated cluster DB exist
-@@ -291,7 +291,7 @@
+@@ -277,7 +277,9 @@
+ ptr = Host_Tbl_Begin;
+ while(ptr->useFlag != DB_TBL_END)
+ {
++ set_function("replicate_packet_send");
+ sem_num = ptr->hostNum;
++ show_debug("loop: cnt=%d, hostNum=%d, hostName=%s, port=%d, recoveryPort=%d, useFlag=%d", cnt, ptr->hostNum, ptr->hostName, ptr->port, ptr->recoveryPort, ptr->useFlag);
+ /*
+ * check the status of the cluster DB
+ */
+@@ -291,7 +293,7 @@
*/
if (PGRis_master_in_recovery(ptr->hostName, ptr->port) == true)
{
@@ -40,7 +68,26 @@
ptr ++;
continue;
}
-@@ -412,10 +412,10 @@
+@@ -368,6 +370,8 @@
+ if (sem_num > 0)
+ PGRsem_lock(SemID,sem_num);
+ rtn = replicate_packet_send_each_server( ptr, cnt,header, query, dest);
++ set_function("replicate_packet_send");
++ show_debug("replicate_packet_send_each_server returns %d (useFlag=%d", rtn, ptr->useFlag);
+ show_debug("sem_unlock[%d]",sem_num);
+ if (sem_num > 0)
+ PGRsem_unlock(SemID,sem_num);
+@@ -382,7 +386,8 @@
+ cnt ++;
+ }
+ ptr ++;
+- }
++ }
++ show_debug("replicate_packet_send() end");
+ return STATUS_OK;
+ }
+
+@@ -412,10 +417,10 @@
set_function("replicate_packet_send_each_server");
host = ptr->hostName;
@@ -53,25 +100,138 @@
/*
* send query to cluster DB
*/
-@@ -560,7 +560,7 @@
+@@ -427,6 +432,8 @@
+ memset(PGR_Result,0,PGR_MESSAGE_BUFSIZE);
+
+ rtn = PGRsend_replicate_packet_to_server( ptr, header,query,PGR_Result);
++ set_function("replicate_packet_send_each_server");
++ show_debug("PGRsend_replicate_packet_to_server() returns %d", rtn);
+ if ((header->cmdSts == CMD_STS_QUERY ) &&
+ ((header->cmdType == CMD_TYPE_INSERT) ||
+ (header->cmdType == CMD_TYPE_UPDATE)))
+@@ -476,7 +483,7 @@
+ }
+ send_ptr = PGR_Result;
+ buf_size = PGR_MESSAGE_BUFSIZE;
+- show_debug("%d[%s]",buf_size,send_ptr);
++ show_debug("buf_size=%d[send_ptr=%s]",buf_size,send_ptr);
+ if (buf_size < 1)
+ buf_size = 1;
+
+@@ -491,7 +498,7 @@
+ rtn = select(dest+1, (fd_set *)NULL, &wmask, (fd_set *)NULL, &timeout);
+ if (rtn && FD_ISSET(dest, &wmask))
+ {
+- show_debug("return_result[%s]",send_ptr);
++ show_debug("select() and FD_ISSET() [send_ptr=%s]",send_ptr);
+ for (;;)
+ {
+ s = send(dest,send_ptr + send_size,buf_size - send_size ,0);
+@@ -513,7 +520,7 @@
+ send_size += s;
+ if (send_size == buf_size)
+ {
+- show_debug("%d send",send_size);
++ show_debug("%d bytes sent", send_size);
+ status = STATUS_OK;
+ if (wait == PGR_WAIT_ANSWER)
+ {
+@@ -560,7 +567,7 @@
rtn = select(dest+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
if (rtn && FD_ISSET(dest, &rmask))
{
- show_debug("read_answer selected\n");
-+ show_debug("read_answer selected");
++ show_debug("read_answer selected (dest=%d)", dest);
answer = NULL;
answer = read_packet(dest,&header);
show_debug("answer[%s]",answer);
-@@ -689,7 +689,7 @@
+@@ -630,6 +637,43 @@
+ return NULL;
+ }
+
++static void
++dump_status(int fd)
++{
++ HostTbl *host = Host_Tbl_Begin;
++ while (host->useFlag != DB_TBL_END) {
++ char buf[256];
++ const char *flag = buf;
++ if (host->useFlag == DB_TBL_FREE) {
++ flag = "FREE";
++ } else if (host->useFlag == DB_TBL_INIT) {
++ flag = "INIT";
++ } else if (host->useFlag == DB_TBL_USE) {
++ flag = "USE";
++ } else if (host->useFlag == DB_TBL_ERROR) {
++ flag = "ERROR";
++ } else {
++ snprintf(buf, sizeof(buf), "UNKNOWN(%d)", host->useFlag);
++ }
++ show_debug("%s:%d flag=%s, recoveryPort=%d",
++ host->hostName, host->port, flag, host->recoveryPort);
++
++ snprintf(buf, sizeof(buf), "hostNum=%d\n", host->hostNum);
++ write(fd, buf, strlen(buf));
++ snprintf(buf, sizeof(buf), "hostName=%s\n", host->hostName);
++ write(fd, buf, strlen(buf));
++ snprintf(buf, sizeof(buf), "port=%d\n", host->port);
++ write(fd, buf, strlen(buf));
++ snprintf(buf, sizeof(buf), "useFlag=%d\n", host->useFlag);
++ write(fd, buf, strlen(buf));
++ snprintf(buf, sizeof(buf), "recoveryPort=%d\n", host->recoveryPort);
++ write(fd, buf, strlen(buf));
++ write(fd, "\n", strlen("\n"));
++
++ host++;
++ }
++}
++
+ /*--------------------------------------------------------------------
+ * SYMBOL
+ * replicate_loop()
+@@ -665,11 +709,11 @@
+ }
+ if (pid == 0)
+ {
+- signal(SIGHUP, quick_exit);
+- signal(SIGINT, quick_exit);
+- signal(SIGQUIT, quick_exit);
+- signal(SIGTERM, quick_exit);
+- signal(SIGALRM, quick_exit);
++ signal(SIGHUP, quick_exit);
++ signal(SIGINT, quick_exit);
++ signal(SIGQUIT, quick_exit);
++ signal(SIGTERM, quick_exit);
++ signal(SIGALRM, quick_exit);
+ setpgid(0,pgid);
+
+ /* child loop */
+@@ -687,14 +731,21 @@
+ FD_ZERO(&rmask);
+ FD_SET(sock,&rmask);
rtn = select(sock+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
++ if (rtn < 0) {
++ show_debug("select() = %d (%s)", rtn, strerror(errno));
++ }
if (rtn && FD_ISSET(sock, &rmask))
{
- show_debug("replicate_loop selected\n");
-+ show_debug("replicate_loop selected");
++ show_debug("replicate_loop selected (sock=%d)", sock);
query = NULL;
query = read_packet(sock,&header);
- if (query == NULL)
-@@ -708,7 +708,7 @@
+- if (query == NULL)
++ if (query == NULL && errno != 0)
+ {
+- show_error("read_packet failed");
++ show_error("read_packet failed (errno=%d)", errno);
++ break;
++ }
++ if (header.cmdType == 'o') {
++ dump_status(sock);
+ break;
+ }
+ if (header.cmdSts == 0)
+@@ -708,7 +759,7 @@
}
}
gettimeofday(&(header.tv),NULL);
@@ -80,7 +240,7 @@
RecoveryStatus = PGRget_recovery_status();
PGRcheck_recovered_host();
-@@ -781,7 +781,7 @@
+@@ -781,7 +832,7 @@
show_error("fopen failed: (%s)",strerror(errno));
return STATUS_ERROR;
}
@@ -89,7 +249,19 @@
/*
* read configuration file
-@@ -954,13 +954,13 @@
+@@ -915,10 +966,10 @@
+ /* set load balance table */
+ for ( i = 0 ; i <= lb_cnt ; i ++)
+ {
++ memset((LoadBalanceTbl + i),0,sizeof(RecoveryTbl));
+ (LoadBalanceTbl + i)->port = -1;
+ (LoadBalanceTbl + i)->sock = -1;
+ }
+- memset((LoadBalanceTbl + i),0,sizeof(RecoveryTbl));
+ PGR_Free_Conf_Data();
+
+ /* allocate result buffer of query */
+@@ -954,13 +1005,13 @@
/* set function name */
set_function("replicate_main");
@@ -105,21 +277,24 @@
for (;;)
{
-@@ -976,11 +976,11 @@
+@@ -976,11 +1027,14 @@
*/
FD_ZERO(&rmask);
FD_SET(fd,&rmask);
- show_debug("wait replicate\n");
+ show_debug("wait replicate");
rtn = select(fd+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
++ if (rtn < 0) {
++ show_debug("select() = %d (%s)", rtn, strerror(errno));
++ }
if (rtn && FD_ISSET(fd, &rmask))
{
- show_debug("replicate main: selected\n");
-+ show_debug("replicate main: selected");
++ show_debug("replicate main: selected (fd=%d)", fd);
/*
* get recovery status.
*/
-@@ -1315,12 +1315,12 @@
+@@ -1315,12 +1369,12 @@
if (init_server_tbl(path) != STATUS_OK)
{
@@ -134,3 +309,18 @@
PGRreplicate_exit(0);
}
pgid = getpgid(0);
+@@ -1332,10 +1386,10 @@
+ }
+ if (pid == 0)
+ {
+- signal(SIGHUP, quick_exit);
+- signal(SIGINT, quick_exit);
+- signal(SIGQUIT, quick_exit);
+- signal(SIGTERM, quick_exit);
++ signal(SIGHUP, quick_exit);
++ signal(SIGINT, quick_exit);
++ signal(SIGQUIT, quick_exit);
++ signal(SIGTERM, quick_exit);
+ /*
+ * in child process,
+ * call recovery module
diff --git a/databases/pgcluster/files/patch-pg_proc.h b/databases/pgcluster/files/patch-pg_proc.h
new file mode 100644
index 000000000000..37eb61e8e6b8
--- /dev/null
+++ b/databases/pgcluster/files/patch-pg_proc.h
@@ -0,0 +1,12 @@
+--- src/include/catalog/pg_proc.h.orig Tue Feb 24 23:17:16 2004
++++ src/include/catalog/pg_proc.h Tue Feb 24 23:28:44 2004
+@@ -3117,7 +3117,8 @@
+ DATA(insert OID = 2307 ( opaque_out PGNSP PGUID 12 f f t f i 1 2275 "2282" opaque_out - _null_ ));
+ DESCR("(internal)");
+
+-
++DATA(insert OID = 2400 ( pgr_current_replicator PGNSP PGUID 12 f f t f v 0 25 "" pgr_current_replicator - _null_ ));
++DESCR("Current replication server");
+ /*
+ * Symbolic values for provolatile column: these indicate whether the result
+ * of a function is dependent *only* on the values of its explicit arguments,
diff --git a/databases/pgcluster/files/patch-postmaster.c b/databases/pgcluster/files/patch-postmaster.c
new file mode 100644
index 000000000000..61a7f5afd458
--- /dev/null
+++ b/databases/pgcluster/files/patch-postmaster.c
@@ -0,0 +1,19 @@
+--- src/backend/postmaster/postmaster.c.orig.1 Mon Feb 23 15:33:29 2004
++++ src/backend/postmaster/postmaster.c Mon Feb 23 15:34:53 2004
+@@ -610,7 +610,7 @@
+ */
+ checkDataDir(potential_DataDir); /* issues error messages */
+ SetDataDir(potential_DataDir);
+-
++ ProcessConfigFile(PGC_POSTMASTER);
+ #ifdef USE_REPLICATION
+ PGR_Get_Conf_Data( potential_DataDir, CLUSTER_CONF_FILE );
+ PGR_Init_Replicate_Server_Data();
+@@ -627,7 +627,6 @@
+ }
+ }
+ #endif /* USE_REPLICATION */
+- ProcessConfigFile(PGC_POSTMASTER);
+
+ /*
+ * Check for invalid combinations of GUC settings.
diff --git a/databases/pgcluster/files/patch-recovery.c b/databases/pgcluster/files/patch-recovery.c
index 85d7b36afed0..4ae303c5fc3a 100644
--- a/databases/pgcluster/files/patch-recovery.c
+++ b/databases/pgcluster/files/patch-recovery.c
@@ -1,5 +1,14 @@
---- src/pgcluster/pgrp/recovery.c.orig Tue Feb 3 23:40:16 2004
-+++ src/pgcluster/pgrp/recovery.c Tue Feb 3 23:43:47 2004
+--- src/pgcluster/pgrp/recovery.c.orig Fri Feb 20 11:38:40 2004
++++ src/pgcluster/pgrp/recovery.c Fri Feb 20 16:25:21 2004
+@@ -121,7 +121,7 @@
+ int packet_size = 0;
+
+ /* set function name */
+- set_function("read_packet");
++ set_function("recovery::read_packet");
+
+ read_ptr = (char*)packet;
+ packet_size = sizeof(RecoveryPacket);
@@ -140,7 +140,7 @@
}
read_size += r;
@@ -18,6 +27,15 @@
for(;;)
{
rtn = select(host->sock+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
+@@ -227,7 +227,7 @@
+ {
+ if (count > MAX_RETRY_TIMES )
+ {
+- show_error("PGR_Create_Socket_Connect failed");
++ show_error("PGR_Create_Socket_Connect(%d, %s, %d) failed", host->sock, host->hostName, host->recoveryPort);
+ return STATUS_ERROR;
+ }
+ count ++;
@@ -331,18 +331,18 @@
Target->port = packet->port;
Target->recoveryPort = packet->recoveryPort;
@@ -46,7 +64,7 @@
* add recovery target to host table
*/
- show_debug("add recovery target to host table\n");
-+ show_debug("add recovery target to host table");
++ show_debug("add recovery target to host table (%s)", packet->hostName);
memcpy(host_tbl.hostName,packet->hostName,sizeof(host_tbl.hostName));
host_tbl.port = packet->port;
PGRset_recovered_host(&host_tbl,DB_TBL_INIT);
@@ -177,16 +195,33 @@
switch (packet.packet_no)
{
-@@ -721,7 +721,7 @@
+@@ -694,6 +694,7 @@
+ if (status == STATUS_OK)
+ {
+ show_debug("PGRsend_queue ok");
++ memset(&new_host, 0, sizeof(new_host));
+ memcpy(new_host.hostName,Target.hostName,sizeof(new_host.hostName));
+ new_host.port = Target.port;
+ new_host.recoveryPort = Target.recoveryPort;
+@@ -708,7 +709,7 @@
+ status = send_packet(&Target,&packet);
+ }
+ /*
+- * stop queueing, and initiarise recovery status
++ * stop queueing, and initialise recovery status
+ */
+ finish_recovery();
+ loop_end = true;
+@@ -721,7 +722,7 @@
memset((char *)&MasterPacketData,0,sizeof(RecoveryPacket));
break;
case RECOVERY_ERROR_ANS :
- show_debug("recovery error accept. top queueing and initiarse recovery status\n");
-+ show_debug("recovery error accept. top queueing and initiarse recovery status");
++ show_debug("recovery error accept. top queueing and initialise recovery status");
status = PGRsend_queue(&Master,NULL);
memset(&packet,0,sizeof(RecoveryPacket));
packet.packet_no = RECOVERY_ERROR_ANS ;
-@@ -776,7 +776,7 @@
+@@ -776,7 +777,7 @@
*/
FD_ZERO(&rmask);
FD_SET(fd,&rmask);
diff --git a/databases/pgcluster/files/patch-replicate.c b/databases/pgcluster/files/patch-replicate.c
index b7231f3bc20a..c99f7b21eda6 100644
--- a/databases/pgcluster/files/patch-replicate.c
+++ b/databases/pgcluster/files/patch-replicate.c
@@ -1,5 +1,14 @@
---- src/pgcluster/pgrp/replicate.c.orig Tue Feb 3 23:36:49 2004
-+++ src/pgcluster/pgrp/replicate.c Tue Feb 3 23:44:28 2004
+--- src/pgcluster/pgrp/replicate.c.orig Fri Feb 20 11:38:40 2004
++++ src/pgcluster/pgrp/replicate.c Sat Feb 21 20:50:01 2004
+@@ -133,7 +133,7 @@
+ ptr = Dbserver_Tbl_Begin;
+ while (ptr != NULL)
+ {
+-show_debug("search host(%d):port(%d):db(%s)",ptr->hostIP,ptr->port,ptr->dbName);
++show_debug("search host(%08x):port(%d):db(%s)",ptr->hostIP,ptr->port,ptr->dbName);
+ if ((ptr->useFlag == DB_TBL_USE) &&
+ (ptr->hostIP == host) &&
+ (ptr->port == host_ptr->port) &&
@@ -165,7 +165,7 @@
hostName = host_ptr->hostName;
@@ -49,7 +58,15 @@
return conn;
}
-@@ -451,12 +451,12 @@
+@@ -379,6 +379,7 @@
+ show_error("insertTransactionTbl failed");
+ return (TransactionTbl *)NULL;
+ }
++ show_debug("setTransactionTbl return %p (hostIP=%08x, port=%d, srcHostIP=%08x", ptr, work.hostIP, work.port, work.srcHostIP);
+ return ptr;
+ }
+
+@@ -451,12 +452,12 @@
(!memcmp(ptr->dbName,header->dbName,strlen(ptr->dbName))) &&
(ptr->pid == header->pid))
{
@@ -64,25 +81,95 @@
return (TransactionTbl * )NULL;
}
-@@ -606,7 +606,7 @@
+@@ -561,8 +562,10 @@
+ set_function("PGRadd_HostTbl");
+
+ ptr = PGRget_HostTbl(conf_data->hostName, conf_data->port);
++ set_function("PGRadd_HostTbl");
+ if (ptr != (HostTbl*)NULL)
+ {
++ show_debug("found ptr");
+ PGRset_host_status(ptr,useFlag);
+ return ptr;
+ }
+@@ -586,6 +589,7 @@
+ {
+ (ptr + 1) -> useFlag = DB_TBL_END;
+ }
++ show_debug("not found, allocate new one");
+ ptr->hostNum = cnt;
+ memcpy(ptr->hostName,conf_data->hostName,sizeof(ptr->hostName));
+ ptr->port = conf_data->port;
+@@ -604,19 +608,22 @@
+ set_function("PGRget_master");
+
host_tbl = Host_Tbl_Begin;
++ show_debug("start get_master loop");
while(host_tbl->useFlag != DB_TBL_END)
{
- show_debug("name %s flg %d port %d recoveryPort %d \n",
-+ show_debug("name %s flg %d port %d recoveryPort %d",
++ show_debug(" %s:%d flg %d recoveryPort %d",
host_tbl->hostName,
- host_tbl->useFlag,
+- host_tbl->useFlag,
host_tbl->port,
-@@ -763,7 +763,7 @@
++ host_tbl->useFlag,
+ host_tbl->recoveryPort);
+ if (host_tbl->useFlag == DB_TBL_USE)
+ {
++ show_debug("found master");
+ return host_tbl;
+ }
+ host_tbl ++;
+ }
++ show_debug("not found master");
+ return (HostTbl *)NULL;
+ }
+
+@@ -629,6 +636,9 @@
+ PGRsem_lock(SemID,SEM_NUM_OF_RECOVERY);
+ if (Recovery_Status_Inf != (RecoveryStatusInf *)NULL)
+ {
++ if (Recovery_Status_Inf->recovery_status != status) {
++ show_debug("status change %d -> %d", Recovery_Status_Inf->recovery_status, status);
++ }
+ Recovery_Status_Inf->recovery_status = status;
+ }
+ PGRsem_unlock(SemID,SEM_NUM_OF_RECOVERY);
+@@ -763,7 +773,7 @@
{
if (Recovery_Status_Inf->useFlag != DB_TBL_FREE)
{
- show_debug("check recovered host %d\n",Recovery_Status_Inf->useFlag);
-+ show_debug("check recovered host %d",Recovery_Status_Inf->useFlag);
++ show_debug("check recovered host (useFlag=%d)",Recovery_Status_Inf->useFlag);
ptr = PGRadd_HostTbl((HostTbl *)&(Recovery_Status_Inf->target_host),Recovery_Status_Inf->useFlag);
if (ptr == (HostTbl *) NULL)
{
-@@ -1144,7 +1144,7 @@
+@@ -792,6 +802,8 @@
+ if (target != (HostTbl*)NULL)
+ {
+ memcpy((HostTbl *)&(Recovery_Status_Inf->target_host),target,sizeof(HostTbl));
++ set_function("PGRset_recovered_host");
++ show_debug("status=%d", useFlag);
+ PGRset_host_status(target,useFlag);
+ }
+
+@@ -961,6 +973,7 @@
+ return STATUS_ERROR;
+ }
+ host_ptr->useFlag = status;
++ show_debug("hostName=%s, port=%d, recoveryPort=%d, hostNum=%d, useFlag=%d", host_ptr->hostName, host_ptr->port, host_ptr->recoveryPort, host_ptr->hostNum, host_ptr->useFlag);
+ switch( host_ptr->useFlag)
+ {
+ case DB_TBL_FREE:
+@@ -990,7 +1003,6 @@
+ host_ptr->hostName);
+ break;
+ }
+-
+ return STATUS_OK;
+ }
+
+@@ -1144,7 +1156,7 @@
/*
* re-use the connection data
*/
@@ -91,7 +178,7 @@
if ((db_server_tbl->conn != (PGconn *)NULL) &&
(db_server_tbl->conn->sock <= 0) )
{
-@@ -1153,17 +1153,17 @@
+@@ -1153,17 +1165,18 @@
}
}
conn = db_server_tbl->conn;
@@ -99,6 +186,7 @@
+ show_debug("send_replicate_packet_to_server query=%s",query);
}
++ set_function("PGRsend_replicate_packet_to_server");
if (conn == NULL)
{
- show_error("conn is null\n");
@@ -112,7 +200,7 @@
database,port,userName,host,query);
/*
* execute query
-@@ -1184,7 +1184,7 @@
+@@ -1184,7 +1197,7 @@
(header->cmdType == CMD_TYPE_COPY_DATA_END))
{
/* copy data replication */
@@ -121,7 +209,7 @@
rtn =PQputnbytes(conn, query,header->query_size);
if (header->cmdType == CMD_TYPE_COPY_DATA_END)
{
-@@ -1201,11 +1201,11 @@
+@@ -1201,11 +1214,11 @@
if (res == NULL)
{
@@ -135,7 +223,7 @@
str = PQcmdStatus(res);
if ((str == NULL) || (*str == '\0'))
-@@ -1258,7 +1258,7 @@
+@@ -1258,7 +1271,7 @@
}
}
}
@@ -144,7 +232,7 @@
if ((! strcmp(database,"template1")) ||
(! strcmp(database,"template0")))
{
-@@ -1337,12 +1337,12 @@
+@@ -1337,12 +1350,12 @@
* send header data to queue
*/
rtn = msgsnd(RecoveryMsgid, msg_header, sizeof(ReplicateHeader), IPC_NOWAIT);
@@ -159,3 +247,47 @@
/*
* release memory
+@@ -1364,6 +1377,7 @@
+
+ len = strlen(hostName);
+ ptr = Host_Tbl_Begin;
++ show_debug("hostName=%s, port=%d", hostName, port);
+ if (len > sizeof(ptr->hostName))
+ {
+ len = sizeof(ptr->hostName);
+@@ -1379,10 +1393,12 @@
+ }
+ if (ptr->useFlag != DB_TBL_END)
+ {
++ show_debug("found: %s:%d", ptr->hostName, ptr->port);
+ return ptr;
+ }
+ else
+ {
++ show_debug("not found");
+ return (HostTbl*)NULL;
+ }
+ }
+@@ -1392,7 +1408,6 @@
+ {
+ char buf[256];
+ char log[288];
+- int len1;
+ char * p;
+ va_list ap;
+ time_t t;
+@@ -1410,13 +1425,12 @@
+ {
+ *p = ' ';
+ }
+- len1 = strlen(log);
+ va_start(ap,fmt);
+ vsnprintf(buf,sizeof(buf),fmt,ap);
+ va_end(ap);
+ strcat(log,buf);
+ strcat(log,"\n");
+- if (fputs(log,LogFp) > 0)
++ if (fputs(log,LogFp) >= 0)
+ {
+ fflush(LogFp);
+ }