From 0eea8047bf0e15b402b951e383e39236bdfe57d5 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 14 Oct 2014 15:00:55 -0300 Subject: pg_dump: Reduce use of global variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most pg_dump.c global variables, which were passed down individually to dumping routines, are now grouped as members of the new DumpOptions struct, which is used as a local variable and passed down into routines that need it. This helps future development efforts; in particular it is said to enable a mode in which a parallel pg_dump run can output multiple streams, and have them restored in parallel. Also take the opportunity to clean up the pg_dump header files somewhat, to avoid circularity. Author: Joachim Wieland, revised by Álvaro Herrera Reviewed by Peter Eisentraut --- src/bin/pg_dump/parallel.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/bin/pg_dump/parallel.c') diff --git a/src/bin/pg_dump/parallel.c b/src/bin/pg_dump/parallel.c index e50dd8b43f8..3b8d5848b3a 100644 --- a/src/bin/pg_dump/parallel.c +++ b/src/bin/pg_dump/parallel.c @@ -18,8 +18,8 @@ #include "postgres_fe.h" -#include "pg_backup_utils.h" #include "parallel.h" +#include "pg_backup_utils.h" #ifndef WIN32 #include @@ -89,11 +89,12 @@ static void WaitForTerminatingWorkers(ParallelState *pstate); static void sigTermHandler(int signum); #endif static void SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, + DumpOptions *dopt, RestoreOptions *ropt); static bool HasEveryWorkerTerminated(ParallelState *pstate); static void lockTableNoWait(ArchiveHandle *AH, TocEntry *te); -static void WaitForCommands(ArchiveHandle *AH, int pipefd[2]); +static void WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2]); static char *getMessageFromMaster(int pipefd[2]); static void sendMessageToMaster(int pipefd[2], const char *str); static int select_loop(int maxFd, fd_set *workerset); @@ -436,6 +437,7 @@ sigTermHandler(int signum) */ static void SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, + DumpOptions *dopt, RestoreOptions *ropt) { /* @@ -445,11 +447,11 @@ SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, * properly when we shut down. This happens only that way when it is * brought down because of an error. */ - (AH->SetupWorkerPtr) ((Archive *) AH, ropt); + (AH->SetupWorkerPtr) ((Archive *) AH, dopt, ropt); Assert(AH->connection != NULL); - WaitForCommands(AH, pipefd); + WaitForCommands(AH, dopt, pipefd); closesocket(pipefd[PIPE_READ]); closesocket(pipefd[PIPE_WRITE]); @@ -481,7 +483,7 @@ init_spawned_worker_win32(WorkerInfo *wi) * of threads while it does a fork() on Unix. */ ParallelState * -ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt) +ParallelBackupStart(ArchiveHandle *AH, DumpOptions *dopt, RestoreOptions *ropt) { ParallelState *pstate; int i; @@ -598,7 +600,7 @@ ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt) closesocket(pstate->parallelSlot[j].pipeWrite); } - SetupWorker(pstate->parallelSlot[i].args->AH, pipefd, i, ropt); + SetupWorker(pstate->parallelSlot[i].args->AH, pipefd, i, dopt, ropt); exit(0); } @@ -856,7 +858,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te) * exit. */ static void -WaitForCommands(ArchiveHandle *AH, int pipefd[2]) +WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2]) { char *command; DumpId dumpId; @@ -896,7 +898,7 @@ WaitForCommands(ArchiveHandle *AH, int pipefd[2]) * The message we return here has been pg_malloc()ed and we are * responsible for free()ing it. */ - str = (AH->WorkerJobDumpPtr) (AH, te); + str = (AH->WorkerJobDumpPtr) (AH, dopt, te); Assert(AH->connection != NULL); sendMessageToMaster(pipefd, str); free(str); -- cgit v1.2.3