-
Notifications
You must be signed in to change notification settings - Fork 23
Add concurrency to snapshot delete. Concurrency offloaded to celery #2298
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,18 @@ | |
| import os | ||
| import copy | ||
| import time | ||
| from celery import group | ||
| from celery.utils import uuid | ||
| from celery.result import GroupResult | ||
| from datetime import datetime, timedelta | ||
| from threading import Thread | ||
| from time import mktime | ||
| from ovs.constants.vdisk import SCRUB_VDISK_EXCEPTION_MESSAGE | ||
| from ovs.dal.hybrids.servicetype import ServiceType | ||
| from ovs.dal.hybrids.storagedriver import StorageDriver | ||
| from ovs.dal.hybrids.vdisk import VDisk | ||
| from ovs.dal.lists.servicelist import ServiceList | ||
| from ovs.dal.lists.storagedriverlist import StorageDriverList | ||
| from ovs.dal.lists.storagerouterlist import StorageRouterList | ||
| from ovs.dal.lists.vdisklist import VDiskList | ||
| from ovs.extensions.db.arakooninstaller import ArakoonClusterConfig | ||
|
|
@@ -74,21 +80,53 @@ def snapshot_all_vdisks(): | |
| @staticmethod | ||
| @ovs_task(name='ovs.generic.delete_snapshots', schedule=Schedule(minute='1', hour='2'), ensure_single_info={'mode': 'DEFAULT'}) | ||
| def delete_snapshots(timestamp=None): | ||
| # type: (float) -> GroupResult | ||
| """ | ||
| Delete snapshots & scrubbing policy | ||
| Delete snapshots based on the retention policy | ||
| Offloads concurrency to celery | ||
| Returns a GroupResult. Waiting for the result can be done using result.get() | ||
| :param timestamp: Timestamp to determine whether snapshots should be kept or not, if none provided, current time will be used | ||
| :type timestamp: float | ||
| :return: The GroupResult | ||
| :rtype: GroupResult | ||
| """ | ||
| # The result cannot be fetched in this task | ||
| group_id = uuid() | ||
| return group(GenericController.delete_snapshots_storagedriver.s(storagedriver.guid, timestamp, group_id) | ||
| for storagedriver in StorageDriverList.get_storagedrivers()).apply_async(task_id=group_id) | ||
|
|
||
| @staticmethod | ||
| @ovs_task(name='ovs.generic.delete_snapshots_storagedriver', ensure_single_info={'mode': 'DEDUPED'}) | ||
| def delete_snapshots_storagedriver(storagedriver_guid, timestamp=None, group_id=None): | ||
| """ | ||
|
Contributor
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. Typing |
||
| Delete snapshots per storagedriver & scrubbing policy | ||
|
|
||
| Implemented delete snapshot policy: | ||
| < 1d | 1d bucket | 1 | best of bucket | 1d | ||
| < 1w | 1d bucket | 6 | oldest of bucket | 7d = 1w | ||
| < 1m | 1w bucket | 3 | oldest of bucket | 4w = 1m | ||
| > 1m | delete | ||
|
|
||
| :param storagedriver_guid: Guid of the StorageDriver to remove snapshots on | ||
| :type storagedriver_guid: str | ||
| :param timestamp: Timestamp to determine whether snapshots should be kept or not, if none provided, current time will be used | ||
| :type timestamp: float | ||
|
|
||
| :param group_id: ID of the group task. Used to identify which snapshot deletes were called during the scheduled task | ||
| :type group_id: str | ||
| :return: None | ||
| """ | ||
| GenericController._logger.info('Delete snapshots started') | ||
| if group_id: | ||
| log_id = 'Group job {} - '.format(group_id) | ||
| else: | ||
| log_id = '' | ||
|
|
||
| def format_log(message): | ||
| return '{}{}'.format(log_id, message) | ||
|
|
||
| GenericController._logger.info(format_log('Delete snapshots started for StorageDriver {0}'.format(storagedriver_guid))) | ||
|
|
||
| storagedriver = StorageDriver(storagedriver_guid) | ||
| exceptions = [] | ||
|
|
||
| day = timedelta(1) | ||
| week = day * 7 | ||
|
|
@@ -128,27 +166,31 @@ def make_timestamp(offset): | |
|
|
||
| # Place all snapshots in bucket_chains | ||
| bucket_chains = [] | ||
| for vdisk in VDiskList.get_vdisks(): | ||
| vdisk.invalidate_dynamics('being_scrubbed') | ||
| if vdisk.being_scrubbed: | ||
| continue | ||
| for vdisk_guid in storagedriver.vdisks_guids: | ||
| try: | ||
| vdisk = VDisk(vdisk_guid) | ||
| vdisk.invalidate_dynamics('being_scrubbed') | ||
| if vdisk.being_scrubbed: | ||
| continue | ||
|
|
||
| if vdisk.info['object_type'] in ['BASE']: | ||
| bucket_chain = copy.deepcopy(buckets) | ||
| for snapshot in vdisk.snapshots: | ||
| if snapshot.get('is_sticky') is True: | ||
| continue | ||
| if snapshot['guid'] in parent_snapshots: | ||
| GenericController._logger.info('Not deleting snapshot {0} because it has clones'.format(snapshot['guid'])) | ||
| continue | ||
| timestamp = int(snapshot['timestamp']) | ||
| for bucket in bucket_chain: | ||
| if bucket['start'] >= timestamp > bucket['end']: | ||
| bucket['snapshots'].append({'timestamp': timestamp, | ||
| 'snapshot_id': snapshot['guid'], | ||
| 'vdisk_guid': vdisk.guid, | ||
| 'is_consistent': snapshot['is_consistent']}) | ||
| bucket_chains.append(bucket_chain) | ||
| if vdisk.info['object_type'] in ['BASE']: | ||
| bucket_chain = copy.deepcopy(buckets) | ||
| for snapshot in vdisk.snapshots: | ||
| if snapshot.get('is_sticky') is True: | ||
| continue | ||
| if snapshot['guid'] in parent_snapshots: | ||
| GenericController._logger.info(format_log('Not deleting snapshot {0} because it has clones'.format(snapshot['guid']))) | ||
| continue | ||
| timestamp = int(snapshot['timestamp']) | ||
| for bucket in bucket_chain: | ||
| if bucket['start'] >= timestamp > bucket['end']: | ||
| bucket['snapshots'].append({'timestamp': timestamp, | ||
| 'snapshot_id': snapshot['guid'], | ||
| 'vdisk_guid': vdisk.guid, | ||
| 'is_consistent': snapshot['is_consistent']}) | ||
| bucket_chains.append(bucket_chain) | ||
| except Exception as ex: | ||
| exceptions.append(ex) | ||
|
|
||
| # Clean out the snapshot bucket_chains, we delete the snapshots we want to keep | ||
| # And we'll remove all snapshots that remain in the buckets | ||
|
|
@@ -181,7 +223,6 @@ def make_timestamp(offset): | |
| bucket['snapshots'] = [s for s in bucket['snapshots'] if | ||
| s['timestamp'] != oldest['timestamp']] | ||
|
|
||
| exceptions = [] | ||
| # Delete obsolete snapshots | ||
| for bucket_chain in bucket_chains: | ||
| # Each bucket chain represents one vdisk's snapshots | ||
|
|
@@ -196,13 +237,13 @@ def make_timestamp(offset): | |
| if vdisk_guid: | ||
| vdisk_id_log = ' for VDisk with guid {}'.format(vdisk_guid) | ||
| if SCRUB_VDISK_EXCEPTION_MESSAGE in ex.message: | ||
| GenericController._logger.warning('Being scrubbed exception occurred while deleting snapshots{}'.format(vdisk_id_log)) | ||
| GenericController._logger.warning(format_log('Being scrubbed exception occurred while deleting snapshots{}'.format(vdisk_id_log))) | ||
| else: | ||
| GenericController._logger.exception('Exception occurred while deleting snapshots{}'.format(vdisk_id_log)) | ||
| GenericController._logger.exception(format_log('Exception occurred while deleting snapshots{}'.format(vdisk_id_log))) | ||
| exceptions.append(ex) | ||
| if exceptions: | ||
| raise RuntimeError('Exceptions occurred while deleting snapshots: \n- {}'.format('\n- '.join((str(ex) for ex in exceptions)))) | ||
| GenericController._logger.info('Delete snapshots finished') | ||
| GenericController._logger.info(format_log('Delete snapshots finished for StorageDriver {0}')) | ||
|
|
||
| @staticmethod | ||
| @ovs_task(name='ovs.generic.execute_scrub', schedule=Schedule(minute='0', hour='3'), ensure_single_info={'mode': 'DEDUPED'}) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional[float]