Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance glitch while sorting image locations #88

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bindep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ postgresql-server [platform:rpm]
postgresql-server-devel [platform:suse] # Provides pg_config
libpython3-dev [platform:dpkg]
python3-devel [platform:rpm]
qemu [platform:dpkg devstack build-image-dib]
qemu-utils [platform:dpkg devstack build-image-dib]
qemu-img [platform:redhat]
qemu-tools [platform:suse] # Provides qemu-img
qemu [platform:dpkg devstack build-image-dib test]
qemu-utils [platform:dpkg devstack build-image-dib test]
qemu-img [platform:redhat test]
qemu-tools [platform:suse test] # Provides qemu-img
libpq-dev [platform:dpkg]
libpcre3-dev [platform:dpkg]
pcre-devel [platform:redhat]
3 changes: 1 addition & 2 deletions glance/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,12 @@ def get_store_weight(location):
if not store_id:
return 0
try:
store = glance_store.get_store_from_store_identifier(store_id)
return glance_store.get_store_weight(store_id)
except glance_store.exceptions.UnknownScheme:
msg = (_LW("Unable to find store '%s', returning "
"default weight '0'") % store_id)
LOG.warning(msg)
return 0
return store.weight if store is not None else 0

sorted_locations = sorted(locations, key=get_store_weight, reverse=True)
LOG.debug(('Sorted locations: %s'), sorted_locations)
Expand Down
16 changes: 7 additions & 9 deletions glance/tests/unit/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_sort_image_locations_multistore_disabled(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {'store': 'rbd3'}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
utils.sort_image_locations(locations)

Expand All @@ -215,10 +215,9 @@ def test_sort_image_locations(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {'store': 'rbd3'}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
mock_store = mock_get_store.return_value
mock_store.weight = 100
mock_get_store.return_value = 100
utils.sort_image_locations(locations)

# Since 3 stores are configured, internal method will be called 3 times
Expand All @@ -243,7 +242,7 @@ def test_sort_image_locations_without_metadata(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
utils.sort_image_locations(locations)

Expand All @@ -270,10 +269,9 @@ def test_sort_image_locations_with_partial_metadata(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
mock_store = mock_get_store.return_value
mock_store.weight = 100
mock_get_store.return_value = 100
utils.sort_image_locations(locations)

# Since 3 stores are configured, but only one location has
Expand All @@ -300,7 +298,7 @@ def test_sort_image_locations_unknownscheme(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {'store': 'rbd3'}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
mock_get_store.side_effect = store.UnknownScheme()
sorted_locations = utils.sort_image_locations(locations)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ retrying!=1.3.0,>=1.2.3 # Apache-2.0
osprofiler>=1.4.0 # Apache-2.0

# Glance Store
glance-store>=2.3.0 # Apache-2.0
glance-store @ git+https://github.com/stackhpc/glance_store@stackhpc/4.7.0.3 # Apache-2.0


debtcollector>=1.19.0 # Apache-2.0
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ setenv =
OS_TEST_DBAPI_ADMIN_CONNECTION=sqlite:////tmp/placeholder-never-created-nor-used.db
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
SQLALCHEMY_WARN_20=1
TOX_CONSTRAINTS_FILE=https://raw.githubusercontent.com/stackhpc/requirements/refs/heads/stackhpc/2024.1/upper-constraints.txt
usedevelop = True
install_command = python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1} {opts} {packages}
deps = -r{toxinidir}/test-requirements.txt
Expand Down
Loading