Commit 583b6b9
authored
Refactor task spawner into QueryCoordinator and StageCoordinator (#479)
This is one PR from the following stack of PRs:
- #477
- #463
- #464
- #478
- #479
<- you are here
- #486
- #432
---
This is a pure refactor PR with a couple of implementation detail
changes:
# Reducing the bloat of complex functions in already complicated parts
of the codebase.
For this, two key structs are introduced:
- `QueryCoordinator`: scoped to a whole distributed query, it handles
references to pieces of data global to a query's lifetime, like the
`TaskContext`, the metrics, the `JoinSet` used for spawning tasks,
etc... it's in charge also of building `StageCoordinator` instances,
which are scoped per-stage instead of per-query.
- `StageCoordinator`: this is the old `CoordinatorToWorkerTaskSpawner`,
but with some more methods that allow reusability and some better
naming. It handles all the comms between workers and coordinator needed
for driving a stage forward.
This allows reducing the bloat in `prepare_static_plan` and the future
`prepare_dynamic_plan` functions.
# Ensuring a coordinator->worker channel is held active for as long as
the `DistributedExec` node is executing the query on the coordinator.
For the static planner, this is a noop, as the previous model worked
fine before, but this will become important in the future for the
dynamic planner. In the dynamic planner, the plan can be set for some
stages, but they might never reach execution, so instead of coupling the
task entry cache invalidation to the task execution finish, it's coupled
instead of the coordinator->channel lifetime.
This has one collateral effect: `WorkUnit` feeds can no longer rely on
the global `coordinator->worker` EOS signal for ensuring that no further
`WorkUnit` feed is going to be sent by the coordinator, so they need an
explicit EOS message that signals that no further `WorkUnit`s will be
received, even though the `coordinator->worker` channel will still be
alive for a while.
# Add a `plan_for_viz` field in `DistributedExec`.
This is a new slot in `DistributedExec` that holds a reference of the
plan that is supposed to be rewritten with metrics for visualization
purposes.
Again, for the static planner this is a noop, because the plan meant for
visualization is equal to the plan that arrived as child to
`DistributedExec` on the first place. However, during dynamic planning,
the plan that arrives to `DistributedExec` is not going to be the same
as the final one after execution, so we need a slot for storing that
final plan.1 parent 579f3ac commit 583b6b9
11 files changed
Lines changed: 460 additions & 314 deletions
File tree
- src
- coordinator
- execution_plans
- metrics
- worker
- generated
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
31 | 42 | | |
| 43 | + | |
| 44 | + | |
32 | 45 | | |
33 | 46 | | |
34 | 47 | | |
35 | 48 | | |
| 49 | + | |
36 | 50 | | |
37 | | - | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
41 | | - | |
| 56 | + | |
42 | 57 | | |
43 | | - | |
44 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
68 | 84 | | |
69 | 85 | | |
70 | 86 | | |
71 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
72 | 91 | | |
73 | 92 | | |
74 | 93 | | |
| |||
93 | 112 | | |
94 | 113 | | |
95 | 114 | | |
96 | | - | |
97 | | - | |
| 115 | + | |
| 116 | + | |
98 | 117 | | |
99 | 118 | | |
100 | 119 | | |
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
104 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
105 | 136 | | |
106 | 137 | | |
107 | 138 | | |
| |||
116 | 147 | | |
117 | 148 | | |
118 | 149 | | |
119 | | - | |
| 150 | + | |
120 | 151 | | |
121 | 152 | | |
122 | 153 | | |
123 | | - | |
| 154 | + | |
124 | 155 | | |
125 | 156 | | |
126 | 157 | | |
127 | 158 | | |
128 | 159 | | |
129 | 160 | | |
130 | 161 | | |
131 | | - | |
132 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
133 | 165 | | |
134 | 166 | | |
135 | 167 | | |
| |||
150 | 182 | | |
151 | 183 | | |
152 | 184 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
164 | 195 | | |
165 | 196 | | |
166 | | - | |
| 197 | + | |
167 | 198 | | |
168 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
169 | 212 | | |
170 | 213 | | |
171 | 214 | | |
172 | 215 | | |
173 | 216 | | |
| 217 | + | |
| 218 | + | |
174 | 219 | | |
175 | 220 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 221 | + | |
183 | 222 | | |
184 | 223 | | |
185 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 2 | + | |
6 | 3 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 4 | + | |
12 | 5 | | |
13 | 6 | | |
14 | | - | |
15 | 7 | | |
16 | | - | |
17 | | - | |
18 | 8 | | |
19 | 9 | | |
20 | 10 | | |
| |||
28 | 18 | | |
29 | 19 | | |
30 | 20 | | |
| 21 | + | |
31 | 22 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 23 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | 24 | | |
44 | 25 | | |
45 | 26 | | |
| |||
50 | 31 | | |
51 | 32 | | |
52 | 33 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 34 | + | |
58 | 35 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 36 | + | |
84 | 37 | | |
85 | 38 | | |
86 | 39 | | |
87 | 40 | | |
88 | 41 | | |
89 | 42 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
93 | 46 | | |
94 | 47 | | |
95 | 48 | | |
| |||
102 | 55 | | |
103 | 56 | | |
104 | 57 | | |
105 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
106 | 61 | | |
107 | 62 | | |
0 commit comments