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

Commit5b5fea2

Browse files
committed
Access pg_dump's options structs through Archive struct, not directly.
Rather than passing around DumpOptions and RestoreOptions as separatearguments, add fields to struct Archive to carry pointers to these objects,and access them through those fields when needed. There already was aRestoreOptions pointer in Archive, though for no obvious reason it was partof the "private" struct rather than out where pg_dump.c could see it.Doing this allows reversion of quite a lot of parameter-addition changesmade in commit0eea804, which is a good thing IMO because this willreduce the code delta between 9.4 and 9.5, probably easing a few futureback-patch efforts. Moreover, the previous commit only added a DumpOptionsargument to functions that had to have it at the time, which means we couldanticipate still more code churn (and more back-patch hazard) as therequirement spread further. I'd hit exactly that problem in my upcomingpatch to fix extension membership marking, which is what motivated me todo this.
1 parent26905e0 commit5b5fea2

13 files changed

+486
-405
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static intstrInArray(const char *pattern, char **arr, int arr_size);
8181
* Collect information about all potentially dumpable objects
8282
*/
8383
TableInfo*
84-
getSchemaData(Archive*fout,DumpOptions*dopt,int*numTablesPtr)
84+
getSchemaData(Archive*fout,int*numTablesPtr)
8585
{
8686
ExtensionInfo*extinfo;
8787
InhInfo*inhinfo;
@@ -118,19 +118,19 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
118118
*/
119119
if (g_verbose)
120120
write_msg(NULL,"reading user-defined tables\n");
121-
tblinfo=getTables(fout,dopt,&numTables);
121+
tblinfo=getTables(fout,&numTables);
122122
tblinfoindex=buildIndexArray(tblinfo,numTables,sizeof(TableInfo));
123123

124124
/* Do this after we've built tblinfoindex */
125125
getOwnedSeqs(fout,tblinfo,numTables);
126126

127127
if (g_verbose)
128128
write_msg(NULL,"reading extensions\n");
129-
extinfo=getExtensions(fout,dopt,&numExtensions);
129+
extinfo=getExtensions(fout,&numExtensions);
130130

131131
if (g_verbose)
132132
write_msg(NULL,"reading user-defined functions\n");
133-
funinfo=getFuncs(fout,dopt,&numFuncs);
133+
funinfo=getFuncs(fout,&numFuncs);
134134
funinfoindex=buildIndexArray(funinfo,numFuncs,sizeof(FuncInfo));
135135

136136
/* this must be after getTables and getFuncs */
@@ -146,7 +146,7 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
146146

147147
if (g_verbose)
148148
write_msg(NULL,"reading user-defined aggregate functions\n");
149-
getAggregates(fout,dopt,&numAggregates);
149+
getAggregates(fout,&numAggregates);
150150

151151
if (g_verbose)
152152
write_msg(NULL,"reading user-defined operators\n");
@@ -187,7 +187,7 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
187187

188188
if (g_verbose)
189189
write_msg(NULL,"reading default privileges\n");
190-
getDefaultACLs(fout,dopt,&numDefaultACLs);
190+
getDefaultACLs(fout,&numDefaultACLs);
191191

192192
if (g_verbose)
193193
write_msg(NULL,"reading user-defined collations\n");
@@ -200,7 +200,7 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
200200

201201
if (g_verbose)
202202
write_msg(NULL,"reading type casts\n");
203-
getCasts(fout,dopt,&numCasts);
203+
getCasts(fout,&numCasts);
204204

205205
if (g_verbose)
206206
write_msg(NULL,"reading transforms\n");
@@ -221,7 +221,7 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
221221
*/
222222
if (g_verbose)
223223
write_msg(NULL,"finding extension members\n");
224-
getExtensionMembership(fout,dopt,extinfo,numExtensions);
224+
getExtensionMembership(fout,extinfo,numExtensions);
225225

226226
/* Link tables to parents, mark parents of target tables interesting */
227227
if (g_verbose)
@@ -230,11 +230,11 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
230230

231231
if (g_verbose)
232232
write_msg(NULL,"reading column info for interesting tables\n");
233-
getTableAttrs(fout,dopt,tblinfo,numTables);
233+
getTableAttrs(fout,tblinfo,numTables);
234234

235235
if (g_verbose)
236236
write_msg(NULL,"flagging inherited columns in subtables\n");
237-
flagInhAttrs(dopt,tblinfo,numTables);
237+
flagInhAttrs(fout->dopt,tblinfo,numTables);
238238

239239
if (g_verbose)
240240
write_msg(NULL,"reading indexes\n");

‎src/bin/pg_dump/parallel.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ static intpiperead(int s, char *buf, int len);
4646
typedefstruct
4747
{
4848
ArchiveHandle*AH;
49-
RestoreOptions*ropt;
50-
DumpOptions*dopt;
5149
intworker;
5250
intpipeRead;
5351
intpipeWrite;
@@ -87,13 +85,11 @@ static void WaitForTerminatingWorkers(ParallelState *pstate);
8785
#ifndefWIN32
8886
staticvoidsigTermHandler(intsignum);
8987
#endif
90-
staticvoidSetupWorker(ArchiveHandle*AH,intpipefd[2],intworker,
91-
DumpOptions*dopt,
92-
RestoreOptions*ropt);
88+
staticvoidSetupWorker(ArchiveHandle*AH,intpipefd[2],intworker);
9389
staticboolHasEveryWorkerTerminated(ParallelState*pstate);
9490

9591
staticvoidlockTableNoWait(ArchiveHandle*AH,TocEntry*te);
96-
staticvoidWaitForCommands(ArchiveHandle*AH,DumpOptions*dopt,intpipefd[2]);
92+
staticvoidWaitForCommands(ArchiveHandle*AH,intpipefd[2]);
9793
staticchar*getMessageFromMaster(intpipefd[2]);
9894
staticvoidsendMessageToMaster(intpipefd[2],constchar*str);
9995
staticintselect_loop(intmaxFd,fd_set*workerset);
@@ -435,9 +431,7 @@ sigTermHandler(int signum)
435431
* worker process.
436432
*/
437433
staticvoid
438-
SetupWorker(ArchiveHandle*AH,intpipefd[2],intworker,
439-
DumpOptions*dopt,
440-
RestoreOptions*ropt)
434+
SetupWorker(ArchiveHandle*AH,intpipefd[2],intworker)
441435
{
442436
/*
443437
* Call the setup worker function that's defined in the ArchiveHandle.
@@ -446,11 +440,11 @@ SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
446440
* properly when we shut down. This happens only that way when it is
447441
* brought down because of an error.
448442
*/
449-
(AH->SetupWorkerPtr) ((Archive*)AH,dopt,ropt);
443+
(AH->SetupWorkerPtr) ((Archive*)AH);
450444

451445
Assert(AH->connection!=NULL);
452446

453-
WaitForCommands(AH,dopt,pipefd);
447+
WaitForCommands(AH,pipefd);
454448

455449
closesocket(pipefd[PIPE_READ]);
456450
closesocket(pipefd[PIPE_WRITE]);
@@ -463,13 +457,11 @@ init_spawned_worker_win32(WorkerInfo *wi)
463457
ArchiveHandle*AH;
464458
intpipefd[2]= {wi->pipeRead,wi->pipeWrite};
465459
intworker=wi->worker;
466-
DumpOptions*dopt=wi->dopt;
467-
RestoreOptions*ropt=wi->ropt;
468460

469461
AH=CloneArchive(wi->AH);
470462

471463
free(wi);
472-
SetupWorker(AH,pipefd,worker,dopt,ropt);
464+
SetupWorker(AH,pipefd,worker);
473465

474466
DeCloneArchive(AH);
475467
_endthreadex(0);
@@ -483,7 +475,7 @@ init_spawned_worker_win32(WorkerInfo *wi)
483475
* of threads while it does a fork() on Unix.
484476
*/
485477
ParallelState*
486-
ParallelBackupStart(ArchiveHandle*AH,DumpOptions*dopt,RestoreOptions*ropt)
478+
ParallelBackupStart(ArchiveHandle*AH)
487479
{
488480
ParallelState*pstate;
489481
inti;
@@ -545,8 +537,6 @@ ParallelBackupStart(ArchiveHandle *AH, DumpOptions *dopt, RestoreOptions *ropt)
545537
/* Allocate a new structure for every worker */
546538
wi= (WorkerInfo*)pg_malloc(sizeof(WorkerInfo));
547539

548-
wi->ropt=ropt;
549-
wi->dopt=dopt;
550540
wi->worker=i;
551541
wi->AH=AH;
552542
wi->pipeRead=pstate->parallelSlot[i].pipeRevRead=pipeMW[PIPE_READ];
@@ -601,7 +591,7 @@ ParallelBackupStart(ArchiveHandle *AH, DumpOptions *dopt, RestoreOptions *ropt)
601591
closesocket(pstate->parallelSlot[j].pipeWrite);
602592
}
603593

604-
SetupWorker(pstate->parallelSlot[i].args->AH,pipefd,i,dopt,ropt);
594+
SetupWorker(pstate->parallelSlot[i].args->AH,pipefd,i);
605595

606596
exit(0);
607597
}
@@ -859,7 +849,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te)
859849
* exit.
860850
*/
861851
staticvoid
862-
WaitForCommands(ArchiveHandle*AH,DumpOptions*dopt,intpipefd[2])
852+
WaitForCommands(ArchiveHandle*AH,intpipefd[2])
863853
{
864854
char*command;
865855
DumpIddumpId;
@@ -899,7 +889,7 @@ WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2])
899889
* The message we return here has been pg_malloc()ed and we are
900890
* responsible for free()ing it.
901891
*/
902-
str= (AH->WorkerJobDumpPtr) (AH,dopt,te);
892+
str= (AH->WorkerJobDumpPtr) (AH,te);
903893
Assert(AH->connection!=NULL);
904894
sendMessageToMaster(pipefd,str);
905895
free(str);

