feat(db): bulk all-VO read queries for ResourceStatusDB#939
Conversation
Replaces the per-resource lookups with bulk queries returning every site/resource status across all VOs, keyed by VO so that rows for the same resource in different VOs cannot overwrite each other, plus max(DateEffective)/count queries to serve as cache revisions. The logic layer maps the rows to the rss Pydantic models per VO, skipping storage elements with an incomplete set of access rows. Co-authored-by: Loxeris <30194187+Loxeris@users.noreply.github.com>
| SiteStatus.status, | ||
| SiteStatus.reason, | ||
| SiteStatus.vo, | ||
| ).where(SiteStatus.status_type == "all") |
There was a problem hiding this comment.
Status type is expected to always be "all" for sites I believe. Is this condition needed ?
| ).where(SiteStatus.status_type == "all") | |
| ) |
| stmt = select( | ||
| func.max(SiteStatus.date_effective), | ||
| func.count(), | ||
| ).where(SiteStatus.status_type == "all") |
There was a problem hiding this comment.
same here
| ).where(SiteStatus.status_type == "all") | |
| ) |
There was a problem hiding this comment.
AFAIK diracx-logic tests are not running when using pytest.
I think the base pyproject needs to be updated: pyproject.toml
| async def get_resource_statuses( | ||
| self, | ||
| name: str, | ||
| status_types: list[str] | None = None, |
There was a problem hiding this comment.
Don't we also need to be able to filter the element type?
| all_rows = await resource_status_db.get_resource_statuses(["all"]) | ||
|
|
||
| result: dict[str, dict[str, FTSStatus]] = {} | ||
| for vo, names in all_rows.items(): | ||
| result[vo] = { | ||
| name: FTSStatus(all=map_status(rows["all"].Status, rows["all"].Reason)) | ||
| for name, rows in names.items() | ||
| } | ||
|
|
There was a problem hiding this comment.
Here we would get every resource status casted as a FTS status, right? i.e {TestSE: FTSStatus}
I think we need to filter element_type to fts in get_resource_statuses()
Same for get_compute_statuses, and get_storage_statuses.
| stmt = insert(SiteStatus).values( | ||
| Name=name, | ||
| Status=status, | ||
| StatusType="all", | ||
| VO=vo, | ||
| Reason=reason, | ||
| DateEffective=date_effective or now, | ||
| LastCheckTime=last_check_time or now, | ||
| ) |
There was a problem hiding this comment.
| stmt = insert(SiteStatus).values( | |
| Name=name, | |
| Status=status, | |
| StatusType="all", | |
| VO=vo, | |
| Reason=reason, | |
| DateEffective=date_effective or now, | |
| LastCheckTime=last_check_time or now, | |
| ) | |
| stmt = insert(SiteStatus).values( | |
| Name=name, | |
| Status=status, | |
| StatusType="all", | |
| VO=vo, | |
| Reason=reason, | |
| ElementType="Site", | |
| DateEffective=date_effective or now, | |
| LastCheckTime=last_check_time or now, | |
| ) |
| name: str, | ||
| status: str, | ||
| status_type: str, | ||
| vo: str, |
There was a problem hiding this comment.
| vo: str, | |
| vo: str, | |
| element_type: str, |
| name: Resource name. | ||
| status: Status value. | ||
| status_type: One of "all", "ReadAccess", "WriteAccess", etc. | ||
| vo: Virtual organisation (e.g. "lhcb", "all"). |
There was a problem hiding this comment.
| vo: Virtual organisation (e.g. "lhcb", "all"). | |
| vo: Virtual organisation (e.g. "lhcb", "all"). | |
| element_type: One of "ComputeElement", "FTS", "StorageElement". |
| Name=name, | ||
| Status=status, | ||
| StatusType=status_type, | ||
| VO=vo, |
There was a problem hiding this comment.
| VO=vo, | |
| VO=vo, | |
| ElementType=element_type, |
Replaces the per-resource lookups with bulk queries returning every site/resource status across all VOs, keyed by VO so that rows for the same resource in different VOs cannot overwrite each other, plus max(DateEffective)/count queries to serve as cache revisions. The logic layer maps the rows to the rss Pydantic models per VO, skipping storage elements with an incomplete set of access rows.
Replaces #910
Part of #839