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