summaryrefslogtreecommitdiffstats
path: root/swift/1.4.8/plugins/utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2012-10-19 01:03:00 -0400
committerAnand Avati <avati@redhat.com>2012-10-25 15:04:17 -0700
commit4f6aeb63d380f726b185bc25db1e50093b3119b3 (patch)
tree2277917f4e8019391e85da0388d756c084a84eaa /swift/1.4.8/plugins/utils.py
parent3ab5404fab2a26399cb6a3a58d8930378e4ccb23 (diff)
Further reduce extended attribute reads/writes
More refactoring towards reducing the number of extended attribute reads/writes to the file system. See BZ 868120: http://bugzilla.redhat.com/show_bug.cgi?id=868120 Basically the redundant routines restore_object, restore_account and restore_container have been collapsed to one routine, restore_metadata, which will only write out metadata if the new metadata is different from what was originally read. Along with these changes come a set of unit tests for all the functions related to the routines that are in this module in the call tree where restore_metadata is invoked. Change-Id: I957ee2f8646cbe6df4d4420d3bdfb1f6ac62bdd2 BUG: 868120 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4111 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Tested-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'swift/1.4.8/plugins/utils.py')
-rw-r--r--swift/1.4.8/plugins/utils.py53
1 files changed, 15 insertions, 38 deletions
diff --git a/swift/1.4.8/plugins/utils.py b/swift/1.4.8/plugins/utils.py
index ef5f9d62f61..289420cb93f 100644
--- a/swift/1.4.8/plugins/utils.py
+++ b/swift/1.4.8/plugins/utils.py
@@ -98,7 +98,6 @@ def do_makedirs(path):
raise
return True
-
def do_listdir(path):
try:
buf = os.listdir(path)
@@ -278,7 +277,6 @@ def dir_empty(path):
if not os.path.exists(path):
return True
-
def get_device_from_account(account):
if account.startswith(RESELLER_PREFIX):
device = account.replace(RESELLER_PREFIX, '', 1)
@@ -517,7 +515,6 @@ def get_account_details_from_memcache(acc_path, memcache=None):
container_count = memcache.get(strip_obj_storage_path(acc_path)+'_container_count')
return container_list, container_count
-
def get_account_details(acc_path, memcache=None):
"""
Return container_list and container_count.
@@ -527,8 +524,6 @@ def get_account_details(acc_path, memcache=None):
else:
return get_account_details_from_fs(acc_path, memcache)
-
-
def get_etag(path):
etag = None
if os.path.exists(path):
@@ -613,45 +608,28 @@ def get_account_metadata(acc_path, memcache=None):
X_CONTAINER_COUNT: container_count}
return _add_timestamp(metadata)
-def restore_object(obj_path, metadata):
- meta = read_metadata(obj_path)
- if meta:
- meta.update(metadata)
- write_metadata(obj_path, meta)
+def restore_metadata(path, metadata):
+ meta_orig = read_metadata(path)
+ if meta_orig:
+ meta_new = meta_orig.copy()
+ meta_new.update(metadata)
else:
- write_metadata(obj_path, metadata)
-
-def restore_container(cont_path, metadata):
- meta = read_metadata(cont_path)
- if meta:
- meta.update(metadata)
- write_metadata(cont_path, meta)
- else:
- write_metadata(cont_path, metadata)
-
-def restore_account(acc_path, metadata):
- meta = read_metadata(acc_path)
- if meta:
- meta.update(metadata)
- write_metadata(acc_path, meta)
- else:
- write_metadata(acc_path, metadata)
+ meta_new = metadata
+ if meta_orig != meta_new:
+ write_metadata(path, meta_new)
+ return meta_new
def create_object_metadata(obj_path):
- meta = get_object_metadata(obj_path)
- restore_object(obj_path, meta)
- return meta
+ metadata = get_object_metadata(obj_path)
+ return restore_metadata(obj_path, metadata)
def create_container_metadata(cont_path, memcache=None):
- meta = get_container_metadata(cont_path, memcache)
- restore_container(cont_path, meta)
- return meta
+ metadata = get_container_metadata(cont_path, memcache)
+ return restore_metadata(cont_path, metadata)
def create_account_metadata(acc_path, memcache=None):
- meta = get_account_metadata(acc_path, memcache)
- restore_account(acc_path, meta)
- return meta
-
+ metadata = get_account_metadata(acc_path, memcache)
+ return restore_metadata(acc_path, metadata)
def check_account_exists(account, fs_object):
if account not in get_account_list(fs_object):
@@ -666,7 +644,6 @@ def get_account_list(fs_object):
account_list = fs_object.get_export_list()
return account_list
-
def get_account_id(account):
return RESELLER_PREFIX + md5(account + HASH_PATH_SUFFIX).hexdigest()