Skip to content

Commit 53ddefb

Browse files
committed
Remove pg_rewind's private logging.h/logging.c files.
The existence of these files became rather confusing with the introduction of a widely-known logging.h header in commit cc8d415. (Indeed, there's already some duplicative #includes here, perhaps betraying such confusion.) The only thing left in them, after that commit, is a progress-reporting function that's neither general-purpose nor tied in any way to other logging infrastructure. Hence, let's just move that function to pg_rewind.c, and get rid of the separate files. Discussion: https://postgr.es/m/3971.1557787914@sss.pgh.pa.us
1 parent 7c85032 commit 53ddefb

12 files changed

+74
-116
lines changed

src/bin/pg_rewind/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ override CPPFLAGS := -I$(libpq_srcdir) -DFRONTEND $(CPPFLAGS)
1919
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)
2020

2121
OBJS = pg_rewind.o parsexlog.o xlogreader.o datapagemap.o timeline.o \
22-
fetch.o file_ops.o copy_fetch.o libpq_fetch.o filemap.o logging.o \
22+
fetch.o file_ops.o copy_fetch.o libpq_fetch.o filemap.o \
2323
$(WIN32RES)
2424

2525
EXTRA_CLEAN = xlogreader.c

src/bin/pg_rewind/copy_fetch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "fetch.h"
1919
#include "file_ops.h"
2020
#include "filemap.h"
21-
#include "logging.h"
2221
#include "pg_rewind.h"
2322

