38 #define LocalBufHdrGetBlock(bufHdr) \ 39 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] 74 if (LocalBufHash == NULL)
123 if (LocalBufHash == NULL)
136 fprintf(stderr,
"LB ALLOC (%u,%d,%d) %d\n",
164 fprintf(stderr,
"LB ALLOC (%u,%d,%d) %d\n",
202 else if (--trycounter == 0)
204 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
205 errmsg(
"no empty local buffer available")));
230 buf_state &= ~BM_DIRTY;
254 elog(
ERROR,
"local buffer hash table corrupted");
264 elog(
ERROR,
"local buffer hash table corrupted");
270 bufHdr->
tag = newTag;
295 fprintf(stderr,
"LB DIRTY %d\n", buffer);
298 bufid = -(buffer + 1);
345 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
355 elog(
ERROR,
"local buffer hash table corrupted");
389 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
399 elog(
ERROR,
"local buffer hash table corrupted");
432 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
433 errmsg(
"cannot access temporary tables during a parallel operation")));
441 (
errcode(ERRCODE_OUT_OF_MEMORY),
442 errmsg(
"out of memory")));
447 for (i = 0; i < nbufs; i++)
471 LocalBufHash =
hash_create(
"Local Buffer Lookup Table",
477 elog(
ERROR,
"could not initialize local buffer hash table");
495 static char *cur_block = NULL;
496 static int next_buf_in_block = 0;
497 static int num_bufs_in_block = 0;
498 static int total_bufs_allocated = 0;
505 if (next_buf_in_block >= num_bufs_in_block)
515 if (LocalBufferContext == NULL)
518 "LocalBufferContext",
522 num_bufs =
Max(num_bufs_in_block * 2, 16);
530 next_buf_in_block = 0;
531 num_bufs_in_block = num_bufs;
535 this_buf = cur_block + next_buf_in_block * BLCKSZ;
537 total_bufs_allocated++;
539 return (
Block) this_buf;
550 #ifdef USE_ASSERT_CHECKING 553 int RefCountErrors = 0;
566 Assert(RefCountErrors == 0);
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
#define AllocSetContextCreate
void PrintBufferLeakWarning(Buffer buffer)
static int nextFreeLocalBuf
ResourceOwner CurrentResourceOwner
static void CheckForLocalBufferLeaks(void)
PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum)
void DropRelFileNodeLocalBuffers(RelFileNode rnode, ForkNumber forkNum, BlockNumber firstDelBlock)
#define GetLocalBufferDescriptor(id)
int errcode(int sqlerrcode)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
#define LocalBufHdrGetBlock(bufHdr)
void DropRelFileNodeAllLocalBuffers(RelFileNode rnode)
BufferDesc * LocalBufferDescriptors
#define ALLOCSET_DEFAULT_SIZES
RelFileNodeBackend smgr_rnode
static void InitLocalBuffers(void)
void AtProcExit_LocalBuffers(void)
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
#define BUF_USAGECOUNT_ONE
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
#define IsParallelWorker()
MemoryContext TopMemoryContext
#define BUFFERTAGS_EQUAL(a, b)
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
void MarkLocalBufferDirty(Buffer buffer)
#define ereport(elevel,...)
#define Assert(condition)
#define CLEAR_BUFFERTAG(a)
#define INIT_BUFFERTAG(a, xx_rnode, xx_forkNum, xx_blockNum)
#define BUF_USAGECOUNT_MASK
static HTAB * LocalBufHash
#define BufferIsLocal(buffer)
#define BufferDescriptorGetBuffer(bdesc)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
static Block GetLocalBufferStorage(void)
#define BM_MAX_USAGE_COUNT
int errmsg(const char *fmt,...)
void * MemoryContextAlloc(MemoryContext context, Size size)
Block * LocalBufferBlockPointers
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
#define BUF_STATE_GET_USAGECOUNT(state)
#define relpathbackend(rnode, backend, forknum)
void AtEOXact_LocalBuffers(bool isCommit)
#define RelFileNodeEquals(node1, node2)
BufferUsage pgBufferUsage
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)