]> granicus.if.org Git - postgresql/commitdiff
Remove pg_rewind's private logging.h/logging.c files.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 May 2019 17:11:23 +0000 (13:11 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 May 2019 17:11:23 +0000 (13:11 -0400)
The existence of these files became rather confusing with the
introduction of a widely-known logging.h header in commit cc8d41511.
(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

12 files changed:
src/bin/pg_rewind/Makefile
src/bin/pg_rewind/copy_fetch.c
src/bin/pg_rewind/file_ops.c
src/bin/pg_rewind/filemap.c
src/bin/pg_rewind/libpq_fetch.c
src/bin/pg_rewind/logging.c [deleted file]
src/bin/pg_rewind/logging.h [deleted file]
src/bin/pg_rewind/nls.mk
src/bin/pg_rewind/parsexlog.c
src/bin/pg_rewind/pg_rewind.c
src/bin/pg_rewind/pg_rewind.h
src/bin/pg_rewind/timeline.c

index 019e19986eb0f41d014bd04381ca9539de699fdc..5455fd4e296decc65e43bf2128891722b3ac89ec 100644 (file)
@@ -19,7 +19,7 @@ override CPPFLAGS := -I$(libpq_srcdir) -DFRONTEND $(CPPFLAGS)
 LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)
 
 OBJS   = pg_rewind.o parsexlog.o xlogreader.o datapagemap.o timeline.o \
-       fetch.o file_ops.o copy_fetch.o libpq_fetch.o filemap.o logging.o \
+       fetch.o file_ops.o copy_fetch.o libpq_fetch.o filemap.o \
        $(WIN32RES)
 
 EXTRA_CLEAN = xlogreader.c
