Skip to content

Commit a93f871

Browse files
authored
Cosmetic renames in ChunkAppend code (#9790)
While fixing a bug with wrong result with parallel workers + startup exclusion, I had to rename many things to make it more clear what's going on. Commit the rename separately, because the fix itself is complex and it makes it difficult to review. No functional changes.
1 parent 903aaf0 commit a93f871

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

src/nodes/chunk_append/exec.c

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
#define INVALID_SUBPLAN_INDEX (-1)
4141
#define NO_MATCHING_SUBPLANS (-2)
4242

43-
typedef enum SubplanState
43+
typedef enum ChunkAppendSubplanState
4444
{
45-
SUBPLAN_STATE_INCLUDED = 1 << 0, /* Used and not removed by startup exclusion */
46-
SUBPLAN_STATE_FINISHED = 1 << 1, /* The subplan is finished */
47-
} SubplanState;
45+
CASS_Included = 1 << 0, /* Used and not removed by startup exclusion */
46+
CASS_Finished = 1 << 1, /* The subplan is finished */
47+
} ChunkAppendSubplanState;
4848

4949
/* ParallelChunkAppendState is stored in shared memory to coordinate the parallel workers.
5050
*
@@ -120,7 +120,7 @@ typedef struct ChunkAppendState
120120

121121
LWLock *lock;
122122
ParallelContext *pcxt;
123-
ParallelChunkAppendState *pstate;
123+
ParallelChunkAppendState *parallel_state;
124124
EState *estate;
125125
int eflags;
126126
void (*choose_next_subplan)(struct ChunkAppendState *);
@@ -151,7 +151,7 @@ static CustomExecMethods chunk_append_state_methods = {
151151
};
152152

153153
static void choose_next_subplan_non_parallel(ChunkAppendState *state);
154-
static void choose_next_subplan_for_worker(ChunkAppendState *state);
154+
static void choose_next_subplan_in_worker(ChunkAppendState *state);
155155

156156
static bool can_exclude_chunk(List *constraints, List *baserestrictinfo);
157157
static void do_startup_exclusion(ChunkAppendState *state);
@@ -164,7 +164,7 @@ static void show_sort_group_keys(ChunkAppendState *planstate, List *ancestors, E
164164
static void show_sortorder_options(StringInfo buf, Node *sortexpr, Oid sortOperator, Oid collation,
165165
bool nullsFirst);
166166

167-
static void perform_plan_init(ChunkAppendState *state, EState *estate, int eflags);
167+
static void init_subplanstates(ChunkAppendState *state, EState *estate, int eflags);
168168

169169
Node *
170170
ts_chunk_append_state_create(CustomScan *cscan)
@@ -383,14 +383,14 @@ chunk_append_begin(CustomScanState *node, EState *estate, int eflags)
383383
do_startup_exclusion(state);
384384
}
385385

386-
perform_plan_init(state, estate, eflags);
386+
init_subplanstates(state, estate, eflags);
387387
}
388388

389389
/*
390390
* Perform an initialization of the filtered_subplans.
391391
*/
392392
static void
393-
perform_plan_init(ChunkAppendState *state, EState *estate, int eflags)
393+
init_subplanstates(ChunkAppendState *state, EState *estate, int eflags)
394394
{
395395
ListCell *lc;
396396
int i;
@@ -469,7 +469,7 @@ can_exclude_constraints_using_clauses(ChunkAppendState *state, List *constraints
469469
* build bitmap of valid subplans for runtime exclusion
470470
*/
471471
static void
472-
initialize_runtime_exclusion(ChunkAppendState *state)
472+
do_runtime_exclusion(ChunkAppendState *state)
473473
{
474474
ListCell *lc_clauses, *lc_constraints;
475475
int i = 0;
@@ -633,7 +633,7 @@ get_next_subplan(ChunkAppendState *state, int last_plan)
633633
{
634634
if (!state->runtime_initialized)
635635
{
636-
initialize_runtime_exclusion(state);
636+
do_runtime_exclusion(state);
637637
}
638638

639639
/*
@@ -662,50 +662,50 @@ choose_next_subplan_non_parallel(ChunkAppendState *state)
662662
}
663663

664664
static void
665-
choose_next_subplan_for_worker(ChunkAppendState *state)
665+
choose_next_subplan_in_worker(ChunkAppendState *worker_state)
666666
{
667-
ParallelChunkAppendState *pstate = state->pstate;
667+
ParallelChunkAppendState *parallel_state = worker_state->parallel_state;
668668
int next_plan;
669669
int start;
670670

671-
LWLockAcquire(state->lock, LW_EXCLUSIVE);
671+
LWLockAcquire(worker_state->lock, LW_EXCLUSIVE);
672672

673673
/* mark just completed subplan as finished */
674-
if (state->current >= 0)
674+
if (worker_state->current >= 0)
675675
{
676-
pstate->subplan_state[state->current] =
677-
ts_set_flags_32(pstate->subplan_state[state->current], SUBPLAN_STATE_FINISHED);
676+
parallel_state->subplan_state[worker_state->current] =
677+
ts_set_flags_32(parallel_state->subplan_state[worker_state->current], CASS_Finished);
678678
}
679679

680-
if (pstate->next_plan == INVALID_SUBPLAN_INDEX)
680+
if (parallel_state->next_plan == INVALID_SUBPLAN_INDEX)
681681
{
682-
next_plan = get_next_subplan(state, INVALID_SUBPLAN_INDEX);
682+
next_plan = get_next_subplan(worker_state, INVALID_SUBPLAN_INDEX);
683683
}
684684
else
685685
{
686-
next_plan = pstate->next_plan;
686+
next_plan = parallel_state->next_plan;
687687
}
688688

689689
if (next_plan == NO_MATCHING_SUBPLANS)
690690
{
691691
/* all subplans are finished */
692-
pstate->next_plan = NO_MATCHING_SUBPLANS;
693-
state->current = NO_MATCHING_SUBPLANS;
694-
LWLockRelease(state->lock);
692+
parallel_state->next_plan = NO_MATCHING_SUBPLANS;
693+
worker_state->current = NO_MATCHING_SUBPLANS;
694+
LWLockRelease(worker_state->lock);
695695
return;
696696
}
697697

698698
start = next_plan;
699699

700700
/* skip finished subplans */
701-
while (ts_flags_are_set_32(pstate->subplan_state[next_plan], SUBPLAN_STATE_FINISHED))
701+
while (ts_flags_are_set_32(parallel_state->subplan_state[next_plan], CASS_Finished))
702702
{
703-
next_plan = get_next_subplan(state, next_plan);
703+
next_plan = get_next_subplan(worker_state, next_plan);
704704

705705
/* wrap around if we reach end of subplan list */
706706
if (next_plan < 0)
707707
{
708-
next_plan = get_next_subplan(state, INVALID_SUBPLAN_INDEX);
708+
next_plan = get_next_subplan(worker_state, INVALID_SUBPLAN_INDEX);
709709
}
710710

711711
if (next_plan == start || next_plan < 0)
@@ -720,39 +720,39 @@ choose_next_subplan_for_worker(ChunkAppendState *state)
720720
* that in the check
721721
*/
722722
Assert(next_plan >= 0);
723-
pstate->next_plan = NO_MATCHING_SUBPLANS;
724-
state->current = NO_MATCHING_SUBPLANS;
725-
LWLockRelease(state->lock);
723+
parallel_state->next_plan = NO_MATCHING_SUBPLANS;
724+
worker_state->current = NO_MATCHING_SUBPLANS;
725+
LWLockRelease(worker_state->lock);
726726
return;
727727
}
728728
}
729729

730-
Assert(next_plan >= 0 && next_plan < state->num_subplans);
731-
state->current = next_plan;
730+
Assert(next_plan >= 0 && next_plan < worker_state->num_subplans);
731+
worker_state->current = next_plan;
732732

733733
/*
734734
* if this is not a partial plan we mark it as finished
735735
* immediately so it does not get assigned another worker
736736
*/
737-
if (next_plan < state->filtered_first_partial_plan)
737+
if (next_plan < worker_state->filtered_first_partial_plan)
738738
{
739-
pstate->subplan_state[next_plan] =
740-
ts_set_flags_32(pstate->subplan_state[next_plan], SUBPLAN_STATE_FINISHED);
739+
parallel_state->subplan_state[next_plan] =
740+
ts_set_flags_32(parallel_state->subplan_state[next_plan], CASS_Finished);
741741
}
742742

743743
/* advance next_plan for next worker */
744-
pstate->next_plan = get_next_subplan(state, state->current);
744+
parallel_state->next_plan = get_next_subplan(worker_state, worker_state->current);
745745
/*
746746
* if we reach the end of the list of subplans we set next_plan
747747
* to INVALID_SUBPLAN_INDEX to allow rechecking unfinished subplans
748748
* on next call
749749
*/
750-
if (pstate->next_plan < 0)
750+
if (parallel_state->next_plan < 0)
751751
{
752-
pstate->next_plan = INVALID_SUBPLAN_INDEX;
752+
parallel_state->next_plan = INVALID_SUBPLAN_INDEX;
753753
}
754754

755-
LWLockRelease(state->lock);
755+
LWLockRelease(worker_state->lock);
756756
}
757757

758758
/*
@@ -825,26 +825,26 @@ chunk_append_estimate_dsm(CustomScanState *node, ParallelContext *pcxt)
825825
* Initialize the parallel state.
826826
*/
827827
static void
828-
init_pstate(ChunkAppendState *state, ParallelChunkAppendState *pstate)
828+
init_parallel_state(ChunkAppendState *state, ParallelChunkAppendState *parallel_state)
829829
{
830830
Assert(state != NULL);
831-
Assert(pstate != NULL);
831+
Assert(parallel_state != NULL);
832832
Assert(state->csstate.pscan_len > 0);
833833

834834
/* The parallel worker state has to be (re-)initialized by the parallel leader */
835835
Assert(!IsParallelWorker());
836836

837-
memset(pstate, 0, state->csstate.pscan_len);
837+
memset(parallel_state, 0, state->csstate.pscan_len);
838838

839-
pstate->next_plan = INVALID_SUBPLAN_INDEX;
840-
pstate->filtered_first_partial_plan = state->filtered_first_partial_plan;
839+
parallel_state->next_plan = INVALID_SUBPLAN_INDEX;
840+
parallel_state->filtered_first_partial_plan = state->filtered_first_partial_plan;
841841

842842
/* Mark active subplans in parallel state */
843843
int plan = -1;
844844
while ((plan = bms_next_member(state->included_subplans_by_se, plan)) >= 0)
845845
{
846-
pstate->subplan_state[plan] =
847-
ts_set_flags_32(pstate->subplan_state[plan], SUBPLAN_STATE_INCLUDED);
846+
parallel_state->subplan_state[plan] =
847+
ts_set_flags_32(parallel_state->subplan_state[plan], CASS_Included);
848848
}
849849
}
850850

@@ -861,7 +861,7 @@ chunk_append_initialize_dsm(CustomScanState *node, ParallelContext *pcxt, void *
861861
{
862862
ChunkAppendState *state = (ChunkAppendState *) node;
863863
ParallelChunkAppendState *pstate = (ParallelChunkAppendState *) coordinate;
864-
init_pstate(state, pstate);
864+
init_parallel_state(state, pstate);
865865

866866
state->lock = chunk_append_get_lock_pointer();
867867

@@ -870,10 +870,10 @@ chunk_append_initialize_dsm(CustomScanState *node, ParallelContext *pcxt, void *
870870
* disallow running plans on the leader they should do so via the parallel_leader_participation
871871
* GUC.
872872
*/
873-
state->choose_next_subplan = choose_next_subplan_for_worker;
873+
state->choose_next_subplan = choose_next_subplan_in_worker;
874874
state->current = INVALID_SUBPLAN_INDEX;
875875
state->pcxt = pcxt;
876-
state->pstate = pstate;
876+
state->parallel_state = pstate;
877877
}
878878

879879
/*
@@ -891,7 +891,7 @@ chunk_append_reinitialize_dsm(CustomScanState *node, ParallelContext *pcxt, void
891891
{
892892
ChunkAppendState *state = (ChunkAppendState *) node;
893893
ParallelChunkAppendState *pstate = (ParallelChunkAppendState *) coordinate;
894-
init_pstate(state, pstate);
894+
init_parallel_state(state, pstate);
895895
}
896896

897897
/*
@@ -921,7 +921,7 @@ chunk_append_initialize_worker(CustomScanState *node, shm_toc *toc, void *coordi
921921

922922
for (int plan = 0; plan < list_length(state->initial_subplans); plan++)
923923
{
924-
if (ts_flags_are_set_32(pstate->subplan_state[plan], SUBPLAN_STATE_INCLUDED))
924+
if (ts_flags_are_set_32(pstate->subplan_state[plan], CASS_Included))
925925
{
926926
filtered_subplans =
927927
lappend(filtered_subplans, list_nth(state->filtered_subplans, plan));
@@ -940,11 +940,11 @@ chunk_append_initialize_worker(CustomScanState *node, shm_toc *toc, void *coordi
940940
Assert(list_length(state->filtered_ri_clauses) == list_length(state->filtered_constraints));
941941

942942
state->lock = chunk_append_get_lock_pointer();
943-
state->choose_next_subplan = choose_next_subplan_for_worker;
943+
state->choose_next_subplan = choose_next_subplan_in_worker;
944944
state->current = INVALID_SUBPLAN_INDEX;
945-
state->pstate = pstate;
945+
state->parallel_state = pstate;
946946

947-
perform_plan_init(state, state->estate, state->eflags);
947+
init_subplanstates(state, state->estate, state->eflags);
948948
Assert(state->num_subplans == list_length(state->filtered_subplans));
949949
}
950950

0 commit comments

Comments
 (0)