summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/DiskDir.py
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-05-26 15:00:13 +0530
committerThiago da Silva <thiago@redhat.com>2016-11-18 09:48:42 -0800
commit3330c26f199f4a149bf0091259d88534d61f53fa (patch)
treeca9a4cd433c0887a807b5919ea926aa367803cbf /gluster/swift/common/DiskDir.py
parentce0feed60b2077085a66d34021a3c96bbb7f5558 (diff)
Fix redundant stat in account and container server
Multiple stat() calls were made while serving GET requests for container and account. This removes those calls and can be easily verified using strace. There is room for further refactoring of code to simplify it. This will be addressed as a separate change to keep things simple in this patch. Change-Id: Ief457ff869c58519e9dbeb4ef13797185f536673 Signed-off-by: Prashanth Pai <ppai@redhat.com> Reviewed-on: http://review.gluster.org/14543 Reviewed-by: Thiago da Silva <thiago@redhat.com> Tested-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'gluster/swift/common/DiskDir.py')
-rw-r--r--gluster/swift/common/DiskDir.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/gluster/swift/common/DiskDir.py b/gluster/swift/common/DiskDir.py
index 204ae1d..4f4a2ef 100644
--- a/gluster/swift/common/DiskDir.py
+++ b/gluster/swift/common/DiskDir.py
@@ -14,6 +14,7 @@
# limitations under the License.
import os
+import stat
import errno
from gluster.swift.common.fs_utils import dir_empty, mkdirs, do_chown, \
@@ -177,7 +178,7 @@ class DiskCommon(object):
self.logger = logger
self.account = account
self.datadir = os.path.join(root, drive)
- self._dir_exists = None
+ self._dir_exists = False
# nthread=0 is intentional. This ensures that no green pool is
# used. Call to force_run_in_thread() will ensure that the method
@@ -186,7 +187,7 @@ class DiskCommon(object):
self.threadpool = ThreadPool(nthreads=0)
def _dir_exists_read_metadata(self):
- self._dir_exists = do_exists(self.datadir)
+ self._dir_exists = os.path.isdir(self.datadir)
if self._dir_exists:
try:
self.metadata = _read_metadata(self.datadir)
@@ -199,7 +200,7 @@ class DiskCommon(object):
def is_deleted(self):
# The intention of this method is to check the file system to see if
# the directory actually exists.
- return not do_exists(self.datadir)
+ return not self._dir_exists
def empty(self):
# If it does not exist, then it is empty. A value of True is
@@ -356,6 +357,8 @@ class DiskDir(DiskCommon):
# object count and bytes used. Return immediately before metadata
# validation and creation happens.
info = do_stat(self.datadir)
+ if info and stat.S_ISDIR(info.st_mode):
+ self._dir_exists = True
if not info:
# Container no longer exists.
return
@@ -526,7 +529,7 @@ class DiskDir(DiskCommon):
return objects
def get_info_is_deleted(self):
- if not do_exists(self.datadir):
+ if not self._dir_exists:
return {}, True
info = self.get_info()
return info, False
@@ -622,6 +625,7 @@ class DiskDir(DiskCommon):
# where created by the code, but not by the
# caller as objects
rmobjdir(self.datadir)
+ self._dir_exists = False
def set_x_container_sync_points(self, sync_point1, sync_point2):
self.metadata['x_container_sync_point1'] = sync_point1
@@ -679,6 +683,8 @@ class DiskAccount(DiskCommon):
# used. Return immediately before metadata validation and
# creation happens.
info = do_stat(self.datadir)
+ if info and stat.S_ISDIR(info.st_mode):
+ self._dir_exists = True
semi_fake_md = {
'X-Object-Count': (0, 0),
'X-Container-Count': (0, 0),