summaryrefslogtreecommitdiffstats
path: root/ufo/gluster/swift/common/DiskFile.py
diff options
context:
space:
mode:
authorMohammed Junaid <junaid@redhat.com>2012-12-18 10:55:24 +0530
committerVijay Bellur <vbellur@redhat.com>2013-01-22 19:14:30 -0800
commit16d2801f072f5eb1d2ddb56a2ab5eecd3a42010a (patch)
tree23629bbc03ed925200745cc84e75cb8dfbb48f47 /ufo/gluster/swift/common/DiskFile.py
parent2f60c8a4776a6052cfba43605263dd32c616cfa2 (diff)
object-storage: use temp file optimization
A file name '.<FILENAME>.<RANDOM>' will hash to the same GlusterFS node as a file named '<FILENAME>', thus avoiding creation/deletion of linkfiles on a rename. This is part of the work needed to address BZ 876660 (https://bugzilla.redhat.com/show_bug.cgi?id=876660). Change-Id: I6f18c14b8eaa7a35c96f7e455ef3a19bee7dbde5 BUG: 876660 Signed-off-by: Mohammed Junaid <junaid@redhat.com> Reviewed-on: http://review.gluster.org/4325 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Peter Portante <pportant@redhat.com>
Diffstat (limited to 'ufo/gluster/swift/common/DiskFile.py')
-rw-r--r--ufo/gluster/swift/common/DiskFile.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/ufo/gluster/swift/common/DiskFile.py b/ufo/gluster/swift/common/DiskFile.py
index 62f98103762..a25ba806575 100644
--- a/ufo/gluster/swift/common/DiskFile.py
+++ b/ufo/gluster/swift/common/DiskFile.py
@@ -15,8 +15,9 @@
import os
import errno
+import random
+from hashlib import md5
from eventlet import tpool
-from tempfile import mkstemp
from contextlib import contextmanager
from swift.common.utils import normalize_timestamp, renamer
from swift.common.exceptions import DiskFileNotExist
@@ -102,7 +103,6 @@ class Gluster_DiskFile(DiskFile):
self.device_path = os.path.join(path, device)
self._container_path = os.path.join(path, device, container)
self._is_dir = False
- self.tmpdir = os.path.join(path, device, 'tmp')
self.tmppath = None
self.logger = logger
self.metadata = {}
@@ -309,9 +309,24 @@ class Gluster_DiskFile(DiskFile):
def mkstemp(self):
"""Contextmanager to make a temporary file."""
- if not os.path.exists(self.tmpdir):
- mkdirs(self.tmpdir)
- fd, self.tmppath = mkstemp(dir=self.tmpdir)
+ # Creating intermidiate directories and corresponding metadata.
+ # For optimization, check if the subdirectory already exists,
+ # if exists, then it means that it also has its metadata.
+ # Not checking for container, since the container should already
+ # exist for the call to come here.
+ if not os.path.exists(self.datadir):
+ path = self._container_path
+ subdir_list = self._obj_path.split(os.path.sep)
+ for i in range(len(subdir_list)):
+ path = os.path.join(path, subdir_list[i]);
+ if not os.path.exists(path):
+ self._create_dir_object(path)
+
+ tmpfile = '.' + self._obj + '.' + md5(self._obj + \
+ str(random.random())).hexdigest()
+
+ self.tmppath = os.path.join(self.datadir, tmpfile)
+ fd = os.open(self.tmppath, os.O_RDWR | os.O_CREAT | os.O_EXCL)
try:
yield fd
finally: