diff options
author | Peter Portante <peter.portante@redhat.com> | 2013-08-20 19:13:42 -0400 |
---|---|---|
committer | Luis Pabon <lpabon@redhat.com> | 2013-08-28 19:25:29 -0700 |
commit | 01444e6b6de9fc32e5927064760faf906c6c66fc (patch) | |
tree | 2ad63140e5ddd4a858c920e363e5ee1965d56c2a /gluster | |
parent | 4735980723dbdc10e86dab15a34a2eab9073b693 (diff) |
Try to ensure we'll have a truly random postfix
While it is very improbable, it seemed fairly straight forward to add
a small bit of code to ensure the temporary file name is random and
won't clash with another host, pid or thread potentially working on
the same object.
BUG: XXXXXX (https://bugzilla.redhat.com/show_bug.cgi?id=XXXXXX)
Change-Id: I862021b725efbfe58b98754c4470aef4882eb8f7
Signed-off-by: Peter Portante <peter.portante@redhat.com>
Reviewed-on: http://review.gluster.org/5671
Reviewed-by: Luis Pabon <lpabon@redhat.com>
Tested-by: Luis Pabon <lpabon@redhat.com>
Diffstat (limited to 'gluster')
-rw-r--r-- | gluster/swift/obj/diskfile.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index ea39659..4d50488 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -17,10 +17,16 @@ import os import stat import fcntl import errno -import random +try: + from random import SystemRandom + random = SystemRandom() +except ImportError: + import random import logging +from socket import gethostname from hashlib import md5 from eventlet import sleep +from greenlet import getcurrent from contextlib import contextmanager from swift.common.utils import TRUE_VALUES, drop_buffer_cache, ThreadPool from swift.common.exceptions import DiskFileNotExist, DiskFileError, \ @@ -53,6 +59,9 @@ DISALLOWED_HEADERS = set('content-length content-type deleted etag'.split()) 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)) @@ -623,9 +632,11 @@ class DiskFile(SwiftDiskFile): # 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: - tmpfile = '.' + self._obj + '.' + md5(self._obj + - str(random.random())).hexdigest() + postfix = md5(self._obj + _cur_host + _cur_pid + cur_thread + + str(random.random())).hexdigest() + tmpfile = '.' + self._obj + '.' + postfix tmppath = os.path.join(self.put_datadir, tmpfile) try: fd = do_open(tmppath, |