|
7 | 7 | * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.237 2006/04/20 04:07:38 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.238 2006/06/15 19:15:00 momjian Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -478,6 +478,7 @@ static bool InstallXLogFileSegment(uint32 *log, uint32 *seg, char *tmppath,
|
478 | 478 | bool use_lock);
|
479 | 479 | static int XLogFileOpen(uint32 log, uint32 seg);
|
480 | 480 | static int XLogFileRead(uint32 log, uint32 seg, int emode);
|
| 481 | +static void XLogFileClose(void); |
481 | 482 | static bool RestoreArchivedFile(char *path, const char *xlogfname,
|
482 | 483 | const char *recovername, off_t expectedSize);
|
483 | 484 | static int PreallocXlogFiles(XLogRecPtr endptr);
|
@@ -1384,14 +1385,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
|
1384 | 1385 | */
|
1385 | 1386 | Assert(npages == 0);
|
1386 | 1387 | if (openLogFile >= 0)
|
1387 |
| - { |
1388 |
| - if (close(openLogFile)) |
1389 |
| - ereport(PANIC, |
1390 |
| - (errcode_for_file_access(), |
1391 |
| - errmsg("could not close log file %u, segment %u: %m", |
1392 |
| - openLogId, openLogSeg))); |
1393 |
| - openLogFile = -1; |
1394 |
| - } |
| 1388 | + XLogFileClose(); |
1395 | 1389 | XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg);
|
1396 | 1390 |
|
1397 | 1391 | /* create/use new log file */
|
@@ -1567,14 +1561,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
|
1567 | 1561 | {
|
1568 | 1562 | if (openLogFile >= 0 &&
|
1569 | 1563 | !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
|
1570 |
| - { |
1571 |
| - if (close(openLogFile)) |
1572 |
| - ereport(PANIC, |
1573 |
| - (errcode_for_file_access(), |
1574 |
| - errmsg("could not close log file %u, segment %u: %m", |
1575 |
| - openLogId, openLogSeg))); |
1576 |
| - openLogFile = -1; |
1577 |
| - } |
| 1564 | + XLogFileClose(); |
1578 | 1565 | if (openLogFile < 0)
|
1579 | 1566 | {
|
1580 | 1567 | XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg);
|
@@ -2152,6 +2139,34 @@ XLogFileRead(uint32 log, uint32 seg, int emode)
|
2152 | 2139 | return -1;
|
2153 | 2140 | }
|
2154 | 2141 |
|
| 2142 | +/* |
| 2143 | + * Close the current logfile segment for writing. |
| 2144 | + */ |
| 2145 | +static void |
| 2146 | +XLogFileClose(void) |
| 2147 | +{ |
| 2148 | + Assert(openLogFile >= 0); |
| 2149 | + |
| 2150 | +#ifdef _POSIX_ADVISORY_INFO |
| 2151 | + /* |
| 2152 | + * WAL caches will not be accessed in the future, so we advise OS to |
| 2153 | + * free them. But we will not do so if WAL archiving is active, |
| 2154 | + * because archivers might use the caches to read the WAL segment. |
| 2155 | + * While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync() |
| 2156 | + * and O_SYNC, and some platforms only have posix_fadvise(). |
| 2157 | + */ |
| 2158 | + if (!XLogArchivingActive()) |
| 2159 | + posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED); |
| 2160 | +#endif |
| 2161 | + |
| 2162 | + if (close(openLogFile)) |
| 2163 | + ereport(PANIC, |
| 2164 | + (errcode_for_file_access(), |
| 2165 | + errmsg("could not close log file %u, segment %u: %m", |
| 2166 | + openLogId, openLogSeg))); |
| 2167 | + openLogFile = -1; |
| 2168 | +} |
| 2169 | + |
2155 | 2170 | /*
|
2156 | 2171 | * Attempt to retrieve the specified file from off-line archival storage.
|
2157 | 2172 | * If successful, fill "path" with its complete path (note that this will be
|
@@ -5609,14 +5624,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
|
5609 | 5624 | errmsg("could not fsync log file %u, segment %u: %m",
|
5610 | 5625 | openLogId, openLogSeg)));
|
5611 | 5626 | if (open_sync_bit != new_sync_bit)
|
5612 |
| - { |
5613 |
| - if (close(openLogFile)) |
5614 |
| - ereport(PANIC, |
5615 |
| - (errcode_for_file_access(), |
5616 |
| - errmsg("could not close log file %u, segment %u: %m", |
5617 |
| - openLogId, openLogSeg))); |
5618 |
| - openLogFile = -1; |
5619 |
| - } |
| 5627 | + XLogFileClose(); |
5620 | 5628 | }
|
5621 | 5629 | sync_method = new_sync_method;
|
5622 | 5630 | open_sync_bit = new_sync_bit;
|
|
0 commit comments