Merge lp:~verterok/ubuntuone-client/tritcask-win-compat into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1077
Merged at revision: 1083
Proposed branch: lp:~verterok/ubuntuone-client/tritcask-win-compat
Merge into: lp:ubuntuone-client
Diff against target: 167 lines (+26/-17)
2 files modified
tests/syncdaemon/test_tritcask.py (+17/-15)
ubuntuone/syncdaemon/tritcask.py (+9/-2)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/tritcask-win-compat
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+69725@code.launchpad.net

Commit message

Fix tritcask to use time.clock() on windows and time.time() on others.

Description of the change

Fix tritcask to use time.clock() on windows and time.time() on others.

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

The expected tests pass and the failing ones are due to a fd being open when we try to do a rename.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I have 2 tests failing in windows:

===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\u1\client\review_tritcask-win-compat\tests\syncdaemon\test_tritcask.p
y", line 1406, in test_merge_mixed_dead_entries
    db = Tritcask(self.base_dir, auto_merge=False)
  File "E:\u1\client\review_tritcask-win-compat\ubuntuone\syncdaemon\tritcask.py
", line 590, in __init__
    self._rotate_and_merge()
  File "E:\u1\client\review_tritcask-win-compat\ubuntuone\syncdaemon\tritcask.py
", line 646, in _rotate_and_merge
    self.rotate(create_file=False)
  File "E:\u1\client\review_tritcask-win-compat\ubuntuone\syncdaemon\tritcask.py
", line 694, in rotate
    data_file = self.live_file.make_immutable()
  File "E:\u1\client\review_tritcask-win-compat\ubuntuone\syncdaemon\tritcask.py
", line 187, in make_immutable
    os.rename(self.filename, new_name)
exceptions.WindowsError: [Error 32] The process cannot access the file because i
t is being used by another process

tests.syncdaemon.test_tritcask.MergeTests.test_merge_mixed_dead_entries
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\u1\client\review_tritcask-win-compat\tests\syncdaemon\test_tritcask.p
y", line 323, in test_delete
    new_file.delete()
  File "E:\u1\client\review_tritcask-win-compat\ubuntuone\syncdaemon\tritcask.py
", line 398, in delete
    os.unlink(self.filename)
exceptions.WindowsError: [Error 32] The process cannot access the file because i
t is being used by another process: 'C:\\Temp\\5\\_trial_temp\\tmp\\tests.syncda
emon.test_tritcask\\TempDataFileTest\\test_delete\\data_dir\\1258630.tmp7u7m6a.t
ritcask-v1.data'

tests.syncdaemon.test_tritcask.TempDataFileTest.test_delete
-------------------------------------------------------------------------------

Can you please replace os.rename by the ubuntuone.platform.rename?

review: Needs Fixing
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

> I have 2 tests failing in windows:

Those tests area already failing in trunk, and will be fixed in a different branch

> Can you please replace os.rename by the ubuntuone.platform.rename?

