MCPcopy Create free account
hub / github.com/apache/cloudberry / ConditionalLockBufferForCleanup

Function ConditionalLockBufferForCleanup

src/backend/storage/buffer/bufmgr.c:4522–4568  ·  view source on GitHub ↗

* ConditionalLockBufferForCleanup - as above, but don't wait to get the lock * * We won't loop, but just check once to see if the pin count is OK. If * not, return false with no lock held. */

Source from the content-addressed store, hash-verified

4520 * not, return false with no lock held.
4521 */
4522bool
4523ConditionalLockBufferForCleanup(Buffer buffer)
4524{
4525 BufferDesc *bufHdr;
4526 uint32 buf_state,
4527 refcount;
4528
4529 Assert(BufferIsValid(buffer));
4530
4531 if (BufferIsLocal(buffer))
4532 {
4533 refcount = LocalRefCount[-buffer - 1];
4534 /* There should be exactly one pin */
4535 Assert(refcount > 0);
4536 if (refcount != 1)
4537 return false;
4538 /* Nobody else to wait for */
4539 return true;
4540 }
4541
4542 /* There should be exactly one local pin */
4543 refcount = GetPrivateRefCount(buffer);
4544 Assert(refcount);
4545 if (refcount != 1)
4546 return false;
4547
4548 /* Try to acquire lock */
4549 if (!ConditionalLockBuffer(buffer))
4550 return false;
4551
4552 bufHdr = GetBufferDescriptor(buffer - 1);
4553 buf_state = LockBufHdr(bufHdr);
4554 refcount = BUF_STATE_GET_REFCOUNT(buf_state);
4555
4556 Assert(refcount > 0);
4557 if (refcount == 1)
4558 {
4559 /* Successfully acquired exclusive lock with pincount 1 */
4560 UnlockBufHdr(bufHdr, buf_state);
4561 return true;
4562 }
4563
4564 /* Failed, so release the lock */
4565 UnlockBufHdr(bufHdr, buf_state);
4566 LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
4567 return false;
4568}
4569
4570/*
4571 * IsBufferCleanupOK - as above, but we already have the lock

Callers 4

heap_page_prune_optFunction · 0.85
lazy_scan_heapFunction · 0.85
_hash_finish_splitFunction · 0.85

Calls 4

GetPrivateRefCountFunction · 0.85
ConditionalLockBufferFunction · 0.85
LockBufHdrFunction · 0.85
LockBufferFunction · 0.85

Tested by

no test coverage detected