Skip to content

Commit ffb4e27

Browse files
committed
pg_rewind: Move syncTargetDirectory() to file_ops.c
For consistency. All the other low-level functions that operate on the target directory are in file_ops.c. Reviewed-by: Michael Paquier Discussion: https://www.postgresql.org/message-id/0c5b3783-af52-3ee5-f8fa-6e794061f70d%40iki.fi
1 parent ac22929 commit ffb4e27

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/bin/pg_rewind/file_ops.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <unistd.h>
2020

2121
#include "common/file_perm.h"
22+
#include "common/file_utils.h"
2223
#include "file_ops.h"
2324
#include "filemap.h"
2425
#include "pg_rewind.h"
@@ -266,6 +267,24 @@ remove_target_symlink(const char *path)
266267
dstpath);
267268
}
268269

270+
/*
271+
* Sync target data directory to ensure that modifications are safely on disk.
272+
*
273+
* We do this once, for the whole data directory, for performance reasons. At
274+
* the end of pg_rewind's run, the kernel is likely to already have flushed
275+
* most dirty buffers to disk. Additionally fsync_pgdata uses a two-pass
276+
* approach (only initiating writeback in the first pass), which often reduces
277+
* the overall amount of IO noticeably.
278+
*/
279+
void
280+
sync_target_dir(void)
281+
{
282+
if (!do_sync || dry_run)
283+
return;
284+
285+
fsync_pgdata(datadir_target, PG_VERSION_NUM);
286+
}
287+
269288

270289
/*
271290
* Read a file into memory. The file to be read is <datadir>/<path>.

src/bin/pg_rewind/file_ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern void remove_target_file(const char *path, bool missing_ok);
1919
extern void truncate_target_file(const char *path, off_t newsize);
2020
extern void create_target(file_entry_t *t);
2121
extern void remove_target(file_entry_t *t);
22+
extern void sync_target_dir(void);
2223

2324
extern char *slurpFile(const char *datadir, const char *path, size_t *filesize);
2425

src/bin/pg_rewind/pg_rewind.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "catalog/pg_control.h"
2121
#include "common/controldata_utils.h"
2222
#include "common/file_perm.h"
23-
#include "common/file_utils.h"
2423
#include "common/restricted_token.h"
2524
#include "common/string.h"
2625
#include "fe_utils/recovery_gen.h"
@@ -38,7 +37,6 @@ static void createBackupLabel(XLogRecPtr startpoint, TimeLineID starttli,
3837

3938
static void digestControlFile(ControlFileData *ControlFile, char *source,
4039
size_t size);
41-
static void syncTargetDirectory(void);
4240
static void getRestoreCommand(const char *argv0);
4341
static void sanityChecks(void);
4442
static void findCommonAncestorTimeline(XLogRecPtr *recptr, int *tliIndex);
@@ -455,7 +453,7 @@ main(int argc, char **argv)
455453

456454
if (showprogress)
457455
pg_log_info("syncing target data directory");
458-
syncTargetDirectory();
456+
sync_target_dir();
459457

460458
if (writerecoveryconf && !dry_run)
461459
WriteRecoveryConfig(conn, datadir_target,
@@ -803,24 +801,6 @@ digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
803801
checkControlFile(ControlFile);
804802
}
805803

806-
/*
807-
* Sync target data directory to ensure that modifications are safely on disk.
808-
*
809-
* We do this once, for the whole data directory, for performance reasons. At
810-
* the end of pg_rewind's run, the kernel is likely to already have flushed
811-
* most dirty buffers to disk. Additionally fsync_pgdata uses a two-pass
812-
* approach (only initiating writeback in the first pass), which often reduces
813-
* the overall amount of IO noticeably.
814-
*/
815-
static void
816-
syncTargetDirectory(void)
817-
{
818-
if (!do_sync || dry_run)
819-
return;
820-
821-
fsync_pgdata(datadir_target, PG_VERSION_NUM);
822-
}
823-
824804
/*
825805
* Get value of GUC parameter restore_command from the target cluster.
826806
*

src/bin/pg_rewind/pg_rewind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern char *datadir_source;
2424
extern char *connstr_source;
2525
extern bool showprogress;
2626
extern bool dry_run;
27+
extern bool do_sync;
2728
extern int WalSegSz;
2829

2930
/* Target history */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy