--------------------------------------------------------------------- * FindAndDropRelFileNodeBuffers * * This function performs look up in BufMapping table and removes from the * buffer pool all the pages of the specified relation fork that has block * number >= firstDelBlock. (In particular, with firstDelBlock = 0, all * pages are removed.) * -----------------------------------------
| 3548 | * -------------------------------------------------------------------- |
| 3549 | */ |
| 3550 | static void |
| 3551 | FindAndDropRelFileNodeBuffers(RelFileNode rnode, ForkNumber forkNum, |
| 3552 | BlockNumber nForkBlock, |
| 3553 | BlockNumber firstDelBlock) |
| 3554 | { |
| 3555 | BlockNumber curBlock; |
| 3556 | |
| 3557 | for (curBlock = firstDelBlock; curBlock < nForkBlock; curBlock++) |
| 3558 | { |
| 3559 | uint32 bufHash; /* hash value for tag */ |
| 3560 | BufferTag bufTag; /* identity of requested block */ |
| 3561 | LWLock *bufPartitionLock; /* buffer partition lock for it */ |
| 3562 | int buf_id; |
| 3563 | BufferDesc *bufHdr; |
| 3564 | uint32 buf_state; |
| 3565 | |
| 3566 | /* create a tag so we can lookup the buffer */ |
| 3567 | INIT_BUFFERTAG(bufTag, rnode, forkNum, curBlock); |
| 3568 | |
| 3569 | /* determine its hash code and partition lock ID */ |
| 3570 | bufHash = BufTableHashCode(&bufTag); |
| 3571 | bufPartitionLock = BufMappingPartitionLock(bufHash); |
| 3572 | |
| 3573 | /* Check that it is in the buffer pool. If not, do nothing. */ |
| 3574 | LWLockAcquire(bufPartitionLock, LW_SHARED); |
| 3575 | buf_id = BufTableLookup(&bufTag, bufHash); |
| 3576 | LWLockRelease(bufPartitionLock); |
| 3577 | |
| 3578 | if (buf_id < 0) |
| 3579 | continue; |
| 3580 | |
| 3581 | bufHdr = GetBufferDescriptor(buf_id); |
| 3582 | |
| 3583 | /* |
| 3584 | * We need to lock the buffer header and recheck if the buffer is |
| 3585 | * still associated with the same block because the buffer could be |
| 3586 | * evicted by some other backend loading blocks for a different |
| 3587 | * relation after we release lock on the BufMapping table. |
| 3588 | */ |
| 3589 | buf_state = LockBufHdr(bufHdr); |
| 3590 | |
| 3591 | if (RelFileNodeEquals(bufHdr->tag.rnode, rnode) && |
| 3592 | bufHdr->tag.forkNum == forkNum && |
| 3593 | bufHdr->tag.blockNum >= firstDelBlock) |
| 3594 | InvalidateBuffer(bufHdr); /* releases spinlock */ |
| 3595 | else |
| 3596 | UnlockBufHdr(bufHdr, buf_state); |
| 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | /* --------------------------------------------------------------------- |
| 3601 | * DropDatabaseBuffers |
no test coverage detected