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
changes/91/479091/2
Kevin Benton 6 years ago
parent ce33de5f51
commit 5be1ace546
  1. 4
      neutron/plugins/ml2/drivers/l2pop/db.py

@ -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.models import agent as agent_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,
agent_model.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):
agent_model.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 ==

Loading…
Cancel
Save