From 3985b600f57d75b9743d86430cb5c21370057a23 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Wed, 8 Apr 2020 13:36:45 +1200 Subject: 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 Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CA%2BhUKGJ4VJN8ttxScUFM8dOKX0BrBiboo5uz1cq%3DAovOddfHpA%40mail.gmail.com --- src/backend/storage/buffer/localbuf.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/backend/storage/buffer/localbuf.c') 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; } -- cgit v1.2.3