From b7371a62b350954a6c5d967e10056753c3888ff3 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Wed, 29 Apr 2020 11:57:56 -0400
Subject: [PATCH 1/2] Don't export basebackup.c's sendTablespace().

Commit 72d422a5227ef6f76f412486a395aba9f53bf3f0 made xlog.c call
sendTablespace() with the 'sizeonly' argument set to true, which
required basebackup.c to export sendTablespace(). However, that's
kind of ugly, so instead defer the call to sendTablespace() until
basebackup.c regains control. That way, it can still be a static
function.
---
 src/backend/access/transam/xlog.c      |  6 ++----
 src/backend/access/transam/xlogfuncs.c |  4 ++--
 src/backend/replication/basebackup.c   | 18 +++++++++++-------
 src/include/access/xlog.h              |  2 +-
 src/include/replication/basebackup.h   |  6 ------
 5 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 065eb275b1..220dcf1053 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -10468,8 +10468,7 @@ issue_xlog_fsync(int fd, XLogSegNo segno)
 XLogRecPtr
 do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
 				   StringInfo labelfile, List **tablespaces,
-				   StringInfo tblspcmapfile, bool infotbssize,
-				   bool needtblspcmapfile)
+				   StringInfo tblspcmapfile, bool needtblspcmapfile)
 {
 	bool		exclusive = (labelfile == NULL);
 	bool		backup_started_in_recovery = false;
@@ -10761,8 +10760,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
 			ti->oid = pstrdup(de->d_name);
 			ti->path = pstrdup(buflinkpath.data);
 			ti->rpath = relpath ? pstrdup(relpath) : NULL;
-			ti->size = infotbssize ?
-				sendTablespace(fullpath, ti->oid, true, NULL) : -1;
+			ti->size = -1;
 
 			if (tablespaces)
 				*tablespaces = lappend(*tablespaces, ti);
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 00e1b33ed5..290658b22c 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -76,7 +76,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
 	if (exclusive)
 	{
 		startpoint = do_pg_start_backup(backupidstr, fast, NULL, NULL,
-										NULL, NULL, false, true);
+										NULL, NULL, true);
 	}
 	else
 	{
@@ -94,7 +94,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
 		register_persistent_abort_backup_handler();
 
 		startpoint = do_pg_start_backup(backupidstr, fast, NULL, label_file,
-										NULL, tblspc_map_file, false, true);
+										NULL, tblspc_map_file, true);
 	}
 
 	PG_RETURN_LSN(startpoint);
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index fbdc28ec39..b83c1edab0 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -58,6 +58,8 @@ typedef struct
 	pg_checksum_type manifest_checksum_type;
 } basebackup_options;
 
+static int64 sendTablespace(char *path, char *oid, bool sizeonly,
+							struct backup_manifest_info *manifest);
 static int64 sendDir(const char *path, int basepathlen, bool sizeonly,
 					 List *tablespaces, bool sendtblspclinks,
 					 backup_manifest_info *manifest, const char *spcoid);
@@ -307,8 +309,7 @@ perform_base_backup(basebackup_options *opt)
 								 PROGRESS_BASEBACKUP_PHASE_WAIT_CHECKPOINT);
 	startptr = do_pg_start_backup(opt->label, opt->fastcheckpoint, &starttli,
 								  labelfile, &tablespaces,
-								  tblspc_map_file,
-								  opt->progress, opt->sendtblspcmapfile);
+								  tblspc_map_file, opt->sendtblspcmapfile);
 
 	/*
 	 * Once do_pg_start_backup has been called, ensure that any failure causes
@@ -337,10 +338,7 @@ perform_base_backup(basebackup_options *opt)
 
 		/* Add a node for the base directory at the end */
 		ti = palloc0(sizeof(tablespaceinfo));
-		if (opt->progress)
-			ti->size = sendDir(".", 1, true, tablespaces, true, NULL, NULL);
-		else
-			ti->size = -1;
+		ti->size = -1;
 		tablespaces = lappend(tablespaces, ti);
 
 		/*
@@ -353,6 +351,12 @@ perform_base_backup(basebackup_options *opt)
 			{
 				tablespaceinfo *tmp = (tablespaceinfo *) lfirst(lc);
 
+				if (tmp->path == NULL)
+					tmp->size = sendDir(".", 1, true, tablespaces, true, NULL,
+										NULL);
+				else
+					tmp->size = sendTablespace(tmp->path, tmp->oid, true,
+											   NULL);
 				backup_total += tmp->size;
 			}
 		}
@@ -1141,7 +1145,7 @@ sendFileWithContent(const char *filename, const char *content,
  *
  * Only used to send auxiliary tablespaces, not PGDATA.
  */
-int64
+static int64
 sendTablespace(char *path, char *spcoid, bool sizeonly,
 			   backup_manifest_info *manifest)
 {
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 0a12afb59e..26504c633a 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -372,7 +372,7 @@ typedef enum SessionBackupState
 
 extern XLogRecPtr do_pg_start_backup(const char *backupidstr, bool fast,
 									 TimeLineID *starttli_p, StringInfo labelfile,
-									 List **tablespaces, StringInfo tblspcmapfile, bool infotbssize,
+									 List **tablespaces, StringInfo tblspcmapfile,
 									 bool needtblspcmapfile);
 extern XLogRecPtr do_pg_stop_backup(char *labelfile, bool waitforarchive,
 									TimeLineID *stoptli_p);
diff --git a/src/include/replication/basebackup.h b/src/include/replication/basebackup.h
index 923a651cac..f5f044dacd 100644
--- a/src/include/replication/basebackup.h
+++ b/src/include/replication/basebackup.h
@@ -14,9 +14,6 @@
 
 #include "nodes/replnodes.h"
 
-struct backup_manifest_info;	/* avoid including backup_manifest.h */
-
-
 /*
  * Minimum and maximum values of MAX_RATE option in BASE_BACKUP command.
  */
@@ -33,7 +30,4 @@ typedef struct
 
 extern void SendBaseBackup(BaseBackupCmd *cmd);
 
-extern int64 sendTablespace(char *path, char *oid, bool sizeonly,
-							struct backup_manifest_info *manifest);
-
 #endif							/* _BASEBACKUP_H */
-- 
2.24.2 (Apple Git-127)

