diff options
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 5f0ee50092c..ad084684205 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2499,14 +2499,21 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) pgstat_report_wait_end(); if (written <= 0) { + char xlogfname[MAXFNAMELEN]; + int save_errno; + if (errno == EINTR) continue; + + save_errno = errno; + XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, + wal_segment_size); + errno = save_errno; ereport(PANIC, (errcode_for_file_access(), errmsg("could not write to log file %s " "at offset %u, length %zu: %m", - XLogFileNameP(ThisTimeLineID, openLogSegNo), - startoffset, nleft))); + xlogfname, startoffset, nleft))); } nleft -= written; from += written; @@ -3792,10 +3799,17 @@ XLogFileClose(void) #endif if (close(openLogFile) != 0) + { + char xlogfname[MAXFNAMELEN]; + int save_errno = errno; + + XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, wal_segment_size); + errno = save_errno; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not close file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, openLogSegNo)))); + errmsg("could not close file \"%s\": %m", xlogfname))); + } + openLogFile = -1; } @@ -5510,10 +5524,17 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog) fd = XLogFileInit(startLogSegNo, &use_existent, true); if (close(fd) != 0) + { + char xlogfname[MAXFNAMELEN]; + int save_errno = errno; + + XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, + wal_segment_size); + errno = save_errno; ereport(ERROR, (errcode_for_file_access(), - errmsg("could not close file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, startLogSegNo)))); + errmsg("could not close file \"%s\": %m", xlogfname))); + } } /* @@ -10079,10 +10100,19 @@ assign_xlog_sync_method(int new_sync_method, void *extra) { pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN); if (pg_fsync(openLogFile) != 0) + { + char xlogfname[MAXFNAMELEN]; + int save_errno; + + save_errno = errno; + XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, + wal_segment_size); + errno = save_errno; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not fsync file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, openLogSegNo)))); + errmsg("could not fsync file \"%s\": %m", xlogfname))); + } + pgstat_report_wait_end(); if (get_sync_bit(sync_method) != get_sync_bit(new_sync_method)) XLogFileClose(); @@ -10100,32 +10130,25 @@ assign_xlog_sync_method(int new_sync_method, void *extra) void issue_xlog_fsync(int fd, XLogSegNo segno) { + char *msg = NULL; + pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC); switch (sync_method) { case SYNC_METHOD_FSYNC: if (pg_fsync_no_writethrough(fd) != 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not fsync file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, segno)))); + msg = _("could not fsync file \"%s\": %m"); break; #ifdef HAVE_FSYNC_WRITETHROUGH case SYNC_METHOD_FSYNC_WRITETHROUGH: if (pg_fsync_writethrough(fd) != 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not fsync write-through file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, segno)))); + msg = _("could not fsync write-through file \"%s\": %m"); break; #endif #ifdef HAVE_FDATASYNC case SYNC_METHOD_FDATASYNC: if (pg_fdatasync(fd) != 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not fdatasync file \"%s\": %m", - XLogFileNameP(ThisTimeLineID, segno)))); + msg = _("could not fdatasync file \"%s\": %m"); break; #endif case SYNC_METHOD_OPEN: @@ -10136,19 +10159,22 @@ issue_xlog_fsync(int fd, XLogSegNo segno) elog(PANIC, "unrecognized wal_sync_method: %d", sync_method); break; } - pgstat_report_wait_end(); -} -/* - * Return the filename of given log segment, as a palloc'd string. - */ -char * -XLogFileNameP(TimeLineID tli, XLogSegNo segno) -{ - char *result = palloc(MAXFNAMELEN); + /* PANIC if failed to fsync */ + if (msg) + { + char xlogfname[MAXFNAMELEN]; + int save_errno = errno; - XLogFileName(result, tli, segno, wal_segment_size); - return result; + XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, + wal_segment_size); + errno = save_errno; + ereport(PANIC, + (errcode_for_file_access(), + errmsg(msg, xlogfname))); + } + + pgstat_report_wait_end(); } /* |