‎src/bin/pg_dump/parallel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ extern intReapWorkerStatus(ParallelState *pstate, int *status);
7676
externvoidEnsureIdleWorker(ArchiveHandle*AH,ParallelState*pstate);
7777
externvoidEnsureWorkersFinished(ArchiveHandle*AH,ParallelState*pstate);
7878

79-
externParallelState*ParallelBackupStart(ArchiveHandle*AH,
80-
DumpOptions*dopt,
81-
RestoreOptions*ropt);
79+
externParallelState*ParallelBackupStart(ArchiveHandle*AH);
8280
externvoidDispatchJobForTocEntry(ArchiveHandle*AH,
8381
ParallelState*pstate,
8482
TocEntry*te,T_Actionact);

‎src/bin/pg_dump/pg_backup.h

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,6 @@ typedef enum _teSection
5858
SECTION_POST_DATA/* stuff to be processed after data */
5959
}teSection;
6060

61-
/*
62-
*We may want to have some more user-readable data, but in the mean
63-
*time this gives us some abstraction and type checking.
64-
*/
65-
typedefstructArchive
66-
{
67-
intverbose;
68-
char*remoteVersionStr;/* server's version string */
69-
intremoteVersion;/* same in numeric form */
70-
71-
intminRemoteVersion;/* allowable range */
72-
intmaxRemoteVersion;
73-
74-
intnumWorkers;/* number of parallel processes */
75-
char*sync_snapshot_id;/* sync snapshot id for parallel
76-
* operation */
77-
78-
/* info needed for string escaping */
79-
intencoding;/* libpq code for client_encoding */
80-
boolstd_strings;/* standard_conforming_strings */
81-
char*use_role;/* Issue SET ROLE to this */
82-
83-
/* error handling */
84-
boolexit_on_error;/* whether to exit on SQL errors... */
85-
intn_errors;/* number of errors (if no die) */
86-
87-
/* The rest is private */
88-
}Archive;
89-
9061
typedefstruct_restoreOptions
9162
{
9263
intcreateDB;/* Issue commands to create the database */
@@ -190,6 +161,38 @@ typedef struct _dumpOptions
190161
char*outputSuperuser;
191162
}DumpOptions;
192163

