Merge lp:~greglange/swift/lp759572 into lp:~hudson-openstack/swift/trunk

Proposed by Greg Lange
Status: Merged
Approved by: David Goetz
Approved revision: 267
Merged at revision: 269
Proposed branch: lp:~greglange/swift/lp759572
Merge into: lp:~hudson-openstack/swift/trunk
Diff against target: 59 lines (+7/-10)
2 files modified
swift/common/utils.py (+4/-3)
swift/obj/replicator.py (+3/-7)
To merge this branch: bzr merge lp:~greglange/swift/lp759572
Reviewer Review Type Date Requested Status
Swift Core security contacts Pending
Review via email: mp+57773@code.launchpad.net

Commit message

Update get_hashes in objrep to use utils.write_pickle

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'swift/common/utils.py'
--- swift/common/utils.py 2011-03-30 20:04:15 +0000
+++ swift/common/utils.py 2011-04-14 20:57:28 +0000
@@ -776,7 +776,7 @@
776 return conf776 return conf
777777
778778
779def write_pickle(obj, dest, tmp):779def write_pickle(obj, dest, tmp, pickle_protocol=0):
780 """780 """
781 Ensure that a pickle file gets written to disk. The file781 Ensure that a pickle file gets written to disk. The file
782 is first written to a tmp location, ensure it is synced to disk, then782 is first written to a tmp location, ensure it is synced to disk, then
@@ -785,10 +785,11 @@
785 :param obj: python object to be pickled785 :param obj: python object to be pickled
786 :param dest: path of final destination file786 :param dest: path of final destination file
787 :param tmp: path to tmp to use787 :param tmp: path to tmp to use
788 :param pickle_protocol: protocol to pickle the obj with, defaults to 0
788 """789 """
789 fd, tmppath = mkstemp(dir=tmp)790 fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
790 with os.fdopen(fd, 'wb') as fo:791 with os.fdopen(fd, 'wb') as fo:
791 pickle.dump(obj, fo)792 pickle.dump(obj, fo, pickle_protocol)
792 fo.flush()793 fo.flush()
793 os.fsync(fd)794 os.fsync(fd)
794 renamer(tmppath, dest)795 renamer(tmppath, dest)
795796
=== modified file 'swift/obj/replicator.py'
--- swift/obj/replicator.py 2011-04-11 23:06:20 +0000
+++ swift/obj/replicator.py 2011-04-14 20:57:28 +0000
@@ -30,7 +30,7 @@
3030
31from swift.common.ring import Ring31from swift.common.ring import Ring
32from swift.common.utils import whataremyips, unlink_older_than, lock_path, \32from swift.common.utils import whataremyips, unlink_older_than, lock_path, \
33 renamer, compute_eta, get_logger33 compute_eta, get_logger, write_pickle
34from swift.common.bufferedhttp import http_connect34from swift.common.bufferedhttp import http_connect
35from swift.common.daemon import Daemon35from swift.common.daemon import Daemon
3636
@@ -105,9 +105,7 @@
105 except Exception:105 except Exception:
106 return106 return
107 hashes[suffix] = None107 hashes[suffix] = None
108 with open(hashes_file + '.tmp', 'wb') as fp:108 write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
109 pickle.dump(hashes, fp, PICKLE_PROTOCOL)
110 renamer(hashes_file + '.tmp', hashes_file)
111109
112110
113def get_hashes(partition_dir, recalculate=[], do_listdir=False,111def get_hashes(partition_dir, recalculate=[], do_listdir=False,
@@ -157,9 +155,7 @@
157 modified = True155 modified = True
158 sleep()156 sleep()
159 if modified:157 if modified:
160 with open(hashes_file + '.tmp', 'wb') as fp:158 write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
161 pickle.dump(hashes, fp, PICKLE_PROTOCOL)
162 renamer(hashes_file + '.tmp', hashes_file)
163 return hashed, hashes159 return hashed, hashes
164160
165161