Merge "Optimize populate_queued_for_delete online data migration"
This commit is contained in:
commit
1893a700ce
@ -161,12 +161,14 @@ def populate_queued_for_delete(context, max_count):
|
|||||||
# have not yet received a defined value decision for
|
# have not yet received a defined value decision for
|
||||||
# queued_for_delete
|
# queued_for_delete
|
||||||
context.session.query(api_models.InstanceMapping)
|
context.session.query(api_models.InstanceMapping)
|
||||||
.options(joinedload('cell_mapping'))
|
|
||||||
.filter(
|
.filter(
|
||||||
api_models.InstanceMapping.queued_for_delete == None) # noqa
|
api_models.InstanceMapping.queued_for_delete == None) # noqa
|
||||||
.filter(api_models.InstanceMapping.cell_id == cell.id)
|
.filter(api_models.InstanceMapping.cell_id == cell.id)
|
||||||
.limit(max_count).all())
|
.limit(max_count).all())
|
||||||
ims_by_inst = {im.instance_uuid: im for im in ims}
|
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:
|
with nova_context.target_cell(context, cell) as cctxt:
|
||||||
filters = {'uuid': list(ims_by_inst.keys()),
|
filters = {'uuid': list(ims_by_inst.keys()),
|
||||||
'deleted': True,
|
'deleted': True,
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
from oslo_utils.fixture import uuidsentinel
|
from oslo_utils.fixture import uuidsentinel
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
@ -196,6 +197,15 @@ class InstanceMappingTestCase(test.NoDBTestCase):
|
|||||||
self.assertEqual(4, len(
|
self.assertEqual(4, len(
|
||||||
[im for im in mappings if im.queued_for_delete is False]))
|
[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):
|
class InstanceMappingListTestCase(test.NoDBTestCase):
|
||||||
USES_DB_SELF = True
|
USES_DB_SELF = True
|
||||||
|
Loading…
Reference in New Issue
Block a user