39 #define LocalBufHdrGetBlock(bufHdr) \
40 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
145 fprintf(stderr,
"LB ALLOC (%u,%d,%d) %d\n",
173 fprintf(stderr,
"LB ALLOC (%u,%d,%d) %d\n",
211 else if (--trycounter == 0)
213 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
214 errmsg(
"no empty local buffer available")));
263 elog(
ERROR,
"local buffer hash table corrupted");
274 elog(
ERROR,
"local buffer hash table corrupted");
280 bufHdr->
tag = newTag;
305 fprintf(stderr,
"LB DIRTY %d\n", buffer);
308 bufid = -(buffer + 1);
355 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
366 elog(
ERROR,
"local buffer hash table corrupted");
400 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
410 elog(
ERROR,
"local buffer hash table corrupted");
443 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
444 errmsg(
"cannot access temporary tables during a parallel operation")));
452 (
errcode(ERRCODE_OUT_OF_MEMORY),
453 errmsg(
"out of memory")));
458 for (
i = 0;
i < nbufs;
i++)
468 buf->buf_id = -
i - 2;
488 elog(
ERROR,
"could not initialize local buffer hash table");
506 GUC_check_errdetail(
"\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
524 static char *cur_block = NULL;
525 static int next_buf_in_block = 0;
526 static int num_bufs_in_block = 0;
527 static int total_bufs_allocated = 0;
534 if (next_buf_in_block >= num_bufs_in_block)
544 if (LocalBufferContext == NULL)
547 "LocalBufferContext",
551 num_bufs =
Max(num_bufs_in_block * 2, 16);
559 next_buf_in_block = 0;
560 num_bufs_in_block = num_bufs;
564 this_buf = cur_block + next_buf_in_block * BLCKSZ;
566 total_bufs_allocated++;
568 return (
Block) this_buf;
579 #ifdef USE_ASSERT_CHECKING
582 int RefCountErrors = 0;
595 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 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 BufferDesc * GetLocalBufferDescriptor(uint32 id)
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)
#define BUF_USAGECOUNT_ONE
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
void PrintBufferLeakWarning(Buffer buffer)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
elog(ERROR, "%s: %s", p2, 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
Assert(fmt[strlen(fmt) - 1] !='\n')
static HTAB * LocalBufHash
void AtEOXact_LocalBuffers(bool isCommit)
#define LocalBufHdrGetBlock(bufHdr)
static void CheckForLocalBufferLeaks(void)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber firstDelBlock)
static Block GetLocalBufferStorage(void)
bool check_temp_buffers(int *newval, void **extra, GucSource source)
void AtProcExit_LocalBuffers(void)
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr, IOContext *io_context)
static void InitLocalBuffers(void)
void MarkLocalBufferDirty(Buffer buffer)
void DropRelationAllLocalBuffers(RelFileLocator rlocator)
PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum)
Block * LocalBufferBlockPointers
BufferDesc * LocalBufferDescriptors
static int nextFreeLocalBuf
MemoryContext TopMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static rewind_source * source
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
#define relpathbackend(rlocator, backend, forknum)
ResourceOwner CurrentResourceOwner
void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
SMgrRelation smgropen(RelFileLocator rlocator, BackendId backend)
RelFileLocatorBackend smgr_rlocator