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

File tree

12 files changed

+74
-116
lines changed

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

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