Use subqueryload in l2pop DB for binding ports

This adjusts the l2pop DB queries that leverage the port relationship
on the PortBinding and DistributedPortBinding models to ensure that the
port gets loaded from the DB as part of the initial query.

Without this the number of DB queries will increase with the number
of ports since the port wasn't being loaded until the 'port' attribute
was referenced on its corresponding binding object.

Closes-Bug: #1701288
Change-Id: I7c3b08d525b2c90100c9fe4efaee973cf3a076f3
(cherry picked from commit 5be1ace546)
This commit is contained in:
Kevin Benton 2017-06-29 15:46:21 -07:00 committed by Swaminathan Vasudevan
parent 4c6afa54b1
commit a8d9ad9336
1 changed files with 4 additions and 0 deletions

View File

@ -16,6 +16,7 @@
from neutron_lib import constants as const
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from sqlalchemy import orm
from neutron.db import agents_db
from neutron.db import l3_hamode_db
@ -70,6 +71,7 @@ def _get_active_network_ports(session, network_id):
query = query.join(agents_db.Agent,
agents_db.Agent.host == ml2_models.PortBinding.host)
query = query.join(models_v2.Port)
query = query.options(orm.subqueryload(ml2_models.PortBinding.port))
query = query.filter(models_v2.Port.network_id == network_id,
models_v2.Port.status == const.PORT_STATUS_ACTIVE)
return query
@ -109,6 +111,8 @@ def get_dvr_active_network_ports(session, network_id):
agents_db.Agent.host ==
ml2_models.DistributedPortBinding.host)
query = query.join(models_v2.Port)
query = query.options(
orm.subqueryload(ml2_models.DistributedPortBinding.port))
query = query.filter(models_v2.Port.network_id == network_id,
models_v2.Port.status == const.PORT_STATUS_ACTIVE,
models_v2.Port.device_owner ==