Skip to content

backport: usage: widen usage_volume unique key to include vm_id (#13909) - #13933

Open
Alpha162 wants to merge 1 commit into
apache:4.22from
Alpha162:usage-volume-key-4222
Open

backport: usage: widen usage_volume unique key to include vm_id (#13909)#13933
Alpha162 wants to merge 1 commit into
apache:4.22from
Alpha162:usage-volume-key-4222

Conversation

@Alpha162

Copy link
Copy Markdown
Contributor

Description

Backport of #13909 to 4.22, per @winterhazel's guidance on that PR, targeting 4.22.2 as @abh1sar flagged. The DDL is identical to what merged on main.

It also creates the 4.22.1.0 to 4.22.2.0 upgrade path, which didn't exist yet. The chain in DatabaseUpgradeChecker ended at Upgrade42200to42210, and since the branch is already 4.22.2.0-SNAPSHOT, 4.22.2.0 is the declared next version. Nothing had needed a schema change on 4.22 since 4.22.1.0 was cut, so nobody had reason to add it.

The CALLs can't go into schema-42200to42210.sql instead. Every 4.22.1.0 install has already run that file, and those are the affected clusters. The -cleanup.sql has no statements in it, but the file has to exist: getCleanupScripts() throws if it's absent.

See #13909 for the note on NULL semantics in the widened key, and on this preventing the problem rather than remediating clusters that already have it.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Not tested end to end. The environment where this was found has since been rebuilt, so I can't exercise a 4.22.1.0 to 4.22.2.0 upgrade myself.

What I can attest to:

  • The DDL is byte-identical to what merged on main in usage: widen usage_volume unique key to include vm_id #13909, which passed packaging on el8/el9/el10/debian/suse15 and a Trillian smoke run there (156 pass, 0 errors, tid-16778).
  • The narrow UNIQUE KEY id (volume_id, created) was confirmed by SHOW CREATE TABLE against a restored backup of a live 4.22.1.0 install, alongside the vm_id column added by Track volume usage data at a vm granularity as well #11531.
  • The key name id is set explicitly by schema-41600to41610.sql:72, so the drop targets a name present on any install that has passed through 4.16.1.0.
  • Widening a unique key is strictly less restrictive, so no existing row can violate the new constraint and the DDL can't fail on data.
  • Both procedures carry CONTINUE HANDLERs (1091 and 1061), so a re-run or a resumed upgrade is a no-op.

The new upgrade path is the part that genuinely wants a reviewer with an environment. Upgrade42210to42220 is the first 4.22.1 to 4.22.2 step on this branch, and its script filenames are derived from getUpgradableVersionRange() rather than declared, so the naming is mechanically correct. But nobody has run a real upgrade through it. I'd appreciate someone doing that before merge.

How did you try to break this feature and the system with this change?

Reasoned through the failure modes rather than executing them, since I have no environment to run an upgrade in.

  • A 4.22.0.x cluster upgrading straight to 4.22.2.0. Traced the chain: Upgrade42200to42210 runs first and adds vm_id with the narrow key, then Upgrade42210to42220 widens it. Both populations land correct.
  • A cluster where an operator has already widened the key by hand. IDEMPOTENT_DROP_INDEX drops the three-column key and IDEMPOTENT_ADD_UNIQUE_INDEX recreates it identically, so the net effect is the same.
  • A re-run or a resumed upgrade. Handlers 1091 and 1061 swallow the missing-index and duplicate-key-name cases, so both CALLs are no-ops second time round.
  • A missing or misnamed cleanup script. getCleanupScripts() throws CloudRuntimeException when the file is absent, so that fails the upgrade rather than silently skipping it. Both script names derive from getUpgradableVersionRange(), so they can't drift from the class referencing them.
  • Existing data violating the widened key. That can't happen; the new key is less restrictive than the one it replaces.

Backport of apache#13909 to 4.22, targeting 4.22.2.

This also creates the 4.22.1.0 to 4.22.2.0 upgrade path, which didn't
exist yet: schema-42210to42220.sql, its cleanup companion, the
Upgrade42210to42220 class, and the registration in DatabaseUpgradeChecker.

The CALLs can't go into schema-42200to42210.sql instead, because every
4.22.1.0 install has already run that file and those are the affected
clusters.

@weizhouapache weizhouapache 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.

code lgtm

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.77%. Comparing base (85bcdb1) to head (615eacc).

Files with missing lines Patch % Lines
...ava/com/cloud/upgrade/dao/Upgrade42210to42220.java 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #13933   +/-   ##
=========================================
  Coverage     17.77%   17.77%           
- Complexity    15982    15983    +1     
=========================================
  Files          5928     5929    +1     
  Lines        534301   534309    +8     
  Branches      65382    65382           
=========================================
+ Hits          94987    94989    +2     
- Misses       428568   428574    +6     
  Partials      10746    10746           
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.86% <62.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Alpha162

Copy link
Copy Markdown
Contributor Author

build (component/test_affinity_groups_projects ...) is the only red check. It failed at the "Build with Maven" step before any test in that shard ran, and the other 19 build jobs compiled the same code, so it looks environmental. Could someone re-run that job when convenient? I don't have permissions to.

Also worth a @blueorangutan package and test if anyone's willing. A fresh Trillian deploy walks the whole upgrade chain, so it would exercise Upgrade42210to42220 even though it wouldn't cover an in-place 4.22.1.0 to 4.22.2.0 upgrade. That's the closest automated coverage this gets to the part I flagged as untested.

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18931

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

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.

3 participants