29
29
*
30
30
*
31
31
* 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 $
33
33
*
34
34
*-------------------------------------------------------------------------
35
35
*/
@@ -76,9 +76,15 @@ static uint32 recvOff = 0;
76
76
static volatile sig_atomic_t got_SIGHUP = false;
77
77
static volatile sig_atomic_t got_SIGTERM = false;
78
78
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 ;
82
88
83
89
/*
84
90
* About SIGTERM handling:
@@ -98,6 +104,21 @@ static void DisableWalRcvImmediateExit(void);
98
104
*/
99
105
static volatile bool WalRcvImmediateInterruptOK = false;
100
106
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 (unsigned char 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
+
101
122
static void
102
123
ProcessWalRcvInterrupts (void )
103
124
{
@@ -118,47 +139,25 @@ ProcessWalRcvInterrupts(void)
118
139
}
119
140
120
141
static void
121
- EnableWalRcvImmediateExit ()
142
+ EnableWalRcvImmediateExit (void )
122
143
{
123
144
WalRcvImmediateInterruptOK = true;
124
145
ProcessWalRcvInterrupts ();
125
146
}
126
147
127
148
static void
128
- DisableWalRcvImmediateExit ()
149
+ DisableWalRcvImmediateExit (void )
129
150
{
130
151
WalRcvImmediateInterruptOK = false;
131
152
ProcessWalRcvInterrupts ();
132
153
}
133
154
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 (unsigned char 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
-
155
155
/* Main entry point for walreceiver process */
156
156
void
157
157
WalReceiverMain (void )
158
158
{
159
159
char conninfo [MAXCONNINFO ];
160
160
XLogRecPtr startpoint ;
161
-
162
161
/* use volatile pointer to prevent code rearrangement */
163
162
volatile WalRcvData * walrcv = WalRcv ;
164
163
@@ -398,19 +397,21 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len)
398
397
399
398
if (len < sizeof (XLogRecPtr ))
400
399
ereport (ERROR ,
401
- (errmsg ("invalid WAL message received from primary" )));
400
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
401
+ errmsg_internal ("invalid WAL message received from primary" )));
402
402
403
- recptr = * (( XLogRecPtr * ) buf );
403
+ memcpy ( & recptr , buf , sizeof ( XLogRecPtr ) );
404
404
buf += sizeof (XLogRecPtr );
405
405
len -= sizeof (XLogRecPtr );
406
+
406
407
XLogWalRcvWrite (buf , len , recptr );
407
408
break ;
408
409
}
409
410
default :
410
411
ereport (ERROR ,
411
412
(errcode (ERRCODE_PROTOCOL_VIOLATION ),
412
- errmsg ("invalid replication message type %d" ,
413
- type )));
413
+ errmsg_internal ("invalid replication message type %d" ,
414
+ type )));
414
415
}
415
416
}
416
417
0 commit comments