Merge "Simplify temp file naming convention"
This commit is contained in:
commit
8e3b642a40
@ -23,10 +23,8 @@ except ImportError:
|
|||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from socket import gethostname
|
from uuid import uuid4
|
||||||
from hashlib import md5
|
|
||||||
from eventlet import sleep
|
from eventlet import sleep
|
||||||
from greenlet import getcurrent
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from swiftonfile.swift.common.exceptions import AlreadyExistsAsFile, \
|
from swiftonfile.swift.common.exceptions import AlreadyExistsAsFile, \
|
||||||
AlreadyExistsAsDir
|
AlreadyExistsAsDir
|
||||||
@ -57,9 +55,6 @@ O_CLOEXEC = 02000000
|
|||||||
MAX_RENAME_ATTEMPTS = 10
|
MAX_RENAME_ATTEMPTS = 10
|
||||||
MAX_OPEN_ATTEMPTS = 10
|
MAX_OPEN_ATTEMPTS = 10
|
||||||
|
|
||||||
_cur_pid = str(os.getpid())
|
|
||||||
_cur_host = str(gethostname())
|
|
||||||
|
|
||||||
|
|
||||||
def _random_sleep():
|
def _random_sleep():
|
||||||
sleep(random.uniform(0.5, 0.15))
|
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
|
# Assume the full directory path exists to the file already, and
|
||||||
# construct the proper name for the temporary file.
|
# construct the proper name for the temporary file.
|
||||||
attempts = 1
|
attempts = 1
|
||||||
cur_thread = str(getcurrent())
|
|
||||||
while True:
|
while True:
|
||||||
postfix = md5(self._obj + _cur_host + _cur_pid + cur_thread
|
# To know more about why following temp file naming convention is
|
||||||
+ str(random.random())).hexdigest()
|
# used, please read this GlusterFS doc:
|
||||||
tmpfile = '.' + self._obj + '.' + postfix
|
# 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)
|
tmppath = os.path.join(self._put_datadir, tmpfile)
|
||||||
try:
|
try:
|
||||||
fd = do_open(tmppath,
|
fd = do_open(tmppath,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user