aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/parallel.h
blob: 7422f12db4e3b83df76707bdec86f54394a2ad6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*-------------------------------------------------------------------------
 *
 * parallel.h
 *
 *	Parallel support header file for the pg_dump archiver
 *
 * Portions Copyright (c) 1996-2011, 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
 *
 *-------------------------------------------------------------------------
 */

#include "pg_backup_db.h"

struct _archiveHandle;
struct _tocEntry;

typedef enum
{
	WRKR_TERMINATED = 0,
	WRKR_IDLE,
	WRKR_WORKING,
	WRKR_FINISHED
}	T_WorkerStatus;

/* Arguments needed for a worker process */
typedef struct ParallelArgs
{
	struct _archiveHandle *AH;
	struct _tocEntry *te;
}	ParallelArgs;

/* 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;

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);