made objrep use utils.write_pickle
This commit is contained in:
parent
8f6a374ad7
commit
80c1cd4998
@ -776,7 +776,7 @@ def readconf(conf, section_name=None, log_name=None, defaults=None):
|
||||
return conf
|
||||
|
||||
|
||||
def write_pickle(obj, dest, tmp):
|
||||
def write_pickle(obj, dest, tmp, pickle_protocol=0):
|
||||
"""
|
||||
Ensure that a pickle file gets written to disk. The file
|
||||
is first written to a tmp location, ensure it is synced to disk, then
|
||||
@ -785,10 +785,11 @@ def write_pickle(obj, dest, tmp):
|
||||
:param obj: python object to be pickled
|
||||
:param dest: path of final destination file
|
||||
:param tmp: path to tmp to use
|
||||
:param pickle_protocol: protocol to pickle the obj with, defaults to 0
|
||||
"""
|
||||
fd, tmppath = mkstemp(dir=tmp)
|
||||
fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
|
||||
with os.fdopen(fd, 'wb') as fo:
|
||||
pickle.dump(obj, fo)
|
||||
pickle.dump(obj, fo, pickle_protocol)
|
||||
fo.flush()
|
||||
os.fsync(fd)
|
||||
renamer(tmppath, dest)
|
||||
|
@ -30,7 +30,7 @@ from eventlet.support.greenlets import GreenletExit
|
||||
|
||||
from swift.common.ring import Ring
|
||||
from swift.common.utils import whataremyips, unlink_older_than, lock_path, \
|
||||
renamer, compute_eta, get_logger
|
||||
compute_eta, get_logger, write_pickle
|
||||
from swift.common.bufferedhttp import http_connect
|
||||
from swift.common.daemon import Daemon
|
||||
|
||||
@ -105,9 +105,7 @@ def invalidate_hash(suffix_dir):
|
||||
except Exception:
|
||||
return
|
||||
hashes[suffix] = None
|
||||
with open(hashes_file + '.tmp', 'wb') as fp:
|
||||
pickle.dump(hashes, fp, PICKLE_PROTOCOL)
|
||||
renamer(hashes_file + '.tmp', hashes_file)
|
||||
write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
|
||||
|
||||
|
||||
def get_hashes(partition_dir, recalculate=[], do_listdir=False,
|
||||
@ -157,9 +155,7 @@ def get_hashes(partition_dir, recalculate=[], do_listdir=False,
|
||||
modified = True
|
||||
sleep()
|
||||
if modified:
|
||||
with open(hashes_file + '.tmp', 'wb') as fp:
|
||||
pickle.dump(hashes, fp, PICKLE_PROTOCOL)
|
||||
renamer(hashes_file + '.tmp', hashes_file)
|
||||
write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
|
||||
return hashed, hashes
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user