@@ -149,7 +149,10 @@ OpenAOSegmentFile(Relation rel,
149149 File fd ;
150150
151151 errno = 0 ;
152- fd = PathNameOpenFile (filepathname , fileFlags );
152+
153+ RelationOpenSmgr (rel );
154+
155+ fd = rel -> rd_smgr -> smgr_ao -> smgr_AORelOpenSegFile (filepathname , fileFlags );
153156 if (fd < 0 )
154157 {
155158 if (logicalEof == 0 && errno == ENOENT )
@@ -168,9 +171,9 @@ OpenAOSegmentFile(Relation rel,
168171 * Close an Append Only relation file segment
169172 */
170173void
171- CloseAOSegmentFile (File fd )
174+ CloseAOSegmentFile (File fd , Relation rel )
172175{
173- FileClose (fd );
176+ rel -> rd_smgr -> smgr_ao -> smgr_FileClose (fd );
174177}
175178
176179/*
@@ -184,11 +187,13 @@ TruncateAOSegmentFile(File fd, Relation rel, int32 segFileNum, int64 offset)
184187 Assert (fd > 0 );
185188 Assert (offset >= 0 );
186189
190+ RelationOpenSmgr (rel );
191+
187192 /*
188193 * Call the 'fd' module with a 64-bit length since AO segment files
189194 * can be multi-gigabyte to the terabytes...
190195 */
191- if (FileTruncate (fd , offset , WAIT_EVENT_DATA_FILE_TRUNCATE ) != 0 )
196+ if (rel -> rd_smgr -> smgr_ao -> smgr_FileTruncate (fd , offset , WAIT_EVENT_DATA_FILE_TRUNCATE ) != 0 )
192197 ereport (ERROR ,
193198 (errmsg ("\"%s\": failed to truncate data after eof: %m" ,
194199 relname )));
@@ -363,7 +368,8 @@ mdunlink_ao_perFile(const int segno, void *ctx)
363368
364369static void
365370copy_file (char * srcsegpath , char * dstsegpath ,
366- RelFileNode dst , int segfilenum , bool use_wal )
371+ RelFileNode dst , SMgrRelation srcSMGR , SMgrRelation dstSMGR ,
372+ int segfilenum , bool use_wal )
367373{
368374 File srcFile ;
369375 File dstFile ;
@@ -372,7 +378,7 @@ copy_file(char *srcsegpath, char *dstsegpath,
372378 char * buffer = palloc (BLCKSZ );
373379 int dstflags ;
374380
375- srcFile = PathNameOpenFile (srcsegpath , O_RDONLY | PG_BINARY );
381+ srcFile = srcSMGR -> smgr_ao -> smgr_AORelOpenSegFile (srcsegpath , O_RDONLY | PG_BINARY );
376382 if (srcFile < 0 )
377383 ereport (ERROR ,
378384 (errcode_for_file_access (),
@@ -387,13 +393,13 @@ copy_file(char *srcsegpath, char *dstsegpath,
387393 if (segfilenum )
388394 dstflags |= O_CREAT ;
389395
390- dstFile = PathNameOpenFile (dstsegpath , dstflags );
396+ dstFile = dstSMGR -> smgr_ao -> smgr_AORelOpenSegFile (dstsegpath , dstflags );
391397 if (dstFile < 0 )
392398 ereport (ERROR ,
393399 (errcode_for_file_access (),
394400 (errmsg ("could not create destination file %s: %m" , dstsegpath ))));
395401
396- left = FileDiskSize (srcFile );
402+ left = srcSMGR -> smgr_ao -> smgr_FileDiskSize (srcFile );
397403 if (left < 0 )
398404 ereport (ERROR ,
399405 (errcode_for_file_access (),
@@ -407,13 +413,13 @@ copy_file(char *srcsegpath, char *dstsegpath,
407413 CHECK_FOR_INTERRUPTS ();
408414
409415 len = Min (left , BLCKSZ );
410- if (FileRead (srcFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_READ ) != len )
416+ if (srcSMGR -> smgr_ao -> smgr_FileRead (srcFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_READ ) != len )
411417 ereport (ERROR ,
412418 (errcode_for_file_access (),
413419 errmsg ("could not read %d bytes from file \"%s\": %m" ,
414420 len , srcsegpath )));
415421
416- if (FileWrite (dstFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_WRITE ) != len )
422+ if (dstSMGR -> smgr_ao -> smgr_FileWrite (dstFile , buffer , len , offset , WAIT_EVENT_DATA_FILE_WRITE ) != len )
417423 ereport (ERROR ,
418424 (errcode_for_file_access (),
419425 errmsg ("could not write %d bytes to file \"%s\": %m" ,
@@ -425,19 +431,21 @@ copy_file(char *srcsegpath, char *dstsegpath,
425431 left -= len ;
426432 }
427433
428- if (FileSync (dstFile , WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC ) != 0 )
434+ if (dstSMGR -> smgr_ao -> smgr_FileSync (dstFile , WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC ) != 0 )
429435 ereport (ERROR ,
430436 (errcode_for_file_access (),
431437 errmsg ("could not fsync file \"%s\": %m" ,
432438 dstsegpath )));
433- FileClose (srcFile );
434- FileClose (dstFile );
439+ srcSMGR -> smgr_ao -> smgr_FileClose (srcFile );
440+ dstSMGR -> smgr_ao -> smgr_FileClose (dstFile );
435441 pfree (buffer );
436442}
437443
438444struct copy_append_only_data_callback_ctx {
439445 char * srcPath ;
440446 char * dstPath ;
447+ SMgrRelation srcSMGR ;
448+ SMgrRelation dstSMGR ;
441449 RelFileNode src ;
442450 RelFileNode dst ;
443451 bool useWal ;
@@ -449,6 +457,7 @@ struct copy_append_only_data_callback_ctx {
449457 */
450458void
451459copy_append_only_data (RelFileNode src , RelFileNode dst ,
460+ SMgrRelation srcSMGR , SMgrRelation dstSMGR ,
452461 BackendId backendid , char relpersistence )
453462{
454463 char * srcPath ;
@@ -464,10 +473,12 @@ copy_append_only_data(RelFileNode src, RelFileNode dst,
464473 srcPath = relpathbackend (src , backendid , MAIN_FORKNUM );
465474 dstPath = relpathbackend (dst , backendid , MAIN_FORKNUM );
466475
467- copy_file (srcPath , dstPath , dst , 0 , useWal );
476+ copy_file (srcPath , dstPath , dst , srcSMGR , dstSMGR , 0 , useWal );
468477
469478 copyFiles .srcPath = srcPath ;
470479 copyFiles .dstPath = dstPath ;
480+ copyFiles .srcSMGR = srcSMGR ;
481+ copyFiles .dstSMGR = dstSMGR ;
471482 copyFiles .src = src ;
472483 copyFiles .dst = dst ;
473484 copyFiles .useWal = useWal ;
@@ -502,7 +513,7 @@ copy_append_only_data_perFile(const int segno, void *ctx)
502513 return false;
503514 }
504515 sprintf (dstSegPath , "%s.%u" , copyFiles -> dstPath , segno );
505- copy_file (srcSegPath , dstSegPath , copyFiles -> dst , segno , copyFiles -> useWal );
516+ copy_file (srcSegPath , dstSegPath , copyFiles -> dst , copyFiles -> srcSMGR , copyFiles -> dstSMGR , segno , copyFiles -> useWal );
506517
507518 return true;
508519}
@@ -571,7 +582,7 @@ truncate_ao_perFile(const int segno, void *ctx)
571582 if (fd >= 0 )
572583 {
573584 TruncateAOSegmentFile (fd , aorel , segno , 0 );
574- CloseAOSegmentFile (fd );
585+ CloseAOSegmentFile (fd , aorel );
575586 }
576587 else
577588 {
0 commit comments