Skip to content

Add Manila quota reads and logical-share inventory - #12

Merged
Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/manila-2b3
Dec 4, 2026
Merged

Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/manila-2b3

Conversation

@legit-ninja

@legit-ninja Jeremy Lee (legit-ninja) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a logical-share inventory query and six read-only quota queries to manila/db.

  • ShareGetInventory: one row per nondeleted logical share, with status, availability zone and share type taken from its representative instance.
  • QuotaGetAllByProject, QuotaGetAllByProjectAndUser, QuotaGetAllByProjectAndShareType: project, user and share-type limit overrides.
  • QuotaClassGetDefault: limits of the persisted default quota class.
  • QuotaUsageGetAllByProject, QuotaUsageGetAllByProjectAndShareType: project and share-type usage rows from quota_usages.

The quota queries are named after the Manila DB API functions they follow. Each reads every project at once and returns raw rows instead of a per-project dictionary.

Motivation

ShareGetAllWithInstances returns one row per share instance, so replicated or migrating shares appear more than once and their status depends on which row a consumer picks. ShareGetInventory applies Manila's own Share.instance rules so consumers get one row per share with the status the Manila API reports.

The quota reads expose Manila's persisted limits and usage separately, so consumers can resolve effective limits and reproduce Manila's totals without losing NULL or malformed rows.

Behavior

Share inventory

  • Follows Share.instance: status precedence, active-replica preference and the replication-change exception. Instance ID breaks otherwise unspecified ties.
  • Status, AZ and type come from the same representative instance, chosen in one pass with window functions.
  • Shares without instances are included. Retained is_soft_deleted shares stay in inventory; row-soft-deleted shares and instances are excluded.
  • The transitional status ranking copies constants.TRANSITIONAL_STATUSES and must be re-checked on Manila upgrades.

Quota accounting

  • Rows with a NULL or empty project ID are excluded. Results are ordered by their identifying columns and row ID.
  • Usage rows are not aggregated: in_use and reserved are returned as stored, including NULL. Summing QuotaUsageGetAllByProject by project and resource reproduces Manila's _quota_usage_get_all totals. Share-type usage describes the same allocations and must not be added to project totals.
  • The share-type queries left-join share_types, so limits and usage for deleted or missing share types stay visible with a NULL name.
  • User, project and share-type overrides stay in their separate tables. Callers resolve effective limits: share-type override, then project override, then the default class, then service configuration.
  • Quota tables keep Manila's integer soft delete: deleted = 0 for active rows, the row ID for soft-deleted rows.

Compatibility

The change is additive; ShareGetAllWithInstances and existing Manila queries are unchanged. The quota tables are added to the Manila schema fixture for tests and code generation; they are not production migrations.

Tests and docs

  • Unit tests for scanning and error propagation.
  • TestManilaInventory and TestManilaQuotas (MariaDB integration, in tests/) with fixtures covering replication and revert cases, shares without instances, soft-deleted rows, NULL usage, usage-only projects and deleted share types.
  • Smoke calls for all seven queries in TestManilaQueries.
  • Register the MySQL driver in the integration test helper.
  • Query semantics and Manila-upgrade notes documented in API.md; README.md only updates the manila/db summary row.

@mnaser Mohammed Naser (mnaser) left a comment

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.

The SQL work here is solid—the six raw quota queries cleanly preserve Manila's integer soft-delete (deleted = 0) and project vs share-type separation, and ShareGetInventory's single-pass window-function query mirrors Manila's Share.instance selection rules accurately.

A few items to clean up before we run CI and merge:

  1. Move the MariaDB integration tests into tests/: Please move manila/db/inventory_integration_test.go and manila/db/quotas_integration_test.go into tests/ so all integration tests live in one place (matching #10, #11, #13, and the rest of the repo, rather than reading ../../tests/fixtures/... from inside manila/db/). Keeping the _ "github.com/go-sql-driver/mysql" import in internal/testutil/integration.go is fine either way.
  2. Update the PR title and description to match the final code, and squash the two commits into one clean commit (keeping DCO sign-off). The title is currently the raw branch name (Contrib/manila 2b3) and the description still mentions commit 1's scoped usage totals and Python SQL tests.
  3. Move the detailed Manila quota and inventory docs from README.md into API.md: Please keep README.md to the package summary table entry (matching #13 and Designate #9) and place the detailed semantics and Manila-upgrade notes in API.md.
  4. Minor nit: In ShareGetInventory's CASE flagged.status ranking in manila/db/queries.sql, numbering the transitional ranks consecutively (closing the small 12 → 14 and 15 → 18 gaps) would make future Manila upgrade checks a bit clearer (regenerate sqlc if adjusted).

Add ShareGetInventory, which returns one row per nondeleted logical
share, including shares without instances. It follows Manila's
Share.instance rules (status precedence, active-replica preference and
the replication-change exception) and takes status, availability zone
and share type from one representative instance, chosen in a single
pass with window functions. The transitional status ranking copies
constants.TRANSITIONAL_STATUSES and must be re-checked on Manila
upgrades. ShareGetAllWithInstances is unchanged.

Add six read-only quota queries, named after the Manila DB API
functions they follow, that read every project at once and return raw
rows:

- QuotaGetAllByProject, QuotaGetAllByProjectAndUser and
  QuotaGetAllByProjectAndShareType: project, user and share-type
  limit overrides from their separate tables.
- QuotaClassGetDefault: limits of the persisted default quota class.
- QuotaUsageGetAllByProject and QuotaUsageGetAllByProjectAndShareType:
  project and share-type usage rows from quota_usages, with nullable
  in_use and reserved returned as stored rather than summed.

Rows with a NULL or empty project ID are excluded, and results are
ordered by their identifying columns and row ID. The share-type queries
left-join share_types, so limits and usage for deleted share types stay
visible with a NULL name. Quota tables keep Manila's integer soft
delete (deleted = 0 for active rows).

Add the quota tables to the Manila schema fixture, unit tests, MariaDB
integration tests in tests/ with inventory and quota fixtures, smoke
calls in TestManilaQueries, and API.md documentation. Register the
MySQL driver in the integration test helper.

Co-authored-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: Jeremy Lee <jeremy.lee1664@gmail.com>

@mnaser Mohammed Naser (mnaser) left a comment

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.

Thanks for the updates—CI is green, approving and merging.

@mnaser
Mohammed Naser (mnaser) merged commit 7b1291b into vexxhost:main Dec 4, 2026
5 checks passed
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.

2 participants