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

Function ReadBuffer_common

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

* ReadBuffer_common -- common logic for all ReadBuffer variants * * *hit is set to true if the request was satisfied from shared buffer cache. */

Source from the content-addressed store, hash-verified

892 * *hit is set to true if the request was satisfied from shared buffer cache.
893 */
894static Buffer
895ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
896 BlockNumber blockNum, ReadBufferMode mode,
897 BufferAccessStrategy strategy, bool *hit)
898{
899 BufferDesc *bufHdr;
900 Block bufBlock;
901 bool found;
902 bool isExtend;
903
904 if (ReadBuffer_hook)
905 {
906 return ReadBuffer_hook(smgr, relpersistence, forkNum, blockNum, mode, strategy, hit);
907 }
908
909 /*
910 * Temp tables in Cloudberry use shared buffers so that backends executing
911 * multiple slices of the same query can share them.
912 */
913 bool isLocalBuf = false; /* SmgrIsTemp(smgr); */
914
915 *hit = false;
916
917 Assert(smgr != NULL);
918
919 /* Make sure we will have room to remember the buffer pin */
920 ResourceOwnerEnlargeBuffers(CurrentResourceOwner);
921
922 isExtend = (blockNum == P_NEW);
923
924 TRACE_POSTGRESQL_BUFFER_READ_START(forkNum, blockNum,
925 smgr->smgr_rnode.node.spcNode,
926 smgr->smgr_rnode.node.dbNode,
927 smgr->smgr_rnode.node.relNode,
928 smgr->smgr_rnode.backend,
929 isExtend);
930
931 /* Substitute proper block number if caller asked for P_NEW */
932 if (isExtend)
933 {
934 blockNum = smgrnblocks(smgr, forkNum);
935 /* Fail if relation is already at maximum possible length */
936 if (blockNum == P_NEW)
937 ereport(ERROR,
938 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
939 errmsg("cannot extend relation %s beyond %u blocks",
940 relpath(smgr->smgr_rnode, forkNum),
941 P_NEW)));
942 }
943
944 if (isLocalBuf)
945 {
946 bufHdr = LocalBufferAlloc(smgr, forkNum, blockNum, &found, InvalidBuffer);
947 if (found)
948 pgBufferUsage.local_blks_hit++;
949 else if (isExtend)
950 pgBufferUsage.local_blks_written++;
951 else if (mode == RBM_NORMAL || mode == RBM_NORMAL_NO_LOG ||

Callers 2

ReadBufferExtendedFunction · 0.85

Calls 15

smgrnblocksFunction · 0.85
LocalBufferAllocFunction · 0.85
BufferAllocFunction · 0.85
AcquireContentLockFunction · 0.85
LockBufferForCleanupFunction · 0.85
pg_atomic_read_u32Function · 0.85
LockBufHdrFunction · 0.85
StartBufferIOFunction · 0.85
BufferMProtectFunction · 0.85
smgrextendFunction · 0.85

Tested by

no test coverage detected