Repository navigation
Conversation
…writing them `upsert_tasks_from_project` now fetches `required_resources` and the pricing links before it opens the transaction. The transaction then only takes `FOR KEY SHARE` on the `projects` row and writes `comp_tasks`, so neither a row lock nor a pooled connection is held while the catalog and resource-usage-tracker calls run. - director-v2 no longer writes `projects_nodes.required_resources` nor `projects_node_to_pricing_unit`; the web server owns both since PR 2 of the pricing/resources ownership rework (sanderegg/9851) - pricing comes from the linked unit only; a billed computational node without a link raises `PricingPlanUnitNotFoundError`, which is a 404 - catalog service resources and RUT pricing units are cached per upsert call - dropped the EC2 sizing of nodes from the upsert: `_update_project_node_resources_from_hardware_info`, `EC2InstanceTypeNotFoundError`, `MultiContainerOverrideNotSupportedError` and their handlers, and the clusters-keeper calls - tests: the PR 3 characterization tests now pin the new contract (billed scenarios create the pricing links up front), `test_comp_tasks_node_resources_sizing.py` goes with the removed helper, and `test_comp_tasks_upsert_project_lock.py` pins the duration and scope of the `projects` row lock Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`list_required_resources` and `list_pricing_unit_ids` become a single `list_required_resources_and_pricing_unit_ids`: one outer join, one connection and one pool checkout instead of two of each. - `_get_pricing_and_hardware_infos` → `_get_computational_pricing_and_hardware_infos`, which is what the early return already restricted it to - the projects-row comment now names the mode the statement actually renders (`with_for_update(key_share=True)` is `FOR NO KEY UPDATE`, not `FOR KEY SHARE`, and that is the lock `lock_project_for_write` takes) - dropped the comments on the backend-first reads, on the frontend/dynamic early return, on the missing pricing link, and the history paragraph of the upsert docstring Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues remain: billed project creation through /view can fail with a 404 after insertion, and concurrent node deletion can leave an orphan computational task.
2 open issues
What changed in this PR
Completes the pricing/resources ownership rework: web-server owns node resources and pricing links, while director-v2 reads them when preparing computational tasks.
Changes:
- Moves backend calls outside the task-write transaction.
- Prices only computational nodes from existing links and removes computation-start sizing.
- Updates ownership, missing-link, caching, and lock-scope tests.
| File | Description |
|---|---|
services/director-v2/tests/unit/with_dbs/test_comp_tasks_upsert_project_lock.py |
Tests read-only ownership and shorter lock scope. |
services/director-v2/tests/unit/with_dbs/conftest.py |
Removes sizing fixtures and types wallet IDs. |
services/director-v2/tests/unit/with_dbs/comp_scheduler/test_api_route_computations.py |
Updates billed computation and missing-link expectations. |
services/director-v2/tests/unit/test_comp_tasks_node_resources_sizing.py |
Removes obsolete sizing tests. |
services/director-v2/src/simcore_service_director_v2/modules/db/tables.py |
Exports the pricing-link table. |
services/director-v2/src/simcore_service_director_v2/modules/db/repositories/projects_nodes.py |
Reads resources and pricing links together. |
services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_tasks/_utils.py |
Reads linked pricing and removes resource sizing. |
services/director-v2/src/simcore_service_director_v2/modules/db/repositories/comp_tasks/_core.py |
Prepares tasks before opening the write transaction. |
services/director-v2/src/simcore_service_director_v2/core/errors.py |
Removes obsolete sizing errors. |
services/director-v2/src/simcore_service_director_v2/api/routes/computations.py |
Removes sizing-related dependencies and error handlers. |
Review effort: Balanced
Comment on lines
+164
to
+168
| list_of_comp_tasks_in_project, insufficient_credits = await _utils.generate_tasks_list_from_project( | ||
| project=project, | ||
| project_nodes=project_nodes, | ||
| catalog_client=catalog_client, | ||
| published_nodes=published_nodes, |
Comment on lines
+197
to
+201
| try: | ||
| unit_ids = node_pricing_unit_ids[node_id] | ||
| except KeyError as exc: | ||
| msg = f"node {node_id} of project {project_id} has no pricing unit linked, cannot price the service {node_key}" | ||
| raise PricingPlanUnitNotFoundError(msg=msg) from exc |
director-v2's upsert no longer queries `projects_nodes` and `projects_node_to_pricing_unit` itself. It goes through `simcore_postgres_database.utils_projects_nodes.ProjectNodesRepo`: `list()` for `required_resources`, and a new `list_project_node_pricing_unit_ids()` next to the per-node getter for the links. Both run on one connection, so director-v2's `tables.py` no longer needs to import `projects_node_to_pricing_unit`. - the read validates `required_resources` into a `ServiceResourcesDict`, so `_generate_task_image` takes the proper type instead of a raw JSON dict - `_link_non_frontend_nodes` becomes `_link_computational_nodes`: those are the nodes director-v2 prices, with the `to_node_class` check the module already uses - dropped the comment above the catalog `limited_gather` Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Nothing outside director-v2 reads the pricing links of a whole project, so `packages/postgres-database` does not gain a method for it. The read goes back to `ProjectsNodesRepository.list_required_resources_and_pricing_unit_ids` as one outer join on one connection, and `required_resources` is validated into a `ServiceResourcesDict` there so `_generate_task_image` still takes the proper type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`node_resources = node_required_resources` only existed to hold the validated value. The parameter takes the `ServiceResourcesDict` directly now. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reading `required_resources` and the pricing links before the catalog and resource-usage-tracker calls left a window in which a web-server write lands after that read: the tasks would then carry a pricing unit or resources the project no longer has, and the `projects` row lock does not cover `projects_node_to_pricing_unit`, so holding it does not prevent it. The transaction now reads the same two mappings again once it holds the lock and the generation is repeated when they moved, at most three times. `test_upsert_prices_from_the_link_that_is_stored_when_it_writes` relinks a node while the catalog call is stalled and asserts the written task carries the new unit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`generate_tasks_list_from_project` already needs the class of the node to decide whether a published node becomes PUBLISHED, so it passes it to the pricing helper instead of the helper running `to_node_class` on the key a second time, and reuses it for the task's own `node_class`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The links decide which pricing unit the resource-usage-tracker is asked about, so that read has to precede the backend calls. Since ITISFoundation#9819 asks the calls to run outside the transaction, and a lock lives as long as its transaction, the read leaves the lock together with them. Re-checking the state under the lock and generating again only approximates the guarantee the lock used to give, so it goes as well: the tasks carry the resources and the pricing unit that were stored when the read ran, and the next upsert of the project takes the values a node PATCH wrote in between. `test_upsert_prices_from_the_link_that_is_stored_when_it_writes` pinned the removed guarantee. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Comment on lines
+196
to
+200
| try: | ||
| unit_ids = node_pricing_unit_ids[node_id] | ||
| except KeyError as exc: | ||
| msg = f"node {node_id} of project {project_id} has no pricing unit linked, cannot price the service {node_key}" | ||
| raise PricingPlanUnitNotFoundError(msg=msg) from exc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Goal
director-v2 stops writing node resources and pricing links and reads them instead. Third and last PR of the pricing/resources ownership rework (after #9881 and #9950, discussion in #9851).
What do these changes do?
upsert_tasks_from_projectreadsprojects_nodes.required_resourcesand theprojects_node_to_pricing_unitlinks in one outer join on one connection, before it opens its transaction, and the transaction then only takes theprojectsrow lock and writescomp_tasks. The catalog and resource-usage-tracker calls now run outside the transaction, so neither the row lock nor a pooled connection is held across them ([Maintenance]: Follow-up: director-v2 holds project lock/connection while calling other services when updating comp_tasks #9819). The tasks carry the resources and the pricing unit stored when that read ran; a node sized or relinked in between is picked up by the next upsert of the project.projects_nodes.required_resourcesnorprojects_node_to_pricing_unit. The web-server writes both since ✨ web-server: link pricing units and size nodes at creation/copy (PR 2/3) #9950.COMPUTATIONALnodes are priced, and only from the unit linked to them. Dynamic and frontend nodes no longer ask the resource-usage-tracker for a pricing unit. A computational node of a billed product without a link answers 404 (PricingPlanUnitNotFoundError) where director-v2 previously linked the product's default unit itself._update_project_node_resources_from_hardware_infoand its helpers go, along withEC2InstanceTypeNotFoundError(404) andMultiContainerOverrideNotSupportedError(422) and their handlers inPOST .../computations. The clusters-keeper is no longer called on this path. The sizing RPC of ✨ director-v2: expose node-resources sizing RPC (PR 1/3) #9881 is unchanged and stays the web-server's way of sizing a node.required_resourcesare empty and cached per service for the duration of one call. Pricing units are cached per plan/unit, so nodes sharing a unit ask the resource-usage-tracker once.Bonus
test_comp_tasks_upsert_concurrency.pyis renamedtest_comp_tasks_upsert_project_lock.py.test_upsert_skips_writing_unchanged_required_resourcesbecomestest_upsert_writes_no_projects_nodes_rows, and two tests pin the new lock scope: theprojectsrow is not locked, and no pooled connection is checked out, while the catalog and resource-usage-tracker are called.test_comp_tasks_node_resources_sizing.py(4 tests) goes with the removed sizing helper.Lock-hold time before and after: not measured.
Context
The characterization tests added in #9851 pinned the old contract. The ones marked
flips_in="PR3"flip here: a billed scenario now creates the pricing links up front, and the invalid-EC2-type case becomes a missing-link case. They were the last@pytest.mark.epicuses in the repository.Related issue/s
completes the pricing/resources ownership rework: PR 1 #9881, PR 2 #9950, epic discussion #9851.
Removes the backend calls from the
comp_tasksupsert transaction: #9819.How to test
Both files need the postgres, redis and registry services that
packages/pytest-simcorestarts. They were collected but not run: no Docker daemon available here.Follow-up
epicmarker registered inservices/director-v2/setup.cfgandservices/web/server/setup.cfghas no users left. Remove it, or keep it for the next epic.Dev-ops
No ENV or configuration changes, no schema changes. This PR assumes #9950 is deployed: a billed product whose web-server does not link nodes answers 404 on a computation start instead of director-v2 linking the default unit.
AI assistance
Assisted-by: GitHub Copilot:Qwen3.8-Flash Next