@ -451,7 +451,7 @@ static Buffer ReadBuffer_common(SMgrRelation smgr, char relpersistence,
ForkNumber forkNum , BlockNumber blockNum ,
ForkNumber forkNum , BlockNumber blockNum ,
ReadBufferMode mode , BufferAccessStrategy strategy ,
ReadBufferMode mode , BufferAccessStrategy strategy ,
bool * hit ) ;
bool * hit ) ;
static BlockNumber ExtendBufferedRelCommon ( ExtendBufferedWhat eb ,
static BlockNumber ExtendBufferedRelCommon ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -459,7 +459,7 @@ static BlockNumber ExtendBufferedRelCommon(ExtendBufferedWhat eb,
BlockNumber extend_upto ,
BlockNumber extend_upto ,
Buffer * buffers ,
Buffer * buffers ,
uint32 * extended_by ) ;
uint32 * extended_by ) ;
static BlockNumber ExtendBufferedRelShared ( ExtendBufferedWhat eb ,
static BlockNumber ExtendBufferedRelShared ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -809,7 +809,7 @@ ReadBufferWithoutRelcache(RelFileLocator rlocator, ForkNumber forkNum,
* Convenience wrapper around ExtendBufferedRelBy ( ) extending by one block .
* Convenience wrapper around ExtendBufferedRelBy ( ) extending by one block .
*/
*/
Buffer
Buffer
ExtendBufferedRel ( ExtendBufferedWhat eb ,
ExtendBufferedRel ( BufferManagerRelation bmr ,
ForkNumber forkNum ,
ForkNumber forkNum ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags )
uint32 flags )
@ -817,7 +817,7 @@ ExtendBufferedRel(ExtendBufferedWhat eb,
Buffer buf ;
Buffer buf ;
uint32 extend_by = 1 ;
uint32 extend_by = 1 ;
ExtendBufferedRelBy ( e b, forkNum , strategy , flags , extend_by ,
ExtendBufferedRelBy ( bmr , forkNum , strategy , flags , extend_by ,
& buf , & extend_by ) ;
& buf , & extend_by ) ;
return buf ;
return buf ;
@ -841,7 +841,7 @@ ExtendBufferedRel(ExtendBufferedWhat eb,
* be empty .
* be empty .
*/
*/
BlockNumber
BlockNumber
ExtendBufferedRelBy ( ExtendBufferedWhat eb ,
ExtendBufferedRelBy ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -849,17 +849,17 @@ ExtendBufferedRelBy(ExtendBufferedWhat eb,
Buffer * buffers ,
Buffer * buffers ,
uint32 * extended_by )
uint32 * extended_by )
{
{
Assert ( ( e b. rel ! = NULL ) ! = ( e b. smgr ! = NULL ) ) ;
Assert ( ( bmr . rel ! = NULL ) ! = ( bmr . smgr ! = NULL ) ) ;
Assert ( e b. smgr = = NULL | | e b. relpersistence ! = 0 ) ;
Assert ( bmr . smgr = = NULL | | bmr . relpersistence ! = 0 ) ;
Assert ( extend_by > 0 ) ;
Assert ( extend_by > 0 ) ;
if ( e b. smgr = = NULL )
if ( bmr . smgr = = NULL )
{
{
e b. smgr = RelationGetSmgr ( e b. rel ) ;
bmr . smgr = RelationGetSmgr ( bmr . rel ) ;
e b. relpersistence = e b. rel - > rd_rel - > relpersistence ;
bmr . relpersistence = bmr . rel - > rd_rel - > relpersistence ;
}
}
return ExtendBufferedRelCommon ( e b, fork , strategy , flags ,
return ExtendBufferedRelCommon ( bmr , fork , strategy , flags ,
extend_by , InvalidBlockNumber ,
extend_by , InvalidBlockNumber ,
buffers , extended_by ) ;
buffers , extended_by ) ;
}
}
@ -873,7 +873,7 @@ ExtendBufferedRelBy(ExtendBufferedWhat eb,
* crash recovery ) .
* crash recovery ) .
*/
*/
Buffer
Buffer
ExtendBufferedRelTo ( ExtendBufferedWhat eb ,
ExtendBufferedRelTo ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -885,14 +885,14 @@ ExtendBufferedRelTo(ExtendBufferedWhat eb,
Buffer buffer = InvalidBuffer ;
Buffer buffer = InvalidBuffer ;
Buffer buffers [ 64 ] ;
Buffer buffers [ 64 ] ;
Assert ( ( e b. rel ! = NULL ) ! = ( e b. smgr ! = NULL ) ) ;
Assert ( ( bmr . rel ! = NULL ) ! = ( bmr . smgr ! = NULL ) ) ;
Assert ( e b. smgr = = NULL | | e b. relpersistence ! = 0 ) ;
Assert ( bmr . smgr = = NULL | | bmr . relpersistence ! = 0 ) ;
Assert ( extend_to ! = InvalidBlockNumber & & extend_to > 0 ) ;
Assert ( extend_to ! = InvalidBlockNumber & & extend_to > 0 ) ;
if ( e b. smgr = = NULL )
if ( bmr . smgr = = NULL )
{
{
e b. smgr = RelationGetSmgr ( e b. rel ) ;
bmr . smgr = RelationGetSmgr ( bmr . rel ) ;
e b. relpersistence = e b. rel - > rd_rel - > relpersistence ;
bmr . relpersistence = bmr . rel - > rd_rel - > relpersistence ;
}
}
/*
/*
@ -901,21 +901,21 @@ ExtendBufferedRelTo(ExtendBufferedWhat eb,
* an smgrexists call .
* an smgrexists call .
*/
*/
if ( ( flags & EB_CREATE_FORK_IF_NEEDED ) & &
if ( ( flags & EB_CREATE_FORK_IF_NEEDED ) & &
( e b. smgr - > smgr_cached_nblocks [ fork ] = = 0 | |
( bmr . smgr - > smgr_cached_nblocks [ fork ] = = 0 | |
e b. smgr - > smgr_cached_nblocks [ fork ] = = InvalidBlockNumber ) & &
bmr . smgr - > smgr_cached_nblocks [ fork ] = = InvalidBlockNumber ) & &
! smgrexists ( e b. smgr , fork ) )
! smgrexists ( bmr . smgr , fork ) )
{
{
LockRelationForExtension ( e b. rel , ExclusiveLock ) ;
LockRelationForExtension ( bmr . rel , ExclusiveLock ) ;
/* could have been closed while waiting for lock */
/* could have been closed while waiting for lock */
if ( e b. rel )
if ( bmr . rel )
e b. smgr = RelationGetSmgr ( e b. rel ) ;
bmr . smgr = RelationGetSmgr ( bmr . rel ) ;
/* recheck, fork might have been created concurrently */
/* recheck, fork might have been created concurrently */
if ( ! smgrexists ( e b. smgr , fork ) )
if ( ! smgrexists ( bmr . smgr , fork ) )
smgrcreate ( e b. smgr , fork , flags & EB_PERFORMING_RECOVERY ) ;
smgrcreate ( bmr . smgr , fork , flags & EB_PERFORMING_RECOVERY ) ;
UnlockRelationForExtension ( e b. rel , ExclusiveLock ) ;
UnlockRelationForExtension ( bmr . rel , ExclusiveLock ) ;
}
}
/*
/*
@ -923,13 +923,13 @@ ExtendBufferedRelTo(ExtendBufferedWhat eb,
* kernel .
* kernel .
*/
*/
if ( flags & EB_CLEAR_SIZE_CACHE )
if ( flags & EB_CLEAR_SIZE_CACHE )
e b. smgr - > smgr_cached_nblocks [ fork ] = InvalidBlockNumber ;
bmr . smgr - > smgr_cached_nblocks [ fork ] = InvalidBlockNumber ;
/*
/*
* Estimate how many pages we ' ll need to extend by . This avoids acquiring
* Estimate how many pages we ' ll need to extend by . This avoids acquiring
* unnecessarily many victim buffers .
* unnecessarily many victim buffers .
*/
*/
current_size = smgrnblocks ( e b. smgr , fork ) ;
current_size = smgrnblocks ( bmr . smgr , fork ) ;
/*
/*
* Since no - one else can be looking at the page contents yet , there is no
* Since no - one else can be looking at the page contents yet , there is no
@ -948,7 +948,7 @@ ExtendBufferedRelTo(ExtendBufferedWhat eb,
if ( ( uint64 ) current_size + num_pages > extend_to )
if ( ( uint64 ) current_size + num_pages > extend_to )
num_pages = extend_to - current_size ;
num_pages = extend_to - current_size ;
first_block = ExtendBufferedRelCommon ( e b, fork , strategy , flags ,
first_block = ExtendBufferedRelCommon ( bmr , fork , strategy , flags ,
num_pages , extend_to ,
num_pages , extend_to ,
buffers , & extended_by ) ;
buffers , & extended_by ) ;
@ -975,7 +975,7 @@ ExtendBufferedRelTo(ExtendBufferedWhat eb,
bool hit ;
bool hit ;
Assert ( extended_by = = 0 ) ;
Assert ( extended_by = = 0 ) ;
buffer = ReadBuffer_common ( e b. smgr , e b. relpersistence ,
buffer = ReadBuffer_common ( bmr . smgr , bmr . relpersistence ,
fork , extend_to - 1 , mode , strategy ,
fork , extend_to - 1 , mode , strategy ,
& hit ) ;
& hit ) ;
}
}
@ -1019,7 +1019,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
if ( mode = = RBM_ZERO_AND_LOCK | | mode = = RBM_ZERO_AND_CLEANUP_LOCK )
if ( mode = = RBM_ZERO_AND_LOCK | | mode = = RBM_ZERO_AND_CLEANUP_LOCK )
flags | = EB_LOCK_FIRST ;
flags | = EB_LOCK_FIRST ;
return ExtendBufferedRel ( E B_SMGR( smgr , relpersistence ) ,
return ExtendBufferedRel ( BMR _SMGR ( smgr , relpersistence ) ,
forkNum , strategy , flags ) ;
forkNum , strategy , flags ) ;
}
}
@ -1779,7 +1779,7 @@ LimitAdditionalPins(uint32 *additional_pins)
* avoid duplicating the tracing and relpersistence related logic .
* avoid duplicating the tracing and relpersistence related logic .
*/
*/
static BlockNumber
static BlockNumber
ExtendBufferedRelCommon ( ExtendBufferedWhat eb ,
ExtendBufferedRelCommon ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -1791,27 +1791,27 @@ ExtendBufferedRelCommon(ExtendBufferedWhat eb,
BlockNumber first_block ;
BlockNumber first_block ;
TRACE_POSTGRESQL_BUFFER_EXTEND_START ( fork ,
TRACE_POSTGRESQL_BUFFER_EXTEND_START ( fork ,
e b. smgr - > smgr_rlocator . locator . spcOid ,
bmr . smgr - > smgr_rlocator . locator . spcOid ,
e b. smgr - > smgr_rlocator . locator . dbOid ,
bmr . smgr - > smgr_rlocator . locator . dbOid ,
e b. smgr - > smgr_rlocator . locator . relNumber ,
bmr . smgr - > smgr_rlocator . locator . relNumber ,
e b. smgr - > smgr_rlocator . backend ,
bmr . smgr - > smgr_rlocator . backend ,
extend_by ) ;
extend_by ) ;
if ( e b. relpersistence = = RELPERSISTENCE_TEMP )
if ( bmr . relpersistence = = RELPERSISTENCE_TEMP )
first_block = ExtendBufferedRelLocal ( e b, fork , flags ,
first_block = ExtendBufferedRelLocal ( bmr , fork , flags ,
extend_by , extend_upto ,
extend_by , extend_upto ,
buffers , & extend_by ) ;
buffers , & extend_by ) ;
else
else
first_block = ExtendBufferedRelShared ( e b, fork , strategy , flags ,
first_block = ExtendBufferedRelShared ( bmr , fork , strategy , flags ,
extend_by , extend_upto ,
extend_by , extend_upto ,
buffers , & extend_by ) ;
buffers , & extend_by ) ;
* extended_by = extend_by ;
* extended_by = extend_by ;
TRACE_POSTGRESQL_BUFFER_EXTEND_DONE ( fork ,
TRACE_POSTGRESQL_BUFFER_EXTEND_DONE ( fork ,
e b. smgr - > smgr_rlocator . locator . spcOid ,
bmr . smgr - > smgr_rlocator . locator . spcOid ,
e b. smgr - > smgr_rlocator . locator . dbOid ,
bmr . smgr - > smgr_rlocator . locator . dbOid ,
e b. smgr - > smgr_rlocator . locator . relNumber ,
bmr . smgr - > smgr_rlocator . locator . relNumber ,
e b. smgr - > smgr_rlocator . backend ,
bmr . smgr - > smgr_rlocator . backend ,
* extended_by ,
* extended_by ,
first_block ) ;
first_block ) ;
@ -1823,7 +1823,7 @@ ExtendBufferedRelCommon(ExtendBufferedWhat eb,
* shared buffers .
* shared buffers .
*/
*/
static BlockNumber
static BlockNumber
ExtendBufferedRelShared ( ExtendBufferedWhat eb ,
ExtendBufferedRelShared ( BufferManagerRelation bmr ,
ForkNumber fork ,
ForkNumber fork ,
BufferAccessStrategy strategy ,
BufferAccessStrategy strategy ,
uint32 flags ,
uint32 flags ,
@ -1874,9 +1874,9 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
*/
*/
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
{
{
LockRelationForExtension ( e b. rel , ExclusiveLock ) ;
LockRelationForExtension ( bmr . rel , ExclusiveLock ) ;
if ( e b. rel )
if ( bmr . rel )
e b. smgr = RelationGetSmgr ( e b. rel ) ;
bmr . smgr = RelationGetSmgr ( bmr . rel ) ;
}
}
/*
/*
@ -1884,9 +1884,9 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
* kernel .
* kernel .
*/
*/
if ( flags & EB_CLEAR_SIZE_CACHE )
if ( flags & EB_CLEAR_SIZE_CACHE )
e b. smgr - > smgr_cached_nblocks [ fork ] = InvalidBlockNumber ;
bmr . smgr - > smgr_cached_nblocks [ fork ] = InvalidBlockNumber ;
first_block = smgrnblocks ( e b. smgr , fork ) ;
first_block = smgrnblocks ( bmr . smgr , fork ) ;
/*
/*
* Now that we have the accurate relation size , check if the caller wants
* Now that we have the accurate relation size , check if the caller wants
@ -1918,7 +1918,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
if ( extend_by = = 0 )
if ( extend_by = = 0 )
{
{
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
UnlockRelationForExtension ( e b. rel , ExclusiveLock ) ;
UnlockRelationForExtension ( bmr . rel , ExclusiveLock ) ;
* extended_by = extend_by ;
* extended_by = extend_by ;
return first_block ;
return first_block ;
}
}
@ -1929,7 +1929,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_PROGRAM_LIMIT_EXCEEDED ) ,
( errcode ( ERRCODE_PROGRAM_LIMIT_EXCEEDED ) ,
errmsg ( " cannot extend relation %s beyond %u blocks " ,
errmsg ( " cannot extend relation %s beyond %u blocks " ,
relpath ( e b. smgr - > smgr_rlocator , fork ) ,
relpath ( bmr . smgr - > smgr_rlocator , fork ) ,
MaxBlockNumber ) ) ) ;
MaxBlockNumber ) ) ) ;
/*
/*
@ -1947,7 +1947,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
LWLock * partition_lock ;
LWLock * partition_lock ;
int existing_id ;
int existing_id ;
InitBufferTag ( & tag , & e b. smgr - > smgr_rlocator . locator , fork , first_block + i ) ;
InitBufferTag ( & tag , & bmr . smgr - > smgr_rlocator . locator , fork , first_block + i ) ;
hash = BufTableHashCode ( & tag ) ;
hash = BufTableHashCode ( & tag ) ;
partition_lock = BufMappingPartitionLock ( hash ) ;
partition_lock = BufMappingPartitionLock ( hash ) ;
@ -1996,7 +1996,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
if ( valid & & ! PageIsNew ( ( Page ) buf_block ) )
if ( valid & & ! PageIsNew ( ( Page ) buf_block ) )
ereport ( ERROR ,
ereport ( ERROR ,
( errmsg ( " unexpected data beyond EOF in block %u of relation %s " ,
( errmsg ( " unexpected data beyond EOF in block %u of relation %s " ,
existing_hdr - > tag . blockNum , relpath ( e b. smgr - > smgr_rlocator , fork ) ) ,
existing_hdr - > tag . blockNum , relpath ( bmr . smgr - > smgr_rlocator , fork ) ) ,
errhint ( " This has been seen to occur with buggy kernels; consider updating your system. " ) ) ) ;
errhint ( " This has been seen to occur with buggy kernels; consider updating your system. " ) ) ) ;
/*
/*
@ -2030,7 +2030,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
victim_buf_hdr - > tag = tag ;
victim_buf_hdr - > tag = tag ;
buf_state | = BM_TAG_VALID | BUF_USAGECOUNT_ONE ;
buf_state | = BM_TAG_VALID | BUF_USAGECOUNT_ONE ;
if ( e b. relpersistence = = RELPERSISTENCE_PERMANENT | | fork = = INIT_FORKNUM )
if ( bmr . relpersistence = = RELPERSISTENCE_PERMANENT | | fork = = INIT_FORKNUM )
buf_state | = BM_PERMANENT ;
buf_state | = BM_PERMANENT ;
UnlockBufHdr ( victim_buf_hdr , buf_state ) ;
UnlockBufHdr ( victim_buf_hdr , buf_state ) ;
@ -2054,7 +2054,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
*
*
* We don ' t need to set checksum for all - zero pages .
* We don ' t need to set checksum for all - zero pages .
*/
*/
smgrzeroextend ( e b. smgr , fork , first_block , extend_by , false ) ;
smgrzeroextend ( bmr . smgr , fork , first_block , extend_by , false ) ;
/*
/*
* Release the file - extension lock ; it ' s now OK for someone else to extend
* Release the file - extension lock ; it ' s now OK for someone else to extend
@ -2064,7 +2064,7 @@ ExtendBufferedRelShared(ExtendBufferedWhat eb,
* take noticeable time .
* take noticeable time .
*/
*/
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
if ( ! ( flags & EB_SKIP_EXTENSION_LOCK ) )
UnlockRelationForExtension ( e b. rel , ExclusiveLock ) ;
UnlockRelationForExtension ( bmr . rel , ExclusiveLock ) ;
pgstat_count_io_op_time ( IOOBJECT_RELATION , io_context , IOOP_EXTEND ,
pgstat_count_io_op_time ( IOOBJECT_RELATION , io_context , IOOP_EXTEND ,
io_start , extend_by ) ;
io_start , extend_by ) ;