1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* slru.c
4
- * Simple LRU
4
+ * Simple LRU buffering for transaction status logfiles
5
5
*
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
14
7
* Portions Copyright (c) 1994, Regents of the University of California
15
8
*
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 $
17
10
*
18
11
*-------------------------------------------------------------------------
19
12
*/
@@ -363,7 +356,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid, bool forwrite)
363
356
364
357
LWLockRelease (ctl -> locks -> BufferLocks [slotno ]);
365
358
366
- /* Now it's okay to elog if we failed */
359
+ /* Now it's okay to ereport if we failed */
367
360
if (!ok )
368
361
SlruReportIOError (ctl , pageno , xid );
369
362
@@ -449,15 +442,15 @@ SimpleLruWritePage(SlruCtl ctl, int slotno)
449
442
450
443
LWLockRelease (ctl -> locks -> BufferLocks [slotno ]);
451
444
452
- /* Now it's okay to elog if we failed */
445
+ /* Now it's okay to ereport if we failed */
453
446
if (!ok )
454
447
SlruReportIOError (ctl , pageno , InvalidTransactionId );
455
448
}
456
449
457
450
/*
458
451
* Physical read of a (previously existing) page into a buffer slot
459
452
*
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
461
454
* shared memory that must be undone. So, we return FALSE and save enough
462
455
* info in static variables to let SlruReportIOError make the report.
463
456
*
@@ -493,7 +486,9 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
493
486
return false;
494
487
}
495
488
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 )));
497
492
MemSet (shared -> page_buffer [slotno ], 0 , BLCKSZ );
498
493
return true;
499
494
}
@@ -520,7 +515,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
520
515
/*
521
516
* Physical write of a page from a buffer slot
522
517
*
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
524
519
* shared memory that must be undone. So, we return FALSE and save enough
525
520
* info in static variables to let SlruReportIOError make the report.
526
521
*
@@ -606,33 +601,49 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
606
601
int offset = rpageno * BLCKSZ ;
607
602
char path [MAXPGPATH ];
608
603
609
- /* XXX TODO: provide xid as context in error messages */
610
-
611
604
SlruFileName (ctl , path , segno );
612
605
errno = slru_errno ;
613
606
switch (slru_errcause )
614
607
{
615
608
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 )));
617
614
break ;
618
615
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 )));
620
621
break ;
621
622
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 )));
624
628
break ;
625
629
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 )));
628
635
break ;
629
636
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 )));
632
642
break ;
633
643
default :
634
644
/* 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 );
636
647
break ;
637
648
}
638
649
}
@@ -799,7 +810,9 @@ restart:;
799
810
if (ctl -> PagePrecedes (shared -> latest_page_number , cutoffPage ))
800
811
{
801
812
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 )));
803
816
return ;
804
817
}
805
818
@@ -855,7 +868,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
855
868
856
869
cldir = opendir (ctl -> Dir );
857
870
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 )));
859
874
860
875
errno = 0 ;
861
876
while ((clde = readdir (cldir )) != NULL )
@@ -870,7 +885,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
870
885
found = true;
871
886
if (doDeletions )
872
887
{
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 )));
874
891
snprintf (path , MAXPGPATH , "%s/%s" , ctl -> Dir , clde -> d_name );
875
892
unlink (path );
876
893
}
@@ -879,7 +896,9 @@ SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions)
879
896
errno = 0 ;
880
897
}
881
898
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 )));
883
902
closedir (cldir );
884
903
885
904
return found ;
0 commit comments