diff options
Diffstat (limited to 'src/bin/pg_dump/parallel.h')
-rw-r--r-- | src/bin/pg_dump/parallel.h | 72 |
1 files changed, 45 insertions, 27 deletions
diff --git a/src/bin/pg_dump/parallel.h b/src/bin/pg_dump/parallel.h index 21739ca87c1..8ee629b1068 100644 --- a/src/bin/pg_dump/parallel.h +++ b/src/bin/pg_dump/parallel.h @@ -2,14 +2,11 @@ * * parallel.h * - * Parallel support header file for the pg_dump archiver + * Parallel support for pg_dump and pg_restore * * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * The author is not responsible for loss or damages that may - * result from its use. - * * IDENTIFICATION * src/bin/pg_dump/parallel.h * @@ -21,31 +18,53 @@ #include "pg_backup_archiver.h" +/* Function to call in master process on completion of a worker task */ +typedef void (*ParallelCompletionPtr) (ArchiveHandle *AH, + TocEntry *te, + int status, + void *callback_data); + +/* Wait options for WaitForWorkers */ +typedef enum +{ + WFW_NO_WAIT, + WFW_GOT_STATUS, + WFW_ONE_IDLE, + WFW_ALL_IDLE +} WFW_WaitOption; + +/* Worker process statuses */ typedef enum { - WRKR_TERMINATED = 0, WRKR_IDLE, WRKR_WORKING, - WRKR_FINISHED + WRKR_TERMINATED } T_WorkerStatus; -/* Arguments needed for a worker process */ -typedef struct ParallelArgs -{ - ArchiveHandle *AH; - TocEntry *te; -} ParallelArgs; - -/* State for each parallel activity slot */ +/* + * Per-parallel-worker state of parallel.c. + * + * Much of this is valid only in the master process (or, on Windows, should + * be touched only by the master thread). But the AH field should be touched + * only by workers. The pipe descriptors are valid everywhere. + */ typedef struct ParallelSlot { - ParallelArgs *args; - T_WorkerStatus workerStatus; - int status; + T_WorkerStatus workerStatus; /* see enum above */ + + /* These fields are valid if workerStatus == WRKR_WORKING: */ + TocEntry *te; /* item being worked on */ + ParallelCompletionPtr callback; /* function to call on completion */ + void *callback_data; /* passthru data for it */ + + ArchiveHandle *AH; /* Archive data worker is using */ + int pipeRead; /* master's end of the pipes */ int pipeWrite; int pipeRevRead; /* child's end of the pipes */ int pipeRevWrite; + + /* Child process/thread identity info: */ #ifdef WIN32 uintptr_t hThread; unsigned int threadId; @@ -54,12 +73,11 @@ typedef struct ParallelSlot #endif } ParallelSlot; -#define NO_SLOT (-1) - +/* Overall state for parallel.c */ typedef struct ParallelState { - int numWorkers; - ParallelSlot *parallelSlot; + int numWorkers; /* allowed number of workers */ + ParallelSlot *parallelSlot; /* array of numWorkers slots */ } ParallelState; #ifdef WIN32 @@ -69,17 +87,17 @@ extern DWORD mainThreadId; extern void init_parallel_dump_utils(void); -extern int GetIdleWorker(ParallelState *pstate); extern bool IsEveryWorkerIdle(ParallelState *pstate); -extern void ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait); -extern int ReapWorkerStatus(ParallelState *pstate, int *status); -extern void EnsureIdleWorker(ArchiveHandle *AH, ParallelState *pstate); -extern void EnsureWorkersFinished(ArchiveHandle *AH, ParallelState *pstate); +extern void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, + WFW_WaitOption mode); extern ParallelState *ParallelBackupStart(ArchiveHandle *AH); extern void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, - TocEntry *te, T_Action act); + TocEntry *te, + T_Action act, + ParallelCompletionPtr callback, + void *callback_data); extern void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate); extern void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn); |