2013-03-24 16:27:20 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* parallel.h
|
|
|
|
*
|
|
|
|
* Parallel support header file for the pg_dump archiver
|
|
|
|
*
|
2014-01-07 22:05:30 +01:00
|
|
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
2013-03-24 16:27:20 +01:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2013-03-27 17:10:40 +01:00
|
|
|
#ifndef PG_DUMP_PARALLEL_H
|
|
|
|
#define PG_DUMP_PARALLEL_H
|
|
|
|
|
2013-03-24 16:27:20 +01:00
|
|
|
#include "pg_backup_db.h"
|
|
|
|
|
|
|
|
struct _archiveHandle;
|
|
|
|
struct _tocEntry;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WRKR_TERMINATED = 0,
|
|
|
|
WRKR_IDLE,
|
|
|
|
WRKR_WORKING,
|
|
|
|
WRKR_FINISHED
|
2013-05-29 22:58:43 +02:00
|
|
|
} T_WorkerStatus;
|
2013-03-24 16:27:20 +01:00
|
|
|
|
|
|
|
/* Arguments needed for a worker process */
|
|
|
|
typedef struct ParallelArgs
|
|
|
|
{
|
|
|
|
struct _archiveHandle *AH;
|
|
|
|
struct _tocEntry *te;
|
2013-05-29 22:58:43 +02:00
|
|
|
} ParallelArgs;
|
2013-03-24 16:27:20 +01:00
|
|
|
|
|
|
|
/* State for each parallel activity slot */
|
|
|
|
typedef struct ParallelSlot
|
|
|
|
{
|
|
|
|
ParallelArgs *args;
|
|
|
|
T_WorkerStatus workerStatus;
|
|
|
|
int status;
|
|
|
|
int pipeRead;
|
|
|
|
int pipeWrite;
|
|
|
|
int pipeRevRead;
|
|
|
|
int pipeRevWrite;
|
|
|
|
#ifdef WIN32
|
|
|
|
uintptr_t hThread;
|
|
|
|
unsigned int threadId;
|
|
|
|
#else
|
|
|
|
pid_t pid;
|
|
|
|
#endif
|
|
|
|
} ParallelSlot;
|
|
|
|
|
|
|
|
#define NO_SLOT (-1)
|
|
|
|
|
|
|
|
typedef struct ParallelState
|
|
|
|
{
|
|
|
|
int numWorkers;
|
|
|
|
ParallelSlot *parallelSlot;
|
|
|
|
} ParallelState;
|
|
|
|
|
2013-03-27 17:10:40 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
extern bool parallel_init_done;
|
|
|
|
extern DWORD mainThreadId;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void init_parallel_dump_utils(void);
|
|
|
|
|
2013-03-24 16:27:20 +01:00
|
|
|
extern int GetIdleWorker(ParallelState *pstate);
|
|
|
|
extern bool IsEveryWorkerIdle(ParallelState *pstate);
|
|
|
|
extern void ListenToWorkers(struct _archiveHandle * AH, ParallelState *pstate, bool do_wait);
|
|
|
|
extern int ReapWorkerStatus(ParallelState *pstate, int *status);
|
|
|
|
extern void EnsureIdleWorker(struct _archiveHandle * AH, ParallelState *pstate);
|
|
|
|
extern void EnsureWorkersFinished(struct _archiveHandle * AH, ParallelState *pstate);
|
|
|
|
|
|
|
|
extern ParallelState *ParallelBackupStart(struct _archiveHandle * AH,
|
|
|
|
RestoreOptions *ropt);
|
|
|
|
extern void DispatchJobForTocEntry(struct _archiveHandle * AH,
|
|
|
|
ParallelState *pstate,
|
|
|
|
struct _tocEntry * te, T_Action act);
|
|
|
|
extern void ParallelBackupEnd(struct _archiveHandle * AH, ParallelState *pstate);
|
|
|
|
|
|
|
|
extern void checkAborting(struct _archiveHandle * AH);
|
2013-03-27 17:10:40 +01:00
|
|
|
|
|
|
|
extern void
|
|
|
|
exit_horribly(const char *modulename, const char *fmt,...)
|
|
|
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
|
|
|
|
|
|
|
|
#endif /* PG_DUMP_PARALLEL_H */
|