From 5567797b3a3aece597d06d0f4b05740aa8b56158 Mon Sep 17 00:00:00 2001 From: wangxiyuan Date: Thu, 3 Mar 2016 11:37:25 +0800 Subject: [PATCH] Make query to quota usage table order preserved Currently, the query to quota usage table is not order preserved. This might cause deadlock in large-scale deployment: different calls may lock rows in different order, and deadlock will happen. This patch adds order_by to the query and make the query to the table order preserved. Change-Id: I7c439235f8927d5eb52274a59d0a87ad76879de1 Closes-bug: #1552510 --- cinder/db/sqlalchemy/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 1d7815189..14f94dd44 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -826,6 +826,7 @@ def _get_quota_usages(context, session, project_id): read_deleted="no", session=session).\ filter_by(project_id=project_id).\ + order_by(models.QuotaUsage.id.asc()).\ with_lockmode('update').\ all() return {row.resource: row for row in rows} @@ -836,6 +837,7 @@ def _get_quota_usages_by_resource(context, session, resource): deleted="no", session=session).\ filter_by(resource=resource).\ + order_by(models.QuotaUsage.id.asc()).\ with_lockmode('update').\ all() return rows -- 2.45.2