Skip to content

Commit 466f0da

Browse files
Niklaus-xiezhaoqin-github
authored andcommitted
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. (cherry picked from commit 4e7eb06)
1 parent dbc28b1 commit 466f0da

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

f5lbaasdriver/v2/bigip/agent_scheduler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,12 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
200200
"""
201201

202202
with context.session.begin(subtransactions=True):
203-
loadbalancer = plugin.db.get_loadbalancer(context, loadbalancer_id)
204203
# If the loadbalancer is hosted on an active agent
205204
# already, return that agent or one in its env
206205
lbaas_agent = self.get_lbaas_agent_hosting_loadbalancer(
207206
plugin,
208207
context,
209-
loadbalancer.id,
208+
loadbalancer_id,
210209
env
211210
)
212211

@@ -216,6 +215,14 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
216215
% (lbaas_agent['id']))
217216
return lbaas_agent
218217

218+
# moving this part here so that this db call basically only called
219+
# while creating lb. If it was for creating lb, then this call
220+
# returns immediately. For other ops, it should have returned
221+
# already above, so this db call is avoided.
222+
LOG.info('get_loadbalancer start inside schedule')
223+
loadbalancer = plugin.db.get_loadbalancer(context, loadbalancer_id)
224+
LOG.info('get_loadbalancer end inside schedule')
225+
219226
# There is no existing loadbalancer agent binding.
220227
# Find all active agent candidates in this env.
221228
# We use environment_prefix to find F5® agents

0 commit comments

Comments
 (0)