Hello.
I happened to see the following in XLogWrite.
> ereport(PANIC,
> (errcode_for_file_access(),
> errmsg("could not seek in log file %s to offset %u: %m",
> XLogFileNameP(ThisTimeLineID, openLogSegNo),
> startoffset)));
where XLogFileNameP calls palloc within, and it is within a
critical section there. So it ends with assertion failure hiding
the PANIC message. We should use XLogFileName instead. The
problem has existed at least since 9.3. The code is frequently
revised so the patch needed to vary into four files.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 1641,1651 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! startoffset)));
openLogOff = startoffset;
}
--- 1641,1660 ----
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! xlogfname, startoffset)));
! }
!
openLogOff = startoffset;
}
***************
*** 1655,1660 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
--- 1664,1677 ----
errno = 0;
if (write(openLogFile, from, nbytes) != nbytes)
{
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
+
/* if write didn't set errno, assume no disk space */
if (errno == 0)
errno = ENOSPC;
***************
*** 1662,1668 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %lu: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
openLogOff, (unsigned long) nbytes)));
}
--- 1679,1685 ----
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %lu: %m",
! xlogfname,
openLogOff, (unsigned long) nbytes)));
}
***************
*** 2802,2811 **** XLogFileClose(void)
#endif
if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo))));
openLogFile = -1;
}
--- 2819,2837 ----
#endif
if (close(openLogFile))
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m", xlogfname)));
! }
!
openLogFile = -1;
}
***************
*** 8607,8612 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 8633,8646 ----
void
issue_xlog_fsync(int fd, XLogSegNo segno)
{
+ /*
+ * We are within a critical section here so we cannot use let
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, segno);
+
switch (sync_method)
{
case SYNC_METHOD_FSYNC:
***************
*** 8614,8620 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
--- 8648,8654 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! xlogfname)));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
***************
*** 8622,8628 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
#ifdef HAVE_FDATASYNC
--- 8656,8662 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! xlogfname)));
break;
#endif
#ifdef HAVE_FDATASYNC
***************
*** 8631,8637 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
case SYNC_METHOD_OPEN:
--- 8665,8671 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! xlogfname)));
break;
#endif
case SYNC_METHOD_OPEN:
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 2463,2473 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! startoffset)));
openLogOff = startoffset;
}
--- 2463,2482 ----
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! xlogfname, startoffset)));
! }
!
openLogOff = startoffset;
}
***************
*** 2481,2494 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
written = write(openLogFile, from, nleft);
if (written <= 0)
{
if (errno == EINTR)
continue;
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! openLogOff, nbytes)));
}
nleft -= written;
from += written;
--- 2490,2510 ----
written = write(openLogFile, from, nleft);
if (written <= 0)
{
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
if (errno == EINTR)
continue;
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! xlogfname, openLogOff, nbytes)));
}
nleft -= written;
from += written;
***************
*** 3669,3678 **** XLogFileClose(void)
#endif
if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo))));
openLogFile = -1;
}
--- 3685,3703 ----
#endif
if (close(openLogFile))
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m", xlogfname)));
! }
!
openLogFile = -1;
}
***************
*** 9799,9804 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 9824,9837 ----
void
issue_xlog_fsync(int fd, XLogSegNo segno)
{
+ /*
+ * We are within a critical section here so we cannot use let
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, segno);
+
switch (sync_method)
{
case SYNC_METHOD_FSYNC:
***************
*** 9806,9812 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
--- 9839,9845 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! xlogfname)));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
***************
*** 9814,9820 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
#ifdef HAVE_FDATASYNC
--- 9847,9853 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! xlogfname)));
break;
#endif
#ifdef HAVE_FDATASYNC
***************
*** 9823,9829 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
case SYNC_METHOD_OPEN:
--- 9856,9862 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! xlogfname)));
break;
#endif
case SYNC_METHOD_OPEN:
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 2450,2460 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! startoffset)));
openLogOff = startoffset;
}
--- 2450,2469 ----
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! xlogfname, startoffset)));
! }
!
openLogOff = startoffset;
}
***************
*** 2470,2483 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
pgstat_report_wait_end();
if (written <= 0)
{
if (errno == EINTR)
continue;
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! openLogOff, nbytes)));
}
nleft -= written;
from += written;
--- 2479,2499 ----
pgstat_report_wait_end();
if (written <= 0)
{
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
if (errno == EINTR)
continue;
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! xlogfname, openLogOff, nbytes)));
}
nleft -= written;
from += written;
***************
*** 3718,3727 **** XLogFileClose(void)
#endif
if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo))));
openLogFile = -1;
}
--- 3734,3752 ----
#endif
if (close(openLogFile))
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo);
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m", xlogfname)));
! }
!
openLogFile = -1;
}
***************
*** 10117,10122 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 10142,10155 ----
void
issue_xlog_fsync(int fd, XLogSegNo segno)
{
+ /*
+ * We are within a critical section here so we cannot use let
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, segno);
+
switch (sync_method)
{
case SYNC_METHOD_FSYNC:
***************
*** 10124,10130 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
--- 10157,10163 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! xlogfname)));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
***************
*** 10132,10138 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
#ifdef HAVE_FDATASYNC
--- 10165,10171 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! xlogfname)));
break;
#endif
#ifdef HAVE_FDATASYNC
***************
*** 10141,10147 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
case SYNC_METHOD_OPEN:
--- 10174,10180 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! xlogfname)));
break;
#endif
case SYNC_METHOD_OPEN:
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 2474,2484 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! startoffset)));
openLogOff = startoffset;
}
--- 2474,2494 ----
if (openLogOff != startoffset)
{
if (lseek(openLogFile, (off_t) startoffset, SEEK_SET) < 0)
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo,
+ wal_segment_size);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not seek in log file %s to offset %u: %m",
! xlogfname, startoffset)));
! }
!
openLogOff = startoffset;
}
***************
*** 2494,2507 **** XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
pgstat_report_wait_end();
if (written <= 0)
{
if (errno == EINTR)
continue;
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo),
! openLogOff, nbytes)));
}
nleft -= written;
from += written;
--- 2504,2525 ----
pgstat_report_wait_end();
if (written <= 0)
{
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
if (errno == EINTR)
continue;
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo,
+ wal_segment_size);
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not write to log file %s "
"at offset %u, length %zu: %m",
! xlogfname, openLogOff, nbytes)));
}
nleft -= written;
from += written;
***************
*** 3740,3749 **** XLogFileClose(void)
#endif
if (close(openLogFile))
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m",
! XLogFileNameP(ThisTimeLineID, openLogSegNo))));
openLogFile = -1;
}
--- 3758,3776 ----
#endif
if (close(openLogFile))
+ {
+ /*
+ * We are within a critical section here so we cannot use
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, openLogSegNo, wal_segment_size);
ereport(PANIC,
(errcode_for_file_access(),
! errmsg("could not close log file %s: %m", xlogfname)));
! }
!
openLogFile = -1;
}
***************
*** 10153,10158 **** assign_xlog_sync_method(int new_sync_method, void *extra)
--- 10180,10193 ----
void
issue_xlog_fsync(int fd, XLogSegNo segno)
{
+ /*
+ * We are within a critical section here so we cannot use let
+ * XLogFileNameP. Use this buffer instead.
+ */
+ char xlogfname[MAXFNAMELEN];
+
+ XLogFileName(xlogfname, ThisTimeLineID, segno, wal_segment_size);
+
switch (sync_method)
{
case SYNC_METHOD_FSYNC:
***************
*** 10160,10166 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
--- 10195,10201 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync log file %s: %m",
! xlogfname)));
break;
#ifdef HAVE_FSYNC_WRITETHROUGH
case SYNC_METHOD_FSYNC_WRITETHROUGH:
***************
*** 10168,10174 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
#ifdef HAVE_FDATASYNC
--- 10203,10209 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fsync write-through log file %s: %m",
! xlogfname)));
break;
#endif
#ifdef HAVE_FDATASYNC
***************
*** 10177,10183 **** issue_xlog_fsync(int fd, XLogSegNo segno)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! XLogFileNameP(ThisTimeLineID, segno))));
break;
#endif
case SYNC_METHOD_OPEN:
--- 10212,10218 ----
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not fdatasync log file %s: %m",
! xlogfname)));
break;
#endif
case SYNC_METHOD_OPEN: