Improve Cinder API cache implementation

Bug #1358524 reported by Mathieu Gagné
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Wishlist
Mathieu Gagné

Bug Description

The current cache implementation found in cinder.api.openstack.wsgi is too simple.

Only a bunch of generic methods are provided:
- cache_resource(self, resource_to_cache, id_attribute='id', name=None)
- cached_resource(self, name=None):
- cached_resource_by_id(self, resource_id, name=None):

As you can see, the name is optional. Current API code never explicitly provides the resource type name. This could be problematic is we try to cache 2 types of resources during the same request.

Furthermore, the documentation provided in cinder.api.openstack.wsgi is wrong:

    Different resources types might need to be cached during the same
    request, they can be cached using the name parameter. For example:

        Controller 1:
            request.cache_resource(db_volumes, 'volumes')
            request.cache_resource(db_volume_types, 'types')
        Controller 2:
            db_volumes = request.cached_resource('volumes')
            db_type_1 = request.cached_resource_by_id('1', 'types')

The second parameter of cache_resource is id_attribute, not name.

To improve the situation, it has been suggested to take the Nova's implementation instead.

The Nova's implementation provides a better interface. Each resource type has a dedicated method which makes the resource type cached explicitly mentioned.

An example of such implementation for Cinder would be:
- cache_db_volumes(volumes) vs cache_resource(volumes, name='volumes')
- cache_db_volume(volume) vs cache_resource(volumes, name='volumes')
- get_db_volumes() vs cached_resource('volumes')
- get_db_volume(id) vs cached_resource_by_id(id, name='volumes')

This interface makes it clear that a volume is added or retrieved from the cache. A side-effect is that code will be shorter.

The proposed implementation will be backward compatible for people with out-of-tree extensions by preserving existing methods and still using the same variable to store the cached resources.

Changed in cinder:
status: New → Confirmed
importance: Undecided → Wishlist
Revision history for this message
Duncan Thomas (duncan-thomas) wrote :

Can you provide either a few more details (or a spec please)? As it stands I'd say this was incomplete, I don't even know which cache you are referring to.

Mathieu Gagné (mgagne)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/115404

Changed in cinder:
assignee: nobody → Mathieu Gagné (mgagne)
status: Confirmed → In Progress
Mike Perez (thingee)
Changed in cinder:
milestone: none → kilo-1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/115404
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=4aeb7256ef4cc75bae4ff9258a5bcf6092b3c834
Submitter: Jenkins
Branch: master

commit 4aeb7256ef4cc75bae4ff9258a5bcf6092b3c834
Author: Mathieu Gagné <email address hidden>
Date: Tue Aug 19 17:07:42 2014 -0400

    Improve Cinder API internal cache interface

    Improve the internal caching system used by the API layer
    by borrowing the implementation used by Nova.

    Unlike the previous implementation, this new interface makes it clear
    which resource types are added or retrieved from the cache.

    This change also adds other resources to the cache:
    - backups
    - snapshots
    - volume types

    It's now possible to remove database access those extensions:
    - extended_snapshot_attributes
    - volume_host_attribute
    - volume_mig_status_attribute
    - volume_tenant_attribute

    Closes-bug: #1358524
    Change-Id: I1fc673d0c01c41faa98292d5813d4471b455d712

Changed in cinder:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: kilo-1 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.