aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/localbuf.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2020-04-08 13:36:45 +1200
committerThomas Munro <tmunro@postgresql.org>2020-04-08 14:56:57 +1200
commit3985b600f57d75b9743d86430cb5c21370057a23 (patch)
treef367f4511386eeacf127a8e8b25afc9f8ea46101 /src/backend/storage/buffer/localbuf.c
parent981643dcdb70b6ce70d8a08417f71f465f236cb5 (diff)
downloadpostgresql-3985b600f57d75b9743d86430cb5c21370057a23.tar.gz
postgresql-3985b600f57d75b9743d86430cb5c21370057a23.zip
Support PrefetchBuffer() in recovery.
Provide PrefetchSharedBuffer(), a variant that takes SMgrRelation, for use in recovery. Rename LocalPrefetchBuffer() to PrefetchLocalBuffer() for consistency. Add a return value to all of these. In recovery, tolerate and report missing files, so we can handle relations unlinked before crash recovery began. Also report cache hits and misses, so that callers can do faster buffer lookups and better I/O accounting. Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKGJ4VJN8ttxScUFM8dOKX0BrBiboo5uz1cq%3DAovOddfHpA%40mail.gmail.com
Diffstat (limited to 'src/backend/storage/buffer/localbuf.c')
-rw-r--r--src/backend/storage/buffer/localbuf.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index cac08e1b1ac..6ffd7b33062 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -54,17 +54,17 @@ static Block GetLocalBufferStorage(void);
/*
- * LocalPrefetchBuffer -
+ * PrefetchLocalBuffer -
* initiate asynchronous read of a block of a relation
*
* Do PrefetchBuffer's work for temporary relations.
* No-op if prefetching isn't compiled in.
*/
-void
-LocalPrefetchBuffer(SMgrRelation smgr, ForkNumber forkNum,
+PrefetchBufferResult
+PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum,
BlockNumber blockNum)
{
-#ifdef USE_PREFETCH
+ PrefetchBufferResult result = {InvalidBuffer, false};
BufferTag newTag; /* identity of requested block */
LocalBufferLookupEnt *hresult;
@@ -81,12 +81,18 @@ LocalPrefetchBuffer(SMgrRelation smgr, ForkNumber forkNum,
if (hresult)
{
/* Yes, so nothing to do */
- return;
+ result.recent_buffer = -hresult->id - 1;
}
-
- /* Not in buffers, so initiate prefetch */
- smgrprefetch(smgr, forkNum, blockNum);
+ else
+ {
+#ifdef USE_PREFETCH
+ /* Not in buffers, so initiate prefetch */
+ smgrprefetch(smgr, forkNum, blockNum);
+ result.initiated_io = true;
#endif /* USE_PREFETCH */
+ }
+
+ return result;
}