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
This commit is contained in:
Kevin Benton 2017-06-29 15:46:21 -07:00
parent ce33de5f51
commit 5be1ace546
1 changed files with 4 additions and 0 deletions

View File

@ -16,6 +16,7 @@
from neutron_lib import constants as const from neutron_lib import constants as const
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import timeutils from oslo_utils import timeutils
from sqlalchemy import orm
from neutron.db.models import agent as agent_model from neutron.db.models import agent as agent_model
from neutron.db.models import l3ha as l3ha_model from neutron.db.models import l3ha as l3ha_model
@ -70,6 +71,7 @@ def _get_active_network_ports(session, network_id):
query = query.join(agent_model.Agent, query = query.join(agent_model.Agent,
agent_model.Agent.host == ml2_models.PortBinding.host) agent_model.Agent.host == ml2_models.PortBinding.host)
query = query.join(models_v2.Port) 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, query = query.filter(models_v2.Port.network_id == network_id,
models_v2.Port.status == const.PORT_STATUS_ACTIVE) models_v2.Port.status == const.PORT_STATUS_ACTIVE)
return query return query
@ -109,6 +111,8 @@ def get_dvr_active_network_ports(session, network_id):
agent_model.Agent.host == agent_model.Agent.host ==
ml2_models.DistributedPortBinding.host) ml2_models.DistributedPortBinding.host)
query = query.join(models_v2.Port) 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, query = query.filter(models_v2.Port.network_id == network_id,
models_v2.Port.status == const.PORT_STATUS_ACTIVE, models_v2.Port.status == const.PORT_STATUS_ACTIVE,
models_v2.Port.device_owner == models_v2.Port.device_owner ==