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
364357LWLockRelease (ctl -> locks -> BufferLocks [slotno ]);
365358
366- /* Now it's okay toelog if we failed */
359+ /* Now it's okay toereport if we failed */
367360if (!ok )
368361SlruReportIOError (ctl ,pageno ,xid );
369362
@@ -449,15 +442,15 @@ SimpleLruWritePage(SlruCtl ctl, int slotno)
449442
450443LWLockRelease (ctl -> locks -> BufferLocks [slotno ]);
451444
452- /* Now it's okay toelog if we failed */
445+ /* Now it's okay toereport if we failed */
453446if (!ok )
454447SlruReportIOError (ctl ,pageno ,InvalidTransactionId );
455448}
456449
457450/*
458451 * Physical read of a (previously existing) page into a buffer slot
459452 *
460- * On failure, we cannot justelog (ERROR) since caller has put state in
453+ * On failure, we cannot justereport (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)
493486return 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 )));
497492MemSet (shared -> page_buffer [slotno ],0 ,BLCKSZ );
498493return 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 justelog (ERROR) since caller has put state in
518+ * On failure, we cannot justereport (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)
606601int offset = rpageno * BLCKSZ ;
607602char path [MAXPGPATH ];
608603
609- /* XXX TODO: provide xid as context in error messages */
610-
611604SlruFileName (ctl ,path ,segno );
612605errno = slru_errno ;
613606switch (slru_errcause )
614607{
615608case 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 )));
617614break ;
618615case 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 )));
620621break ;
621622case 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 )));
624628break ;
625629case 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 )));
628635break ;
629636case 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 )));
632642break ;
633643default :
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 );
636647break ;
637648}
638649}
@@ -799,7 +810,9 @@ restart:;
799810if (ctl -> PagePrecedes (shared -> latest_page_number ,cutoffPage ))
800811{
801812LWLockRelease (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 )));
803816return ;
804817}
805818
@@ -855,7 +868,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
855868
856869cldir = opendir (ctl -> Dir );
857870if (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
860875errno = 0 ;
861876while ((clde = readdir (cldir ))!= NULL )
@@ -870,7 +885,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
870885found = true;
871886if (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 )));
874891snprintf (path ,MAXPGPATH ,"%s/%s" ,ctl -> Dir ,clde -> d_name );
875892unlink (path );
876893}
@@ -879,7 +896,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
879896errno = 0 ;
880897}
881898if (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 )));
883902closedir (cldir );
884903
885904return found ;