@@ -1657,8 +1657,8 @@ ReleaseAndReadBuffer(Buffer buffer,
16571657{
16581658bufHdr = GetLocalBufferDescriptor (- buffer - 1 );
16591659if (bufHdr -> tag .blockNum == blockNum &&
1660- RelFileLocatorEquals ( bufHdr -> tag . rlocator , relation -> rd_locator )&&
1661- bufHdr -> tag . forkNum == forkNum )
1660+ BufTagMatchesRelFileLocator ( & bufHdr -> tag , & relation -> rd_locator )&&
1661+ BufTagGetForkNum ( & bufHdr -> tag ) == forkNum )
16621662return buffer ;
16631663ResourceOwnerForgetBuffer (CurrentResourceOwner ,buffer );
16641664LocalRefCount [- buffer - 1 ]-- ;
@@ -1668,8 +1668,8 @@ ReleaseAndReadBuffer(Buffer buffer,
16681668bufHdr = GetBufferDescriptor (buffer - 1 );
16691669/* we have pin, so it's ok to examine tag without spinlock */
16701670if (bufHdr -> tag .blockNum == blockNum &&
1671- RelFileLocatorEquals ( bufHdr -> tag . rlocator , relation -> rd_locator )&&
1672- bufHdr -> tag . forkNum == forkNum )
1671+ BufTagMatchesRelFileLocator ( & bufHdr -> tag , & relation -> rd_locator )&&
1672+ BufTagGetForkNum ( & bufHdr -> tag ) == forkNum )
16731673return buffer ;
16741674UnpinBuffer (bufHdr , true);
16751675}
@@ -2010,9 +2010,9 @@ BufferSync(int flags)
20102010
20112011item = & CkptBufferIds [num_to_scan ++ ];
20122012item -> buf_id = buf_id ;
2013- item -> tsId = bufHdr -> tag .rlocator . spcOid ;
2014- item -> relNumber = bufHdr -> tag . rlocator . relNumber ;
2015- item -> forkNum = bufHdr -> tag . forkNum ;
2013+ item -> tsId = bufHdr -> tag .spcOid ;
2014+ item -> relNumber = BufTagGetRelNumber ( & bufHdr -> tag ) ;
2015+ item -> forkNum = BufTagGetForkNum ( & bufHdr -> tag ) ;
20162016item -> blockNum = bufHdr -> tag .blockNum ;
20172017}
20182018
@@ -2718,7 +2718,8 @@ PrintBufferLeakWarning(Buffer buffer)
27182718}
27192719
27202720/* theoretically we should lock the bufhdr here */
2721- path = relpathbackend (buf -> tag .rlocator ,backend ,buf -> tag .forkNum );
2721+ path = relpathbackend (BufTagGetRelFileLocator (& buf -> tag ),backend ,
2722+ BufTagGetForkNum (& buf -> tag ));
27222723buf_state = pg_atomic_read_u32 (& buf -> state );
27232724elog (WARNING ,
27242725"buffer refcount leak: [%03d] "
@@ -2797,8 +2798,8 @@ BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum,
27972798bufHdr = GetBufferDescriptor (buffer - 1 );
27982799
27992800/* pinned, so OK to read tag without spinlock */
2800- * rlocator = bufHdr -> tag . rlocator ;
2801- * forknum = bufHdr -> tag . forkNum ;
2801+ * rlocator = BufTagGetRelFileLocator ( & bufHdr -> tag ) ;
2802+ * forknum = BufTagGetForkNum ( & bufHdr -> tag ) ;
28022803* blknum = bufHdr -> tag .blockNum ;
28032804}
28042805
@@ -2848,9 +2849,9 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
28482849
28492850/* Find smgr relation for buffer */
28502851if (reln == NULL )
2851- reln = smgropen (buf -> tag . rlocator ,InvalidBackendId );
2852+ reln = smgropen (BufTagGetRelFileLocator ( & buf -> tag ) ,InvalidBackendId );
28522853
2853- TRACE_POSTGRESQL_BUFFER_FLUSH_START (buf -> tag . forkNum ,
2854+ TRACE_POSTGRESQL_BUFFER_FLUSH_START (BufTagGetForkNum ( & buf -> tag ) ,
28542855buf -> tag .blockNum ,
28552856reln -> smgr_rlocator .locator .spcOid ,
28562857reln -> smgr_rlocator .locator .dbOid ,
@@ -2909,7 +2910,7 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
29092910 * bufToWrite is either the shared buffer or a copy, as appropriate.
29102911 */
29112912smgrwrite (reln ,
2912- buf -> tag . forkNum ,
2913+ BufTagGetForkNum ( & buf -> tag ) ,
29132914buf -> tag .blockNum ,
29142915bufToWrite ,
29152916 false);
@@ -2930,7 +2931,7 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
29302931 */
29312932TerminateBufferIO (buf , true,0 );
29322933
2933- TRACE_POSTGRESQL_BUFFER_FLUSH_DONE (buf -> tag . forkNum ,
2934+ TRACE_POSTGRESQL_BUFFER_FLUSH_DONE (BufTagGetForkNum ( & buf -> tag ) ,
29342935buf -> tag .blockNum ,
29352936reln -> smgr_rlocator .locator .spcOid ,
29362937reln -> smgr_rlocator .locator .dbOid ,
@@ -3151,15 +3152,15 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
31513152 * We could check forkNum and blockNum as well as the rlocator, but
31523153 * the incremental win from doing so seems small.
31533154 */
3154- if (!RelFileLocatorEquals ( bufHdr -> tag . rlocator , rlocator .locator ))
3155+ if (!BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rlocator .locator ))
31553156continue ;
31563157
31573158buf_state = LockBufHdr (bufHdr );
31583159
31593160for (j = 0 ;j < nforks ;j ++ )
31603161{
3161- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , rlocator .locator )&&
3162- bufHdr -> tag . forkNum == forkNum [j ]&&
3162+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rlocator .locator )&&
3163+ BufTagGetForkNum ( & bufHdr -> tag ) == forkNum [j ]&&
31633164bufHdr -> tag .blockNum >=firstDelBlock [j ])
31643165{
31653166InvalidateBuffer (bufHdr );/* releases spinlock */
@@ -3309,7 +3310,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
33093310
33103311for (j = 0 ;j < n ;j ++ )
33113312{
3312- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , locators [j ]))
3313+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & locators [j ]))
33133314{
33143315rlocator = & locators [j ];
33153316break ;
@@ -3318,7 +3319,10 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
33183319}
33193320else
33203321{
3321- rlocator = bsearch ((const void * )& (bufHdr -> tag .rlocator ),
3322+ RelFileLocator locator ;
3323+
3324+ locator = BufTagGetRelFileLocator (& bufHdr -> tag );
3325+ rlocator = bsearch ((const void * )& (locator ),
33223326locators ,n ,sizeof (RelFileLocator ),
33233327rlocator_comparator );
33243328}
@@ -3328,7 +3332,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
33283332continue ;
33293333
33303334buf_state = LockBufHdr (bufHdr );
3331- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , ( * rlocator ) ))
3335+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , rlocator ))
33323336InvalidateBuffer (bufHdr );/* releases spinlock */
33333337else
33343338UnlockBufHdr (bufHdr ,buf_state );
@@ -3388,8 +3392,8 @@ FindAndDropRelationBuffers(RelFileLocator rlocator, ForkNumber forkNum,
33883392 */
33893393buf_state = LockBufHdr (bufHdr );
33903394
3391- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , rlocator )&&
3392- bufHdr -> tag . forkNum == forkNum &&
3395+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rlocator )&&
3396+ BufTagGetForkNum ( & bufHdr -> tag ) == forkNum &&
33933397bufHdr -> tag .blockNum >=firstDelBlock )
33943398InvalidateBuffer (bufHdr );/* releases spinlock */
33953399else
@@ -3427,11 +3431,11 @@ DropDatabaseBuffers(Oid dbid)
34273431 * As in DropRelationBuffers, an unlocked precheck should be
34283432 * safe and saves some cycles.
34293433 */
3430- if (bufHdr -> tag .rlocator . dbOid != dbid )
3434+ if (bufHdr -> tag .dbOid != dbid )
34313435continue ;
34323436
34333437buf_state = LockBufHdr (bufHdr );
3434- if (bufHdr -> tag .rlocator . dbOid == dbid )
3438+ if (bufHdr -> tag .dbOid == dbid )
34353439InvalidateBuffer (bufHdr );/* releases spinlock */
34363440else
34373441UnlockBufHdr (bufHdr ,buf_state );
@@ -3461,7 +3465,8 @@ PrintBufferDescs(void)
34613465"[%02d] (freeNext=%d, rel=%s, "
34623466"blockNum=%u, flags=0x%x, refcount=%u %d)" ,
34633467i ,buf -> freeNext ,
3464- relpathbackend (buf -> tag .rlocator ,InvalidBackendId ,buf -> tag .forkNum ),
3468+ relpathbackend (BufTagGetRelFileLocator (& buf -> tag ),
3469+ InvalidBackendId ,BufTagGetForkNum (& buf -> tag )),
34653470buf -> tag .blockNum ,buf -> flags ,
34663471buf -> refcount ,GetPrivateRefCount (b ));
34673472}
@@ -3486,7 +3491,8 @@ PrintPinnedBufs(void)
34863491"[%02d] (freeNext=%d, rel=%s, "
34873492"blockNum=%u, flags=0x%x, refcount=%u %d)" ,
34883493i ,buf -> freeNext ,
3489- relpathperm (buf -> tag .rlocator ,buf -> tag .forkNum ),
3494+ relpathperm (BufTagGetRelFileLocator (& buf -> tag ),
3495+ BufTagGetForkNum (& buf -> tag )),
34903496buf -> tag .blockNum ,buf -> flags ,
34913497buf -> refcount ,GetPrivateRefCount (b ));
34923498}
@@ -3525,7 +3531,7 @@ FlushRelationBuffers(Relation rel)
35253531uint32 buf_state ;
35263532
35273533bufHdr = GetLocalBufferDescriptor (i );
3528- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , rel -> rd_locator )&&
3534+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rel -> rd_locator )&&
35293535((buf_state = pg_atomic_read_u32 (& bufHdr -> state ))&
35303536 (BM_VALID |BM_DIRTY ))== (BM_VALID |BM_DIRTY ))
35313537{
@@ -3543,7 +3549,7 @@ FlushRelationBuffers(Relation rel)
35433549PageSetChecksumInplace (localpage ,bufHdr -> tag .blockNum );
35443550
35453551smgrwrite (RelationGetSmgr (rel ),
3546- bufHdr -> tag . forkNum ,
3552+ BufTagGetForkNum ( & bufHdr -> tag ) ,
35473553bufHdr -> tag .blockNum ,
35483554localpage ,
35493555 false);
@@ -3572,13 +3578,13 @@ FlushRelationBuffers(Relation rel)
35723578 * As in DropRelationBuffers, an unlocked precheck should be
35733579 * safe and saves some cycles.
35743580 */
3575- if (!RelFileLocatorEquals ( bufHdr -> tag . rlocator , rel -> rd_locator ))
3581+ if (!BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rel -> rd_locator ))
35763582continue ;
35773583
35783584ReservePrivateRefCountEntry ();
35793585
35803586buf_state = LockBufHdr (bufHdr );
3581- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , rel -> rd_locator )&&
3587+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & rel -> rd_locator )&&
35823588(buf_state & (BM_VALID |BM_DIRTY ))== (BM_VALID |BM_DIRTY ))
35833589{
35843590PinBuffer_Locked (bufHdr );
@@ -3652,7 +3658,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
36523658
36533659for (j = 0 ;j < nrels ;j ++ )
36543660{
3655- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , srels [j ].rlocator ))
3661+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & srels [j ].rlocator ))
36563662{
36573663srelent = & srels [j ];
36583664break ;
@@ -3661,7 +3667,10 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
36613667}
36623668else
36633669{
3664- srelent = bsearch ((const void * )& (bufHdr -> tag .rlocator ),
3670+ RelFileLocator rlocator ;
3671+
3672+ rlocator = BufTagGetRelFileLocator (& bufHdr -> tag );
3673+ srelent = bsearch ((const void * )& (rlocator ),
36653674srels ,nrels ,sizeof (SMgrSortArray ),
36663675rlocator_comparator );
36673676}
@@ -3673,7 +3682,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
36733682ReservePrivateRefCountEntry ();
36743683
36753684buf_state = LockBufHdr (bufHdr );
3676- if (RelFileLocatorEquals ( bufHdr -> tag . rlocator , srelent -> rlocator )&&
3685+ if (BufTagMatchesRelFileLocator ( & bufHdr -> tag , & srelent -> rlocator )&&
36773686(buf_state & (BM_VALID |BM_DIRTY ))== (BM_VALID |BM_DIRTY ))
36783687{
36793688PinBuffer_Locked (bufHdr );
@@ -3877,13 +3886,13 @@ FlushDatabaseBuffers(Oid dbid)
38773886 * As in DropRelationBuffers, an unlocked precheck should be
38783887 * safe and saves some cycles.
38793888 */
3880- if (bufHdr -> tag .rlocator . dbOid != dbid )
3889+ if (bufHdr -> tag .dbOid != dbid )
38813890continue ;
38823891
38833892ReservePrivateRefCountEntry ();
38843893
38853894buf_state = LockBufHdr (bufHdr );
3886- if (bufHdr -> tag .rlocator . dbOid == dbid &&
3895+ if (bufHdr -> tag .dbOid == dbid &&
38873896(buf_state & (BM_VALID |BM_DIRTY ))== (BM_VALID |BM_DIRTY ))
38883897{
38893898PinBuffer_Locked (bufHdr );
@@ -4052,7 +4061,7 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
40524061 * See src/backend/storage/page/README for longer discussion.
40534062 */
40544063if (RecoveryInProgress ()||
4055- RelFileLocatorSkippingWAL (bufHdr -> tag . rlocator ))
4064+ RelFileLocatorSkippingWAL (BufTagGetRelFileLocator ( & bufHdr -> tag ) ))
40564065return ;
40574066
40584067/*
@@ -4661,7 +4670,8 @@ AbortBufferIO(void)
46614670/* Buffer is pinned, so we can read tag without spinlock */
46624671char * path ;
46634672
4664- path = relpathperm (buf -> tag .rlocator ,buf -> tag .forkNum );
4673+ path = relpathperm (BufTagGetRelFileLocator (& buf -> tag ),
4674+ BufTagGetForkNum (& buf -> tag ));
46654675ereport (WARNING ,
46664676(errcode (ERRCODE_IO_ERROR ),
46674677errmsg ("could not write block %u of %s" ,
@@ -4685,7 +4695,8 @@ shared_buffer_write_error_callback(void *arg)
46854695/* Buffer is pinned, so we can read the tag without locking the spinlock */
46864696if (bufHdr != NULL )
46874697{
4688- char * path = relpathperm (bufHdr -> tag .rlocator ,bufHdr -> tag .forkNum );
4698+ char * path = relpathperm (BufTagGetRelFileLocator (& bufHdr -> tag ),
4699+ BufTagGetForkNum (& bufHdr -> tag ));
46894700
46904701errcontext ("writing block %u of relation %s" ,
46914702bufHdr -> tag .blockNum ,path );
@@ -4703,8 +4714,9 @@ local_buffer_write_error_callback(void *arg)
47034714
47044715if (bufHdr != NULL )
47054716{
4706- char * path = relpathbackend (bufHdr -> tag .rlocator ,MyBackendId ,
4707- bufHdr -> tag .forkNum );
4717+ char * path = relpathbackend (BufTagGetRelFileLocator (& bufHdr -> tag ),
4718+ MyBackendId ,
4719+ BufTagGetForkNum (& bufHdr -> tag ));
47084720
47094721errcontext ("writing block %u of relation %s" ,
47104722bufHdr -> tag .blockNum ,path );
@@ -4798,15 +4810,20 @@ static inline int
47984810buffertag_comparator (const BufferTag * ba ,const BufferTag * bb )
47994811{
48004812int ret ;
4813+ RelFileLocator rlocatora ;
4814+ RelFileLocator rlocatorb ;
48014815
4802- ret = rlocator_comparator (& ba -> rlocator ,& bb -> rlocator );
4816+ rlocatora = BufTagGetRelFileLocator (ba );
4817+ rlocatorb = BufTagGetRelFileLocator (bb );
4818+
4819+ ret = rlocator_comparator (& rlocatora ,& rlocatorb );
48034820
48044821if (ret != 0 )
48054822return ret ;
48064823
4807- if (ba -> forkNum < bb -> forkNum )
4824+ if (BufTagGetForkNum ( ba ) < BufTagGetForkNum ( bb ) )
48084825return -1 ;
4809- if (ba -> forkNum > bb -> forkNum )
4826+ if (BufTagGetForkNum ( ba ) > BufTagGetForkNum ( bb ) )
48104827return 1 ;
48114828
48124829if (ba -> blockNum < bb -> blockNum )
@@ -4956,22 +4973,26 @@ IssuePendingWritebacks(WritebackContext *context)
49564973SMgrRelation reln ;
49574974int ahead ;
49584975BufferTag tag ;
4976+ RelFileLocator currlocator ;
49594977Size nblocks = 1 ;
49604978
49614979cur = & context -> pending_writebacks [i ];
49624980tag = cur -> tag ;
4981+ currlocator = BufTagGetRelFileLocator (& tag );
49634982
49644983/*
49654984 * Peek ahead, into following writeback requests, to see if they can
49664985 * be combined with the current one.
49674986 */
49684987for (ahead = 0 ;i + ahead + 1 < context -> nr_pending ;ahead ++ )
49694988{
4989+
49704990next = & context -> pending_writebacks [i + ahead + 1 ];
49714991
49724992/* different file, stop */
4973- if (!RelFileLocatorEquals (cur -> tag .rlocator ,next -> tag .rlocator )||
4974- cur -> tag .forkNum != next -> tag .forkNum )
4993+ if (!RelFileLocatorEquals (currlocator ,
4994+ BufTagGetRelFileLocator (& next -> tag ))||
4995+ BufTagGetForkNum (& cur -> tag )!= BufTagGetForkNum (& next -> tag ))
49754996break ;
49764997
49774998/* ok, block queued twice, skip */
@@ -4989,8 +5010,8 @@ IssuePendingWritebacks(WritebackContext *context)
49895010i += ahead ;
49905011
49915012/* and finally tell the kernel to write the data to storage */
4992- reln = smgropen (tag . rlocator ,InvalidBackendId );
4993- smgrwriteback (reln ,tag . forkNum ,tag .blockNum ,nblocks );
5013+ reln = smgropen (currlocator ,InvalidBackendId );
5014+ smgrwriteback (reln ,BufTagGetForkNum ( & tag ) ,tag .blockNum ,nblocks );
49945015}
49955016
49965017context -> nr_pending = 0 ;