From 1a6e22ea88bdeecb3dc653995dbb18ec12d01e7b Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Wed, 15 Apr 2015 16:08:56 +0530 Subject: [PATCH] Simplify temp file naming convention The intent was (and still is) to devise an unique name for the tempfile. I can't think of any reason why uuid wouldn't work. Also, added a comment which has a link to the document explaining why the specific naming convention is used for temp file name. Change-Id: I5f0d2b631e276c47c88c554485caaec767703695 Signed-off-by: Prashanth Pai --- swiftonfile/swift/obj/diskfile.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/swiftonfile/swift/obj/diskfile.py b/swiftonfile/swift/obj/diskfile.py index e91b01d..bbbf913 100644 --- a/swiftonfile/swift/obj/diskfile.py +++ b/swiftonfile/swift/obj/diskfile.py @@ -23,10 +23,8 @@ except ImportError: import random import logging import time -from socket import gethostname -from hashlib import md5 +from uuid import uuid4 from eventlet import sleep -from greenlet import getcurrent from contextlib import contextmanager from swiftonfile.swift.common.exceptions import AlreadyExistsAsFile, \ AlreadyExistsAsDir @@ -57,9 +55,6 @@ O_CLOEXEC = 02000000 MAX_RENAME_ATTEMPTS = 10 MAX_OPEN_ATTEMPTS = 10 -_cur_pid = str(os.getpid()) -_cur_host = str(gethostname()) - def _random_sleep(): sleep(random.uniform(0.5, 0.15)) @@ -846,11 +841,11 @@ class DiskFile(object): # Assume the full directory path exists to the file already, and # construct the proper name for the temporary file. attempts = 1 - cur_thread = str(getcurrent()) while True: - postfix = md5(self._obj + _cur_host + _cur_pid + cur_thread - + str(random.random())).hexdigest() - tmpfile = '.' + self._obj + '.' + postfix + # To know more about why following temp file naming convention is + # used, please read this GlusterFS doc: + # https://github.com/gluster/glusterfs/blob/master/doc/features/dht.md#rename-optimizations # noqa + tmpfile = '.' + self._obj + '.' + uuid4().hex tmppath = os.path.join(self._put_datadir, tmpfile) try: fd = do_open(tmppath,