@@ -487,9 +487,9 @@ static void FindAndDropRelFileNodeBuffers(RelFileNode rnode,
487
487
ForkNumber forkNum ,
488
488
BlockNumber nForkBlock ,
489
489
BlockNumber firstDelBlock );
490
- static void RelationCopyStorageUsingBuffer (Relation src , Relation dst ,
491
- ForkNumber forkNum ,
492
- bool isunlogged );
490
+ static void RelationCopyStorageUsingBuffer (RelFileNode srcnode ,
491
+ RelFileNode dstnode ,
492
+ ForkNumber forkNum , bool permanent );
493
493
static void AtProcExit_Buffers (int code , Datum arg );
494
494
static void CheckForBufferLeaks (void );
495
495
static int rnode_comparator (const void * p1 , const void * p2 );
@@ -3702,8 +3702,9 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
3702
3702
* --------------------------------------------------------------------
3703
3703
*/
3704
3704
static void
3705
- RelationCopyStorageUsingBuffer (Relation src , Relation dst , ForkNumber forkNum ,
3706
- bool permanent )
3705
+ RelationCopyStorageUsingBuffer (RelFileNode srcnode ,
3706
+ RelFileNode dstnode ,
3707
+ ForkNumber forkNum , bool permanent )
3707
3708
{
3708
3709
Buffer srcBuf ;
3709
3710
Buffer dstBuf ;
@@ -3723,7 +3724,8 @@ RelationCopyStorageUsingBuffer(Relation src, Relation dst, ForkNumber forkNum,
3723
3724
use_wal = XLogIsNeeded () && (permanent || forkNum == INIT_FORKNUM );
3724
3725
3725
3726
/* Get number of blocks in the source relation. */
3726
- nblocks = smgrnblocks (RelationGetSmgr (src ), forkNum );
3727
+ nblocks = smgrnblocks (smgropen (srcnode , InvalidBackendId ),
3728
+ forkNum );
3727
3729
3728
3730
/* Nothing to copy; just return. */
3729
3731
if (nblocks == 0 )
@@ -3739,14 +3741,14 @@ RelationCopyStorageUsingBuffer(Relation src, Relation dst, ForkNumber forkNum,
3739
3741
CHECK_FOR_INTERRUPTS ();
3740
3742
3741
3743
/* Read block from source relation. */
3742
- srcBuf = ReadBufferWithoutRelcache (src -> rd_node , forkNum , blkno ,
3744
+ srcBuf = ReadBufferWithoutRelcache (srcnode , forkNum , blkno ,
3743
3745
RBM_NORMAL , bstrategy_src ,
3744
3746
permanent );
3745
3747
LockBuffer (srcBuf , BUFFER_LOCK_SHARE );
3746
3748
srcPage = BufferGetPage (srcBuf );
3747
3749
3748
3750
/* Use P_NEW to extend the destination relation. */
3749
- dstBuf = ReadBufferWithoutRelcache (dst -> rd_node , forkNum , P_NEW ,
3751
+ dstBuf = ReadBufferWithoutRelcache (dstnode , forkNum , P_NEW ,
3750
3752
RBM_NORMAL , bstrategy_dst ,
3751
3753
permanent );
3752
3754
LockBuffer (dstBuf , BUFFER_LOCK_EXCLUSIVE );
@@ -3784,24 +3786,13 @@ void
3784
3786
CreateAndCopyRelationData (RelFileNode src_rnode , RelFileNode dst_rnode ,
3785
3787
bool permanent )
3786
3788
{
3787
- Relation src_rel ;
3788
- Relation dst_rel ;
3789
+ RelFileNodeBackend rnode ;
3789
3790
char relpersistence ;
3790
3791
3791
3792
/* Set the relpersistence. */
3792
3793
relpersistence = permanent ?
3793
3794
RELPERSISTENCE_PERMANENT : RELPERSISTENCE_UNLOGGED ;
3794
3795
3795
- /*
3796
- * We can't use a real relcache entry for a relation in some other
3797
- * database, but since we're only going to access the fields related to
3798
- * physical storage, a fake one is good enough. If we didn't do this and
3799
- * used the smgr layer directly, we would have to worry about
3800
- * invalidations.
3801
- */
3802
- src_rel = CreateFakeRelcacheEntry (src_rnode );
3803
- dst_rel = CreateFakeRelcacheEntry (dst_rnode );
3804
-
3805
3796
/*
3806
3797
* Create and copy all forks of the relation. During create database we
3807
3798
* have a separate cleanup mechanism which deletes complete database
@@ -3811,15 +3802,16 @@ CreateAndCopyRelationData(RelFileNode src_rnode, RelFileNode dst_rnode,
3811
3802
RelationCreateStorage (dst_rnode , relpersistence , false);
3812
3803
3813
3804
/* copy main fork. */
3814
- RelationCopyStorageUsingBuffer (src_rel , dst_rel , MAIN_FORKNUM , permanent );
3805
+ RelationCopyStorageUsingBuffer (src_rnode , dst_rnode , MAIN_FORKNUM ,
3806
+ permanent );
3815
3807
3816
3808
/* copy those extra forks that exist */
3817
3809
for (ForkNumber forkNum = MAIN_FORKNUM + 1 ;
3818
3810
forkNum <= MAX_FORKNUM ; forkNum ++ )
3819
3811
{
3820
- if (smgrexists (RelationGetSmgr ( src_rel ), forkNum ))
3812
+ if (smgrexists (smgropen ( src_rnode , InvalidBackendId ), forkNum ))
3821
3813
{
3822
- smgrcreate (RelationGetSmgr ( dst_rel ), forkNum , false);
3814
+ smgrcreate (smgropen ( dst_rnode , InvalidBackendId ), forkNum , false);
3823
3815
3824
3816
/*
3825
3817
* WAL log creation if the relation is persistent, or this is the
@@ -3829,14 +3821,19 @@ CreateAndCopyRelationData(RelFileNode src_rnode, RelFileNode dst_rnode,
3829
3821
log_smgrcreate (& dst_rnode , forkNum );
3830
3822
3831
3823
/* Copy a fork's data, block by block. */
3832
- RelationCopyStorageUsingBuffer (src_rel , dst_rel , forkNum ,
3824
+ RelationCopyStorageUsingBuffer (src_rnode , dst_rnode , forkNum ,
3833
3825
permanent );
3834
3826
}
3835
3827
}
3836
3828
3837
- /* Release fake relcache entries. */
3838
- FreeFakeRelcacheEntry (src_rel );
3839
- FreeFakeRelcacheEntry (dst_rel );
3829
+ /* close source and destination smgr if exists. */
3830
+ rnode .backend = InvalidBackendId ;
3831
+
3832
+ rnode .node = src_rnode ;
3833
+ smgrclosenode (rnode );
3834
+
3835
+ rnode .node = dst_rnode ;
3836
+ smgrclosenode (rnode );
3840
3837
}
3841
3838
3842
3839
/* ---------------------------------------------------------------------
0 commit comments