164+
/*
165+
*We may want to have some more user-readable data, but in the mean
166+
*time this gives us some abstraction and type checking.
167+
*/
168+
typedefstructArchive
169+
{
170+
DumpOptions*dopt;/* options, if dumping */
171+
RestoreOptions*ropt;/* options, if restoring */
172+
173+
intverbose;
174+
char*remoteVersionStr;/* server's version string */
175+
intremoteVersion;/* same in numeric form */
176+
177+
intminRemoteVersion;/* allowable range */
178+
intmaxRemoteVersion;
179+
180+
intnumWorkers;/* number of parallel processes */
181+
char*sync_snapshot_id;/* sync snapshot id for parallel
182+
* operation */
183+
184+
/* info needed for string escaping */
185+
intencoding;/* libpq code for client_encoding */
186+
boolstd_strings;/* standard_conforming_strings */
187+
char*use_role;/* Issue SET ROLE to this */
188+
189+
/* error handling */
190+
boolexit_on_error;/* whether to exit on SQL errors... */
191+
intn_errors;/* number of errors (if no die) */
192+
193+
/* The rest is private */
194+
}Archive;
195+
193196

194197
/*
195198
* pg_dump uses two different mechanisms for identifying database objects:
@@ -215,9 +218,9 @@ typedef struct
215218

216219
typedefintDumpId;
217220

218-
typedefint (*DataDumperPtr) (Archive*AH,DumpOptions*dopt,void*userArg);
221+
typedefint (*DataDumperPtr) (Archive*AH,void*userArg);
219222

220-
typedefvoid (*SetupWorkerPtr) (Archive*AH,DumpOptions*dopt,RestoreOptions*ropt);
223+
typedefvoid (*SetupWorkerPtr) (Archive*AH);
221224

222225
/*
223226
* Main archiver interface.
@@ -250,9 +253,11 @@ extern void WriteData(Archive *AH, const void *data, size_t dLen);
250253
externintStartBlob(Archive*AH,Oidoid);
251254
externintEndBlob(Archive*AH,Oidoid);
252255

253-
externvoidCloseArchive(Archive*AH,DumpOptions*dopt);
256+
externvoidCloseArchive(Archive*AH);
257+
258+
externvoidSetArchiveOptions(Archive*AH,DumpOptions*dopt,RestoreOptions*ropt);
254259

255-
externvoidSetArchiveRestoreOptions(Archive*AH,RestoreOptions*ropt);
260+
externvoidProcessArchiveRestoreOptions(Archive*AH);
256261

257262
externvoidRestoreArchive(Archive*AH);
258263

@@ -265,7 +270,7 @@ extern Archive *CreateArchive(const char *FileSpec, const ArchiveFormat fmt,
265270
SetupWorkerPtrsetupDumpWorker);
266271

267272
/* The --list option */
268-
externvoidPrintTOCSummary(Archive*AH,RestoreOptions*ropt);
273+
externvoidPrintTOCSummary(Archive*AH);
269274

270275
externRestoreOptions*NewRestoreOptions(void);
271276

@@ -274,7 +279,7 @@ extern void InitDumpOptions(DumpOptions *opts);
274279
externDumpOptions*dumpOptionsFromRestoreOptions(RestoreOptions*ropt);
275280

276281
/* Rearrange and filter TOC entries */
277-
externvoidSortTocFromFile(Archive*AHX,RestoreOptions*ropt);
282+
externvoidSortTocFromFile(Archive*AHX);
278283

279284
/* Convenience functions used only when writing DATA */
280285
externvoidarchputs(constchar*s,Archive*AH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp