mirror of
https://github.com/postgres/postgres.git
synced 2025-10-13 18:28:01 +03:00
Add CHECK_FOR_INTERRUPTS in contrib/pg_buffercache functions.
This commit adds CHECK_FOR_INTERRUPTS to loops iterating over shared buffers in several pg_buffercache functions, allowing them to be interrupted during long-running operations. Backpatch to all supported versions. Add CHECK_FOR_INTERRUPTS to the loop in pg_buffercache_pages() in all supported branches, and to pg_buffercache_summary() and pg_buffercache_usage_counts() in version 16 and newer. Author: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> Discussion: https://postgr.es/m/CAHg+QDcejeLx7WunFT3DX6XKh1KshvGKa8F5au8xVhqVvvQPRw@mail.gmail.com Backpatch-through: 13
This commit is contained in:
@@ -194,6 +194,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
|
|||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
uint32 buf_state;
|
uint32 buf_state;
|
||||||
|
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
bufHdr = GetBufferDescriptor(i);
|
bufHdr = GetBufferDescriptor(i);
|
||||||
/* Lock each buffer header before inspecting. */
|
/* Lock each buffer header before inspecting. */
|
||||||
buf_state = LockBufHdr(bufHdr);
|
buf_state = LockBufHdr(bufHdr);
|
||||||
@@ -560,6 +562,8 @@ pg_buffercache_summary(PG_FUNCTION_ARGS)
|
|||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
uint32 buf_state;
|
uint32 buf_state;
|
||||||
|
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function summarizes the state of all headers. Locking the
|
* This function summarizes the state of all headers. Locking the
|
||||||
* buffer headers wouldn't provide an improved result as the state of
|
* buffer headers wouldn't provide an improved result as the state of
|
||||||
@@ -620,6 +624,8 @@ pg_buffercache_usage_counts(PG_FUNCTION_ARGS)
|
|||||||
uint32 buf_state = pg_atomic_read_u32(&bufHdr->state);
|
uint32 buf_state = pg_atomic_read_u32(&bufHdr->state);
|
||||||
int usage_count;
|
int usage_count;
|
||||||
|
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
usage_count = BUF_STATE_GET_USAGECOUNT(buf_state);
|
usage_count = BUF_STATE_GET_USAGECOUNT(buf_state);
|
||||||
usage_counts[usage_count]++;
|
usage_counts[usage_count]++;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user