Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0eea804

Browse files
committed
pg_dump: Reduce use of global variables
Most pg_dump.c global variables, which were passed down individually todumping routines, are now grouped as members of the new DumpOptionsstruct, which is used as a local variable and passed down into routinesthat need it. This helps future development efforts; in particular itis said to enable a mode in which a parallel pg_dump run can outputmultiple 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 HerreraReviewed by Peter Eisentraut
1 parente0d97d7 commit0eea804

22 files changed

+762
-679
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
16+
#include"postgres_fe.h"
17+
1618
#include"pg_backup_archiver.h"
1719
#include"pg_backup_utils.h"
20+
#include"pg_dump.h"
1821

1922
#include<ctype.h>
2023

@@ -64,7 +67,7 @@ static DumpableObject **nspinfoindex;
6467

6568
staticvoidflagInhTables(TableInfo*tbinfo,intnumTables,
6669
InhInfo*inhinfo,intnumInherits);
67-
staticvoidflagInhAttrs(TableInfo*tblinfo,intnumTables);
70+
staticvoidflagInhAttrs(DumpOptions*dopt,TableInfo*tblinfo,intnumTables);
6871
staticDumpableObject**buildIndexArray(void*objArray,intnumObjs,
6972
SizeobjSize);
7073
staticintDOCatalogIdCompare(constvoid*p1,constvoid*p2);
@@ -78,7 +81,7 @@ static intstrInArray(const char *pattern, char **arr, int arr_size);
7881
* Collect information about all potentially dumpable objects
7982
*/
8083
TableInfo*
81-
getSchemaData(Archive*fout,int*numTablesPtr)
84+
getSchemaData(Archive*fout,DumpOptions*dopt,int*numTablesPtr)
8285
{
8386
ExtensionInfo*extinfo;
8487
InhInfo*inhinfo;
@@ -114,19 +117,19 @@ getSchemaData(Archive *fout, int *numTablesPtr)
114117
*/
115118
if (g_verbose)
116119
write_msg(NULL,"reading user-defined tables\n");
117-
tblinfo=getTables(fout,&numTables);
120+
tblinfo=getTables(fout,dopt,&numTables);
118121
tblinfoindex=buildIndexArray(tblinfo,numTables,sizeof(TableInfo));
119122

120123
/* Do this after we've built tblinfoindex */
121124
getOwnedSeqs(fout,tblinfo,numTables);
122125

123126
if (g_verbose)
124127
write_msg(NULL,"reading extensions\n");
125-
extinfo=getExtensions(fout,&numExtensions);
128+
extinfo=getExtensions(fout,dopt,&numExtensions);
126129

127130
if (g_verbose)
128131
write_msg(NULL,"reading user-defined functions\n");
129-
funinfo=getFuncs(fout,&numFuncs);
132+
funinfo=getFuncs(fout,dopt,&numFuncs);
130133
funinfoindex=buildIndexArray(funinfo,numFuncs,sizeof(FuncInfo));
131134

132135
/* this must be after getTables and getFuncs */
@@ -142,7 +145,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
142145

143146
if (g_verbose)
144147
write_msg(NULL,"reading user-defined aggregate functions\n");
145-
getAggregates(fout,&numAggregates);
148+
getAggregates(fout,dopt,&numAggregates);
146149

147150
if (g_verbose)
148151
write_msg(NULL,"reading user-defined operators\n");
@@ -183,7 +186,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
183186

184187
if (g_verbose)
185188
write_msg(NULL,"reading default privileges\n");
186-
getDefaultACLs(fout,&numDefaultACLs);
189+
getDefaultACLs(fout,dopt,&numDefaultACLs);
187190

188191
if (g_verbose)
189192
write_msg(NULL,"reading user-defined collations\n");
@@ -213,7 +216,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
213216
*/
214217
if (g_verbose)
215218
write_msg(NULL,"finding extension members\n");
216-
getExtensionMembership(fout,extinfo,numExtensions);
219+
getExtensionMembership(fout,dopt,extinfo,numExtensions);
217220

218221
/* Link tables to parents, mark parents of target tables interesting */
219222
if (g_verbose)
@@ -222,11 +225,11 @@ getSchemaData(Archive *fout, int *numTablesPtr)
222225

223226
if (g_verbose)
224227
write_msg(NULL,"reading column info for interesting tables\n");
225-
getTableAttrs(fout,tblinfo,numTables);
228+
getTableAttrs(fout,dopt,tblinfo,numTables);
226229

227230
if (g_verbose)
228231
write_msg(NULL,"flagging inherited columns in subtables\n");
229-
flagInhAttrs(tblinfo,numTables);
232+
flagInhAttrs(dopt,tblinfo,numTables);
230233

231234
if (g_verbose)
232235
write_msg(NULL,"reading indexes\n");
@@ -307,7 +310,7 @@ flagInhTables(TableInfo *tblinfo, int numTables,
307310
* modifies tblinfo
308311
*/
309312
staticvoid
310-
flagInhAttrs(TableInfo*tblinfo,intnumTables)
313+
flagInhAttrs(DumpOptions*dopt,TableInfo*tblinfo,intnumTables)
311314
{
312315
inti,
313316
j,
@@ -384,7 +387,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables)
384387
attrDef->adef_expr=pg_strdup("NULL");
385388

386389
/* Will column be dumped explicitly? */
387-
if (shouldPrintColumn(tbinfo,j))
390+
if (shouldPrintColumn(dopt,tbinfo,j))
388391
{
389392
attrDef->separate= false;
390393
/* No dependency needed: NULL cannot have dependencies */

‎src/bin/pg_dump/compress_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
*
5252
*-------------------------------------------------------------------------
5353
*/
54+
#include"postgres_fe.h"
5455

5556
#include"compress_io.h"
56-
#include"pg_backup_utils.h"
5757
#include"parallel.h"
58+
#include"pg_backup_utils.h"
5859

5960
/*----------------------
6061
* Compressor API

‎src/bin/pg_dump/compress_io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef__COMPRESS_IO__
1616
#define__COMPRESS_IO__
1717

18-
#include"postgres_fe.h"
1918
#include"pg_backup_archiver.h"
2019

2120
/* Initial buffer sizes used in zlib compression. */

‎src/bin/pg_dump/dumputils.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15-
1615
#ifndefDUMPUTILS_H
1716
#defineDUMPUTILS_H
1817

1918
#include"libpq-fe.h"
2019
#include"pqexpbuffer.h"
2120

21+
/*
22+
* Data structures for simple lists of OIDs and strings. The support for
23+
* these is very primitive compared to the backend's List facilities, but
24+
* it's all we need in pg_dump.
25+
*/
26+
typedefstructSimpleOidListCell
27+
{
28+
structSimpleOidListCell*next;
29+
Oidval;
30+
}SimpleOidListCell;
31+
32+
typedefstructSimpleOidList
33+
{
34+
SimpleOidListCell*head;
35+
SimpleOidListCell*tail;
36+
}SimpleOidList;
37+
2238
typedefstructSimpleStringListCell
2339
{
2440
structSimpleStringListCell*next;
@@ -31,6 +47,7 @@ typedef struct SimpleStringList
3147
SimpleStringListCell*tail;
3248
}SimpleStringList;
3349

50+
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
3451

3552
externintquote_all_identifiers;
3653
externPQExpBuffer (*getLocalPQExpBuffer) (void);

‎src/bin/pg_dump/parallel.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#include"postgres_fe.h"
2020

21-
#include"pg_backup_utils.h"
2221
#include"parallel.h"
22+
#include"pg_backup_utils.h"
2323

2424
#ifndefWIN32
2525
#include<sys/types.h>
@@ -89,11 +89,12 @@ static void WaitForTerminatingWorkers(ParallelState *pstate);
8989
staticvoidsigTermHandler(intsignum);
9090
#endif
9191
staticvoidSetupWorker(ArchiveHandle*AH,intpipefd[2],intworker,
92+
DumpOptions*dopt,
9293
RestoreOptions*ropt);
9394
staticboolHasEveryWorkerTerminated(ParallelState*pstate);
9495

9596
staticvoidlockTableNoWait(ArchiveHandle*AH,TocEntry*te);
96-
staticvoidWaitForCommands(ArchiveHandle*AH,intpipefd[2]);
97+
staticvoidWaitForCommands(ArchiveHandle*AH,DumpOptions*dopt,intpipefd[2]);
9798
staticchar*getMessageFromMaster(intpipefd[2]);
9899
staticvoidsendMessageToMaster(intpipefd[2],constchar*str);
99100
staticintselect_loop(intmaxFd,fd_set*workerset);
@@ -436,6 +437,7 @@ sigTermHandler(int signum)
436437
*/
437438
staticvoid
438439
SetupWorker(ArchiveHandle*AH,intpipefd[2],intworker,
440+
DumpOptions*dopt,
439441
RestoreOptions*ropt)
440442
{
441443
/*
@@ -445,11 +447,11 @@ SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
445447
* properly when we shut down. This happens only that way when it is
446448
* brought down because of an error.
447449
*/
448-
(AH->SetupWorkerPtr) ((Archive*)AH,ropt);
450+
(AH->SetupWorkerPtr) ((Archive*)AH,dopt,ropt);
449451

450452
Assert(AH->connection!=NULL);
451453

452-
WaitForCommands(AH,pipefd);
454+
WaitForCommands(AH,dopt,pipefd);
453455

454456
closesocket(pipefd[PIPE_READ]);
455457
closesocket(pipefd[PIPE_WRITE]);
@@ -481,7 +483,7 @@ init_spawned_worker_win32(WorkerInfo *wi)
481483
* of threads while it does a fork() on Unix.
482484
*/
483485
ParallelState*
484-
ParallelBackupStart(ArchiveHandle*AH,RestoreOptions*ropt)
486+
ParallelBackupStart(ArchiveHandle*AH,DumpOptions*dopt,RestoreOptions*ropt)
485487
{
486488
ParallelState*pstate;
487489
inti;
@@ -598,7 +600,7 @@ ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt)
598600
closesocket(pstate->parallelSlot[j].pipeWrite);
599601
}
600602

601-
SetupWorker(pstate->parallelSlot[i].args->AH,pipefd,i,ropt);
603+
SetupWorker(pstate->parallelSlot[i].args->AH,pipefd,i,dopt,ropt);
602604

603605
exit(0);
604606
}
@@ -856,7 +858,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te)
856858
* exit.
857859
*/
858860
staticvoid
859-
WaitForCommands(ArchiveHandle*AH,intpipefd[2])
861+
WaitForCommands(ArchiveHandle*AH,DumpOptions*dopt,intpipefd[2])
860862
{
861863
char*command;
862864
DumpIddumpId;
@@ -896,7 +898,7 @@ WaitForCommands(ArchiveHandle *AH, int pipefd[2])
896898
* The message we return here has been pg_malloc()ed and we are
897899
* responsible for free()ing it.
898900
*/
899-
str= (AH->WorkerJobDumpPtr) (AH,te);
901+
str= (AH->WorkerJobDumpPtr) (AH,dopt,te);
900902
Assert(AH->connection!=NULL);
901903
sendMessageToMaster(pipefd,str);
902904
free(str);

‎src/bin/pg_dump/parallel.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
#ifndefPG_DUMP_PARALLEL_H
2020
#definePG_DUMP_PARALLEL_H
2121

22-
#include"pg_backup_db.h"
23-
24-
struct_archiveHandle;
25-
struct_tocEntry;
22+
#include"pg_backup_archiver.h"
2623

2724
typedefenum
2825
{
@@ -35,8 +32,8 @@ typedef enum
3532
/* Arguments needed for a worker process */
3633
typedefstructParallelArgs
3734
{
38-
struct_archiveHandle*AH;
39-
struct_tocEntry*te;
35+
ArchiveHandle*AH;
36+
TocEntry*te;
4037
}ParallelArgs;
4138

4239
/* State for each parallel activity slot */
@@ -74,22 +71,19 @@ extern void init_parallel_dump_utils(void);
7471

7572
externintGetIdleWorker(ParallelState*pstate);
7673
externboolIsEveryWorkerIdle(ParallelState*pstate);
77-
externvoidListenToWorkers(struct_archiveHandle*AH,ParallelState*pstate,booldo_wait);
74+
externvoidListenToWorkers(ArchiveHandle*AH,ParallelState*pstate,booldo_wait);
7875
externintReapWorkerStatus(ParallelState*pstate,int*status);
79-
externvoidEnsureIdleWorker(struct_archiveHandle*AH,ParallelState*pstate);
80-
externvoidEnsureWorkersFinished(struct_archiveHandle*AH,ParallelState*pstate);
76+
externvoidEnsureIdleWorker(ArchiveHandle*AH,ParallelState*pstate);
77+
externvoidEnsureWorkersFinished(ArchiveHandle*AH,ParallelState*pstate);
8178

82-
externParallelState*ParallelBackupStart(struct_archiveHandle*AH,
79+
externParallelState*ParallelBackupStart(ArchiveHandle*AH,
80+
DumpOptions*dopt,
8381
RestoreOptions*ropt);
84-
externvoidDispatchJobForTocEntry(struct_archiveHandle*AH,
82+
externvoidDispatchJobForTocEntry(ArchiveHandle*AH,
8583
ParallelState*pstate,
86-
struct_tocEntry*te,T_Actionact);
87-
externvoidParallelBackupEnd(struct_archiveHandle*AH,ParallelState*pstate);
88-
89-
externvoidcheckAborting(struct_archiveHandle*AH);
84+
TocEntry*te,T_Actionact);
85+
externvoidParallelBackupEnd(ArchiveHandle*AH,ParallelState*pstate);
9086

91-
externvoid
92-
exit_horribly(constchar*modulename,constchar*fmt,...)
93-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3),noreturn));
87+
externvoidcheckAborting(ArchiveHandle*AH);
9488

9589
#endif/* PG_DUMP_PARALLEL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp