Skip to content

feat(db): bulk all-VO read queries for ResourceStatusDB#939

Open
chrisburr wants to merge 1 commit into
DIRACGrid:mainfrom
chrisburr:rss-4-db-queries
Open

feat(db): bulk all-VO read queries for ResourceStatusDB#939
chrisburr wants to merge 1 commit into
DIRACGrid:mainfrom
chrisburr:rss-4-db-queries

Conversation

@chrisburr

@chrisburr chrisburr commented Jun 11, 2026

Copy link
Copy Markdown
Member

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

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>
@read-the-docs-community

Copy link
Copy Markdown

@chrisburr chrisburr linked an issue Jun 11, 2026 that may be closed by this pull request
5 tasks
@chrisburr chrisburr marked this pull request as ready for review June 11, 2026 08:11
@chrisburr chrisburr requested a review from Loxeris June 11, 2026 08:57
SiteStatus.status,
SiteStatus.reason,
SiteStatus.vo,
).where(SiteStatus.status_type == "all")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status type is expected to always be "all" for sites I believe. Is this condition needed ?

Suggested change
).where(SiteStatus.status_type == "all")
)

stmt = select(
func.max(SiteStatus.date_effective),
func.count(),
).where(SiteStatus.status_type == "all")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Suggested change
).where(SiteStatus.status_type == "all")
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need to be able to filter the element type?

Comment on lines +85 to +93
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()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +177 to +185
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,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VO=vo,
VO=vo,
ElementType=element_type,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceStatusSource + route

2 participants