Merge "Optimize populate_queued_for_delete online data migration"

This commit is contained in:
Zuul 2019-03-04 14:04:28 +00:00 committed by Gerrit Code Review
commit 1893a700ce
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