Optimize populate_queued_for_delete online data migration

The data migration was needlessly querying the cell database
for instances even if there were no instance mappings in that
database that needed to be migrated. This simply continues to
the next cell if the instance mappings in the current cell are
migrated.

While we're in here, the joinedload on 'cell_mapping' can be
removed since it's not used.

Closes-Bug: #1817961

Change-Id: Idf35ed9d57945bc80fbd47393b7de076330160e6
This commit is contained in:
Matt Riedemann 2019-02-27 16:24:24 -05:00
parent eb93d0cffd
commit 47061e699b
2 changed files with 13 additions and 1 deletions

View File

@ -161,12 +161,14 @@ def populate_queued_for_delete(context, max_count):
# have not yet received a defined value decision for
# queued_for_delete
context.session.query(api_models.InstanceMapping)
.options(joinedload('cell_mapping'))
.filter(
api_models.InstanceMapping.queued_for_delete == None) # noqa
.filter(api_models.InstanceMapping.cell_id == cell.id)
.limit(max_count).all())
ims_by_inst = {im.instance_uuid: im for im in ims}
if not ims_by_inst:
# If there is nothing from this cell to migrate, move on.
continue
with nova_context.target_cell(context, cell) as cctxt:
filters = {'uuid': list(ims_by_inst.keys()),
'deleted': True,

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_utils.fixture import uuidsentinel
from oslo_utils import uuidutils
@ -196,6 +197,15 @@ class InstanceMappingTestCase(test.NoDBTestCase):
self.assertEqual(4, len(
[im for im in mappings if im.queued_for_delete is False]))
# Run it again to make sure we don't query the cell database for
# instances if we didn't get any un-migrated mappings.
with mock.patch('nova.objects.InstanceList.get_by_filters',
new_callable=mock.NonCallableMock):
done, total = instance_mapping.populate_queued_for_delete(
self.context, 1000)
self.assertEqual(0, done)
self.assertEqual(0, total)
class InstanceMappingListTestCase(test.NoDBTestCase):
USES_DB_SELF = True