39#define LocalBufHdrGetBlock(bufHdr) \
40 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
151 bufid = -victim_buffer - 1;
157 elog(
ERROR,
"local buffer hash table corrupted");
163 bufHdr->
tag = newTag;
217 else if (--trycounter == 0)
219 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
220 errmsg(
"no empty local buffer available")));
261 buf_state &= ~BM_DIRTY;
277 elog(
ERROR,
"local buffer hash table corrupted");
295 if (*additional_pins <= 1)
305 if (*additional_pins >= max_pins)
306 *additional_pins = max_pins;
341 MemSet((
char *) buf_block, 0, BLCKSZ);
353 Assert(first_block <= extend_upto);
355 Assert((
uint64) first_block + extend_by <= extend_upto);
361 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
362 errmsg(
"cannot extend relation %s beyond %u blocks",
374 victim_buf_id = -buffers[
i] - 1;
398 buf_state &= ~BM_VALID;
407 victim_buf_hdr->
tag = tag;
413 hresult->
id = victim_buf_id;
423 io_start, 1, extend_by * BLCKSZ);
438 *extended_by = extend_by;
459 fprintf(stderr,
"LB DIRTY %d\n", buffer);
509 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
520 elog(
ERROR,
"local buffer hash table corrupted");
523 buf_state &= ~BUF_FLAG_MASK;
524 buf_state &= ~BUF_USAGECOUNT_MASK;
554 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
564 elog(
ERROR,
"local buffer hash table corrupted");
567 buf_state &= ~BUF_FLAG_MASK;
568 buf_state &= ~BUF_USAGECOUNT_MASK;
597 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
598 errmsg(
"cannot access temporary tables during a parallel operation")));
606 (
errcode(ERRCODE_OUT_OF_MEMORY),
607 errmsg(
"out of memory")));
612 for (
i = 0;
i < nbufs;
i++)
622 buf->buf_id = -
i - 2;
642 elog(
ERROR,
"could not initialize local buffer hash table");
660 int bufid = -buffer - 1;
667 if (adjust_usagecount &&
691 int buffid = -buffer - 1;
713 GUC_check_errdetail(
"\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
731 static char *cur_block = NULL;
732 static int next_buf_in_block = 0;
733 static int num_bufs_in_block = 0;
734 static int total_bufs_allocated = 0;
741 if (next_buf_in_block >= num_bufs_in_block)
751 if (LocalBufferContext == NULL)
754 "LocalBufferContext",
758 num_bufs =
Max(num_bufs_in_block * 2, 16);
769 next_buf_in_block = 0;
770 num_bufs_in_block = num_bufs;
774 this_buf = cur_block + next_buf_in_block * BLCKSZ;
776 total_bufs_allocated++;
778 return (
Block) this_buf;
789#ifdef USE_ASSERT_CHECKING
792 int RefCountErrors = 0;
803 elog(
WARNING,
"local buffer refcount leak: %s", s);
809 Assert(RefCountErrors == 0);
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
#define InvalidBlockNumber
#define BufferIsLocal(buffer)
#define BM_MAX_USAGE_COUNT
static void InitBufferTag(BufferTag *tag, const RelFileLocator *rlocator, ForkNumber forkNum, BlockNumber blockNum)
#define BUF_USAGECOUNT_MASK
static ForkNumber BufTagGetForkNum(const BufferTag *tag)
static bool BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2)
static bool BufTagMatchesRelFileLocator(const BufferTag *tag, const RelFileLocator *rlocator)
#define BUF_STATE_GET_USAGECOUNT(state)
static void ClearBufferTag(BufferTag *tag)
static void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
static void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer)
#define BUF_USAGECOUNT_ONE
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
char * DebugPrintBufferRefcount(Buffer buffer)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
#define TYPEALIGN(ALIGNVAL, LEN)
#define Assert(condition)
#define MemSet(start, val, len)
#define fprintf(file, fmt, msg)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define GUC_check_errdetail
#define IsParallelWorker()
BufferUsage pgBufferUsage
void UnpinLocalBuffer(Buffer buffer)
static HTAB * LocalBufHash
static int NLocalPinnedBuffers
void AtEOXact_LocalBuffers(bool isCommit)
#define LocalBufHdrGetBlock(bufHdr)
static void CheckForLocalBufferLeaks(void)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber firstDelBlock)
static Block GetLocalBufferStorage(void)
static int nextFreeLocalBufId
bool check_temp_buffers(int *newval, void **extra, GucSource source)
void AtProcExit_LocalBuffers(void)
bool PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
static void InitLocalBuffers(void)
void LimitAdditionalLocalPins(uint32 *additional_pins)
static Buffer GetLocalVictimBuffer(void)
void MarkLocalBufferDirty(Buffer buffer)
void DropRelationAllLocalBuffers(RelFileLocator rlocator)
PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum)
BlockNumber ExtendBufferedRelLocal(BufferManagerRelation bmr, ForkNumber fork, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
Block * LocalBufferBlockPointers
void UnpinLocalBufferNoOwner(Buffer buffer)
BufferDesc * LocalBufferDescriptors
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static rewind_source * source
instr_time pgstat_prepare_io_time(bool track_io_guc)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
#define relpath(rlocator, forknum)
#define relpathbackend(rlocator, backend, forknum)
ResourceOwner CurrentResourceOwner
void ResourceOwnerEnlarge(ResourceOwner owner)
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
void smgrzeroextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
struct SMgrRelationData * smgr
RelFileLocatorBackend smgr_rlocator