Skip to content

Commit 1893a70

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Optimize populate_queued_for_delete online data migration"
2 parents 65e0c0b + 47061e6 commit 1893a70

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

nova/objects/instance_mapping.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,14 @@ def populate_queued_for_delete(context, max_count):
161161
# have not yet received a defined value decision for
162162
# queued_for_delete
163163
context.session.query(api_models.InstanceMapping)
164-
.options(joinedload('cell_mapping'))
165164
.filter(
166165
api_models.InstanceMapping.queued_for_delete == None) # noqa
167166
.filter(api_models.InstanceMapping.cell_id == cell.id)
168167
.limit(max_count).all())
169168
ims_by_inst = {im.instance_uuid: im for im in ims}
169+
if not ims_by_inst:
170+
# If there is nothing from this cell to migrate, move on.
171+
continue
170172
with nova_context.target_cell(context, cell) as cctxt:
171173
filters = {'uuid': list(ims_by_inst.keys()),
172174
'deleted': True,

nova/tests/functional/db/test_instance_mapping.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import mock
1314
from oslo_utils.fixture import uuidsentinel
1415
from oslo_utils import uuidutils
1516

@@ -196,6 +197,15 @@ def test_populate_queued_for_delete(self):
196197
self.assertEqual(4, len(
197198
[im for im in mappings if im.queued_for_delete is False]))
198199

200+
# Run it again to make sure we don't query the cell database for
201+
# instances if we didn't get any un-migrated mappings.
202+
with mock.patch('nova.objects.InstanceList.get_by_filters',
203+
new_callable=mock.NonCallableMock):
204+
done, total = instance_mapping.populate_queued_for_delete(
205+
self.context, 1000)
206+
self.assertEqual(0, done)
207+
self.assertEqual(0, total)
208+
199209

200210
class InstanceMappingListTestCase(test.NoDBTestCase):
201211
USES_DB_SELF = True

0 commit comments

Comments
 (0)