index 3fd0404ddfbf5806696f58bb18c3f8ec08c4fcd1..2ada8611ee4186ef4c2c281629cab4d17d9ffbdc 100644 (file)
@@ -18,7 +18,6 @@
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "logging.h"
 #include "pg_rewind.h"
 
 static void recurse_dir(const char *datadir, const char *path,
index e442f9355557b72d0c5cf44a239d1614e0aee168..f9e41b1fc40552a8f14d5ce18f7bdd299b9679c1 100644 (file)
@@ -21,7 +21,6 @@
 #include "common/file_perm.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "logging.h"
 #include "pg_rewind.h"
 
 /*
index 63d0baee74565a8654e7ae334770a050db4bdc9d..813eadcb017185f0356405eb34d1fc8807644db4 100644 (file)
 
 #include "datapagemap.h"
 #include "filemap.h"
-#include "logging.h"
 #include "pg_rewind.h"
 
 #include "common/string.h"
 #include "catalog/pg_tablespace_d.h"
-#include "fe_utils/logging.h"
 #include "storage/fd.h"
 
 filemap_t  *filemap = NULL;
index 11ec045b8eccef119af273ab236a1b3300353fbe..b6fa7e5b09c3d52694b51bdd167d6a6a849c00d6 100644 (file)
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "logging.h"
 
 #include "libpq-fe.h"
 #include "catalog/pg_type_d.h"
 #include "fe_utils/connect.h"
-#include "fe_utils/logging.h"
 #include "port/pg_bswap.h"
 
 static PGconn *conn = NULL;
diff --git a/src/bin/pg_rewind/logging.c b/src/bin/pg_rewind/logging.c
deleted file mode 100644 (file)
index 8169f73..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * logging.c
- *      logging functions
- *
- *     Copyright (c) 2010-2019, PostgreSQL Global Development Group
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres_fe.h"
-
-#include <unistd.h>
-#include <time.h>
-
-#include "pg_rewind.h"
-#include "logging.h"
-
-#include "pgtime.h"
-
-/* Progress counters */
-uint64         fetch_size;
-uint64         fetch_done;
-
-static pg_time_t last_progress_report = 0;
-
-
-/*
- * Print a progress report based on the global variables.
- *
- * Progress report is written at maximum once per second, unless the
- * force parameter is set to true.
- */
-void
-progress_report(bool force)
-{
-       int                     percent;
-       char            fetch_done_str[32];
-       char            fetch_size_str[32];
-       pg_time_t       now;
-
-       if (!showprogress)
-               return;
-
-       now = time(NULL);
-       if (now == last_progress_report && !force)
-               return;                                 /* Max once per second */
-
-       last_progress_report = now;
-       percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
-
-       /*
-        * Avoid overflowing past 100% or the full size. This may make the total
-        * size number change as we approach the end of the backup (the estimate
-        * will always be wrong if WAL is included), but that's better than having
-        * the done column be bigger than the total.
-        */
-       if (percent > 100)
-               percent = 100;
-       if (fetch_done > fetch_size)
-               fetch_size = fetch_done;
-
-       /*
-        * Separate step to keep platform-dependent format code out of
-        * translatable strings.  And we only test for INT64_FORMAT availability
-        * in snprintf, not fprintf.
-        */
-       snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
-                        fetch_done / 1024);
-       snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
-                        fetch_size / 1024);
-
-       fprintf(stderr, _("%*s/%s kB (%d%%) copied"),
-                  (int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
-                  percent);
-       if (isatty(fileno(stderr)))
-               fprintf(stderr, "\r");
-       else
-               fprintf(stderr, "\n");
-}
diff --git a/src/bin/pg_rewind/logging.h b/src/bin/pg_rewind/logging.h
deleted file mode 100644 (file)
index 81e17ac..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * logging.h
- *      prototypes for logging functions
- *
- *
- * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PG_REWIND_LOGGING_H
-#define PG_REWIND_LOGGING_H
-
-#include "fe_utils/logging.h"
-
-/* progress counters */
-extern uint64 fetch_size;
-extern uint64 fetch_done;
-
-extern void progress_report(bool force);
-
-#define pg_fatal(...) do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
-
-#endif                                                 /* PG_REWIND_LOGGING_H */
index 58c9ede548d1d56ae62bd8fe5920c32a529b8023..ba29d62545cf2238308667799752f1d570f390f7 100644 (file)
@@ -1,7 +1,7 @@
 # src/bin/pg_rewind/nls.mk
 CATALOG_NAME     = pg_rewind
 AVAIL_LANGUAGES  =de es fr it ja ko pl pt_BR ru sv tr zh_CN
-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
+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
 GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) pg_fatal report_invalid_record:2
 GETTEXT_FLAGS    = $(FRONTEND_COMMON_GETTEXT_FLAGS) \
     pg_fatal:1:c-format \
index 7709b96e00807f3c52a6acae9c3e1b3eabacf3fd..65e523f5d4e87cbaad17d86407c4b0ce0f8199e6 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "pg_rewind.h"
 #include "filemap.h"
-#include "logging.h"
 
 #include "access/rmgr.h"
 #include "access/xlog_internal.h"
index 3702efaf9f42509d8208d4e1a1112b2b34f48efc..d47b5f9648fe3aa2ab8c12f0927356f5de862a91 100644 (file)
@@ -18,7 +18,6 @@
 #include "fetch.h"
 #include "file_ops.h"
 #include "filemap.h"
-#include "logging.h"
 
 #include "access/timeline.h"
 #include "access/xlog_internal.h"
@@ -28,7 +27,6 @@
 #include "common/file_perm.h"
 #include "common/file_utils.h"
 #include "common/restricted_token.h"
-#include "fe_utils/logging.h"
 #include "getopt_long.h"
 #include "storage/bufpage.h"
 
@@ -63,6 +61,11 @@ bool         do_sync = true;
 TimeLineHistoryEntry *targetHistory;
 int                    targetNentries;
 
