-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update the snapshot physical size for the primary storage resource after snapshot creation and during resource count recalculation #12481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.20
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,6 +78,15 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO | |||||||||||||||||||||||||||||||
| " order by created %s " + | ||||||||||||||||||||||||||||||||
| " limit 1"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private static final String GET_PHYSICAL_SIZE_OF_SNAPSHOTS_ON_PRIMARY_BY_ACCOUNT = "SELECT SUM(s.physical_size) " + | ||||||||||||||||||||||||||||||||
| "FROM cloud.snapshot_store_ref s " + | ||||||||||||||||||||||||||||||||
| "LEFT JOIN cloud.snapshots ON s.snapshot_id = snapshots.id " + | ||||||||||||||||||||||||||||||||
| "WHERE snapshots.account_id = ? " + | ||||||||||||||||||||||||||||||||
| "AND snapshots.removed IS NULL " + | ||||||||||||||||||||||||||||||||
| "AND s.state = 'Ready' " + | ||||||||||||||||||||||||||||||||
| "AND s.store_role = 'Primary' " + | ||||||||||||||||||||||||||||||||
| "AND NOT EXISTS (SELECT 1 FROM cloud.snapshot_store_ref i WHERE i.snapshot_id = s.snapshot_id AND i.store_role = 'Image')"; | ||||||||||||||||||||||||||||||||
sureshanaparti marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+81
to
+88
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we include the size of the snapshot in primary which is present on secondary as well?
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, if we are going this way we can just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@abh1sar no, the snapshots in primary are deleted when they are backed up on secondary, but the store_ref record still exists (with 'Ready' state as I noticed - this record needs to removed or state should be updated to 'Destroyed'. Also, location_type column in snapshots table is not populated, which should indicate location of the snapshot - 'Primary' or 'Image'. - these need more testing and can break any existing func, so I'll raise separate PR with these fixes/improvements). the sql would consider the snapshots in primary and not exists in secondary storage. |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||
| public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { | ||||||||||||||||||||||||||||||||
| super.configure(name, params); | ||||||||||||||||||||||||||||||||
|
|
@@ -118,7 +127,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu | |||||||||||||||||||||||||||||||
| stateSearch.and(STATE, stateSearch.entity().getState(), SearchCriteria.Op.IN); | ||||||||||||||||||||||||||||||||
| stateSearch.done(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| idStateNeqSearch = createSearchBuilder(); | ||||||||||||||||||||||||||||||||
| idStateNeqSearch.and(SNAPSHOT_ID, idStateNeqSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); | ||||||||||||||||||||||||||||||||
| idStateNeqSearch.and(STATE, idStateNeqSearch.entity().getState(), SearchCriteria.Op.NEQ); | ||||||||||||||||||||||||||||||||
|
|
@@ -578,4 +586,23 @@ public int expungeBySnapshotList(final List<Long> snapshotIds, final Long batchS | |||||||||||||||||||||||||||||||
| sc.setParameters("snapshotIds", snapshotIds.toArray()); | ||||||||||||||||||||||||||||||||
| return batchExpunge(sc, batchSize); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||
| public long getSnapshotsPhysicalSizeOnPrimaryStorageByAccountId(long accountId) { | ||||||||||||||||||||||||||||||||
| long snapshotsPhysicalSize = 0; | ||||||||||||||||||||||||||||||||
| try (TransactionLegacy transactionLegacy = TransactionLegacy.currentTxn()) { | ||||||||||||||||||||||||||||||||
| try (PreparedStatement preparedStatement = transactionLegacy.prepareStatement(GET_PHYSICAL_SIZE_OF_SNAPSHOTS_ON_PRIMARY_BY_ACCOUNT)) { | ||||||||||||||||||||||||||||||||
| preparedStatement.setLong(1, accountId); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| try (ResultSet resultSet = preparedStatement.executeQuery()) { | ||||||||||||||||||||||||||||||||
| if (resultSet.next()) { | ||||||||||||||||||||||||||||||||
| snapshotsPhysicalSize = resultSet.getLong(1); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } catch (SQLException e) { | ||||||||||||||||||||||||||||||||
| logger.warn("Failed to get the snapshots physical size for the account [{}] due to [{}].", accountId, e.getMessage(), e); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return snapshotsPhysicalSize; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
sureshanaparti marked this conversation as resolved.
Show resolved
Hide resolved
sureshanaparti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.