Commit fa3bd4db authored by Tom Lane's avatar Tom Lane

Error message editing: finish up undone task of reporting the problem

xid when we fail to access pg_clog.
parent 2a4a0c4d
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* slru.c * slru.c
* Simple LRU * Simple LRU buffering for transaction status logfiles
* *
* This module replaces the old "pg_log" access code, which treated pg_log * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* essentially like a relation, in that it went through the regular buffer
* manager. The problem with that was that there wasn't any good way to
* recycle storage space for transactions so old that they'll never be
* looked up again. Now we use specialized access code so that the commit
* log can be broken into relatively small, independent segments.
*
* Portions Copyright (c) 2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/slru.c,v 1.1 2003/06/11 22:37:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/slru.c,v 1.2 2003/07/19 21:37:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -363,7 +356,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid, bool forwrite) ...@@ -363,7 +356,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid, bool forwrite)
LWLockRelease(ctl->locks->BufferLocks[slotno]); LWLockRelease(ctl->locks->BufferLocks[slotno]);
/* Now it's okay to elog if we failed */ /* Now it's okay to ereport if we failed */
if (!ok) if (!ok)
SlruReportIOError(ctl, pageno, xid); SlruReportIOError(ctl, pageno, xid);
...@@ -449,7 +442,7 @@ SimpleLruWritePage(SlruCtl ctl, int slotno) ...@@ -449,7 +442,7 @@ SimpleLruWritePage(SlruCtl ctl, int slotno)
LWLockRelease(ctl->locks->BufferLocks[slotno]); LWLockRelease(ctl->locks->BufferLocks[slotno]);
/* Now it's okay to elog if we failed */ /* Now it's okay to ereport if we failed */
if (!ok) if (!ok)
SlruReportIOError(ctl, pageno, InvalidTransactionId); SlruReportIOError(ctl, pageno, InvalidTransactionId);
} }
...@@ -457,7 +450,7 @@ SimpleLruWritePage(SlruCtl ctl, int slotno) ...@@ -457,7 +450,7 @@ SimpleLruWritePage(SlruCtl ctl, int slotno)
/* /*
* Physical read of a (previously existing) page into a buffer slot * Physical read of a (previously existing) page into a buffer slot
* *
* On failure, we cannot just elog(ERROR) since caller has put state in * On failure, we cannot just ereport(ERROR) since caller has put state in
* shared memory that must be undone. So, we return FALSE and save enough * shared memory that must be undone. So, we return FALSE and save enough
* info in static variables to let SlruReportIOError make the report. * info in static variables to let SlruReportIOError make the report.
* *
...@@ -493,7 +486,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno) ...@@ -493,7 +486,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
return false; return false;
} }
elog(LOG, "file %s doesn't exist, reading as zeroes", path); ereport(LOG,
(errmsg("file \"%s\" doesn't exist, reading as zeroes",
path)));
MemSet(shared->page_buffer[slotno], 0, BLCKSZ); MemSet(shared->page_buffer[slotno], 0, BLCKSZ);
return true; return true;
} }
...@@ -520,7 +515,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno) ...@@ -520,7 +515,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
/* /*
* Physical write of a page from a buffer slot * Physical write of a page from a buffer slot
* *
* On failure, we cannot just elog(ERROR) since caller has put state in * On failure, we cannot just ereport(ERROR) since caller has put state in
* shared memory that must be undone. So, we return FALSE and save enough * shared memory that must be undone. So, we return FALSE and save enough
* info in static variables to let SlruReportIOError make the report. * info in static variables to let SlruReportIOError make the report.
* *
...@@ -606,33 +601,49 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid) ...@@ -606,33 +601,49 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
int offset = rpageno * BLCKSZ; int offset = rpageno * BLCKSZ;
char path[MAXPGPATH]; char path[MAXPGPATH];
/* XXX TODO: provide xid as context in error messages */
SlruFileName(ctl, path, segno); SlruFileName(ctl, path, segno);
errno = slru_errno; errno = slru_errno;
switch (slru_errcause) switch (slru_errcause)
{ {
case SLRU_OPEN_FAILED: case SLRU_OPEN_FAILED:
elog(ERROR, "open of %s failed: %m", path); ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not access status of transaction %u", xid),
errdetail("open of file \"%s\" failed: %m",
path)));
break; break;
case SLRU_CREATE_FAILED: case SLRU_CREATE_FAILED:
elog(ERROR, "creation of file %s failed: %m", path); ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not access status of transaction %u", xid),
errdetail("creation of file \"%s\" failed: %m",
path)));
break; break;
case SLRU_SEEK_FAILED: case SLRU_SEEK_FAILED:
elog(ERROR, "lseek of file %s, offset %u failed: %m", ereport(ERROR,
path, offset); (errcode_for_file_access(),
errmsg("could not access status of transaction %u", xid),
errdetail("lseek of file \"%s\", offset %u failed: %m",
path, offset)));
break; break;
case SLRU_READ_FAILED: case SLRU_READ_FAILED:
elog(ERROR, "read of file %s, offset %u failed: %m", ereport(ERROR,
path, offset); (errcode_for_file_access(),
errmsg("could not access status of transaction %u", xid),
errdetail("read of file \"%s\", offset %u failed: %m",
path, offset)));
break; break;
case SLRU_WRITE_FAILED: case SLRU_WRITE_FAILED:
elog(ERROR, "write of file %s, offset %u failed: %m", ereport(ERROR,
path, offset); (errcode_for_file_access(),
errmsg("could not access status of transaction %u", xid),
errdetail("write of file \"%s\", offset %u failed: %m",
path, offset)));
break; break;
default: default:
/* can't get here, we trust */ /* can't get here, we trust */
elog(ERROR, "unknown SimpleLru I/O error"); elog(ERROR, "unrecognized SimpleLru error cause: %d",
(int) slru_errcause);
break; break;
} }
} }
...@@ -799,7 +810,9 @@ restart:; ...@@ -799,7 +810,9 @@ restart:;
if (ctl->PagePrecedes(shared->latest_page_number, cutoffPage)) if (ctl->PagePrecedes(shared->latest_page_number, cutoffPage))
{ {
LWLockRelease(ctl->locks->ControlLock); LWLockRelease(ctl->locks->ControlLock);
elog(LOG, "unable to truncate %s: apparent wraparound", ctl->Dir); ereport(LOG,
(errmsg("unable to truncate \"%s\": apparent wraparound",
ctl->Dir)));
return; return;
} }
...@@ -855,7 +868,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions) ...@@ -855,7 +868,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
cldir = opendir(ctl->Dir); cldir = opendir(ctl->Dir);
if (cldir == NULL) if (cldir == NULL)
elog(ERROR, "could not open directory (%s): %m", ctl->Dir); ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m", ctl->Dir)));
errno = 0; errno = 0;
while ((clde = readdir(cldir)) != NULL) while ((clde = readdir(cldir)) != NULL)
...@@ -870,7 +885,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions) ...@@ -870,7 +885,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
found = true; found = true;
if (doDeletions) if (doDeletions)
{ {
elog(LOG, "removing file %s/%s", ctl->Dir, clde->d_name); ereport(LOG,
(errmsg("removing file \"%s/%s\"",
ctl->Dir, clde->d_name)));
snprintf(path, MAXPGPATH, "%s/%s", ctl->Dir, clde->d_name); snprintf(path, MAXPGPATH, "%s/%s", ctl->Dir, clde->d_name);
unlink(path); unlink(path);
} }
...@@ -879,7 +896,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions) ...@@ -879,7 +896,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
errno = 0; errno = 0;
} }
if (errno) if (errno)
elog(ERROR, "could not read directory (%s): %m", ctl->Dir); ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read directory \"%s\": %m", ctl->Dir)));
closedir(cldir); closedir(cldir);
return found; return found;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment