@@ -156,7 +156,10 @@ OpenAOSegmentFile(Relation rel,
156156 File fd ;
157157
158158 errno = 0 ;
159- fd = PathNameOpenFile (filepathname , fileFlags );
159+
160+ RelationOpenSmgr (rel );
161+
162+ fd = rel -> rd_smgr -> smgr_ao -> smgr_AORelOpenSegFile (filepathname , fileFlags );
160163 if (fd < 0 )
161164 {
162165 if (logicalEof == 0 && errno == ENOENT )
@@ -175,9 +178,12 @@ OpenAOSegmentFile(Relation rel,
175178 * Close an Append Only relation file segment
176179 */
177180void
178- CloseAOSegmentFile (File fd )
181+ CloseAOSegmentFile (File fd , Relation rel )
179182{
180- FileClose (fd );
183+ Assert (fd > 0 );
184+ RelationOpenSmgr (rel );
185+
186+ rel -> rd_smgr -> smgr_ao -> smgr_FileClose (fd );
181187}
182188
183189/*
@@ -192,7 +198,9 @@ TruncateAOSegmentFile(File fd, Relation rel, int32 segFileNum, int64 offset, AOV
192198 Assert (fd > 0 );
193199 Assert (offset >= 0 );
194200
195- filesize_before = FileSize (fd );
201+ RelationOpenSmgr (rel );
202+
203+ filesize_before = rel -> rd_smgr -> smgr_ao -> smgr_FileSize (fd );
196204 if (filesize_before < offset )
197205 ereport (ERROR ,
198206 (errmsg ("\"%s\": file size smaller than logical eof: %m" ,
@@ -202,7 +210,7 @@ TruncateAOSegmentFile(File fd, Relation rel, int32 segFileNum, int64 offset, AOV
202210 * Call the 'fd' module with a 64-bit length since AO segment files
203211 * can be multi-gigabyte to the terabytes...
204212 */
205- if (FileTruncate (fd , offset , WAIT_EVENT_DATA_FILE_TRUNCATE ) != 0 )
213+ if (rel -> rd_smgr -> smgr_ao -> smgr_FileTruncate (fd , offset , WAIT_EVENT_DATA_FILE_TRUNCATE ) != 0 )
206214 ereport (ERROR ,
207215 (errmsg ("\"%s\": failed to truncate data after eof: %m" ,
208216 relname )));
@@ -387,7 +395,8 @@ mdunlink_ao_perFile(const int segno, void *ctx)
387395
388396static void
389397copy_file (char * srcsegpath , char * dstsegpath ,
390- RelFileNode dst , int segfilenum , bool use_wal )
398+ RelFileNode dst , SMgrRelation srcSMGR , SMgrRelation dstSMGR ,
399+ int segfilenum , bool use_wal )
391400{
392401 File srcFile ;
393402 File dstFile ;
@@ -396,7 +405,7 @@ copy_file(char *srcsegpath, char *dstsegpath,
396405 char * buffer = palloc (BLCKSZ );
397406 int dstflags ;
398407
399- srcFile = PathNameOpenFile (srcsegpath , O_RDONLY | PG_BINARY );
408+ srcFile = srcSMGR -> smgr_ao -> smgr_AORelOpenSegFile (srcsegpath , O_RDONLY | PG_BINARY );
400409 if (srcFile < 0 )
401410 ereport (ERROR ,
402411 (errcode_for_file_access (),
@@ -411,13 +420,13 @@ copy_file(char *srcsegpath, char *dstsegpath,
411420 if (segfilenum )
412421 dstflags |= O_CREAT ;
413422
414- dstFile = PathNameOpenFile (dstsegpath , dstflags );
423+ dstFile = dstSMGR -> smgr_ao -> smgr_AORelOpenSegFile (dstsegpath , dstflags );
415424 if (dstFile < 0 )
416425 ereport (ERROR ,
417426 (errcode_for_file_access (),
418427 (errmsg ("could not create destination file %s: %m" , dstsegpath ))));
419428
420- left = FileDiskSize (srcFile );
429+ left = srcSMGR -> smgr_ao -> smgr_FileDiskSize (srcFile );
421430 if (left < 0 )
422431 ereport (ERROR ,
423432 (errcode_for_file_access (),
@@ -431,13 +440,13 @@ copy_file(char *srcsegpath, char *dstsegpath,
431440 CHECK_FOR_INTERRUPTS ();
432441
433442 len = Min (left , BLCKSZ );
434- if (FileRead (srcFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_READ ) != len )
443+ if (srcSMGR -> smgr_ao -> smgr_FileRead (srcFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_READ ) != len )
435444 ereport (ERROR ,
436445 (errcode_for_file_access (),
437446 errmsg ("could not read %d bytes from file \"%s\": %m" ,
438447 len , srcsegpath )));
439448
440- if (FileWrite (dstFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_WRITE ) != len )
449+ if (dstSMGR -> smgr_ao -> smgr_FileWrite (dstFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_WRITE ) != len )
441450 ereport (ERROR ,
442451 (errcode_for_file_access (),
443452 errmsg ("could not write %d bytes to file \"%s\": %m" ,
@@ -449,19 +458,21 @@ copy_file(char *srcsegpath, char *dstsegpath,
449458 left -= len ;
450459 }
451460
452- if (FileSync (dstFile , WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC ) != 0 )
461+ if (dstSMGR -> smgr_ao -> smgr_FileSync (dstFile , WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC ) != 0 )
453462 ereport (ERROR ,
454463 (errcode_for_file_access (),
455464 errmsg ("could not fsync file \"%s\": %m" ,
456465 dstsegpath )));
457- FileClose (srcFile );
458- FileClose (dstFile );
466+ srcSMGR -> smgr_ao -> smgr_FileClose (srcFile );
467+ dstSMGR -> smgr_ao -> smgr_FileClose (dstFile );
459468 pfree (buffer );
460469}
461470
462471struct copy_append_only_data_callback_ctx {
463472 char * srcPath ;
464473 char * dstPath ;
474+ SMgrRelation srcSMGR ;
475+ SMgrRelation dstSMGR ;
465476 RelFileNode src ;
466477 RelFileNode dst ;
467478 bool useWal ;
@@ -473,6 +484,7 @@ struct copy_append_only_data_callback_ctx {
473484 */
474485void
475486copy_append_only_data (RelFileNode src , RelFileNode dst ,
487+ SMgrRelation srcSMGR , SMgrRelation dstSMGR ,
476488 BackendId backendid , char relpersistence )
477489{
478490 char * srcPath ;
@@ -488,10 +500,12 @@ copy_append_only_data(RelFileNode src, RelFileNode dst,
488500 srcPath = relpathbackend (src , backendid , MAIN_FORKNUM );
489501 dstPath = relpathbackend (dst , backendid , MAIN_FORKNUM );
490502
491- copy_file (srcPath , dstPath , dst , 0 , useWal );
503+ copy_file (srcPath , dstPath , dst , srcSMGR , dstSMGR , 0 , useWal );
492504
493505 copyFiles .srcPath = srcPath ;
494506 copyFiles .dstPath = dstPath ;
507+ copyFiles .srcSMGR = srcSMGR ;
508+ copyFiles .dstSMGR = dstSMGR ;
495509 copyFiles .src = src ;
496510 copyFiles .dst = dst ;
497511 copyFiles .useWal = useWal ;
@@ -526,7 +540,7 @@ copy_append_only_data_perFile(const int segno, void *ctx)
526540 return false;
527541 }
528542 sprintf (dstSegPath , "%s.%u" , copyFiles -> dstPath , segno );
529- copy_file (srcSegPath , dstSegPath , copyFiles -> dst , segno , copyFiles -> useWal );
543+ copy_file (srcSegPath , dstSegPath , copyFiles -> dst , copyFiles -> srcSMGR , copyFiles -> dstSMGR , segno , copyFiles -> useWal );
530544
531545 return true;
532546}
@@ -595,7 +609,7 @@ truncate_ao_perFile(const int segno, void *ctx)
595609 if (fd >= 0 )
596610 {
597611 TruncateAOSegmentFile (fd , aorel , segno , 0 , NULL );
598- CloseAOSegmentFile (fd );
612+ CloseAOSegmentFile (fd , aorel );
599613 }
600614 else
601615 {
0 commit comments