2423
static void recurse_dir(const char *datadir, const char *path,

src/bin/pg_rewind/file_ops.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "common/file_perm.h"
2222
#include "file_ops.h"
2323
#include "filemap.h"
24-
#include "logging.h"
2524
#include "pg_rewind.h"
2625

2726
/*

src/bin/pg_rewind/filemap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616
#include "datapagemap.h"
1717
#include "filemap.h"
18-
#include "logging.h"
1918
#include "pg_rewind.h"
2019

2120
#include "common/string.h"
2221
#include "catalog/pg_tablespace_d.h"
23-
#include "fe_utils/logging.h"
2422
#include "storage/fd.h"
2523

2624
filemap_t *filemap = NULL;

src/bin/pg_rewind/libpq_fetch.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
#include "fetch.h"
2020
#include "file_ops.h"
2121
#include "filemap.h"
22-
#include "logging.h"
2322

2423
#include "libpq-fe.h"
2524
#include "catalog/pg_type_d.h"
2625
#include "fe_utils/connect.h"
27-
#include "fe_utils/logging.h"
2826
#include "port/pg_bswap.h"
2927

3028
static PGconn *conn = NULL;

src/bin/pg_rewind/logging.c

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/bin/pg_rewind/logging.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/bin/pg_rewind/nls.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# src/bin/pg_rewind/nls.mk
22
CATALOG_NAME = pg_rewind
33
AVAIL_LANGUAGES =de es fr it ja ko pl pt_BR ru sv tr zh_CN
4-
GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) copy_fetch.c datapagemap.c fetch.c file_ops.c filemap.c libpq_fetch.c logging.c parsexlog.c pg_rewind.c timeline.c ../../common/fe_memutils.c ../../common/restricted_token.c xlogreader.c
4+
GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) copy_fetch.c datapagemap.c fetch.c file_ops.c filemap.c libpq_fetch.c parsexlog.c pg_rewind.c timeline.c ../../common/fe_memutils.c ../../common/restricted_token.c xlogreader.c
55
GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) pg_fatal report_invalid_record:2
66
GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS) \
77
pg_fatal:1:c-format \

src/bin/pg_rewind/parsexlog.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "pg_rewind.h"
1717
#include "filemap.h"
18-
#include "logging.h"
1918

2019
#include "access/rmgr.h"
2120
#include "access/xlog_internal.h"

src/bin/pg_rewind/pg_rewind.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "fetch.h"
1919
#include "file_ops.h"
2020
#include "filemap.h"
21-
#include "logging.h"
2221

2322
#include "access/timeline.h"
2423
#include "access/xlog_internal.h"
@@ -28,7 +27,6 @@
2827
#include "common/file_perm.h"
2928
#include "common/file_utils.h"
3029
#include "common/restricted_token.h"
31-
#include "fe_utils/logging.h"
3230
#include "getopt_long.h"
3331
#include "storage/bufpage.h"
3432

@@ -63,6 +61,11 @@ bool do_sync = true;
6361
TimeLineHistoryEntry *targetHistory;
6462
int targetNentries;
6563

64+
/* Progress counters */
65+
uint64 fetch_size;
66+
uint64 fetch_done;
67+
68+
6669
static void
6770
usage(const char *progname)
6871
{
@@ -445,6 +448,61 @@ sanityChecks(void)
445448
pg_fatal("source data directory must be shut down cleanly");
446449
}
447450

451+
/*
452+
* Print a progress report based on the fetch_size and fetch_done variables.
453+
*
454+
* Progress report is written at maximum once per second, unless the
455+
* force parameter is set to true.
456+
*/
457+
void
458+
progress_report(bool force)
459+
{
460+
static pg_time_t last_progress_report = 0;
461+
int percent;
462+
char fetch_done_str[32];
463+
char fetch_size_str[32];
464+
pg_time_t now;
465+
466+
if (!showprogress)
467+
return;
468+
469+
now = time(NULL);
470+
if (now == last_progress_report && !force)
471+
return; /* Max once per second */
472+
473+
last_progress_report = now;
474+
percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
475+
476+
/*
477+
* Avoid overflowing past 100% or the full size. This may make the total
478+
* size number change as we approach the end of the backup (the estimate
479+
* will always be wrong if WAL is included), but that's better than having
480+
* the done column be bigger than the total.
481+
*/
482+
if (percent > 100)
483+
percent = 100;
484+
if (fetch_done > fetch_size)
485+
fetch_size = fetch_done;
486+
487+
/*
488+
* Separate step to keep platform-dependent format code out of
489+
* translatable strings. And we only test for INT64_FORMAT availability
490+
* in snprintf, not fprintf.
491+
*/
492+
snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
493+
fetch_done / 1024);
494+
snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
495+
fetch_size / 1024);
496+
497+
fprintf(stderr, _("%*s/%s kB (%d%%) copied"),
498+
(int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
499+
percent);
500+
if (isatty(fileno(stderr)))
501+
fprintf(stderr, "\r");
502+
else
503+
fprintf(stderr, "\n");
504+
}
505+
448506
/*
449507
* Find minimum from two WAL locations assuming InvalidXLogRecPtr means
450508
* infinity as src/include/access/timeline.h states. This routine should

src/bin/pg_rewind/pg_rewind.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "storage/block.h"
1818
#include "storage/relfilenode.h"
1919

20+
#include "fe_utils/logging.h"
21+
2022
/* Configuration options */
2123
extern char *datadir_target;
2224
extern char *datadir_source;
@@ -29,6 +31,13 @@ extern int WalSegSz;
2931
extern TimeLineHistoryEntry *targetHistory;
3032
extern int targetNentries;
3133

34+
/* Progress counters */
35+
extern uint64 fetch_size;
36+
extern uint64 fetch_done;
37+
38+
/* logging support */
39+
#define pg_fatal(...) do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
40+
3241
/* in parsexlog.c */
3342
extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
3443
int tliIndex, XLogRecPtr endpoint);
@@ -39,6 +48,9 @@ extern void findLastCheckpoint(const char *datadir, XLogRecPtr searchptr,
3948
extern XLogRecPtr readOneRecord(const char *datadir, XLogRecPtr ptr,
4049
int tliIndex);
4150

51+
/* in pg_rewind.c */
52+
extern void progress_report(bool force);
53+
4254
/* in timeline.c */
4355
extern TimeLineHistoryEntry *rewind_parseTimeLineHistory(char *buffer,
4456
TimeLineID targetTLI, int *nentries);

src/bin/pg_rewind/timeline.c

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

1414
#include "access/timeline.h"
1515
#include "access/xlog_internal.h"
16-
#include "fe_utils/logging.h"
1716

1817
/*
1918
* This is copy-pasted from the backend readTimeLineHistory, modified to

0 commit comments

Comments
 (0)