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
1=== modified file 'swift/common/utils.py'
2--- swift/common/utils.py 2011-03-30 20:04:15 +0000
3+++ swift/common/utils.py 2011-04-14 20:57:28 +0000
4@@ -776,7 +776,7 @@
5 return conf
6
7
8-def write_pickle(obj, dest, tmp):
9+def write_pickle(obj, dest, tmp, pickle_protocol=0):
10 """
11 Ensure that a pickle file gets written to disk. The file
12 is first written to a tmp location, ensure it is synced to disk, then
13@@ -785,10 +785,11 @@
14 :param obj: python object to be pickled
15 :param dest: path of final destination file
16 :param tmp: path to tmp to use
17+ :param pickle_protocol: protocol to pickle the obj with, defaults to 0
18 """
19- fd, tmppath = mkstemp(dir=tmp)
20+ fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
21 with os.fdopen(fd, 'wb') as fo:
22- pickle.dump(obj, fo)
23+ pickle.dump(obj, fo, pickle_protocol)
24 fo.flush()
25 os.fsync(fd)
26 renamer(tmppath, dest)
27
28=== modified file 'swift/obj/replicator.py'
29--- swift/obj/replicator.py 2011-04-11 23:06:20 +0000
30+++ swift/obj/replicator.py 2011-04-14 20:57:28 +0000
31@@ -30,7 +30,7 @@
32
33 from swift.common.ring import Ring
34 from swift.common.utils import whataremyips, unlink_older_than, lock_path, \
35- renamer, compute_eta, get_logger
36+ compute_eta, get_logger, write_pickle
37 from swift.common.bufferedhttp import http_connect
38 from swift.common.daemon import Daemon
39
40@@ -105,9 +105,7 @@
41 except Exception:
42 return
43 hashes[suffix] = None
44- with open(hashes_file + '.tmp', 'wb') as fp:
45- pickle.dump(hashes, fp, PICKLE_PROTOCOL)
46- renamer(hashes_file + '.tmp', hashes_file)
47+ write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
48
49
50 def get_hashes(partition_dir, recalculate=[], do_listdir=False,
51@@ -157,9 +155,7 @@
52 modified = True
53 sleep()
54 if modified:
55- with open(hashes_file + '.tmp', 'wb') as fp:
56- pickle.dump(hashes, fp, PICKLE_PROTOCOL)
57- renamer(hashes_file + '.tmp', hashes_file)
58+ write_pickle(hashes, hashes_file, partition_dir, PICKLE_PROTOCOL)
59 return hashed, hashes
60
61