tritcask isn't using any of the platform stuff as it will be moved out of syncdaemon.

Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_tritcask.py'
2--- tests/syncdaemon/test_tritcask.py 2011-07-27 17:31:25 +0000
3+++ tests/syncdaemon/test_tritcask.py 2011-07-28 22:31:19 +0000
4@@ -22,7 +22,6 @@
5 import mmap
6 import marshal
7 import os
8-import time
9 import types
10 import uuid
11 import zlib
12@@ -59,6 +58,7 @@
13 is_live,
14 is_immutable,
15 is_hint,
16+ timestamp,
17 logger,
18 )
19
20@@ -89,9 +89,10 @@
21
22 def test__get_next_file_id(self):
23 """Test for _get_next_file_id method."""
24- curr = int(time.time() * 100000)
25+ curr = int(timestamp() * 100000)
26+
27 self.assertTrue(curr <= int(self.file_class._get_next_file_id()))
28- curr = int(time.time() * 100000)
29+ curr = int(timestamp() * 100000)
30 self.assertTrue(curr <= int(self.file_class._get_next_file_id()))
31
32 def test_exists(self):
33@@ -125,6 +126,7 @@
34 """Test for make_immutable method."""
35 new_file = self.file_class(self.base_dir)
36 new_file.fd.write('foo')
37+ new_file.fd.flush()
38 immutable_file = new_file.make_immutable()
39 # the DataFile should be closed
40 self.assertEqual(None, new_file.fd)
41@@ -630,10 +632,10 @@
42 def test_write(self):
43 """Test the write method."""
44 hint_file = HintFile(os.path.join(self.base_dir, 'hint_file'))
45- tstamp1 = time.time()
46+ tstamp1 = timestamp()
47 entry = HintEntry(tstamp1, len('foo'), 0, len('bar'), 100, 'foo')
48 hint_file.write(entry)
49- tstamp2 = time.time()
50+ tstamp2 = timestamp()
51 entry2 = HintEntry(tstamp2, len('foo1'), 1, len('bar1'), 100, 'foo1')
52 hint_file.write(entry2)
53 hint_file.close()
54@@ -665,7 +667,7 @@
55
56 def test_header_property(self):
57 """Test the header property."""
58- tstamp = time.time()
59+ tstamp = timestamp()
60 entry = HintEntry(tstamp, len('foo'), 0, len('bar'), 100, 'foo')
61 self.assertEqual((entry.tstamp, entry.key_sz, entry.row_type,
62 entry.value_sz, entry.value_pos), entry.header)
63@@ -1494,11 +1496,11 @@
64 keydir = Keydir()
65 file_id = DataFile._get_next_file_id()
66 for i in range(10):
67- keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id, time.time(),
68+ keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id, timestamp(),
69 len(str(uuid.uuid4())), i+10)
70 file_id_1 = DataFile._get_next_file_id()
71 for i in range(20):
72- keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id_1, time.time(),
73+ keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id_1, timestamp(),
74 len(str(uuid.uuid4())), i+10)
75 entry_size = len(str(uuid.uuid4()))*2 + header_size + crc32_size
76 self.assertEqual(entry_size*10, keydir._stats[file_id]['live_bytes'])
77@@ -1509,11 +1511,11 @@
78 keydir = Keydir()
79 file_id = DataFile._get_next_file_id()
80 key = str(uuid.uuid4())
81- entry = KeydirEntry(file_id, time.time(), 1, 1)
82+ entry = KeydirEntry(file_id, timestamp(), 1, 1)
83 keydir[(0, key)] = entry
84 base_size = len(key) + header_size + crc32_size
85 self.assertEqual(keydir._stats[file_id]['live_bytes'], base_size + 1)
86- new_entry = KeydirEntry(file_id, time.time(), 2, 2)
87+ new_entry = KeydirEntry(file_id, timestamp(), 2, 2)
88 keydir[(0, key)] = new_entry
89 self.assertEqual(keydir._stats[file_id]['live_bytes'], base_size + 2)
90
91@@ -1525,12 +1527,12 @@
92 keydir = Keydir()
93 file_id = DataFile._get_next_file_id()
94 key = str(uuid.uuid4())
95- entry = KeydirEntry(file_id, time.time(), 10, 1)
96+ entry = KeydirEntry(file_id, timestamp(), 10, 1)
97 keydir[(0, key)] = entry
98 base_size = len(key) + header_size + crc32_size
99 self.assertEqual(keydir._stats[file_id]['live_bytes'], base_size + 10)
100 new_file_id = DataFile._get_next_file_id()
101- new_entry = KeydirEntry(new_file_id, time.time(), 5, 10)
102+ new_entry = KeydirEntry(new_file_id, timestamp(), 5, 10)
103 keydir[(0, key)] = new_entry
104 self.assertEqual(keydir._stats[new_file_id]['live_bytes'],
105 base_size + 5)
106@@ -1542,14 +1544,14 @@
107 file_id = DataFile._get_next_file_id()
108 for i in range(10):
109 key = str(uuid.uuid4())
110- keydir[(0, key)] = KeydirEntry(file_id, time.time(),
111+ keydir[(0, key)] = KeydirEntry(file_id, timestamp(),
112 len(str(uuid.uuid4())), i+10)
113 if i % 2:
114 keydir.remove((0, key))
115 file_id_1 = DataFile._get_next_file_id()
116 for i in range(20):
117 key = str(uuid.uuid4())
118- keydir[(0, key)] = KeydirEntry(file_id_1, time.time(),
119+ keydir[(0, key)] = KeydirEntry(file_id_1, timestamp(),
120 len(str(uuid.uuid4())), i+10)
121 if i % 2:
122 keydir.remove((0, key))
123@@ -1573,7 +1575,7 @@
124 keydir = Keydir()
125 file_id = DataFile._get_next_file_id()
126 for i in range(10):
127- keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id, time.time(),
128+ keydir[(0, str(uuid.uuid4()))] = KeydirEntry(file_id, timestamp(),
129 len(str(uuid.uuid4())), i+10)
130 self.assertEqual(keydir._stats[file_id], keydir.get_stats(file_id))
131 self.assertTrue(keydir._stats[file_id] is not \
132
133=== modified file 'ubuntuone/syncdaemon/tritcask.py'
134--- ubuntuone/syncdaemon/tritcask.py 2011-06-29 14:50:05 +0000
135+++ ubuntuone/syncdaemon/tritcask.py 2011-07-28 22:31:19 +0000
136@@ -137,6 +137,13 @@
137 """Return True if it's a dead data file."""
138 return DEAD in filename
139
140+def timestamp():
141+ """Return a timestamp (float)"""
142+ if sys.platform == "win32":
143+ return time.clock()
144+ else:
145+ return time.time()
146+
147
148 class DataFile(object):
149 """Class that encapsulates data file handling."""
150@@ -163,7 +170,7 @@
151 @staticmethod
152 def _get_next_file_id():
153 """Return the next file id."""
154- return str(int(time.time() * 100000))
155+ return str(int(timestamp() * 100000))
156
157 @property
158 def has_hint(self):
159@@ -236,7 +243,7 @@
160 """Write an entry to the file."""
161 key_sz = len(key)
162 value_sz = len(value)
163- tstamp = time.time()
164+ tstamp = timestamp()
165 header = header_struct.pack(tstamp, key_sz, value_sz, row_type)
166 crc32 = crc32_struct.pack(zlib.crc32(header+key+value))
167 if EXTRA_SEEK:

Subscribers

People subscribed via source and target branches