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

Commitf71519e

Browse files
committed
Refactor and generalize the ParallelSlot machinery.
Create a wrapper object, ParallelSlotArray, to encapsulate thenumber of slots and the slot array itself, plus some other relevantbits of information. This reduces the number of parameters we haveto pass around all over the place.Allow for a ParallelSlotArray to contain slots connected todifferent databases within a single cluster. The current clientsof this mechanism don't need this, but it is expected to be usedby future patches.Defer connecting to databases until we actually need the connectionfor something. This is a slight behavior change for vacuumdb andreindexdb. If you specify a number of jobs that is larger than thenumber of objects, the extra connections will now not be used.But, on the other hand, if you specify a number of jobs that isso large that it's going to fail, the failure would previously havehappened before any operations were actually started, and now itwon't.Mark Dilger, reviewed by me.Discussion:http://postgr.es/m/12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.comDiscussion:http://postgr.es/m/BA592F2D-F928-46FF-9516-2B827F067F57@enterprisedb.com
1 parent2c0cefc commitf71519e

File tree

5 files changed

+338
-161
lines changed

5 files changed

+338
-161
lines changed

‎src/bin/scripts/reindexdb.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static SimpleStringList *get_parallel_object_list(PGconn *conn,
3636
ReindexTypetype,
3737
SimpleStringList*user_list,
3838
boolecho);
39-
staticvoidreindex_one_database(constConnParams*cparams,ReindexTypetype,
39+
staticvoidreindex_one_database(ConnParams*cparams,ReindexTypetype,
4040
SimpleStringList*user_list,
4141
constchar*progname,
4242
boolecho,boolverbose,boolconcurrently,
@@ -330,7 +330,7 @@ main(int argc, char *argv[])
330330
}
331331

332332
staticvoid
333-
reindex_one_database(constConnParams*cparams,ReindexTypetype,
333+
reindex_one_database(ConnParams*cparams,ReindexTypetype,
334334
SimpleStringList*user_list,
335335
constchar*progname,boolecho,
336336
boolverbose,boolconcurrently,intconcurrentCons,
@@ -341,7 +341,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type,
341341
boolparallel=concurrentCons>1;
342342
SimpleStringList*process_list=user_list;
343343
ReindexTypeprocess_type=type;
344-
ParallelSlot*slots;
344+
ParallelSlotArray*sa;
345345
boolfailed= false;
346346
intitems_count=0;
347347

@@ -461,7 +461,8 @@ reindex_one_database(const ConnParams *cparams, ReindexType type,
461461

462462
Assert(process_list!=NULL);
463463

464-
slots=ParallelSlotsSetup(cparams,progname,echo,conn,concurrentCons);
464+
sa=ParallelSlotsSetup(concurrentCons,cparams,progname,echo,NULL);
465+
ParallelSlotsAdoptConn(sa,conn);
465466

466467
cell=process_list->head;
467468
do
@@ -475,7 +476,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type,
475476
gotofinish;
476477
}
477478

478-
free_slot=ParallelSlotsGetIdle(slots,concurrentCons);
479+
free_slot=ParallelSlotsGetIdle(sa,NULL);
479480
if (!free_slot)
480481
{
481482
failed= true;
@@ -489,7 +490,7 @@ reindex_one_database(const ConnParams *cparams, ReindexType type,
489490
cell=cell->next;
490491
}while (cell!=NULL);
491492

492-
if (!ParallelSlotsWaitCompletion(slots,concurrentCons))
493+
if (!ParallelSlotsWaitCompletion(sa))
493494
failed= true;
494495

495496
finish:
@@ -499,8 +500,8 @@ reindex_one_database(const ConnParams *cparams, ReindexType type,
499500
pg_free(process_list);
500501
}
501502

502-
ParallelSlotsTerminate(slots,concurrentCons);
503-
pfree(slots);
503+
ParallelSlotsTerminate(sa);
504+
pfree(sa);
504505

505506
if (failed)
506507
exit(1);

‎src/bin/scripts/vacuumdb.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef struct vacuumingOptions
4545
}vacuumingOptions;
4646

4747

48-
staticvoidvacuum_one_database(constConnParams*cparams,
48+
staticvoidvacuum_one_database(ConnParams*cparams,
4949
vacuumingOptions*vacopts,
5050
intstage,
5151
SimpleStringList*tables,
@@ -408,7 +408,7 @@ main(int argc, char *argv[])
408408
* a list of tables from the database.
409409
*/
410410
staticvoid
411-
vacuum_one_database(constConnParams*cparams,
411+
vacuum_one_database(ConnParams*cparams,
412412
vacuumingOptions*vacopts,
413413
intstage,
414414
SimpleStringList*tables,
@@ -421,13 +421,14 @@ vacuum_one_database(const ConnParams *cparams,
421421
PGresult*res;
422422
PGconn*conn;
423423
SimpleStringListCell*cell;
424-
ParallelSlot*slots;
424+
ParallelSlotArray*sa;
425425
SimpleStringListdbtables= {NULL,NULL};
426426
inti;
427427
intntups;
428428
boolfailed= false;
429429
booltables_listed= false;
430430
boolhas_where= false;
431+
constchar*initcmd;
431432
constchar*stage_commands[]= {
432433
"SET default_statistics_target=1; SET vacuum_cost_delay=0;",
433434
"SET default_statistics_target=10; RESET vacuum_cost_delay;",
@@ -684,26 +685,25 @@ vacuum_one_database(const ConnParams *cparams,
684685
concurrentCons=1;
685686

686687
/*
687-
*Setup the database connections. We reusetheconnection we already have
688-
*for the first slot.If not in parallel mode,thefirst slot in the
689-
*array containstheconnection.
688+
*All slots need to be prepared to runtheappropriate analyze stage, if
689+
*caller requested that mode.We have to preparetheinitial connection
690+
*ourselves before setting uptheslots.
690691
*/
691-
slots=ParallelSlotsSetup(cparams,progname,echo,conn,concurrentCons);
692+
if (stage==ANALYZE_NO_STAGE)
693+
initcmd=NULL;
694+
else
695+
{
696+
initcmd=stage_commands[stage];
697+
executeCommand(conn,initcmd,echo);
698+
}
692699

693700
/*
694-
* Prepare all the connections to run the appropriate analyze stage, if
695-
* caller requested that mode.
701+
* Setup the database connections. We reuse the connection we already have
702+
* for the first slot. If not in parallel mode, the first slot in the
703+
* array contains the connection.
696704
*/
697-
if (stage!=ANALYZE_NO_STAGE)
698-
{
699-
intj;
700-
701-
/* We already emitted the message above */
702-
703-
for (j=0;j<concurrentCons;j++)
704-
executeCommand((slots+j)->connection,
705-
stage_commands[stage],echo);
706-
}
705+
sa=ParallelSlotsSetup(concurrentCons,cparams,progname,echo,initcmd);
706+
ParallelSlotsAdoptConn(sa,conn);
707707

708708
initPQExpBuffer(&sql);
709709

@@ -719,7 +719,7 @@ vacuum_one_database(const ConnParams *cparams,
719719
gotofinish;
720720
}
721721

722-
free_slot=ParallelSlotsGetIdle(slots,concurrentCons);
722+
free_slot=ParallelSlotsGetIdle(sa,NULL);
723723
if (!free_slot)
724724
{
725725
failed= true;
@@ -740,12 +740,12 @@ vacuum_one_database(const ConnParams *cparams,
740740
cell=cell->next;
741741
}while (cell!=NULL);
742742

743-
if (!ParallelSlotsWaitCompletion(slots,concurrentCons))
743+
if (!ParallelSlotsWaitCompletion(sa))
744744
failed= true;
745745

746746
finish:
747-
ParallelSlotsTerminate(slots,concurrentCons);
748-
pg_free(slots);
747+
ParallelSlotsTerminate(sa);
748+
pg_free(sa);
749749

750750
termPQExpBuffer(&sql);
751751

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp