nova/nova/compute/migration_list.py
Stephen Finucane 100b9dc62c db: Unify 'nova.db.api', 'nova.db.sqlalchemy.api'
Merge these, removing an unnecessary layer of abstraction, and place
them in the new 'nova.db.main' directory. The resulting change is huge,
but it's mainly the result of 's/sqlalchemy import api/main import api/'
and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We
also need to rework how we do the blocking of API calls since we no
longer have a 'DBAPI' object that we can monkey patch as we were doing
before. This is now done via a global variable that is set by the 'main'
function of 'nova.cmd.compute'.

The main impact of this change is that it's no longer possible to set
'[database] use_db_reconnect' and have all APIs automatically wrapped in
a DB retry. Seeing as this behavior is experimental, isn't applied to
any of the API DB methods (which don't use oslo.db's 'DBAPI' helper),
and is used explicitly in what would appear to be the critical cases
(via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't
seem like a huge loss.

Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-08-09 15:34:40 +01:00

87 lines
3.4 KiB
Python

# 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.
import copy
from nova.compute import multi_cell_list
from nova import context
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import base
class MigrationSortContext(multi_cell_list.RecordSortContext):
def __init__(self, sort_keys, sort_dirs):
if not sort_keys:
sort_keys = ['created_at', 'id']
sort_dirs = ['desc', 'desc']
if 'uuid' not in sort_keys:
# Add uuid into the list of sort_keys. Since we're striping
# across cell databases here, many sort_keys arrangements will
# yield nothing unique across all the databases to give us a stable
# ordering, which can mess up expected client pagination behavior.
# So, throw uuid into the sort_keys at the end if it's not already
# there to keep us repeatable.
sort_keys = copy.copy(sort_keys) + ['uuid']
sort_dirs = copy.copy(sort_dirs) + ['asc']
super(MigrationSortContext, self).__init__(sort_keys, sort_dirs)
class MigrationLister(multi_cell_list.CrossCellLister):
def __init__(self, sort_keys, sort_dirs):
super(MigrationLister, self).__init__(
MigrationSortContext(sort_keys, sort_dirs))
@property
def marker_identifier(self):
return 'uuid'
def get_marker_record(self, ctx, marker):
"""Get the marker migration from its cell.
This returns the marker migration from the cell in which it lives
"""
results = context.scatter_gather_skip_cell0(
ctx, db.migration_get_by_uuid, marker)
db_migration = None
for result_cell_uuid, result in results.items():
if not context.is_cell_failure_sentinel(result):
db_migration = result
cell_uuid = result_cell_uuid
break
if not db_migration:
raise exception.MarkerNotFound(marker=marker)
return cell_uuid, db_migration
def get_marker_by_values(self, ctx, values):
return db.migration_get_by_sort_filters(ctx,
self.sort_ctx.sort_keys,
self.sort_ctx.sort_dirs,
values)
def get_by_filters(self, ctx, filters, limit, marker, **kwargs):
return db.migration_get_all_by_filters(
ctx, filters, limit=limit, marker=marker,
sort_keys=self.sort_ctx.sort_keys,
sort_dirs=self.sort_ctx.sort_dirs)
def get_migration_objects_sorted(ctx, filters, limit, marker,
sort_keys, sort_dirs):
mig_generator = MigrationLister(sort_keys, sort_dirs).get_records_sorted(
ctx, filters, limit, marker)
return base.obj_make_list(ctx, objects.MigrationList(), objects.Migration,
mig_generator)