2929 *
3030 *
3131 * IDENTIFICATION
32- * $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.9 2010/04/19 14:10:45 mha Exp $
32+ * $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.10 2010/04/20 22:55:03 tgl Exp $
3333 *
3434 *-------------------------------------------------------------------------
3535 */
@@ -76,9 +76,15 @@ static uint32 recvOff = 0;
7676static volatile sig_atomic_t got_SIGHUP = false;
7777static volatile sig_atomic_t got_SIGTERM = false;
7878
79- static void ProcessWalRcvInterrupts (void );
80- static void EnableWalRcvImmediateExit (void );
81- static void DisableWalRcvImmediateExit (void );
79+ /*
80+ * LogstreamResult indicates the byte positions that we have already
81+ * written/fsynced.
82+ */
83+ static struct
84+ {
85+ XLogRecPtr Write ;/* last byte + 1 written out in the standby */
86+ XLogRecPtr Flush ;/* last byte + 1 flushed in the standby */
87+ }LogstreamResult ;
8288
8389/*
8490 * About SIGTERM handling:
@@ -98,6 +104,21 @@ static void DisableWalRcvImmediateExit(void);
98104 */
99105static volatile bool WalRcvImmediateInterruptOK = false;
100106
107+ /* Prototypes for private functions */
108+ static void ProcessWalRcvInterrupts (void );
109+ static void EnableWalRcvImmediateExit (void );
110+ static void DisableWalRcvImmediateExit (void );
111+ static void WalRcvDie (int code ,Datum arg );
112+ static void XLogWalRcvProcessMsg (unsignedchar type ,char * buf ,Size len );
113+ static void XLogWalRcvWrite (char * buf ,Size nbytes ,XLogRecPtr recptr );
114+ static void XLogWalRcvFlush (void );
115+
116+ /* Signal handlers */
117+ static void WalRcvSigHupHandler (SIGNAL_ARGS );
118+ static void WalRcvShutdownHandler (SIGNAL_ARGS );
119+ static void WalRcvQuickDieHandler (SIGNAL_ARGS );
120+
121+
101122static void
102123ProcessWalRcvInterrupts (void )
103124{
@@ -118,47 +139,25 @@ ProcessWalRcvInterrupts(void)
118139}
119140
120141static void
121- EnableWalRcvImmediateExit ()
142+ EnableWalRcvImmediateExit (void )
122143{
123144WalRcvImmediateInterruptOK = true;
124145ProcessWalRcvInterrupts ();
125146}
126147
127148static void
128- DisableWalRcvImmediateExit ()
149+ DisableWalRcvImmediateExit (void )
129150{
130151WalRcvImmediateInterruptOK = false;
131152ProcessWalRcvInterrupts ();
132153}
133154
134- /* Signal handlers */
135- static void WalRcvSigHupHandler (SIGNAL_ARGS );
136- static void WalRcvShutdownHandler (SIGNAL_ARGS );
137- static void WalRcvQuickDieHandler (SIGNAL_ARGS );
138-
139- /* Prototypes for private functions */
140- static void WalRcvDie (int code ,Datum arg );
141- static void XLogWalRcvProcessMsg (unsignedchar type ,char * buf ,Size len );
142- static void XLogWalRcvWrite (char * buf ,Size nbytes ,XLogRecPtr recptr );
143- static void XLogWalRcvFlush (void );
144-
145- /*
146- * LogstreamResult indicates the byte positions that we have already
147- * written/fsynced.
148- */
149- static struct
150- {
151- XLogRecPtr Write ;/* last byte + 1 written out in the standby */
152- XLogRecPtr Flush ;/* last byte + 1 flushed in the standby */
153- }LogstreamResult ;
154-
155155/* Main entry point for walreceiver process */
156156void
157157WalReceiverMain (void )
158158{
159159char conninfo [MAXCONNINFO ];
160160XLogRecPtr startpoint ;
161-
162161/* use volatile pointer to prevent code rearrangement */
163162volatile WalRcvData * walrcv = WalRcv ;
164163
@@ -398,19 +397,21 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len)
398397
399398if (len < sizeof (XLogRecPtr ))
400399ereport (ERROR ,
401- (errmsg ("invalid WAL message received from primary" )));
400+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
401+ errmsg_internal ("invalid WAL message received from primary" )));
402402
403- recptr = * (( XLogRecPtr * ) buf );
403+ memcpy ( & recptr , buf , sizeof ( XLogRecPtr ) );
404404buf += sizeof (XLogRecPtr );
405405len -= sizeof (XLogRecPtr );
406+
406407XLogWalRcvWrite (buf ,len ,recptr );
407408break ;
408409}
409410default :
410411ereport (ERROR ,
411412(errcode (ERRCODE_PROTOCOL_VIOLATION ),
412- errmsg ("invalid replication message type %d" ,
413- type )));
413+ errmsg_internal ("invalid replication message type %d" ,
414+ type )));
414415}
415416}
416417