o Fix some bugs in startup scripts.

o Add WITH_DEBUG knob.
o Fix a bug of pglb which dumps core (obtained from ML).
o Fix style bugs in debug messages.
This commit is contained in:
Jun Kuriyama 2004-02-16 01:24:58 +00:00
parent 0a654bf653
commit 4d3d3d85c9
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=101004
8 changed files with 550 additions and 4 deletions

View File

@ -6,7 +6,7 @@
PORTNAME= pgcluster
PORTVERSION= 1.0.6b
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= databases
MASTER_SITES= ${MASTER_SITE_PGSQL}
MASTER_SITE_SUBDIR= v${BASEPGSQL}
@ -30,6 +30,12 @@ MAKEFILE= # empty
CONFLICTS= postgresql-*
USE_RC_SUBR= yes
INSTALLS_SHLIB= yes
.if defined(WITH_DEBUG)
CONFIGURE_ARGS+= --enable-debug
INSTALL_TARGET= install
.else
INSTALL_TARGET= install-strip
.endif
BASEPGSQL= 7.3.4
.if defined(WITHOUT_PGCLUSTER_REPLICATION)

View File

@ -0,0 +1,136 @@
--- 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
@@ -258,18 +258,18 @@
/* set function name */
set_function("replicate_packet_send");
- show_debug("cmdSts=%c\n",header->cmdSts);
- show_debug("cmdType=%c\n",header->cmdType);
- show_debug("port=%d\n",header->port);
- show_debug("pid=%d\n",header->pid);
- show_debug("except_host=%s\n",header->except_host);
- show_debug("from_host=%s\n",header->from_host);
- show_debug("dbName=%s\n",header->dbName);
- show_debug("userName=%s\n",header->userName);
- show_debug("recieve sec=%u\n",header->tv.tv_sec);
- show_debug("recieve usec=%u\n",header->tv.tv_usec);
- show_debug("query_size=%d\n",header->query_size);
- show_debug("query=%s\n",query);
+ show_debug("cmdSts=%c",header->cmdSts);
+ show_debug("cmdType=%c",header->cmdType);
+ show_debug("port=%d",header->port);
+ show_debug("pid=%d",header->pid);
+ show_debug("except_host=%s",header->except_host);
+ show_debug("from_host=%s",header->from_host);
+ show_debug("dbName=%s",header->dbName);
+ show_debug("userName=%s",header->userName);
+ show_debug("recieve sec=%u",header->tv.tv_sec);
+ show_debug("recieve usec=%u",header->tv.tv_usec);
+ show_debug("query_size=%d",header->query_size);
+ show_debug("query=%s",query);
/*
* loop while registrated cluster DB exist
@@ -291,7 +291,7 @@
*/
if (PGRis_master_in_recovery(ptr->hostName, ptr->port) == true)
{
- show_debug("%s skipped\n",ptr->hostName);
+ show_debug("%s skipped",ptr->hostName);
ptr ++;
continue;
}
@@ -412,10 +412,10 @@
set_function("replicate_packet_send_each_server");
host = ptr->hostName;
- show_debug("except:%d@%s host:%d@%s\n",
+ show_debug("except:%d@%s host:%d@%s",
header->port,header->except_host,
ptr->port,ptr->hostName);
- show_debug("send replicate to:%s\n",host);
+ show_debug("send replicate to:%s",host);
/*
* send query to cluster DB
*/
@@ -560,7 +560,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");
answer = NULL;
answer = read_packet(dest,&header);
show_debug("answer[%s]",answer);
@@ -689,7 +689,7 @@
rtn = select(sock+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
if (rtn && FD_ISSET(sock, &rmask))
{
- show_debug("replicate_loop selected\n");
+ show_debug("replicate_loop selected");
query = NULL;
query = read_packet(sock,&header);
if (query == NULL)
@@ -708,7 +708,7 @@
}
}
gettimeofday(&(header.tv),NULL);
- show_debug("query :: %s\n",query);
+ show_debug("query :: %s",query);
RecoveryStatus = PGRget_recovery_status();
PGRcheck_recovered_host();
@@ -781,7 +781,7 @@
show_error("fopen failed: (%s)",strerror(errno));
return STATUS_ERROR;
}
- show_debug("%s open ok\n",fname);
+ show_debug("%s open ok",fname);
/*
* read configuration file
@@ -954,13 +954,13 @@
/* set function name */
set_function("replicate_main");
- show_debug("replicate mail %d port bind\n",Port_Number);
+ show_debug("replicate mail %d port bind",Port_Number);
status = PGR_Create_Socket_Bind(&fd, "", Port_Number);
if (status != STATUS_OK)
{
PGRreplicate_exit(0);
}
- show_debug("replicate mail %d port bind OK \n",Port_Number);
+ show_debug("replicate mail %d port bind OK",Port_Number);
for (;;)
{
@@ -976,11 +976,11 @@
*/
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 && FD_ISSET(fd, &rmask))
{
- show_debug("replicate main: selected\n");
+ show_debug("replicate main: selected");
/*
* get recovery status.
*/
@@ -1315,12 +1315,12 @@
if (init_server_tbl(path) != STATUS_OK)
{
- show_debug("init_server_tbl error\n");
+ show_debug("init_server_tbl error");
PGRreplicate_exit(0);
}
if (PGRinit_recovery() != STATUS_OK)
{
- show_debug("PGRinit_recovery error\n");
+ show_debug("PGRinit_recovery error");
PGRreplicate_exit(0);
}
pgid = getpgid(0);

View File

@ -1,6 +1,49 @@
--- src/pgcluster/pglb/pool_process_query.c.orig Sat Jan 24 14:14:51 2004
+++ src/pgcluster/pglb/pool_process_query.c Sat Jan 24 14:15:00 2004
@@ -728,10 +728,11 @@
--- src/pgcluster/pglb/pool_process_query.c.orig.orig Wed Feb 4 23:35:56 2004
+++ src/pgcluster/pglb/pool_process_query.c Wed Feb 4 23:37:29 2004
@@ -459,20 +459,31 @@
pool_write(frontend, &size, sizeof(int));
size = htonl(size) - 4;
- buf = malloc(size);
- if (buf == NULL)
+
+ /* read and send actual data only when size > 0 */
+ if (size > 0)
{
- show_error("AsciiRow: out of memory");
- return POOL_END;
+ buf = malloc(size);
+ if (buf == NULL)
+ {
+ show_error("AsciiRow: out of memory");
+ return POOL_END;
+ }
+ /* actual data */
+ if (pool_read(backend, buf, size) < 0)
+ {
+ free(buf);
+ return POOL_END;
+ }
+ pool_write(frontend, buf, size);
+ snprintf(msgbuf, Min(sizeof(msgbuf), size), "%s", buf);
+ free(buf);
+ }
+ else
+ {
+ *msgbuf = '\0';
}
- /* actual data */
- if (pool_read(backend, buf, size) < 0)
- return POOL_END;
-
- pool_write(frontend, buf, size);
- snprintf(msgbuf, Min(sizeof(msgbuf), size), "%s", buf);
show_debug("AsciiRow: len:%d data: %s", size, msgbuf);
- free(buf);
}
mask >>= 1;
}
@@ -728,10 +739,11 @@
static POOL_STATUS EmptyQueryResponse(POOL_CONNECTION *frontend,
POOL_CONNECTION *backend)
{

View File

@ -0,0 +1,197 @@
--- 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
@@ -140,7 +140,7 @@
}
read_size += r;
if (read_size == packet_size){
- show_debug("receive packet\n");
+ show_debug("receive packet");
show_recovery_packet(packet);
return r;
}
@@ -166,7 +166,7 @@
*/
FD_ZERO(&rmask);
FD_SET(host->sock,&rmask);
- show_debug("wait\n");
+ show_debug("wait");
for(;;)
{
rtn = select(host->sock+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
@@ -331,18 +331,18 @@
Target->port = packet->port;
Target->recoveryPort = packet->recoveryPort;
Target->sock = *sock;
- show_debug("1st setup target %s\n",Target->hostName);
- show_debug("1st setup port %d\n",Target->port);
+ show_debug("1st setup target %s",Target->hostName);
+ show_debug("1st setup port %d",Target->port);
/*
* check another recovery process
*/
- show_debug("check another recovery process\n");
+ show_debug("check another recovery process");
if (PGRget_recovery_status() != RECOVERY_INIT)
{
/*
* recovery process is already running
*/
- show_debug(" already recovery job runing\n");
+ show_debug(" already recovery job runing");
memset(packet,0,sizeof(packet));
packet->packet_no = RECOVERY_ERROR_OCCUPIED ;
status = send_packet(Target,packet);
@@ -352,7 +352,7 @@
/*
* add recovery target to host table
*/
- show_debug("add recovery target to host table\n");
+ show_debug("add recovery target to host table");
memcpy(host_tbl.hostName,packet->hostName,sizeof(host_tbl.hostName));
host_tbl.port = packet->port;
PGRset_recovered_host(&host_tbl,DB_TBL_INIT);
@@ -365,7 +365,7 @@
/*
* set RECOVERY_PGDATA_REQ packet data
*/
- show_debug("set RECOVERY_PGDATA_REQ packet data\n");
+ show_debug("set RECOVERY_PGDATA_REQ packet data");
memset(packet,0,sizeof(RecoveryPacket));
packet->packet_no = RECOVERY_PGDATA_REQ ;
master = PGRget_master();
@@ -374,7 +374,7 @@
/*
* connection error , master may be down
*/
- show_error("get master info error , master may be down\n");
+ show_error("get master info error , master may be down");
packet->packet_no = RECOVERY_ERROR_CONNECTION;
status = send_packet(Target, packet);
reset_recovery_prepare();
@@ -385,14 +385,14 @@
Master->sock = -1;
Master->port = master->port;
Master->recoveryPort = master->recoveryPort;
- show_debug("send packet to master %s recoveryPort %d\n",Master->hostName, Master->recoveryPort);
+ show_debug("send packet to master %s recoveryPort %d",Master->hostName, Master->recoveryPort);
status = send_packet(Master, packet);
if (status != STATUS_OK)
{
/*
* connection error , master may be down
*/
- show_error("connection error , master may be down\n");
+ show_error("connection error , master may be down");
packet->packet_no = RECOVERY_ERROR_CONNECTION;
status = send_packet(Target, packet);
reset_recovery_prepare();
@@ -409,10 +409,10 @@
/*
* wait answer from master server
*/
- show_debug("wait answer from master server\n");
+ show_debug("wait answer from master server");
memset(packet,0,sizeof(RecoveryPacket));
read_packet_from_master(Master, packet);
- show_debug("get answer from master\n");
+ show_debug("get answer from master");
if (packet->packet_no == RECOVERY_PGDATA_ANS)
{
/*
@@ -455,7 +455,7 @@
status = PGRwait_transaction_count_clear();
if (status != STATUS_OK)
{
- show_error("transaction is too busy, please try again after\n");
+ show_error("transaction is too busy, please try again after");
packet->packet_no = RECOVERY_ERROR_CONNECTION;
status = send_packet(Target,packet);
status = send_packet(Master,packet);
@@ -473,7 +473,7 @@
/*
* connection error , master may be down
*/
- show_error("connection error , master may be down\n");
+ show_error("connection error , master may be down");
packet->packet_no = RECOVERY_ERROR_CONNECTION;
status = send_packet(Target,packet);
status = send_packet(Master,packet);
@@ -502,7 +502,7 @@
}
else
{
- show_debug("failer answer returned\n");
+ show_debug("failer answer returned");
packet->packet_no = RECOVERY_ERROR_CONNECTION;
status = send_packet(Target,packet);
status = send_packet(Master,packet);
@@ -534,20 +534,20 @@
show_error("there is no master ");
return STATUS_ERROR;
}
- show_debug("master %s - %d\n",master->hostName,master->port);
+ show_debug("master %s - %d",master->hostName,master->port);
master_ptr = PGRget_HostTbl(master->hostName,master->port);
if (master_ptr == (HostTbl *)NULL)
{
- show_error("master table is null\n");
+ show_error("master table is null");
return STATUS_ERROR;
}
if (target != (RecoveryTbl *)NULL)
{
- show_debug("target %s - %d\n",target->hostName,target->port);
+ show_debug("target %s - %d",target->hostName,target->port);
target_ptr = PGRget_HostTbl(target->hostName,target->port);
if (target_ptr == (HostTbl *)NULL)
{
- show_error("target table is null\n");
+ show_error("target table is null");
return STATUS_ERROR;
}
}
@@ -590,7 +590,7 @@
free(msg_query);
}
free(msg_header);
- show_debug("send_queue return status %d\n",status);
+ show_debug("send_queue return status %d",status);
return status;
}
@@ -611,7 +611,7 @@
set_function("pgrecovery_loop");
count = 0;
- show_debug("recovery accept port %d\n",Recovery_Port_Number);
+ show_debug("recovery accept port %d",Recovery_Port_Number);
while ((status = PGR_Create_Acception(fd,&sock,"",Recovery_Port_Number)) != STATUS_OK)
{
show_error("PGR_Create_Acception failed");
@@ -651,7 +651,7 @@
continue;
}
- show_debug("receive packet no:%d\n",packet.packet_no);
+ show_debug("receive packet no:%d",packet.packet_no);
switch (packet.packet_no)
{
@@ -721,7 +721,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");
status = PGRsend_queue(&Master,NULL);
memset(&packet,0,sizeof(RecoveryPacket));
packet.packet_no = RECOVERY_ERROR_ANS ;
@@ -776,7 +776,7 @@
*/
FD_ZERO(&rmask);
FD_SET(fd,&rmask);
- show_debug("wait recovery\n");
+ show_debug("wait recovery");
rtn = select(fd+1, &rmask, (fd_set *)NULL, (fd_set *)NULL, &timeout);
if (rtn && FD_ISSET(fd, &rmask))
{

View File

@ -0,0 +1,161 @@
--- 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
@@ -165,7 +165,7 @@
hostName = host_ptr->hostName;
- show_debug("host:%s dbName:%s\n",hostName,dbName);
+ show_debug("host:%s dbName:%s",hostName,dbName);
if ((hostName == NULL ) || (dbName == NULL))
{
show_error("hostName or dbName is NULL");
@@ -215,7 +215,7 @@
if ((host_ptr == (HostTbl *)NULL) || (datap == (DBServerTbl*)NULL))
{
- show_error("insertDBServerTbl datap error\n");
+ show_error("insertDBServerTbl datap error");
return (DBServerTbl *)NULL;
}
workp = Dbserver_Tbl_End;
@@ -258,7 +258,7 @@
if ((host1[0] == '\0' ) || (host2[0] == '\0') ||
(port1 <= 0) || (port2 <= 0))
{
- show_debug("not same host:\n");
+ show_debug("not same host:");
return false;
}
ip1 = get_ip_by_name( host1);
@@ -266,10 +266,10 @@
if ((ip1 == ip2) && (port1 == port2))
{
- show_debug("same host:%d@%x - %d@%x\n",port1,ip1,port2,ip2);
+ show_debug("same host:%d@%x - %d@%x",port1,ip1,port2,ip2);
return true;
}
- show_debug("not same host:%d@%x - %d@%x\n",port1,ip1,port2,ip2);
+ show_debug("not same host:%d@%x - %d@%x",port1,ip1,port2,ip2);
return false;
}
@@ -326,7 +326,7 @@
}
cnt ++;
}
- show_debug("PQsetdbLogin ok!!\n");
+ show_debug("PQsetdbLogin ok!!");
return conn;
}
@@ -451,12 +451,12 @@
(!memcmp(ptr->dbName,header->dbName,strlen(ptr->dbName))) &&
(ptr->pid == header->pid))
{
- show_debug("hit !! transaction tbl host %s db:%s pid:%d\n",host_ptr->hostName,ptr->dbName,ptr->pid);
+ show_debug("hit !! transaction tbl host %s db:%s pid:%d",host_ptr->hostName,ptr->dbName,ptr->pid);
return ptr;
}
ptr = (TransactionTbl*)ptr->next;
}
- show_debug("not found in transaction tbl host %s db:%s pid:%d\n",header->from_host,header->dbName,header->pid);
+ show_debug("not found in transaction tbl host %s db:%s pid:%d",header->from_host,header->dbName,header->pid);
return (TransactionTbl * )NULL;
}
@@ -606,7 +606,7 @@
host_tbl = Host_Tbl_Begin;
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",
host_tbl->hostName,
host_tbl->useFlag,
host_tbl->port,
@@ -763,7 +763,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);
ptr = PGRadd_HostTbl((HostTbl *)&(Recovery_Status_Inf->target_host),Recovery_Status_Inf->useFlag);
if (ptr == (HostTbl *) NULL)
{
@@ -1144,7 +1144,7 @@
/*
* re-use the connection data
*/
- show_debug("find conn in db_server_tbl %d\n",db_server_tbl->conn);
+ show_debug("find conn in db_server_tbl %d",db_server_tbl->conn);
if ((db_server_tbl->conn != (PGconn *)NULL) &&
(db_server_tbl->conn->sock <= 0) )
{
@@ -1153,17 +1153,17 @@
}
}
conn = db_server_tbl->conn;
- show_debug("send_replicate_packet_to_server query=%s\n",query);
+ show_debug("send_replicate_packet_to_server query=%s",query);
}
if (conn == NULL)
{
- show_error("conn is null\n");
+ show_error("conn is null");
PGRset_host_status(host_ptr,DB_TBL_ERROR);
return STATUS_ERROR;
}
- show_debug("db:%s port:%s user:%s host:%s query:%s\n",
+ show_debug("db:%s port:%s user:%s host:%s query:%s",
database,port,userName,host,query);
/*
* execute query
@@ -1184,7 +1184,7 @@
(header->cmdType == CMD_TYPE_COPY_DATA_END))
{
/* copy data replication */
- show_debug("query(%s) size(%d)\n",query,header->query_size);
+ show_debug("query(%s) size(%d)",query,header->query_size);
rtn =PQputnbytes(conn, query,header->query_size);
if (header->cmdType == CMD_TYPE_COPY_DATA_END)
{
@@ -1201,11 +1201,11 @@
if (res == NULL)
{
- show_error("PQexec error \n");
+ show_error("PQexec error");
PGRset_host_status(host_ptr,DB_TBL_ERROR);
return STATUS_ERROR;
}
- show_debug("PQexec send :%s\n",query);
+ show_debug("PQexec send :%s",query);
str = PQcmdStatus(res);
if ((str == NULL) || (*str == '\0'))
@@ -1258,7 +1258,7 @@
}
}
}
- show_debug("PQexec end\n");
+ show_debug("PQexec end");
if ((! strcmp(database,"template1")) ||
(! strcmp(database,"template0")))
{
@@ -1337,12 +1337,12 @@
* send header data to queue
*/
rtn = msgsnd(RecoveryMsgid, msg_header, sizeof(ReplicateHeader), IPC_NOWAIT);
- show_debug("msgsnd header rtn:%d\n",rtn);
+ show_debug("msgsnd header rtn:%d",rtn);
/*
* send query data to queue
*/
rtn = msgsnd(RecoveryMsgid, msg_query, header->query_size, IPC_NOWAIT);
- show_debug("msgsnd query rtn:%d\n",rtn);
+ show_debug("msgsnd query rtn:%d",rtn);
/*
* release memory

View File

@ -24,6 +24,7 @@ pgcluster_flags="-w -s"
load_rc_config pgcluster
name=pgcluster
rcvar=`set_rcvar`
command=%%PREFIX%%/bin/pg_ctl
pgcluster_user=pgsql
extra_commands="initdb recover"

View File

@ -20,6 +20,7 @@ pglb_flags=""
load_rc_config pglb
name=pglb
rcvar=`set_rcvar`
command=%%PREFIX%%/bin/pglb
pglb_user=pgsql
stop_cmd="pglb_stop"

View File

@ -21,6 +21,7 @@ pgreplicate_flags=""
load_rc_config pgreplicate
name=pgreplicate
rcvar=`set_rcvar`
command=%%PREFIX%%/bin/pgreplicate
pgreplicate_user=pgsql
stop_cmd="pgreplicate_stop"