[openstack-dev] [Cinder] Question about synchronized decoration usage in cinder-volume

Zhangleiqiang (Trump) zhangleiqiang at huawei.com
Sat Apr 26 09:56:16 UTC 2014


Hi, all:

	I find almost all of the @utils.synchronized decoration usage in cinder-volume (cinder.volume.manager / cinder.volume.drivers.*) with an "external=True" param. Such as cinder.volume.manager.VolumeManager:attach_volume:

	    def attach_volume(self, context, volume_id, instance_uuid, host_name,
                      mountpoint, mode):
        """Updates db to show volume is attached."""
        @utils.synchronized(volume_id, external=True)
        def do_attach():

	However, in docstring of common.lockutils.synchronized, I find param "external" is used for multi-workers scenario:
	
		:param external: The external keyword argument denotes whether this lock
    	should work across multiple processes. This means that if two different
    	workers both run a a method decorated with @synchronized('mylock',
    	external=True), only one of them will execute at a time.
	
	I have two questions about it.
	1. As far as I know, cinder-api has supported multi-worker mode and cinder-volume doesn't support it, does it? So I wonder why the "external=True" param is used here?
	2. Specific to cinder.volume.manager.VolumeManager:attach_volume, all operations in "do_attach" method are database related. As said in [1], operations to the database will block the main thread of a service, so another question I want to know is why this method is needed to be synchronized?

	Thanks.

[1] http://docs.openstack.org/developer/cinder/devref/threading.html#mysql-access-and-eventlet
----------
zhangleiqiang (Trump)

Best Regards





More information about the OpenStack-dev mailing list