Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcccc6cd

Browse files
Add support for syncfs() in frontend support functions.
This commit adds support for using syncfs() in fsync_pgdata() andfsync_dir_recurse() (which have been renamed to sync_pgdata() andsync_dir_recurse()). Like recovery_init_sync_method,sync_pgdata() calls syncfs() for the data directory, eachtablespace, and pg_wal (if it is a symlink). For now, all of thefrontend utilities that use these support functions are hard-codedto use fsync(), but a follow-up commit will allow specifyingsyncfs().Co-authored-by: Justin PryzbyReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/20210930004340.GM831%40telsasoft.com
1 parent3ed1956 commitcccc6cd

File tree

13 files changed

+190
-56
lines changed

13 files changed

+190
-56
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static bool show_setting = false;
165165
staticbooldata_checksums= false;
166166
staticchar*xlog_dir=NULL;
167167
staticintwal_segment_size_mb= (DEFAULT_XLOG_SEG_SIZE) / (1024*1024);
168+
staticDataDirSyncMethodsync_method=DATA_DIR_SYNC_METHOD_FSYNC;
168169

169170

170171
/* internal vars */
@@ -3322,7 +3323,7 @@ main(int argc, char *argv[])
33223323

33233324
atexit(cleanup_directories_atexit);
33243325

3325-
/* If we only need tofsync, just do it and exit */
3326+
/* If we only need tosync, just do it and exit */
33263327
if (sync_only)
33273328
{
33283329
setup_pgdata();
@@ -3333,7 +3334,7 @@ main(int argc, char *argv[])
33333334

33343335
fputs(_("syncing data to disk ... "),stdout);
33353336
fflush(stdout);
3336-
fsync_pgdata(pg_data,PG_VERSION_NUM);
3337+
sync_pgdata(pg_data,PG_VERSION_NUM,sync_method);
33373338
check_ok();
33383339
return0;
33393340
}
@@ -3396,7 +3397,7 @@ main(int argc, char *argv[])
33963397
{
33973398
fputs(_("syncing data to disk ... "),stdout);
33983399
fflush(stdout);
3399-
fsync_pgdata(pg_data,PG_VERSION_NUM);
3400+
sync_pgdata(pg_data,PG_VERSION_NUM,sync_method);
34003401
check_ok();
34013402
}
34023403
else

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static bool verify_checksums = true;
148148
staticboolmanifest= true;
149149
staticboolmanifest_force_encode= false;
150150
staticchar*manifest_checksums=NULL;
151+
staticDataDirSyncMethodsync_method=DATA_DIR_SYNC_METHOD_FSYNC;
151152

152153
staticboolsuccess= false;
153154
staticboolmade_new_pgdata= false;
@@ -2199,11 +2200,11 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
21992200
if (format=='t')
22002201
{
22012202
if (strcmp(basedir,"-")!=0)
2202-
(void)fsync_dir_recurse(basedir);
2203+
(void)sync_dir_recurse(basedir,sync_method);
22032204
}
22042205
else
22052206
{
2206-
(void)fsync_pgdata(basedir,serverVersion);
2207+
(void)sync_pgdata(basedir,serverVersion,sync_method);
22072208
}
22082209
}
22092210

‎src/bin/pg_checksums/pg_checksums.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static char *only_filenode = NULL;
4444
staticbooldo_sync= true;
4545
staticboolverbose= false;
4646
staticboolshowprogress= false;
47+
staticDataDirSyncMethodsync_method=DATA_DIR_SYNC_METHOD_FSYNC;
4748

4849
typedefenum
4950
{
@@ -623,7 +624,7 @@ main(int argc, char *argv[])
623624
if (do_sync)
624625
{
625626
pg_log_info("syncing data directory");
626-
fsync_pgdata(DataDir,PG_VERSION_NUM);
627+
sync_pgdata(DataDir,PG_VERSION_NUM,sync_method);
627628
}
628629

629630
pg_log_info("updating control file");

‎src/bin/pg_dump/pg_backup.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#definePG_BACKUP_H
2525

2626
#include"common/compression.h"
27+
#include"common/file_utils.h"
2728
#include"fe_utils/simple_list.h"
2829
#include"libpq-fe.h"
2930

@@ -307,7 +308,8 @@ extern Archive *OpenArchive(const char *FileSpec, const ArchiveFormat fmt);
307308
externArchive*CreateArchive(constchar*FileSpec,constArchiveFormatfmt,
308309
constpg_compress_specificationcompression_spec,
309310
booldosync,ArchiveModemode,
310-
SetupWorkerPtrTypesetupDumpWorker);
311+
SetupWorkerPtrTypesetupDumpWorker,
312+
DataDirSyncMethodsync_method);
311313

312314
/* The --list option */
313315
externvoidPrintTOCSummary(Archive*AHX);

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ typedef struct _parallelReadyList
6666
staticArchiveHandle*_allocAH(constchar*FileSpec,constArchiveFormatfmt,
6767
constpg_compress_specificationcompression_spec,
6868
booldosync,ArchiveModemode,
69-
SetupWorkerPtrTypesetupWorkerPtr);
69+
SetupWorkerPtrTypesetupWorkerPtr,
70+
DataDirSyncMethodsync_method);
7071
staticvoid_getObjectDescription(PQExpBufferbuf,constTocEntry*te);
7172
staticvoid_printTocEntry(ArchiveHandle*AH,TocEntry*te,boolisData);
7273
staticchar*sanitize_line(constchar*str,boolwant_hyphen);
@@ -238,11 +239,12 @@ Archive *
238239
CreateArchive(constchar*FileSpec,constArchiveFormatfmt,
239240
constpg_compress_specificationcompression_spec,
240241
booldosync,ArchiveModemode,
241-
SetupWorkerPtrTypesetupDumpWorker)
242+
SetupWorkerPtrTypesetupDumpWorker,
243+
DataDirSyncMethodsync_method)
242244

