diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-09-27 13:56:04 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-09-27 13:56:04 -0400 |
commit | fb03d08a89e81a68585f17fd8e7f21c618f4e851 (patch) | |
tree | d1169bd63fa6e1459e60d7ef74420b168a757e06 /src/bin/pg_dump/pg_backup_custom.c | |
parent | b7b8cc0cfcf1c956b752f3e25894f9ad607583b7 (diff) | |
download | postgresql-fb03d08a89e81a68585f17fd8e7f21c618f4e851.tar.gz postgresql-fb03d08a89e81a68585f17fd8e7f21c618f4e851.zip |
Rationalize parallel dump/restore's handling of worker cmd/status messages.
The existing APIs for creating and parsing command and status messages are
rather messy; for example, archive-format modules have to provide code
for constructing command messages, which is entirely pointless since
the code to read them is hard-wired in WaitForCommands() and hence
no format-specific variation is actually possible. But there's little
foreseeable reason to need format-specific variation anyway.
The situation for status messages is no better; at least those are both
constructed and parsed by format-specific code, but said code is quite
redundant since there's no actual need for format-specific variation.
To add insult to injury, the first API involves returning pointers to
static buffers, which is bad, while the second involves returning pointers
to malloc'd strings, which is safer but randomly inconsistent.
Hence, get rid of the MasterStartParallelItem and MasterEndParallelItem
APIs, and instead write centralized functions that construct and parse
command and status messages. If we ever do need more flexibility, these
functions can be the standard implementations of format-specific
callback methods, but that's a long way off if it ever happens.
Tom Lane, reviewed by Kevin Grittner
Discussion: <17340.1464465717@sss.pgh.pa.us>
Diffstat (limited to 'src/bin/pg_dump/pg_backup_custom.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_custom.c | 75 |
1 files changed, 5 insertions, 70 deletions
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index c4f487a7cab..5388c08b29d 100644 --- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -61,9 +61,7 @@ static void _LoadBlobs(ArchiveHandle *AH, bool drop); static void _Clone(ArchiveHandle *AH); static void _DeClone(ArchiveHandle *AH); -static char *_MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action act); -static int _MasterEndParallelItem(ArchiveHandle *AH, TocEntry *te, const char *str, T_Action act); -char *_WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te); +static int _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te); typedef struct { @@ -133,9 +131,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) AH->ClonePtr = _Clone; AH->DeClonePtr = _DeClone; - AH->MasterStartParallelItemPtr = _MasterStartParallelItem; - AH->MasterEndParallelItemPtr = _MasterEndParallelItem; - /* no parallel dump in the custom archive, only parallel restore */ AH->WorkerJobDumpPtr = NULL; AH->WorkerJobRestorePtr = _WorkerJobRestoreCustom; @@ -808,73 +803,13 @@ _DeClone(ArchiveHandle *AH) } /* - * This function is executed in the child of a parallel backup for the - * custom format archive and dumps the actual data. - */ -char * -_WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te) -{ - /* - * short fixed-size string + some ID so far, this needs to be malloc'ed - * instead of static because we work with threads on windows - */ - const int buflen = 64; - char *buf = (char *) pg_malloc(buflen); - int status; - - status = parallel_restore(AH, te); - - snprintf(buf, buflen, "OK RESTORE %d %d %d", te->dumpId, status, - status == WORKER_IGNORED_ERRORS ? AH->public.n_errors : 0); - - return buf; -} - -/* - * This function is executed in the parent process. Depending on the desired - * action (dump or restore) it creates a string that is understood by the - * _WorkerJobDump /_WorkerJobRestore functions of the dump format. - */ -static char * -_MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action act) -{ - /* - * A static char is okay here, even on Windows because we call this - * function only from one process (the master). - */ - static char buf[64]; /* short fixed-size string + number */ - - /* no parallel dump in the custom archive format */ - Assert(act == ACT_RESTORE); - - snprintf(buf, sizeof(buf), "RESTORE %d", te->dumpId); - - return buf; -} - -/* - * This function is executed in the parent process. It analyzes the response of - * the _WorkerJobDump / _WorkerJobRestore functions of the dump format. + * This function is executed in the child of a parallel restore from a + * custom-format archive and restores the actual data for one TOC entry. */ static int -_MasterEndParallelItem(ArchiveHandle *AH, TocEntry *te, const char *str, T_Action act) +_WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te) { - DumpId dumpId; - int nBytes, - status, - n_errors; - - /* no parallel dump in the custom archive */ - Assert(act == ACT_RESTORE); - - sscanf(str, "%d %d %d%n", &dumpId, &status, &n_errors, &nBytes); - - Assert(nBytes == strlen(str)); - Assert(dumpId == te->dumpId); - - AH->public.n_errors += n_errors; - - return status; + return parallel_restore(AH, te); } /*-------------------------------------------------- |