forked from canonical/charmed-openstack-upgrader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add archive old nova data pre-upgrade step (canonical#433)
Add an option to archive old nova data before upgrades. This should improve performance of upgrading nova components, as well as pave the way for purging (deleting) old data once archived. Ref. https://charmhub.io/nova-cloud-controller/actions#archive-data https://docs.openstack.org/project-deploy-guide/charm-deployment-guide/wallaby/upgrade-openstack.html#archive-old-database-data https://docs.openstack.org/nova/rocky/cli/nova-manage.html (see archive_deleted_rows )
- Loading branch information
1 parent
aa6b442
commit c838136
Showing
15 changed files
with
501 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright 2024 Canonical Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Functions for prereq steps relating to nova.""" | ||
import logging | ||
|
||
from cou.exceptions import ApplicationNotFound, COUException, UnitNotFound | ||
from cou.utils.juju_utils import Model | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def archive(model: Model, *, batch_size: int) -> None: | ||
"""Archive data on a nova-cloud-controller unit. | ||
The archive-data action only runs a single batch, | ||
so we run it in a loop until completion. | ||
See also: | ||
https://charmhub.io/nova-cloud-controller/actions#archive-data | ||
https://docs.openstack.org/project-deploy-guide/charm-deployment-guide/wallaby/upgrade-openstack.html#archive-old-database-data | ||
:param model: juju model to work with | ||
:type model: Model | ||
:param batch_size: batch-size to pass to the archive-data action | ||
(default is 1000; decrease if performance issues seen) | ||
:type batch_size: int | ||
:raises COUException: if action returned unexpected output | ||
""" # noqa: E501 line too long | ||
unit_name: str = await _get_nova_cloud_controller_unit_name(model) | ||
# The archive-data action only archives a single batch, | ||
# so we must run it in a loop until everything is archived. | ||
while True: | ||
logger.debug("Running action 'archive-data' on %s", unit_name) | ||
# https://charmhub.io/nova-cloud-controller/actions#archive-data | ||
action = await model.run_action( | ||
unit_name=unit_name, | ||
action_name="archive-data", | ||
raise_on_failure=True, | ||
action_params={"batch-size": batch_size}, | ||
) | ||
logger.info("action output: %s", action.data) | ||
output = action.data["results"].get("archive-deleted-rows") | ||
if output is None: | ||
raise COUException( | ||
"Expected to find output in action results.'archive-deleted-rows', " | ||
"but it was not present." | ||
) | ||
# The command will contain this string if there is nothing left to archive. | ||
# This means we don't need to run the command any more. | ||
if "Nothing was archived" in output: | ||
logger.debug("Archiving complete.") | ||
break | ||
logger.debug("Potentially more data to archive...") | ||
|
||
|
||
async def _get_nova_cloud_controller_unit_name(model: Model) -> str: | ||
"""Get nova-cloud-controller application's first unit's name. | ||
Assumes only a single nova-cloud-controller application is deployed. | ||
:param model: juju model to work with | ||
:type model: Model | ||
:return: unit name | ||
:rtype: str | ||
:raises UnitNotFound: When cannot find a valid unit for 'nova-cloud-controller' | ||
:raises ApplicationNotFound: When cannot find a 'nova-cloud-controller' application | ||
""" | ||
status = await model.get_status() | ||
for app_name, app_config in status.applications.items(): | ||
charm_name = await model.get_charm_name(app_name) | ||
if charm_name == "nova-cloud-controller": | ||
units = list(app_config.units.keys()) | ||
if units: | ||
return units[0] | ||
raise UnitNotFound( | ||
f"Cannot find unit for 'nova-cloud-controller' in model '{model.name}'." | ||
) | ||
|
||
raise ApplicationNotFound(f"Cannot find 'nova-cloud-controller' in model '{model.name}'.") |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
========================================== | ||
Archive old data | ||
========================================== | ||
|
||
By default, **COU** plans for and runs an archive step | ||
before proceeding to actual upgrade steps. | ||
This can be turned off with the `--no-archive` flag. | ||
|
||
This archive step is a performance optimisation, | ||
moving data for soft deleted nova instances into a shadow table. | ||
|
||
The archiving is run in batches. | ||
The default batch size is 1000. | ||
On some clouds, it may be desirable to reduce the batch size to reduce database load. | ||
The batch size can be configured with `--archive-batch-size N`, where `N` is a positive integer. | ||
|
||
Usage examples | ||
-------------- | ||
|
||
With a custom batch size: | ||
|
||
.. terminal:: | ||
:input: cou plan --archive-batch-size 200 | ||
|
||
Full execution log: '/home/ubuntu/.local/share/cou/log/cou-20231215211717.log' | ||
Connected to 'test-model' ✔ | ||
Analyzing cloud... ✔ | ||
Generating upgrade plan... ✔ | ||
Upgrade cloud from 'ussuri' to 'victoria' | ||
Verify that all OpenStack applications are in idle state | ||
Back up MySQL databases | ||
Archive old database data on nova-cloud-controller | ||
Control Plane principal(s) upgrade plan | ||
... | ||
|
||
Disabling the archive step: | ||
|
||
.. terminal:: | ||
:input: cou plan --no-archive | ||
|
||
Full execution log: '/home/ubuntu/.local/share/cou/log/cou-20231215211717.log' | ||
Connected to 'test-model' ✔ | ||
Analyzing cloud... ✔ | ||
Generating upgrade plan... ✔ | ||
Upgrade cloud from 'ussuri' to 'victoria' | ||
Verify that all OpenStack applications are in idle state | ||
Back up MySQL databases | ||
Control Plane principal(s) upgrade plan | ||
... | ||
|
||
More information | ||
---------------- | ||
|
||
- `nova-cloud-controller charm actions`_ | ||
- `nova-manage reference`_ - see `archive_deleted_rows` subcommand | ||
- OpenStack upgrade guide information on `archiving old database data`_ | ||
|
||
|
||
.. LINKS | ||
.. _nova-cloud-controller charm actions: https://charmhub.io/nova-cloud-controller/actions | ||
.. _nova-manage reference: https://docs.openstack.org/nova/rocky/cli/nova-manage.html | ||
.. _archiving old database data: https://docs.openstack.org/project-deploy-guide/charm-deployment-guide/wallaby/upgrade-openstack.html#archive-old-database-data |
This file contains 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 |
---|---|---|
|
@@ -15,4 +15,5 @@ are possible with **COU**. | |
interruption | ||
configure-connection | ||
no-backup | ||
archive-old-data | ||
verbosity |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.