From 4f6aeb63d380f726b185bc25db1e50093b3119b3 Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Fri, 19 Oct 2012 01:03:00 -0400 Subject: 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 Reviewed-on: http://review.gluster.org/4111 Reviewed-by: Kaleb KEITHLEY Reviewed-by: Jeff Darcy Tested-by: Anand Avati --- swift/1.4.8/plugins/utils.py | 53 +++++++++++++------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) (limited to 'swift/1.4.8/plugins/utils.py') diff --git a/swift/1.4.8/plugins/utils.py b/swift/1.4.8/plugins/utils.py index ef5f9d62f..289420cb9 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() -- cgit