+/* Progress counters */
+uint64         fetch_size;
+uint64         fetch_done;
+
+
 static void
 usage(const char *progname)
 {
@@ -445,6 +448,61 @@ sanityChecks(void)
                pg_fatal("source data directory must be shut down cleanly");
 }
 
+/*
+ * Print a progress report based on the fetch_size and fetch_done variables.
+ *
+ * Progress report is written at maximum once per second, unless the
+ * force parameter is set to true.
+ */
+void
+progress_report(bool force)
+{
+       static pg_time_t last_progress_report = 0;
+       int                     percent;
+       char            fetch_done_str[32];
+       char            fetch_size_str[32];
+       pg_time_t       now;
+
+       if (!showprogress)
+               return;
+
+       now = time(NULL);
+       if (now == last_progress_report && !force)
+               return;                                 /* Max once per second */
+
+       last_progress_report = now;
+       percent = fetch_size ? (int) ((fetch_done) * 100 / fetch_size) : 0;
+
+       /*
+        * Avoid overflowing past 100% or the full size. This may make the total
+        * size number change as we approach the end of the backup (the estimate
+        * will always be wrong if WAL is included), but that's better than having
+        * the done column be bigger than the total.
+        */
+       if (percent > 100)
+               percent = 100;
+       if (fetch_done > fetch_size)
+               fetch_size = fetch_done;
+
+       /*
+        * Separate step to keep platform-dependent format code out of
+        * translatable strings.  And we only test for INT64_FORMAT availability
+        * in snprintf, not fprintf.
+        */
+       snprintf(fetch_done_str, sizeof(fetch_done_str), INT64_FORMAT,
+                        fetch_done / 1024);
+       snprintf(fetch_size_str, sizeof(fetch_size_str), INT64_FORMAT,
+                        fetch_size / 1024);
+
+       fprintf(stderr, _("%*s/%s kB (%d%%) copied"),
+                  (int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
+                  percent);
+       if (isatty(fileno(stderr)))
+               fprintf(stderr, "\r");
+       else
+               fprintf(stderr, "\n");
+}
+
 /*
  * Find minimum from two WAL locations assuming InvalidXLogRecPtr means
  * infinity as src/include/access/timeline.h states. This routine should
index f2cc2800aa4ededbb93ff223edf8c4391782a4ee..9e6f9474d5900f5eb1a6f79348fbce894d80338a 100644 (file)
@@ -17,6 +17,8 @@
 #include "storage/block.h"
 #include "storage/relfilenode.h"
 
+#include "fe_utils/logging.h"
+
 /* Configuration options */
 extern char *datadir_target;
 extern char *datadir_source;
@@ -29,6 +31,13 @@ extern int   WalSegSz;
 extern TimeLineHistoryEntry *targetHistory;
 extern int     targetNentries;
 
+/* Progress counters */
+extern uint64 fetch_size;
+extern uint64 fetch_done;
+
+/* logging support */
+#define pg_fatal(...) do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
+
 /* in parsexlog.c */
 extern void extractPageMap(const char *datadir, XLogRecPtr startpoint,
                           int tliIndex, XLogRecPtr endpoint);
@@ -39,6 +48,9 @@ extern void findLastCheckpoint(const char *datadir, XLogRecPtr searchptr,
 extern XLogRecPtr readOneRecord(const char *datadir, XLogRecPtr ptr,
                          int tliIndex);
 
+/* in pg_rewind.c */
+extern void progress_report(bool force);
+
 /* in timeline.c */
 extern TimeLineHistoryEntry *rewind_parseTimeLineHistory(char *buffer,
                                                        TimeLineID targetTLI, int *nentries);
index 12b19b353c2d68457b9246b24e6fbf69d7168cfd..987452c4f41e879e506a3b50e5cb3b30c3b92e9a 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "access/timeline.h"
 #include "access/xlog_internal.h"
-#include "fe_utils/logging.h"
 
 /*
  * This is copy-pasted from the backend readTimeLineHistory, modified to