- Notifications
You must be signed in to change notification settings - Fork1.1k
Commitf6e86c6
authored
feat: cancel pending prebuilds from non-active template versions (#20387)
## DescriptionThis PR introduces an optimization to automatically cancel pendingprebuild-related jobs from non-active template versions in thereconciliation loop.## ProblemCurrently, when a template is configured with more prebuild instancesthan available provisioners, the provisioner queue can become floodedwith pending prebuild jobs. This issue is worsened whenprovisioning/deprovisioning operations take a long time.When the prebuild reconciliation loop generates jobs faster thanprovisioners can process them, pending jobs accumulate in the queue.Since prebuilt workspaces should always run the latest active templateversion, pending prebuild jobs from non-active versions become obsoleteonce a new version is promoted.## SolutionThe reconciliation loop cancels pending prebuild-related jobs fromnon-active template versions that match the following criteria:* Build number: 1 (initial build created by the reconciliation loop)* Job status: `pending`* Not yet picked up by a provisioner (`worker_id` is `NULL`)* Owned by the prebuilds system user* Workspace transition: `start`This prevents the queue from being cluttered with stale prebuild jobsthat would provision workspaces on an outdated template version thatwould consequently need to be deprovisioned.## Changes* Added new SQL query `CountPendingNonActivePrebuilds` to identifypresets with pending jobs from non-active versions* Added new SQL query `UpdatePrebuildProvisionerJobWithCancel` to canceljobs for a specific preset* New reconciliation action type `ActionTypeCancelPending` handles thecancellation logic* Cancellation is non-blocking: failures to cancel prebuild jobs arelogged as errors and don't prevent other reconciliation actions## Follow-up PRCanceling pending prebuild jobs leaves workspaces in a Canceled state.While no Terraform resources need to be destroyed (since jobs werecanceled before provisioning started), these database records shouldstill be cleaned up. This will be addressed in a follow-up PR.Closes:#202421 parentc301a0d commitf6e86c6
File tree
13 files changed
+1016
-63
lines changed- coderd
- database
- dbauthz
- dbfake
- dbmetrics
- dbmock
- queries
- prebuilds
- enterprise/coderd/prebuilds
13 files changed
+1016
-63
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1512 | 1512 | | |
1513 | 1513 | | |
1514 | 1514 | | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
1515 | 1522 | | |
1516 | 1523 | | |
1517 | 1524 | | |
| |||
4875 | 4882 | | |
4876 | 4883 | | |
4877 | 4884 | | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
4878 | 4893 | | |
4879 | 4894 | | |
4880 | 4895 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
644 | 654 | | |
645 | 655 | | |
646 | 656 | | |
| |||
3758 | 3768 | | |
3759 | 3769 | | |
3760 | 3770 | | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
3761 | 3775 | | |
3762 | 3776 | | |
3763 | 3777 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 62 | | |
67 | 63 | | |
68 | 64 | | |
| |||
145 | 141 | | |
146 | 142 | | |
147 | 143 | | |
148 | | - | |
149 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
234 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
235 | 244 | | |
236 | 245 | | |
237 | 246 | | |
| |||
255 | 264 | | |
256 | 265 | | |
257 | 266 | | |
258 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
259 | 284 | | |
260 | 285 | | |
261 | 286 | | |
| |||
571 | 596 | | |
572 | 597 | | |
573 | 598 | | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
574 | 605 | | |
575 | 606 | | |
576 | 607 | | |
| |||
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
0 commit comments
Comments
(0)