Skip to content

Commit 4f4f27b

Browse files
committed
Decorate only Flavor.get_* methods that execute queries
The get_* methods on the Flavor object use a common helper method to build a query object to execute later. Currently, the @api_db_api.context_manager.reader decorator which manages the session is located on the helper method instead of on the methods that actually execute the database queries. Part of the context manager's job is to close the session after the query is executed. Because the decorator is not on the methods that actually execute the queries, those database connections are not being closed and it will eventually lead to errors like: sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 50 reached, connection timed out, timeout 30.00 (Background on this error at: https://sqlalche.me/e/14/3o7r) which means the connection pool size plus the overflow size has been reached and the pool will block for a fixed period of time before timing out and raising this error. This removes the @api_db_api.context_manager.reader decorator from the query build helper method and adds it to the Flavor.get_* methods that execute the database queries. Closes-Bug: #2027755 Change-Id: I4bf83d1642b62ab103716aff6dae7438646e2b31 (cherry picked from commit 9ae6240)
1 parent 252e660 commit 4f4f27b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

nova/objects/flavor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ def _from_db_object(context, flavor, db_flavor, expected_attrs=None):
270270
return flavor
271271

272272
@staticmethod
273-
@api_db_api.context_manager.reader
274273
def _flavor_get_query_from_db(context):
274+
# We don't use a database context decorator on this method because this
275+
# method is not executing a query, it's only building one.
275276
query = context.session.query(api_models.Flavors).options(
276277
orm.joinedload(api_models.Flavors.extra_specs)
277278
)
@@ -285,6 +286,7 @@ def _flavor_get_query_from_db(context):
285286

286287
@staticmethod
287288
@db_utils.require_context
289+
@api_db_api.context_manager.reader
288290
def _flavor_get_from_db(context, id):
289291
"""Returns a dict describing specific flavor."""
290292
result = Flavor._flavor_get_query_from_db(context).\
@@ -296,6 +298,7 @@ def _flavor_get_from_db(context, id):
296298

297299
@staticmethod
298300
@db_utils.require_context
301+
@api_db_api.context_manager.reader
299302
def _flavor_get_by_name_from_db(context, name):
300303
"""Returns a dict describing specific flavor."""
301304
result = Flavor._flavor_get_query_from_db(context).\
@@ -307,6 +310,7 @@ def _flavor_get_by_name_from_db(context, name):
307310

308311
@staticmethod
309312
@db_utils.require_context
313+
@api_db_api.context_manager.reader
310314
def _flavor_get_by_flavor_id_from_db(context, flavor_id):
311315
"""Returns a dict describing specific flavor_id."""
312316
result = Flavor._flavor_get_query_from_db(context).\

0 commit comments

Comments
 (0)