Skip to content

Commit 4e7eb06

Browse files
committed
avoid getting lb from db
Let's avoid modifying the schedule() function's prototype as that might impact too many places. To avoid unnecesary db call when the lb was already scheduled before. This seems to be a safer way which modifies the least code. Seems a little risky if we try to use the lb passed from member.pool.loadbalancer because this content from the third-party might differ.
1 parent 778e879 commit 4e7eb06

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

f5lbaasdriver/v2/bigip/agent_scheduler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,12 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
189189
"""
190190

191191
with context.session.begin(subtransactions=True):
192-
LOG.info('get_loadbalancer start')
193-
loadbalancer = plugin.db.get_loadbalancer(context, loadbalancer_id)
194-
LOG.info('get_loadbalancer end')
195192
# If the loadbalancer is hosted on an active agent
196193
# already, return that agent or one in its env
197194
lbaas_agent = self.get_lbaas_agent_hosting_loadbalancer(
198195
plugin,
199196
context,
200-
loadbalancer.id,
197+
loadbalancer_id,
201198
env
202199
)
203200

@@ -207,6 +204,14 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
207204
% (lbaas_agent['id']))
208205
return lbaas_agent
209206

207+
# moving this part here so that this db call basically only called
208+
# while creating lb. If it was for creating lb, then this call
209+
# returns immediately. For other ops, it should have returned
210+
# already above, so this db call is avoided.
211+
LOG.info('get_loadbalancer start inside schedule')
212+
loadbalancer = plugin.db.get_loadbalancer(context, loadbalancer_id)
213+
LOG.info('get_loadbalancer end inside schedule')
214+
210215
# There is no existing loadbalancer agent binding.
211216
# Find all active agent candidates in this env.
212217
# We use environment_prefix to find F5® agents

0 commit comments

Comments
 (0)