summaryrefslogtreecommitdiff
path: root/nova/virt/block_device.py
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2015-03-19 14:50:57 +0000
committerNikola Dipanov <ndipanov@redhat.com>2015-03-19 14:54:42 +0000
commitb8dc85719795fbd09a2730c76c561d95e2d21589 (patch)
tree049c54f0d24c4c7b1c2dc9de04ef2f5df986ced4 /nova/virt/block_device.py
parent7885b742f3852c95dfec767f8d5b8583114e033e (diff)
downloadnova-b8dc85719795fbd09a2730c76c561d95e2d21589.tar.gz
BDM: Avoiding saving if there were no changes
Since objects currently only check if the attribute was set not that the actual value was changed (and it's not a straightforward task in the general case), we can still make this better in the DriverBlockDevice classes and avoid unnecessary DB traffic while being able to make our saves on as granular level as possible. This patch makes the code check for changes before actually setting them on the underlying object. Change-Id: Ib00ab1a275baabf7d2ea7ad988183b4727905a70
Diffstat (limited to 'nova/virt/block_device.py')
-rw-r--r--nova/virt/block_device.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/nova/virt/block_device.py b/nova/virt/block_device.py
index 78b1bd09bf..6146466cdd 100644
--- a/nova/virt/block_device.py
+++ b/nova/virt/block_device.py
@@ -133,7 +133,9 @@ class DriverBlockDevice(dict):
def save(self):
for attr_name, key_name in self._update_on_save.iteritems():
- setattr(self._bdm_obj, attr_name, self[key_name or attr_name])
+ lookup_name = key_name or attr_name
+ if self[lookup_name] != getattr(self._bdm_obj, attr_name):
+ setattr(self._bdm_obj, attr_name, self[lookup_name])
self._bdm_obj.save()
@@ -285,8 +287,10 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
# NOTE(ndipanov): we might want to generalize this by adding it to the
# _update_on_save and adding a transformation function.
try:
- self._bdm_obj.connection_info = jsonutils.dumps(
- self.get('connection_info'))
+ connection_info_string = jsonutils.dumps(
+ self.get('connection_info'))
+ if connection_info_string != self._bdm_obj.connection_info:
+ self._bdm_obj.connection_info = connection_info_string
except TypeError:
pass
super(DriverVolumeBlockDevice, self).save()