243245
{
244246
ArchiveHandle*AH=_allocAH(FileSpec,fmt,compression_spec,
245-
dosync,mode,setupDumpWorker);
247+
dosync,mode,setupDumpWorker,sync_method);
246248

247249
return (Archive*)AH;
248250
}
@@ -257,7 +259,8 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
257259

258260
compression_spec.algorithm=PG_COMPRESSION_NONE;
259261
AH=_allocAH(FileSpec,fmt,compression_spec, true,
260-
archModeRead,setupRestoreWorker);
262+
archModeRead,setupRestoreWorker,
263+
DATA_DIR_SYNC_METHOD_FSYNC);
261264

262265
return (Archive*)AH;
263266
}
@@ -2233,7 +2236,7 @@ static ArchiveHandle *
22332236
_allocAH(constchar*FileSpec,constArchiveFormatfmt,
22342237
constpg_compress_specificationcompression_spec,
22352238
booldosync,ArchiveModemode,
2236-
SetupWorkerPtrTypesetupWorkerPtr)
2239+
SetupWorkerPtrTypesetupWorkerPtr,DataDirSyncMethodsync_method)
22372240
{
22382241
ArchiveHandle*AH;
22392242
CompressFileHandle*CFH;
@@ -2287,6 +2290,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
22872290
AH->mode=mode;
22882291
AH->compression_spec=compression_spec;
22892292
AH->dosync=dosync;
2293+
AH->sync_method=sync_method;
22902294

22912295
memset(&(AH->sqlparse),0,sizeof(AH->sqlparse));
22922296

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ struct _archiveHandle
312312
pg_compress_specificationcompression_spec;/* Requested specification for
313313
* compression */
314314
booldosync;/* data requested to be synced on sight */
315+
DataDirSyncMethodsync_method;
315316
ArchiveModemode;/* File mode - r or w */
316317
void*formatData;/* Header data specific to file format */
317318

‎src/bin/pg_dump/pg_backup_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ _CloseArchive(ArchiveHandle *AH)
613613
* individually. Just recurse once through all the files generated.
614614
*/
615615
if (AH->dosync)
616-
fsync_dir_recurse(ctx->directory);
616+
sync_dir_recurse(ctx->directory,AH->sync_method);
617617
}
618618
AH->FH=NULL;
619619
}

‎src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ main(int argc, char **argv)
357357
char *compression_algorithm_str = "none";
358358
char *error_detail = NULL;
359359
booluser_compression_defined = false;
360+
DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC;
360361

361362
static DumpOptions dopt;
362363

@@ -777,7 +778,7 @@ main(int argc, char **argv)
777778

778779
/* Open the output file */
779780
fout = CreateArchive(filename, archiveFormat, compression_spec,
780-
dosync, archiveMode, setupDumpWorker);
781+
dosync, archiveMode, setupDumpWorker, sync_method);
781782

782783
/* Make dump options accessible right away */
783784
SetArchiveOptions(fout, &dopt, NULL);

‎src/bin/pg_rewind/file_ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,17 @@ remove_target_symlink(const char *path)
286286
*
287287
* We do this once, for the whole data directory, for performance reasons. At
288288
* the end of pg_rewind's run, the kernel is likely to already have flushed
289-
* most dirty buffers to disk. Additionallyfsync_pgdata uses a two-pass
290-
* approach (only initiating writeback in the first pass), which often reduces
291-
* the overall amount of IO noticeably.
289+
* most dirty buffers to disk. Additionallysync_pgdata uses a two-pass
290+
* approachwhen fsync is specified(only initiating writeback in the first
291+
*pass), which often reducesthe overall amount of IO noticeably.
292292
*/
293293
void
294294
sync_target_dir(void)
295295
{
296296
if (!do_sync||dry_run)
297297
return;
298298

299-
fsync_pgdata(datadir_target,PG_VERSION_NUM);
299+
sync_pgdata(datadir_target,PG_VERSION_NUM,sync_method);
300300
}
301301

302302

‎src/bin/pg_rewind/pg_rewind.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ boolshowprogress = false;
7474
booldry_run= false;
7575
booldo_sync= true;
7676
boolrestore_wal= false;
77+
DataDirSyncMethodsync_method=DATA_DIR_SYNC_METHOD_FSYNC;
7778

7879
/* Target history */
7980
TimeLineHistoryEntry*targetHistory;

‎src/bin/pg_rewind/pg_rewind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include"access/timeline.h"
1515
#include"common/logging.h"
16+
#include"common/file_utils.h"
1617
#include"datapagemap.h"
1718
#include"libpq-fe.h"
1819
#include"storage/block.h"
@@ -24,6 +25,7 @@ extern bool showprogress;
2425
externbooldry_run;
2526
externbooldo_sync;
2627
externintWalSegSz;
28+
externDataDirSyncMethodsync_method;
2729

2830
/* Target history */
2931
externTimeLineHistoryEntry*targetHistory;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp