From d7af577eb42e4c8bbdcadbb45a46d3a37c98193e Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Mon, 7 Mar 2016 14:38:05 +0530 Subject: Remove redundant syscalls in GET path This change removes redundant fstat() and fgetxattr() performed in the GET path when object added from file interface is being accessed for the first time via the object interface. This is a manual backport of this change: https://review.openstack.org/#/c/246365/ Change-Id: I29f56cef80c94779145e2948ba14f35817d46e0c Signed-off-by: Prashanth Pai Reviewed-on: http://review.gluster.org/13624 Reviewed-by: Thiago da Silva Tested-by: Thiago da Silva --- gluster/swift/common/utils.py | 35 +++++++++++++++++++---------------- gluster/swift/obj/diskfile.py | 4 ++-- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'gluster') diff --git a/gluster/swift/common/utils.py b/gluster/swift/common/utils.py index e6f4bcc..3bcd074 100644 --- a/gluster/swift/common/utils.py +++ b/gluster/swift/common/utils.py @@ -432,18 +432,19 @@ def _get_etag(path_or_fd): return etag -def get_object_metadata(obj_path_or_fd): +def get_object_metadata(obj_path_or_fd, stats=None): """ Return metadata of object. """ - if isinstance(obj_path_or_fd, int): - # We are given a file descriptor, so this is an invocation from the - # DiskFile.open() method. - stats = do_fstat(obj_path_or_fd) - else: - # We are given a path to the object when the DiskDir.list_objects_iter - # method invokes us. - stats = do_stat(obj_path_or_fd) + if not stats: + if isinstance(obj_path_or_fd, int): + # We are given a file descriptor, so this is an invocation from the + # DiskFile.open() method. + stats = do_fstat(obj_path_or_fd) + else: + # We are given a path to the object when the + # DiskDir.list_objects_iter method invokes us. + stats = do_stat(obj_path_or_fd) if not stats: metadata = {} @@ -502,8 +503,10 @@ def get_account_metadata(acc_path): return _add_timestamp(metadata) -def restore_metadata(path, metadata): - meta_orig = read_metadata(path) +def restore_metadata(path, metadata, meta_orig): + if not meta_orig: + # Container and account metadata + meta_orig = read_metadata(path) if meta_orig: meta_new = meta_orig.copy() meta_new.update(metadata) @@ -514,23 +517,23 @@ def restore_metadata(path, metadata): return meta_new -def create_object_metadata(obj_path_or_fd): +def create_object_metadata(obj_path_or_fd, stats=None, existing_meta={}): # We must accept either a path or a file descriptor as an argument to this # method, as the diskfile modules uses a file descriptior and the DiskDir # module (for container operations) uses a path. - metadata = get_object_metadata(obj_path_or_fd) - return restore_metadata(obj_path_or_fd, metadata) + metadata_from_stat = get_object_metadata(obj_path_or_fd, stats) + return restore_metadata(obj_path_or_fd, metadata_from_stat, existing_meta) def create_container_metadata(cont_path): metadata = get_container_metadata(cont_path) - rmd = restore_metadata(cont_path, metadata) + rmd = restore_metadata(cont_path, metadata, {}) return rmd def create_account_metadata(acc_path): metadata = get_account_metadata(acc_path) - rmd = restore_metadata(acc_path, metadata) + rmd = restore_metadata(acc_path, metadata, {}) return rmd diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index 21e6cee..b776d0f 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -611,8 +611,8 @@ class DiskFile(object): self._metadata = read_metadata(self._fd) if not validate_object(self._metadata, self._stat): - create_object_metadata(self._fd) - self._metadata = read_metadata(self._fd) + self._metadata = create_object_metadata(self._fd, self._stat, + self._metadata) assert self._metadata is not None self._filter_metadata() -- cgit