Skip to content

server: charge snapshot copy primary storage to the snapshot owner ac… - #14036

Open
rootnomad wants to merge 4 commits into
apache:mainfrom
rootnomad:fix/snapshot-copy-resourcecount-account
Open

rootnomad wants to merge 4 commits into
apache:mainfrom
rootnomad:fix/snapshot-copy-resourcecount-account

Conversation

@rootnomad

Copy link
Copy Markdown
Contributor

Description

When a snapshot is copied to an extra primary storage pool (createSnapshot with
storagepoolids), copySnapshotOnPool incremented the primary_storage resource count
using CallContext.getCallingUserId(). That method's first argument is an account
id, but getCallingUserId() returns a user id, and user ids and account ids are
independent sequences. So the usage was charged to whatever account happens to
share the caller's user id, never to the snapshot's real owner, and the delete
path never decrements it. The following guard also compared the user id against
Account.ACCOUNT_ID_SYSTEM.

Charge the snapshot owner's account id, and use the calling account id for the
system check.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • Minor

How Has This Been Tested?

Added a unit test asserting the primary_storage count is charged to the snapshot
owner's account rather than the calling user id. Also built the standard packages
and deployed on a KVM advanced zone.

@rootnomad

Copy link
Copy Markdown
Contributor Author

@DaanHoogland Could you pls take a look at this

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clgtm, one nit though

@rootnomad

Copy link
Copy Markdown
Contributor Author

Good point, thank you. Made it package-private in 5a5e884.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.77%. Comparing base (6caa33e) to head (73daf4a).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14036   +/-   ##
=========================================
  Coverage     20.77%   20.77%           
- Complexity    20845    20846    +1     
=========================================
  Files          6053     6053           
  Lines        548174   548174           
  Branches      73227    73227           
=========================================
+ Hits         113866   113878   +12     
+ Misses       420967   420954   -13     
- Partials      13341    13342    +1     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.20% <50.00%> (+<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.

@blueorangutan

Copy link
Copy Markdown

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

@Damans227 Damans227 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks @rootnomad, fix looks right. LGTM

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Ramgopal Nagaboina and others added 4 commits November 12, 2026 14:39
…count

copySnapshotOnPool passed CallContext.getCallingUserId() to
incrementResourceCount, whose first argument is an account id, not a user id.
User ids and account ids are independent sequences, so the primary_storage
count was charged to whichever account happened to share the caller's user id
(and never to the real owner), corrupting quota accounting. The following
guard also compared the calling user id against Account.ACCOUNT_ID_SYSTEM.
Use the snapshot owner's account id for the count and the calling account id
for the system check.
The test is in the same package, so the method does not need to be protected.
The resource count already goes to the owner, so the usage event should too,
otherwise an admin copying a user's snapshot is billed for it. Matches the
snapshot create and delete usage events, which also use the owner account.
…ImplTest

Keep a single test suite per class. Move
copySnapshotOnPoolChargesPrimaryStorageToTheSnapshotOwnerAccount into
SnapshotManagerImplTest and drop the separate
SnapshotManagerImplCopyResourceCountTest. The case reuses the mocks already
declared on the suite, so the duplicate mock declarations and the separate
runner are no longer needed.
@rootnomad
rootnomad force-pushed the fix/snapshot-copy-resourcecount-account branch from 9268030 to 73daf4a Compare November 12, 2026 19:46

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants