summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-03-07 14:38:05 +0530
committerThiago da Silva <thiago@redhat.com>2016-03-07 11:58:41 -0800
commitd7af577eb42e4c8bbdcadbb45a46d3a37c98193e (patch)
treecbf5c201ad201d731606550f19bad2edc9d441d0
parentea4750a366123f78411d90082733642376dc6afc (diff)
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 <ppai@redhat.com> Reviewed-on: http://review.gluster.org/13624 Reviewed-by: Thiago da Silva <thiago@redhat.com> Tested-by: Thiago da Silva <thiago@redhat.com>
-rw-r--r--gluster/swift/common/utils.py35
-rw-r--r--gluster/swift/obj/diskfile.py4
-rw-r--r--test/unit/common/test_utils.py11
3 files changed, 24 insertions, 26 deletions
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()
diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py
index 0b173be..5ab6f36 100644
--- a/test/unit/common/test_utils.py
+++ b/test/unit/common/test_utils.py
@@ -320,10 +320,9 @@ class TestUtils(unittest.TestCase):
def test_restore_metadata_none(self):
# No initial metadata
path = "/tmp/foo/i"
- res_d = utils.restore_metadata(path, {'b': 'y'})
+ res_d = utils.restore_metadata(path, {'b': 'y'}, {})
expected_d = {'b': 'y'}
assert res_d == expected_d, "Expected %r, result %r" % (expected_d, res_d)
- assert _xattr_op_cnt['get'] == 1, "%r" % _xattr_op_cnt
assert _xattr_op_cnt['set'] == 1, "%r" % _xattr_op_cnt
def test_restore_metadata(self):
@@ -332,10 +331,9 @@ class TestUtils(unittest.TestCase):
initial_d = {'a': 'z'}
xkey = _xkey(path, utils.METADATA_KEY)
_xattrs[xkey] = serialize_metadata(initial_d)
- res_d = utils.restore_metadata(path, {'b': 'y'})
+ res_d = utils.restore_metadata(path, {'b': 'y'}, initial_d)
expected_d = {'a': 'z', 'b': 'y'}
assert res_d == expected_d, "Expected %r, result %r" % (expected_d, res_d)
- assert _xattr_op_cnt['get'] == 1, "%r" % _xattr_op_cnt
assert _xattr_op_cnt['set'] == 1, "%r" % _xattr_op_cnt
def test_restore_metadata_nochange(self):
@@ -344,10 +342,9 @@ class TestUtils(unittest.TestCase):
initial_d = {'a': 'z'}
xkey = _xkey(path, utils.METADATA_KEY)
_xattrs[xkey] = serialize_metadata(initial_d)
- res_d = utils.restore_metadata(path, {})
+ res_d = utils.restore_metadata(path, {}, initial_d)
expected_d = {'a': 'z'}
assert res_d == expected_d, "Expected %r, result %r" % (expected_d, res_d)
- assert _xattr_op_cnt['get'] == 1, "%r" % _xattr_op_cnt
assert _xattr_op_cnt['set'] == 0, "%r" % _xattr_op_cnt
def test_deserialize_metadata_pickle(self):
@@ -497,7 +494,6 @@ class TestUtils(unittest.TestCase):
xkey = _xkey(tf.name, utils.METADATA_KEY)
assert len(_xattrs.keys()) == 1
assert xkey in _xattrs
- assert _xattr_op_cnt['get'] == 1
assert _xattr_op_cnt['set'] == 1
md = deserialize_metadata(_xattrs[xkey])
assert r_md == md
@@ -519,7 +515,6 @@ class TestUtils(unittest.TestCase):
xkey = _xkey(td, utils.METADATA_KEY)
assert len(_xattrs.keys()) == 1
assert xkey in _xattrs
- assert _xattr_op_cnt['get'] == 1
assert _xattr_op_cnt['set'] == 1
md = deserialize_metadata(_xattrs[xkey])
assert r_md == md