Skip to content

Commit fa3bd4d

Browse files
committed
Error message editing: finish up undone task of reporting the problem
xid when we fail to access pg_clog.
1 parent 2a4a0c4 commit fa3bd4d

File tree

1 file changed

+49
-30
lines changed
  • src/backend/access/transam

1 file changed

+49
-30
lines changed

src/backend/access/transam/slru.c

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
/*-------------------------------------------------------------------------
22
*
33
* slru.c
4-
* Simple LRU
4+
* Simple LRU buffering for transaction status logfiles
55
*
6-
* This module replaces the old "pg_log" access code, which treated pg_log
7-
* essentially like a relation, in that it went through the regular buffer
8-
* manager. The problem with that was that there wasn't any good way to
9-
* recycle storage space for transactions so old that they'll never be
10-
* looked up again. Now we use specialized access code so that the commit
11-
* log can be broken into relatively small, independent segments.
12-
*
13-
* Portions Copyright (c) 2003, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
147
* Portions Copyright (c) 1994, Regents of the University of California
158
*
16-
* $Header: /cvsroot/pgsql/src/backend/access/transam/slru.c,v 1.1 2003/06/11 22:37:45 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/slru.c,v 1.2 2003/07/19 21:37:37 tgl Exp $
1710
*
1811
*-------------------------------------------------------------------------
1912
*/
@@ -363,7 +356,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid, bool forwrite)
363356

364357
LWLockRelease(ctl->locks->BufferLocks[slotno]);
365358

366-
/* Now it's okay to elog if we failed */
359+
/* Now it's okay to ereport if we failed */
367360
if (!ok)
368361
SlruReportIOError(ctl, pageno, xid);
369362

@@ -449,15 +442,15 @@ SimpleLruWritePage(SlruCtl ctl, int slotno)
449442

450443
LWLockRelease(ctl->locks->BufferLocks[slotno]);
451444

452-
/* Now it's okay to elog if we failed */
445+
/* Now it's okay to ereport if we failed */
453446
if (!ok)
454447
SlruReportIOError(ctl, pageno, InvalidTransactionId);
455448
}
456449

457450
/*
458451
* Physical read of a (previously existing) page into a buffer slot
459452
*
460-
* On failure, we cannot just elog(ERROR) since caller has put state in
453+
* On failure, we cannot just ereport(ERROR) since caller has put state in
461454
* shared memory that must be undone. So, we return FALSE and save enough
462455
* info in static variables to let SlruReportIOError make the report.
463456
*
@@ -493,7 +486,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
493486
return false;
494487
}
495488

496-
elog(LOG, "file %s doesn't exist, reading as zeroes", path);
489+
ereport(LOG,
490+
(errmsg("file \"%s\" doesn't exist, reading as zeroes",
491+
path)));
497492
MemSet(shared->page_buffer[slotno], 0, BLCKSZ);
498493
return true;
499494
}
@@ -520,7 +515,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
520515
/*
521516
* Physical write of a page from a buffer slot
522517
*
523-
* On failure, we cannot just elog(ERROR) since caller has put state in
518+
* On failure, we cannot just ereport(ERROR) since caller has put state in
524519
* shared memory that must be undone. So, we return FALSE and save enough
525520
* info in static variables to let SlruReportIOError make the report.
526521
*
@@ -606,33 +601,49 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
606601
int offset = rpageno * BLCKSZ;
607602
char path[MAXPGPATH];
608603

609-
/* XXX TODO: provide xid as context in error messages */
610-
611604
SlruFileName(ctl, path, segno);
612605
errno = slru_errno;
613606
switch (slru_errcause)
614607
{
615608
case SLRU_OPEN_FAILED:
616-
elog(ERROR, "open of %s failed: %m", path);
609+
ereport(ERROR,
610+
(errcode_for_file_access(),
611+
errmsg("could not access status of transaction %u", xid),
612+
errdetail("open of file \"%s\" failed: %m",
613+
path)));
617614
break;
618615
case SLRU_CREATE_FAILED:
619-
elog(ERROR, "creation of file %s failed: %m", path);
616+
ereport(ERROR,
617+
(errcode_for_file_access(),
618+
errmsg("could not access status of transaction %u", xid),
619+
errdetail("creation of file \"%s\" failed: %m",
620+
path)));
620621
break;
621622
case SLRU_SEEK_FAILED:
622-
elog(ERROR, "lseek of file %s, offset %u failed: %m",
623-
path, offset);
623+
ereport(ERROR,
624+
(errcode_for_file_access(),
625+
errmsg("could not access status of transaction %u", xid),
626+
errdetail("lseek of file \"%s\", offset %u failed: %m",
627+
path, offset)));
624628
break;
625629
case SLRU_READ_FAILED:
626-
elog(ERROR, "read of file %s, offset %u failed: %m",
627-
path, offset);
630+
ereport(ERROR,
631+
(errcode_for_file_access(),
632+
errmsg("could not access status of transaction %u", xid),
633+
errdetail("read of file \"%s\", offset %u failed: %m",
634+
path, offset)));
628635
break;
629636
case SLRU_WRITE_FAILED:
630-
elog(ERROR, "write of file %s, offset %u failed: %m",
631-
path, offset);
637+
ereport(ERROR,
638+
(errcode_for_file_access(),
639+
errmsg("could not access status of transaction %u", xid),
640+
errdetail("write of file \"%s\", offset %u failed: %m",
641+
path, offset)));
632642
break;
633643
default:
634644
/* can't get here, we trust */
635-
elog(ERROR, "unknown SimpleLru I/O error");
645+
elog(ERROR, "unrecognized SimpleLru error cause: %d",
646+
(int) slru_errcause);
636647
break;
637648
}
638649
}
@@ -799,7 +810,9 @@ restart:;
799810
if (ctl->PagePrecedes(shared->latest_page_number, cutoffPage))
800811
{
801812
LWLockRelease(ctl->locks->ControlLock);
802-
elog(LOG, "unable to truncate %s: apparent wraparound", ctl->Dir);
813+
ereport(LOG,
814+
(errmsg("unable to truncate \"%s\": apparent wraparound",
815+
ctl->Dir)));
803816
return;
804817
}
805818

@@ -855,7 +868,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
855868

856869
cldir = opendir(ctl->Dir);
857870
if (cldir == NULL)
858-
elog(ERROR, "could not open directory (%s): %m", ctl->Dir);
871+
ereport(ERROR,
872+
(errcode_for_file_access(),
873+
errmsg("could not open directory \"%s\": %m", ctl->Dir)));
859874

860875
errno = 0;
861876
while ((clde = readdir(cldir)) != NULL)
@@ -870,7 +885,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
870885
found = true;
871886
if (doDeletions)
872887
{
873-
elog(LOG, "removing file %s/%s", ctl->Dir, clde->d_name);
888+
ereport(LOG,
889+
(errmsg("removing file \"%s/%s\"",
890+
ctl->Dir, clde->d_name)));
874891
snprintf(path, MAXPGPATH, "%s/%s", ctl->Dir, clde->d_name);
875892
unlink(path);
876893
}
@@ -879,7 +896,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
879896
errno = 0;
880897
}
881898
if (errno)
882-
elog(ERROR, "could not read directory (%s): %m", ctl->Dir);
899+
ereport(ERROR,
900+
(errcode_for_file_access(),
901+
errmsg("could not read directory \"%s\": %m", ctl->Dir)));
883902
closedir(cldir);
884903

885904
return found;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy