41
41
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
42
42
* Portions Copyright (c) 1994, Regents of the University of California
43
43
*
44
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.45 2009/01/01 17:23:36 momjian Exp $
44
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.46 2009/04/02 19:14:33 momjian Exp $
45
45
*
46
46
*-------------------------------------------------------------------------
47
47
*/
57
57
#include "storage/fd.h"
58
58
#include "storage/shmem.h"
59
59
#include "miscadmin.h"
60
+ #include "pg_trace.h"
60
61
61
62
62
63
/*
@@ -372,6 +373,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
372
373
{
373
374
SlruShared shared = ctl -> shared ;
374
375
376
+ TRACE_POSTGRESQL_SLRU_READPAGE_START ((uintptr_t )ctl , pageno , write_ok , xid );
375
377
/* Outer loop handles restart if we must wait for someone else's I/O */
376
378
for (;;)
377
379
{
@@ -399,6 +401,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
399
401
}
400
402
/* Otherwise, it's ready to use */
401
403
SlruRecentlyUsed (shared , slotno );
404
+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
402
405
return slotno ;
403
406
}
404
407
@@ -446,6 +449,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
446
449
SlruReportIOError (ctl , pageno , xid );
447
450
448
451
SlruRecentlyUsed (shared , slotno );
452
+ TRACE_POSTGRESQL_SLRU_READPAGE_DONE (slotno );
449
453
return slotno ;
450
454
}
451
455
}
@@ -470,6 +474,8 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
470
474
SlruShared shared = ctl -> shared ;
471
475
int slotno ;
472
476
477
+ TRACE_POSTGRESQL_SLRU_READPAGE_READONLY ((uintptr_t )ctl , pageno , xid );
478
+
473
479
/* Try to find the page while holding only shared lock */
474
480
LWLockAcquire (shared -> ControlLock , LW_SHARED );
475
481
@@ -511,6 +517,8 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
511
517
int pageno = shared -> page_number [slotno ];
512
518
bool ok ;
513
519
520
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_START ((uintptr_t )ctl , pageno , slotno );
521
+
514
522
/* If a write is in progress, wait for it to finish */
515
523
while (shared -> page_status [slotno ] == SLRU_PAGE_WRITE_IN_PROGRESS &&
516
524
shared -> page_number [slotno ] == pageno )
@@ -525,7 +533,10 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
525
533
if (!shared -> page_dirty [slotno ] ||
526
534
shared -> page_status [slotno ] != SLRU_PAGE_VALID ||
527
535
shared -> page_number [slotno ] != pageno )
536
+ {
537
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_DONE ();
528
538
return ;
539
+ }
529
540
530
541
/*
531
542
* Mark the slot write-busy, and clear the dirtybit. After this point, a
@@ -569,6 +580,8 @@ SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata)
569
580
/* Now it's okay to ereport if we failed */
570
581
if (!ok )
571
582
SlruReportIOError (ctl , pageno , InvalidTransactionId );
583
+
584
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_DONE ();
572
585
}
573
586
574
587
/*
@@ -593,6 +606,8 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
593
606
594
607
SlruFileName (ctl , path , segno );
595
608
609
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_START ((uintptr_t )ctl , path , pageno , slotno );
610
+
596
611
/*
597
612
* In a crash-and-restart situation, it's possible for us to receive
598
613
* commands to set the commit status of transactions whose bits are in
@@ -607,13 +622,15 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
607
622
{
608
623
slru_errcause = SLRU_OPEN_FAILED ;
609
624
slru_errno = errno ;
625
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
610
626
return false;
611
627
}
612
628
613
629
ereport (LOG ,
614
630
(errmsg ("file \"%s\" doesn't exist, reading as zeroes" ,
615
631
path )));
616
632
MemSet (shared -> page_buffer [slotno ], 0 , BLCKSZ );
633
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true, -1 , -1 );
617
634
return true;
618
635
}
619
636
@@ -622,6 +639,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
622
639
slru_errcause = SLRU_SEEK_FAILED ;
623
640
slru_errno = errno ;
624
641
close (fd );
642
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
625
643
return false;
626
644
}
627
645
@@ -631,16 +649,20 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
631
649
slru_errcause = SLRU_READ_FAILED ;
632
650
slru_errno = errno ;
633
651
close (fd );
652
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
634
653
return false;
635
654
}
636
655
637
656
if (close (fd ))
638
657
{
639
658
slru_errcause = SLRU_CLOSE_FAILED ;
640
659
slru_errno = errno ;
660
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
641
661
return false;
642
662
}
643
663
664
+ TRACE_POSTGRESQL_SLRU_READPAGE_PHYSICAL_DONE (true, -1 , -1 );
665
+
644
666
return true;
645
667
}
646
668
@@ -668,6 +690,8 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
668
690
char path [MAXPGPATH ];
669
691
int fd = -1 ;
670
692
693
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_START ((uintptr_t )ctl , pageno , slotno );
694
+
671
695
/*
672
696
* Honor the write-WAL-before-data rule, if appropriate, so that we do not
673
697
* write out data before associated WAL records. This is the same action
@@ -753,6 +777,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
753
777
{
754
778
slru_errcause = SLRU_OPEN_FAILED ;
755
779
slru_errno = errno ;
780
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
756
781
return false;
757
782
}
758
783
@@ -781,6 +806,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
781
806
slru_errno = errno ;
782
807
if (!fdata )
783
808
close (fd );
809
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
784
810
return false;
785
811
}
786
812
@@ -794,6 +820,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
794
820
slru_errno = errno ;
795
821
if (!fdata )
796
822
close (fd );
823
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
797
824
return false;
798
825
}
799
826
@@ -808,17 +835,20 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
808
835
slru_errcause = SLRU_FSYNC_FAILED ;
809
836
slru_errno = errno ;
810
837
close (fd );
838
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
811
839
return false;
812
840
}
813
841
814
842
if (close (fd ))
815
843
{
816
844
slru_errcause = SLRU_CLOSE_FAILED ;
817
845
slru_errno = errno ;
846
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (false, slru_errcause , slru_errno );
818
847
return false;
819
848
}
820
849
}
821
850
851
+ TRACE_POSTGRESQL_SLRU_WRITEPAGE_PHYSICAL_DONE (true, -1 , -1 );
822
852
return true;
823
853
}
824
854
0 commit comments