25
25
#include "receivelog.h"
26
26
#include "streamutil.h"
27
27
28
- /* fd and filename for currently open WAL file */
28
+ /* currently open WAL file */
29
29
static Walfile * walfile = NULL ;
30
- static char current_walfile_name [MAXPGPATH ] = "" ;
31
30
static bool reportFlushPosition = false;
32
31
static XLogRecPtr lastFlushPosition = InvalidXLogRecPtr ;
33
32
@@ -82,8 +81,7 @@ mark_file_as_archived(StreamCtl *stream, const char *fname)
82
81
* Open a new WAL file in the specified directory.
83
82
*
84
83
* Returns true if OK; on failure, returns false after printing an error msg.
85
- * On success, 'walfile' is set to the FD for the file, and the base filename
86
- * (without partial_suffix) is stored in 'current_walfile_name'.
84
+ * On success, 'walfile' is set to the opened WAL file.
87
85
*
88
86
* The file will be padded to 16Mb with zeroes.
89
87
*/
@@ -94,12 +92,13 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
94
92
char * fn ;
95
93
ssize_t size ;
96
94
XLogSegNo segno ;
95
+ char walfile_name [MAXPGPATH ];
97
96
98
97
XLByteToSeg (startpoint , segno , WalSegSz );
99
- XLogFileName (current_walfile_name , stream -> timeline , segno , WalSegSz );
98
+ XLogFileName (walfile_name , stream -> timeline , segno , WalSegSz );
100
99
101
100
/* Note that this considers the compression used if necessary */
102
- fn = stream -> walmethod -> get_file_name (current_walfile_name ,
101
+ fn = stream -> walmethod -> get_file_name (walfile_name ,
103
102
stream -> partial_suffix );
104
103
105
104
/*
@@ -126,7 +125,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
126
125
if (size == WalSegSz )
127
126
{
128
127
/* Already padded file. Open it for use */
129
- f = stream -> walmethod -> open_for_write (current_walfile_name , stream -> partial_suffix , 0 );
128
+ f = stream -> walmethod -> open_for_write (walfile_name , stream -> partial_suffix , 0 );
130
129
if (f == NULL )
131
130
{
132
131
pg_log_error ("could not open existing write-ahead log file \"%s\": %s" ,
@@ -165,7 +164,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
165
164
166
165
/* No file existed, so create one */
167
166
168
- f = stream -> walmethod -> open_for_write (current_walfile_name ,
167
+ f = stream -> walmethod -> open_for_write (walfile_name ,
169
168
stream -> partial_suffix , WalSegSz );
170
169
if (f == NULL )
171
170
{
@@ -191,27 +190,18 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
191
190
char * fn ;
192
191
off_t currpos ;
193
192
int r ;
193
+ char walfile_name [MAXPGPATH ];
194
194
195
195
if (walfile == NULL )
196
196
return true;
197
197
198
+ strlcpy (walfile_name , walfile -> pathname , MAXPGPATH );
199
+ currpos = walfile -> currpos ;
200
+
198
201
/* Note that this considers the compression used if necessary */
199
- fn = stream -> walmethod -> get_file_name (current_walfile_name ,
202
+ fn = stream -> walmethod -> get_file_name (walfile_name ,
200
203
stream -> partial_suffix );
201
204
202
- currpos = stream -> walmethod -> get_current_pos (walfile );
203
-
204
- if (currpos == -1 )
205
- {
206
- pg_log_error ("could not determine seek position in file \"%s\": %s" ,
207
- fn , stream -> walmethod -> getlasterror ());
208
- stream -> walmethod -> close (walfile , CLOSE_UNLINK );
209
- walfile = NULL ;
210
-
211
- pg_free (fn );
212
- return false;
213
- }
214
-
215
205
if (stream -> partial_suffix )
216
206
{
217
207
if (currpos == WalSegSz )
@@ -247,7 +237,7 @@ close_walfile(StreamCtl *stream, XLogRecPtr pos)
247
237
if (currpos == WalSegSz && stream -> mark_done )
248
238
{
249
239
/* writes error message if failed */
250
- if (!mark_file_as_archived (stream , current_walfile_name ))
240
+ if (!mark_file_as_archived (stream , walfile_name ))
251
241
return false;
252
242
}
253
243
@@ -690,7 +680,7 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
690
680
error :
691
681
if (walfile != NULL && stream -> walmethod -> close (walfile , CLOSE_NO_RENAME ) != 0 )
692
682
pg_log_error ("could not close file \"%s\": %s" ,
693
- current_walfile_name , stream -> walmethod -> getlasterror ());
683
+ walfile -> pathname , stream -> walmethod -> getlasterror ());
694
684
walfile = NULL ;
695
685
return false;
696
686
}
@@ -777,7 +767,7 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
777
767
{
778
768
if (stream -> walmethod -> sync (walfile ) != 0 )
779
769
pg_fatal ("could not fsync file \"%s\": %s" ,
780
- current_walfile_name , stream -> walmethod -> getlasterror ());
770
+ walfile -> pathname , stream -> walmethod -> getlasterror ());
781
771
lastFlushPosition = blockpos ;
782
772
783
773
/*
@@ -1024,7 +1014,7 @@ ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
1024
1014
*/
1025
1015
if (stream -> walmethod -> sync (walfile ) != 0 )
1026
1016
pg_fatal ("could not fsync file \"%s\": %s" ,
1027
- current_walfile_name , stream -> walmethod -> getlasterror ());
1017
+ walfile -> pathname , stream -> walmethod -> getlasterror ());
1028
1018
lastFlushPosition = blockpos ;
1029
1019
}
1030
1020
@@ -1092,10 +1082,10 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
1092
1082
else
1093
1083
{
1094
1084
/* More data in existing segment */
1095
- if (stream -> walmethod -> get_current_pos ( walfile ) != xlogoff )
1085
+ if (walfile -> currpos != xlogoff )
1096
1086
{
1097
1087
pg_log_error ("got WAL data offset %08x, expected %08x" ,
1098
- xlogoff , (int ) stream -> walmethod -> get_current_pos ( walfile ) );
1088
+ xlogoff , (int ) walfile -> currpos );
1099
1089
return false;
1100
1090
}
1101
1091
}
@@ -1129,7 +1119,7 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
1129
1119
bytes_to_write ) != bytes_to_write )
1130
1120
{
1131
1121
pg_log_error ("could not write %d bytes to WAL file \"%s\": %s" ,
1132
- bytes_to_write , current_walfile_name ,
1122
+ bytes_to_write , walfile -> pathname ,
1133
1123
stream -> walmethod -> getlasterror ());
1134
1124
return false;
1135
1125
}
0 commit comments