1 | 5 patches for repository /home/davidsarah/tahoe/newtrunk: |
---|
2 | |
---|
3 | Mon Dec 5 02:40:24 GMT 2011 david-sarah@jacaranda.org |
---|
4 | * interfaces.py: 'which -> that' grammar cleanup. |
---|
5 | |
---|
6 | Mon Dec 5 04:35:06 GMT 2011 david-sarah@jacaranda.org |
---|
7 | * Pluggable backends: documentation. refs #999 |
---|
8 | |
---|
9 | Mon Dec 5 04:36:53 GMT 2011 david-sarah@jacaranda.org |
---|
10 | * Pluggable backends: new and moved code files. refs #999 |
---|
11 | |
---|
12 | Fri Dec 16 18:12:07 GMT 2011 david-sarah@jacaranda.org |
---|
13 | * Cosmetic changes in pluggable backends branch. refs #999, #1569 |
---|
14 | |
---|
15 | Fri Dec 16 18:36:51 GMT 2011 david-sarah@jacaranda.org |
---|
16 | * All other changes in pluggable backends branch. refs #999, #1569 |
---|
17 | |
---|
18 | New patches: |
---|
19 | |
---|
20 | [interfaces.py: 'which -> that' grammar cleanup. |
---|
21 | david-sarah@jacaranda.org**20111205024024 |
---|
22 | Ignore-this: 2de8d902dd7b473fb5c15701fcd8e0f7 |
---|
23 | ] { |
---|
24 | merger 0.0 ( |
---|
25 | hunk ./src/allmydata/interfaces.py 33 |
---|
26 | -class RIStubClient(RemoteInterface): |
---|
27 | - """Each client publishes a service announcement for a dummy object called |
---|
28 | - the StubClient. This object doesn't actually offer any services, but the |
---|
29 | - announcement helps the Introducer keep track of which clients are |
---|
30 | - subscribed (so the grid admin can keep track of things like the size of |
---|
31 | - the grid and the client versions in use. This is the (empty) |
---|
32 | - RemoteInterface for the StubClient.""" |
---|
33 | - |
---|
34 | hunk ./src/allmydata/interfaces.py 38 |
---|
35 | - the grid and the client versions in use. This is the (empty) |
---|
36 | + the grid and the client versions in use). This is the (empty) |
---|
37 | ) |
---|
38 | hunk ./src/allmydata/interfaces.py 276 |
---|
39 | (binary) storage index string, and 'shnum' is the integer share |
---|
40 | number. 'reason' is a human-readable explanation of the problem, |
---|
41 | probably including some expected hash values and the computed ones |
---|
42 | - which did not match. Corruption advisories for mutable shares should |
---|
43 | + that did not match. Corruption advisories for mutable shares should |
---|
44 | include a hash of the public key (the same value that appears in the |
---|
45 | mutable-file verify-cap), since the current share format does not |
---|
46 | store that on disk. |
---|
47 | hunk ./src/allmydata/interfaces.py 413 |
---|
48 | remote_host: the IAddress, if connected, otherwise None |
---|
49 | |
---|
50 | This method is intended for monitoring interfaces, such as a web page |
---|
51 | - which describes connecting and connected peers. |
---|
52 | + that describes connecting and connected peers. |
---|
53 | """ |
---|
54 | |
---|
55 | def get_all_peerids(): |
---|
56 | hunk ./src/allmydata/interfaces.py 515 |
---|
57 | |
---|
58 | # TODO: rename to get_read_cap() |
---|
59 | def get_readonly(): |
---|
60 | - """Return another IURI instance, which represents a read-only form of |
---|
61 | + """Return another IURI instance that represents a read-only form of |
---|
62 | this one. If is_readonly() is True, this returns self.""" |
---|
63 | |
---|
64 | def get_verify_cap(): |
---|
65 | hunk ./src/allmydata/interfaces.py 542 |
---|
66 | passing into init_from_string.""" |
---|
67 | |
---|
68 | class IDirnodeURI(Interface): |
---|
69 | - """I am a URI which represents a dirnode.""" |
---|
70 | + """I am a URI that represents a dirnode.""" |
---|
71 | |
---|
72 | class IFileURI(Interface): |
---|
73 | hunk ./src/allmydata/interfaces.py 545 |
---|
74 | - """I am a URI which represents a filenode.""" |
---|
75 | + """I am a URI that represents a filenode.""" |
---|
76 | def get_size(): |
---|
77 | """Return the length (in bytes) of the file that I represent.""" |
---|
78 | |
---|
79 | hunk ./src/allmydata/interfaces.py 851 |
---|
80 | """ |
---|
81 | |
---|
82 | class IFileNode(IFilesystemNode): |
---|
83 | - """I am a node which represents a file: a sequence of bytes. I am not a |
---|
84 | + """I am a node that represents a file: a sequence of bytes. I am not a |
---|
85 | container, like IDirectoryNode.""" |
---|
86 | def get_best_readable_version(): |
---|
87 | """Return a Deferred that fires with an IReadable for the 'best' |
---|
88 | hunk ./src/allmydata/interfaces.py 900 |
---|
89 | multiple versions of a file present in the grid, some of which might be |
---|
90 | unrecoverable (i.e. have fewer than 'k' shares). These versions are |
---|
91 | loosely ordered: each has a sequence number and a hash, and any version |
---|
92 | - with seqnum=N was uploaded by a node which has seen at least one version |
---|
93 | + with seqnum=N was uploaded by a node that has seen at least one version |
---|
94 | with seqnum=N-1. |
---|
95 | |
---|
96 | The 'servermap' (an instance of IMutableFileServerMap) is used to |
---|
97 | hunk ./src/allmydata/interfaces.py 1009 |
---|
98 | as a guide to where the shares are located. |
---|
99 | |
---|
100 | I return a Deferred that fires with the requested contents, or |
---|
101 | - errbacks with UnrecoverableFileError. Note that a servermap which was |
---|
102 | + errbacks with UnrecoverableFileError. Note that a servermap that was |
---|
103 | updated with MODE_ANYTHING or MODE_READ may not know about shares for |
---|
104 | all versions (those modes stop querying servers as soon as they can |
---|
105 | fulfil their goals), so you may want to use MODE_CHECK (which checks |
---|
106 | hunk ./src/allmydata/interfaces.py 1068 |
---|
107 | """Upload was unable to satisfy 'servers_of_happiness'""" |
---|
108 | |
---|
109 | class UnableToFetchCriticalDownloadDataError(Exception): |
---|
110 | - """I was unable to fetch some piece of critical data which is supposed to |
---|
111 | + """I was unable to fetch some piece of critical data that is supposed to |
---|
112 | be identically present in all shares.""" |
---|
113 | |
---|
114 | class NoServersError(Exception): |
---|
115 | hunk ./src/allmydata/interfaces.py 1080 |
---|
116 | exists, and overwrite= was set to False.""" |
---|
117 | |
---|
118 | class NoSuchChildError(Exception): |
---|
119 | - """A directory node was asked to fetch a child which does not exist.""" |
---|
120 | + """A directory node was asked to fetch a child that does not exist.""" |
---|
121 | |
---|
122 | class ChildOfWrongTypeError(Exception): |
---|
123 | """An operation was attempted on a child of the wrong type (file or directory).""" |
---|
124 | hunk ./src/allmydata/interfaces.py 1398 |
---|
125 | if you initially thought you were going to use 10 peers, started |
---|
126 | encoding, and then two of the peers dropped out: you could use |
---|
127 | desired_share_ids= to skip the work (both memory and CPU) of |
---|
128 | - producing shares for the peers which are no longer available. |
---|
129 | + producing shares for the peers that are no longer available. |
---|
130 | |
---|
131 | """ |
---|
132 | |
---|
133 | hunk ./src/allmydata/interfaces.py 1473 |
---|
134 | if you initially thought you were going to use 10 peers, started |
---|
135 | encoding, and then two of the peers dropped out: you could use |
---|
136 | desired_share_ids= to skip the work (both memory and CPU) of |
---|
137 | - producing shares for the peers which are no longer available. |
---|
138 | + producing shares for the peers that are no longer available. |
---|
139 | |
---|
140 | For each call, encode() will return a Deferred that fires with two |
---|
141 | lists, one containing shares and the other containing the shareids. |
---|
142 | hunk ./src/allmydata/interfaces.py 1530 |
---|
143 | required to be of the same length. The i'th element of their_shareids |
---|
144 | is required to be the shareid of the i'th buffer in some_shares. |
---|
145 | |
---|
146 | - This returns a Deferred which fires with a sequence of buffers. This |
---|
147 | + This returns a Deferred that fires with a sequence of buffers. This |
---|
148 | sequence will contain all of the segments of the original data, in |
---|
149 | order. The sum of the lengths of all of the buffers will be the |
---|
150 | 'data_size' value passed into the original ICodecEncode.set_params() |
---|
151 | hunk ./src/allmydata/interfaces.py 1577 |
---|
152 | Encoding parameters can be set in three ways. 1: The Encoder class |
---|
153 | provides defaults (3/7/10). 2: the Encoder can be constructed with |
---|
154 | an 'options' dictionary, in which the |
---|
155 | - needed_and_happy_and_total_shares' key can be a (k,d,n) tuple. 3: |
---|
156 | + 'needed_and_happy_and_total_shares' key can be a (k,d,n) tuple. 3: |
---|
157 | set_params((k,d,n)) can be called. |
---|
158 | |
---|
159 | If you intend to use set_params(), you must call it before |
---|
160 | hunk ./src/allmydata/interfaces.py 1775 |
---|
161 | produced, so that the segment hashes can be generated with only a |
---|
162 | single pass. |
---|
163 | |
---|
164 | - This returns a Deferred which fires with a sequence of hashes, using: |
---|
165 | + This returns a Deferred that fires with a sequence of hashes, using: |
---|
166 | |
---|
167 | tuple(segment_hashes[first:last]) |
---|
168 | |
---|
169 | hunk ./src/allmydata/interfaces.py 1791 |
---|
170 | def get_plaintext_hash(): |
---|
171 | """OBSOLETE; Get the hash of the whole plaintext. |
---|
172 | |
---|
173 | - This returns a Deferred which fires with a tagged SHA-256 hash of the |
---|
174 | + This returns a Deferred that fires with a tagged SHA-256 hash of the |
---|
175 | whole plaintext, obtained from hashutil.plaintext_hash(data). |
---|
176 | """ |
---|
177 | |
---|
178 | hunk ./src/allmydata/interfaces.py 1851 |
---|
179 | be used to encrypt the data. The key will also be hashed to derive |
---|
180 | the StorageIndex. |
---|
181 | |
---|
182 | - Uploadables which want to achieve convergence should hash their file |
---|
183 | + Uploadables that want to achieve convergence should hash their file |
---|
184 | contents and the serialized_encoding_parameters to form the key |
---|
185 | (which of course requires a full pass over the data). Uploadables can |
---|
186 | use the upload.ConvergentUploadMixin class to achieve this |
---|
187 | hunk ./src/allmydata/interfaces.py 1857 |
---|
188 | automatically. |
---|
189 | |
---|
190 | - Uploadables which do not care about convergence (or do not wish to |
---|
191 | + Uploadables that do not care about convergence (or do not wish to |
---|
192 | make multiple passes over the data) can simply return a |
---|
193 | strongly-random 16 byte string. |
---|
194 | |
---|
195 | hunk ./src/allmydata/interfaces.py 1867 |
---|
196 | |
---|
197 | def read(length): |
---|
198 | """Return a Deferred that fires with a list of strings (perhaps with |
---|
199 | - only a single element) which, when concatenated together, contain the |
---|
200 | + only a single element) that, when concatenated together, contain the |
---|
201 | next 'length' bytes of data. If EOF is near, this may provide fewer |
---|
202 | than 'length' bytes. The total number of bytes provided by read() |
---|
203 | before it signals EOF must equal the size provided by get_size(). |
---|
204 | hunk ./src/allmydata/interfaces.py 1914 |
---|
205 | |
---|
206 | def read(length): |
---|
207 | """ |
---|
208 | - Returns a list of strings which, when concatenated, are the next |
---|
209 | + Returns a list of strings that, when concatenated, are the next |
---|
210 | length bytes of the file, or fewer if there are fewer bytes |
---|
211 | between the current location and the end of the file. |
---|
212 | """ |
---|
213 | hunk ./src/allmydata/interfaces.py 1927 |
---|
214 | |
---|
215 | class IUploadResults(Interface): |
---|
216 | """I am returned by upload() methods. I contain a number of public |
---|
217 | - attributes which can be read to determine the results of the upload. Some |
---|
218 | + attributes that can be read to determine the results of the upload. Some |
---|
219 | of these are functional, some are timing information. All of these may be |
---|
220 | None. |
---|
221 | |
---|
222 | hunk ./src/allmydata/interfaces.py 1960 |
---|
223 | |
---|
224 | class IDownloadResults(Interface): |
---|
225 | """I am created internally by download() methods. I contain a number of |
---|
226 | - public attributes which contain details about the download process.:: |
---|
227 | + public attributes that contain details about the download process.:: |
---|
228 | |
---|
229 | .file_size : the size of the file, in bytes |
---|
230 | .servers_used : set of server peerids that were used during download |
---|
231 | hunk ./src/allmydata/interfaces.py 1986 |
---|
232 | class IUploader(Interface): |
---|
233 | def upload(uploadable): |
---|
234 | """Upload the file. 'uploadable' must impement IUploadable. This |
---|
235 | - returns a Deferred which fires with an IUploadResults instance, from |
---|
236 | + returns a Deferred that fires with an IUploadResults instance, from |
---|
237 | which the URI of the file can be obtained as results.uri .""" |
---|
238 | |
---|
239 | def upload_ssk(write_capability, new_version, uploadable): |
---|
240 | hunk ./src/allmydata/interfaces.py 2036 |
---|
241 | kind of lease that is obtained (which account number to claim, etc). |
---|
242 | |
---|
243 | TODO: any problems seen during checking will be reported to the |
---|
244 | - health-manager.furl, a centralized object which is responsible for |
---|
245 | + health-manager.furl, a centralized object that is responsible for |
---|
246 | figuring out why files are unhealthy so corrective action can be |
---|
247 | taken. |
---|
248 | """ |
---|
249 | hunk ./src/allmydata/interfaces.py 2051 |
---|
250 | will be put in the check-and-repair results. The Deferred will not |
---|
251 | fire until the repair is complete. |
---|
252 | |
---|
253 | - This returns a Deferred which fires with an instance of |
---|
254 | + This returns a Deferred that fires with an instance of |
---|
255 | ICheckAndRepairResults.""" |
---|
256 | |
---|
257 | class IDeepCheckable(Interface): |
---|
258 | hunk ./src/allmydata/interfaces.py 2136 |
---|
259 | that was found to be corrupt. Each share |
---|
260 | locator is a list of (serverid, storage_index, |
---|
261 | sharenum). |
---|
262 | - count-incompatible-shares: the number of shares which are of a share |
---|
263 | + count-incompatible-shares: the number of shares that are of a share |
---|
264 | format unknown to this checker |
---|
265 | list-incompatible-shares: a list of 'share locators', one for each |
---|
266 | share that was found to be of an unknown |
---|
267 | hunk ./src/allmydata/interfaces.py 2143 |
---|
268 | format. Each share locator is a list of |
---|
269 | (serverid, storage_index, sharenum). |
---|
270 | servers-responding: list of (binary) storage server identifiers, |
---|
271 | - one for each server which responded to the share |
---|
272 | + one for each server that responded to the share |
---|
273 | query (even if they said they didn't have |
---|
274 | shares, and even if they said they did have |
---|
275 | shares but then didn't send them when asked, or |
---|
276 | hunk ./src/allmydata/interfaces.py 2340 |
---|
277 | will use the data in the checker results to guide the repair process, |
---|
278 | such as which servers provided bad data and should therefore be |
---|
279 | avoided. The ICheckResults object is inside the |
---|
280 | - ICheckAndRepairResults object, which is returned by the |
---|
281 | + ICheckAndRepairResults object that is returned by the |
---|
282 | ICheckable.check() method:: |
---|
283 | |
---|
284 | d = filenode.check(repair=False) |
---|
285 | hunk ./src/allmydata/interfaces.py 2431 |
---|
286 | methods to create new objects. I return synchronously.""" |
---|
287 | |
---|
288 | def create_mutable_file(contents=None, keysize=None): |
---|
289 | - """I create a new mutable file, and return a Deferred which will fire |
---|
290 | + """I create a new mutable file, and return a Deferred that will fire |
---|
291 | with the IMutableFileNode instance when it is ready. If contents= is |
---|
292 | provided (a bytestring), it will be used as the initial contents of |
---|
293 | the new file, otherwise the file will contain zero bytes. keysize= is |
---|
294 | hunk ./src/allmydata/interfaces.py 2439 |
---|
295 | usual.""" |
---|
296 | |
---|
297 | def create_new_mutable_directory(initial_children={}): |
---|
298 | - """I create a new mutable directory, and return a Deferred which will |
---|
299 | + """I create a new mutable directory, and return a Deferred that will |
---|
300 | fire with the IDirectoryNode instance when it is ready. If |
---|
301 | initial_children= is provided (a dict mapping unicode child name to |
---|
302 | (childnode, metadata_dict) tuples), the directory will be populated |
---|
303 | hunk ./src/allmydata/interfaces.py 2447 |
---|
304 | |
---|
305 | class IClientStatus(Interface): |
---|
306 | def list_all_uploads(): |
---|
307 | - """Return a list of uploader objects, one for each upload which |
---|
308 | + """Return a list of uploader objects, one for each upload that |
---|
309 | currently has an object available (tracked with weakrefs). This is |
---|
310 | intended for debugging purposes.""" |
---|
311 | def list_active_uploads(): |
---|
312 | hunk ./src/allmydata/interfaces.py 2457 |
---|
313 | started uploads.""" |
---|
314 | |
---|
315 | def list_all_downloads(): |
---|
316 | - """Return a list of downloader objects, one for each download which |
---|
317 | + """Return a list of downloader objects, one for each download that |
---|
318 | currently has an object available (tracked with weakrefs). This is |
---|
319 | intended for debugging purposes.""" |
---|
320 | def list_active_downloads(): |
---|
321 | hunk ./src/allmydata/interfaces.py 2684 |
---|
322 | |
---|
323 | def provide(provider=RIStatsProvider, nickname=str): |
---|
324 | """ |
---|
325 | - @param provider: a stats collector instance which should be polled |
---|
326 | + @param provider: a stats collector instance that should be polled |
---|
327 | periodically by the gatherer to collect stats. |
---|
328 | @param nickname: a name useful to identify the provided client |
---|
329 | """ |
---|
330 | hunk ./src/allmydata/interfaces.py 2717 |
---|
331 | |
---|
332 | class IValidatedThingProxy(Interface): |
---|
333 | def start(): |
---|
334 | - """ Acquire a thing and validate it. Return a deferred which is |
---|
335 | + """ Acquire a thing and validate it. Return a deferred that is |
---|
336 | eventually fired with self if the thing is valid or errbacked if it |
---|
337 | can't be acquired or validated.""" |
---|
338 | |
---|
339 | } |
---|
340 | [Pluggable backends: documentation. refs #999 |
---|
341 | david-sarah@jacaranda.org**20111205043506 |
---|
342 | Ignore-this: 5290f8788c2b710243572ec04ee032ee |
---|
343 | ] { |
---|
344 | adddir ./docs/backends |
---|
345 | addfile ./docs/backends/S3.rst |
---|
346 | hunk ./docs/backends/S3.rst 1 |
---|
347 | +==================================================== |
---|
348 | +Storing Shares in Amazon Simple Storage Service (S3) |
---|
349 | +==================================================== |
---|
350 | hunk ./docs/backends/S3.rst 5 |
---|
351 | +S3 is a commercial storage service provided by Amazon, described at |
---|
352 | +`<https://aws.amazon.com/s3/>`_. |
---|
353 | + |
---|
354 | +The Tahoe-LAFS storage server can be configured to store its shares in |
---|
355 | +an S3 bucket, rather than on local filesystem. To enable this, add the |
---|
356 | +following keys to the server's ``tahoe.cfg`` file: |
---|
357 | + |
---|
358 | +``[storage]`` |
---|
359 | + |
---|
360 | +``backend = s3`` |
---|
361 | + |
---|
362 | + This turns off the local filesystem backend and enables use of S3. |
---|
363 | + |
---|
364 | +``s3.access_key_id = (string, required)`` |
---|
365 | + |
---|
366 | + This identifies your Amazon Web Services access key. The access key id is |
---|
367 | + not secret, but there is a secret key associated with it. The secret key |
---|
368 | + is stored in a separate file named ``private/s3secret``. |
---|
369 | + |
---|
370 | +``s3.bucket = (string, required)`` |
---|
371 | + |
---|
372 | + This controls which bucket will be used to hold shares. The Tahoe-LAFS |
---|
373 | + storage server will only modify and access objects in the configured S3 |
---|
374 | + bucket. Multiple storage servers cannot share the same bucket. |
---|
375 | + |
---|
376 | +``s3.url = (URL string, optional)`` |
---|
377 | + |
---|
378 | + This URL tells the storage server how to access the S3 service. It |
---|
379 | + defaults to ``http://s3.amazonaws.com``, but by setting it to something |
---|
380 | + else, you may be able to use some other S3-like service if it is |
---|
381 | + sufficiently compatible. |
---|
382 | + |
---|
383 | +The system time of the storage server must be correct to within 15 minutes |
---|
384 | +in order for S3 to accept the authentication provided with requests. |
---|
385 | + |
---|
386 | + |
---|
387 | +DevPay |
---|
388 | +====== |
---|
389 | + |
---|
390 | +Optionally, Amazon `DevPay`_ may be used to delegate billing for a service |
---|
391 | +based on Tahoe-LAFS and S3 to Amazon Payments. |
---|
392 | + |
---|
393 | +If DevPay is to be used, the user token and product token (in base64 form) |
---|
394 | +must be stored in the files ``private/s3usertoken`` and ``private/s3producttoken`` |
---|
395 | +respectively. DevPay-related request headers will be sent only if these files |
---|
396 | +are present when the server is started. It is currently assumed that only one |
---|
397 | +user and product token pair is needed by a given storage server. |
---|
398 | + |
---|
399 | +.. _DevPay: http://docs.amazonwebservices.com/AmazonDevPay/latest/DevPayGettingStartedGuide/ |
---|
400 | addfile ./docs/backends/disk.rst |
---|
401 | hunk ./docs/backends/disk.rst 1 |
---|
402 | +==================================== |
---|
403 | +Storing Shares on a Local Filesystem |
---|
404 | +==================================== |
---|
405 | + |
---|
406 | +The "disk" backend stores shares on the local filesystem. Versions of |
---|
407 | +Tahoe-LAFS <= 1.9.0 always stored shares in this way. |
---|
408 | + |
---|
409 | +``[storage]`` |
---|
410 | + |
---|
411 | +``backend = disk`` |
---|
412 | + |
---|
413 | + This enables use of the disk backend, and is the default. |
---|
414 | + |
---|
415 | +``readonly = (boolean, optional)`` |
---|
416 | + |
---|
417 | + If ``True``, the node will run a storage server but will not accept any |
---|
418 | + shares, making it effectively read-only. Use this for storage servers |
---|
419 | + that are being decommissioned: the ``storage/`` directory could be |
---|
420 | + mounted read-only, while shares are moved to other servers. Note that |
---|
421 | + this currently only affects immutable shares. Mutable shares (used for |
---|
422 | + directories) will be written and modified anyway. See ticket `#390 |
---|
423 | + <http://tahoe-lafs.org/trac/tahoe-lafs/ticket/390>`_ for the current |
---|
424 | + status of this bug. The default value is ``False``. |
---|
425 | + |
---|
426 | +``reserved_space = (quantity of space, optional)`` |
---|
427 | + |
---|
428 | + If provided, this value defines how much disk space is reserved: the |
---|
429 | + storage server will not accept any share that causes the amount of free |
---|
430 | + disk space to drop below this value. (The free space is measured by a |
---|
431 | + call to statvfs(2) on Unix, or GetDiskFreeSpaceEx on Windows, and is the |
---|
432 | + space available to the user account under which the storage server runs.) |
---|
433 | + |
---|
434 | + This string contains a number, with an optional case-insensitive scale |
---|
435 | + suffix like "K" or "M" or "G", and an optional "B" or "iB" suffix. So |
---|
436 | + "100MB", "100M", "100000000B", "100000000", and "100000kb" all mean the |
---|
437 | + same thing. Likewise, "1MiB", "1024KiB", and "1048576B" all mean the same |
---|
438 | + thing. |
---|
439 | + |
---|
440 | + "``tahoe create-node``" generates a tahoe.cfg with |
---|
441 | + "``reserved_space=1G``", but you may wish to raise, lower, or remove the |
---|
442 | + reservation to suit your needs. |
---|
443 | + |
---|
444 | +``expire.enabled =`` |
---|
445 | + |
---|
446 | +``expire.mode =`` |
---|
447 | + |
---|
448 | +``expire.override_lease_duration =`` |
---|
449 | + |
---|
450 | +``expire.cutoff_date =`` |
---|
451 | + |
---|
452 | +``expire.immutable =`` |
---|
453 | + |
---|
454 | +``expire.mutable =`` |
---|
455 | + |
---|
456 | + These settings control garbage collection, causing the server to |
---|
457 | + delete shares that no longer have an up-to-date lease on them. Please |
---|
458 | + see `<garbage-collection.rst>`_ for full details. |
---|
459 | hunk ./docs/configuration.rst 433 |
---|
460 | mounted read-only, while shares are moved to other servers. Note that |
---|
461 | this currently only affects immutable shares. Mutable shares (used for |
---|
462 | directories) will be written and modified anyway. See ticket `#390 |
---|
463 | - <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/390>`_ for the current |
---|
464 | + <http://tahoe-lafs.org/trac/tahoe-lafs/ticket/390>`_ for the current |
---|
465 | status of this bug. The default value is ``False``. |
---|
466 | |
---|
467 | hunk ./docs/configuration.rst 436 |
---|
468 | -``reserved_space = (str, optional)`` |
---|
469 | +``backend = (string, optional)`` |
---|
470 | |
---|
471 | hunk ./docs/configuration.rst 438 |
---|
472 | - If provided, this value defines how much disk space is reserved: the |
---|
473 | - storage server will not accept any share that causes the amount of free |
---|
474 | - disk space to drop below this value. (The free space is measured by a |
---|
475 | - call to statvfs(2) on Unix, or GetDiskFreeSpaceEx on Windows, and is the |
---|
476 | - space available to the user account under which the storage server runs.) |
---|
477 | + Storage servers can store the data into different "backends". Clients |
---|
478 | + need not be aware of which backend is used by a server. The default |
---|
479 | + value is ``disk``. |
---|
480 | |
---|
481 | hunk ./docs/configuration.rst 442 |
---|
482 | - This string contains a number, with an optional case-insensitive scale |
---|
483 | - suffix like "K" or "M" or "G", and an optional "B" or "iB" suffix. So |
---|
484 | - "100MB", "100M", "100000000B", "100000000", and "100000kb" all mean the |
---|
485 | - same thing. Likewise, "1MiB", "1024KiB", and "1048576B" all mean the same |
---|
486 | - thing. |
---|
487 | +``backend = disk`` |
---|
488 | |
---|
489 | hunk ./docs/configuration.rst 444 |
---|
490 | - "``tahoe create-node``" generates a tahoe.cfg with |
---|
491 | - "``reserved_space=1G``", but you may wish to raise, lower, or remove the |
---|
492 | - reservation to suit your needs. |
---|
493 | + The storage server stores shares on the local filesystem (in |
---|
494 | + BASEDIR/storage/shares/). For configuration details (including how to |
---|
495 | + reserve a minimum amount of free space), see `<backends/disk.rst>`_. |
---|
496 | |
---|
497 | hunk ./docs/configuration.rst 448 |
---|
498 | -``expire.enabled =`` |
---|
499 | +``backend = s3`` |
---|
500 | |
---|
501 | hunk ./docs/configuration.rst 450 |
---|
502 | -``expire.mode =`` |
---|
503 | + The storage server stores all shares to an Amazon Simple Storage Service |
---|
504 | + (S3) bucket. For configuration details, see `<backends/S3.rst>`_. |
---|
505 | |
---|
506 | hunk ./docs/configuration.rst 453 |
---|
507 | -``expire.override_lease_duration =`` |
---|
508 | +``backend = debug_discard`` |
---|
509 | |
---|
510 | hunk ./docs/configuration.rst 455 |
---|
511 | -``expire.cutoff_date =`` |
---|
512 | - |
---|
513 | -``expire.immutable =`` |
---|
514 | - |
---|
515 | -``expire.mutable =`` |
---|
516 | - |
---|
517 | - These settings control garbage collection, in which the server will |
---|
518 | - delete shares that no longer have an up-to-date lease on them. Please see |
---|
519 | - `<garbage-collection.rst>`_ for full details. |
---|
520 | + The storage server stores all shares in /dev/null. This is actually used, |
---|
521 | + for testing. It is not recommended for storage of data that you might |
---|
522 | + want to retrieve in the future. |
---|
523 | |
---|
524 | |
---|
525 | Running A Helper |
---|
526 | } |
---|
527 | [Pluggable backends: new and moved code files. refs #999 |
---|
528 | david-sarah@jacaranda.org**20111205043653 |
---|
529 | Ignore-this: 107135f528e48ad51f97dd9616bbc542 |
---|
530 | ] { |
---|
531 | adddir ./src/allmydata/storage/backends |
---|
532 | adddir ./src/allmydata/storage/backends/disk |
---|
533 | move ./src/allmydata/storage/immutable.py ./src/allmydata/storage/backends/disk/immutable.py |
---|
534 | move ./src/allmydata/storage/mutable.py ./src/allmydata/storage/backends/disk/mutable.py |
---|
535 | adddir ./src/allmydata/storage/backends/null |
---|
536 | adddir ./src/allmydata/storage/backends/s3 |
---|
537 | addfile ./src/allmydata/storage/backends/__init__.py |
---|
538 | addfile ./src/allmydata/storage/backends/base.py |
---|
539 | hunk ./src/allmydata/storage/backends/base.py 1 |
---|
540 | + |
---|
541 | +from twisted.application import service |
---|
542 | +from twisted.internet import defer |
---|
543 | + |
---|
544 | +from allmydata.util import fileutil, log, time_format |
---|
545 | +from allmydata.util.deferredutil import async_iterate, gatherResults |
---|
546 | +from allmydata.storage.common import si_b2a |
---|
547 | +from allmydata.storage.lease import LeaseInfo |
---|
548 | +from allmydata.storage.bucket import BucketReader |
---|
549 | + |
---|
550 | + |
---|
551 | +class Backend(service.MultiService): |
---|
552 | + def __init__(self): |
---|
553 | + service.MultiService.__init__(self) |
---|
554 | + self._corruption_advisory_dir = None |
---|
555 | + |
---|
556 | + def supports_crawlers(self): |
---|
557 | + return False |
---|
558 | + |
---|
559 | + def advise_corrupt_share(self, sharetype, storageindex, shnum, reason): |
---|
560 | + si_s = si_b2a(storageindex) |
---|
561 | + if self._corruption_advisory_dir is not None: |
---|
562 | + fileutil.fp_make_dirs(self._corruption_advisory_dir) |
---|
563 | + now = time_format.iso_utc(sep="T") |
---|
564 | + |
---|
565 | + # Windows can't handle colons in the filename. |
---|
566 | + name = ("%s--%s-%d" % (now, si_s, shnum)).replace(":", "") |
---|
567 | + f = self._corruption_advisory_dir.child(name).open("w") |
---|
568 | + try: |
---|
569 | + f.write("report: Share Corruption\n") |
---|
570 | + f.write("type: %s\n" % sharetype) |
---|
571 | + f.write("storage_index: %s\n" % si_s) |
---|
572 | + f.write("share_number: %d\n" % shnum) |
---|
573 | + f.write("\n") |
---|
574 | + f.write(reason) |
---|
575 | + f.write("\n") |
---|
576 | + finally: |
---|
577 | + f.close() |
---|
578 | + |
---|
579 | + log.msg(format=("client claims corruption in (%(share_type)s) " + |
---|
580 | + "%(si)s-%(shnum)d: %(reason)s"), |
---|
581 | + share_type=sharetype, si=si_s, shnum=shnum, reason=reason, |
---|
582 | + level=log.SCARY, umid="2fASGx") |
---|
583 | + |
---|
584 | + |
---|
585 | +class ShareSet(object): |
---|
586 | + """ |
---|
587 | + This class implements shareset logic that could work for all backends, but |
---|
588 | + might be useful to override for efficiency. |
---|
589 | + """ |
---|
590 | + |
---|
591 | + def __init__(self, storageindex): |
---|
592 | + self.storageindex = storageindex |
---|
593 | + |
---|
594 | + def get_shares_synchronous(self): |
---|
595 | + raise NotImplementedError |
---|
596 | + |
---|
597 | + def get_storage_index(self): |
---|
598 | + return self.storageindex |
---|
599 | + |
---|
600 | + def get_storage_index_string(self): |
---|
601 | + return si_b2a(self.storageindex) |
---|
602 | + |
---|
603 | + def make_bucket_reader(self, storageserver, share): |
---|
604 | + return BucketReader(storageserver, share) |
---|
605 | + |
---|
606 | + def testv_and_readv_and_writev(self, storageserver, secrets, |
---|
607 | + test_and_write_vectors, read_vector, |
---|
608 | + expiration_time): |
---|
609 | + # The implementation here depends on the following helper methods, |
---|
610 | + # which must be provided by subclasses: |
---|
611 | + # |
---|
612 | + # def _clean_up_after_unlink(self): |
---|
613 | + # """clean up resources associated with the shareset after some |
---|
614 | + # shares might have been deleted""" |
---|
615 | + # |
---|
616 | + # def _create_mutable_share(self, storageserver, shnum, write_enabler): |
---|
617 | + # """create a mutable share with the given shnum and write_enabler""" |
---|
618 | + |
---|
619 | + (write_enabler, renew_secret, cancel_secret) = secrets |
---|
620 | + |
---|
621 | + sharemap = {} |
---|
622 | + d = self.get_shares() |
---|
623 | + def _got_shares( (shares, corrupted) ): |
---|
624 | + d2 = defer.succeed(None) |
---|
625 | + for share in shares: |
---|
626 | + assert not isinstance(share, defer.Deferred), share |
---|
627 | + # XXX is it correct to ignore immutable shares? Maybe get_shares should |
---|
628 | + # have a parameter saying what type it's expecting. |
---|
629 | + if share.sharetype == "mutable": |
---|
630 | + d2.addCallback(lambda ign, share=share: share.check_write_enabler(write_enabler)) |
---|
631 | + sharemap[share.get_shnum()] = share |
---|
632 | + |
---|
633 | + shnums = sorted(sharemap.keys()) |
---|
634 | + |
---|
635 | + # if d2 does not fail, write_enabler is good for all existing shares |
---|
636 | + |
---|
637 | + # now evaluate test vectors |
---|
638 | + def _check_testv(shnum): |
---|
639 | + (testv, datav, new_length) = test_and_write_vectors[shnum] |
---|
640 | + if shnum in sharemap: |
---|
641 | + d3 = sharemap[shnum].check_testv(testv) |
---|
642 | + elif shnum in corrupted: |
---|
643 | + # a corrupted share does not match any test vector |
---|
644 | + d3 = defer.succeed(False) |
---|
645 | + else: |
---|
646 | + # compare the vectors against an empty share, in which all |
---|
647 | + # reads return empty strings |
---|
648 | + d3 = defer.succeed(empty_check_testv(testv)) |
---|
649 | + |
---|
650 | + def _check_result(res): |
---|
651 | + if not res: |
---|
652 | + storageserver.log("testv failed: [%d] %r" % (shnum, testv)) |
---|
653 | + return res |
---|
654 | + d3.addCallback(_check_result) |
---|
655 | + return d3 |
---|
656 | + |
---|
657 | + d2.addCallback(lambda ign: async_iterate(_check_testv, test_and_write_vectors)) |
---|
658 | + |
---|
659 | + def _gather(testv_is_good): |
---|
660 | + # Gather the read vectors, before we do any writes. This ignores any |
---|
661 | + # corrupted shares. |
---|
662 | + d3 = gatherResults([sharemap[shnum].readv(read_vector) for shnum in shnums]) |
---|
663 | + |
---|
664 | + def _do_writes(reads): |
---|
665 | + read_data = {} |
---|
666 | + for i in range(len(shnums)): |
---|
667 | + read_data[shnums[i]] = reads[i] |
---|
668 | + |
---|
669 | + ownerid = 1 # TODO |
---|
670 | + lease_info = LeaseInfo(ownerid, renew_secret, cancel_secret, |
---|
671 | + expiration_time, storageserver.get_serverid()) |
---|
672 | + |
---|
673 | + d4 = defer.succeed(None) |
---|
674 | + if testv_is_good: |
---|
675 | + if len(set(test_and_write_vectors.keys()) & corrupted) > 0: |
---|
676 | + # XXX think of a better exception to raise |
---|
677 | + raise AssertionError("You asked to write share numbers %r of storage index %r, " |
---|
678 | + "but one or more of those is corrupt (numbers %r)" |
---|
679 | + % (list(sorted(test_and_write_vectors.keys())), |
---|
680 | + self.get_storage_index_string(), |
---|
681 | + list(sorted(corrupted))) ) |
---|
682 | + |
---|
683 | + # now apply the write vectors |
---|
684 | + for shnum in test_and_write_vectors: |
---|
685 | + (testv, datav, new_length) = test_and_write_vectors[shnum] |
---|
686 | + if new_length == 0: |
---|
687 | + if shnum in sharemap: |
---|
688 | + d4.addCallback(lambda ign, shnum=shnum: sharemap[shnum].unlink()) |
---|
689 | + else: |
---|
690 | + if shnum not in sharemap: |
---|
691 | + # allocate a new share |
---|
692 | + d4.addCallback(lambda ign, shnum=shnum: |
---|
693 | + self._create_mutable_share(storageserver, shnum, |
---|
694 | + write_enabler)) |
---|
695 | + def _record_share(share, shnum=shnum): |
---|
696 | + sharemap[shnum] = share |
---|
697 | + d4.addCallback(_record_share) |
---|
698 | + d4.addCallback(lambda ign, shnum=shnum, datav=datav, new_length=new_length: |
---|
699 | + sharemap[shnum].writev(datav, new_length)) |
---|
700 | + # and update the lease |
---|
701 | + d4.addCallback(lambda ign, shnum=shnum: |
---|
702 | + sharemap[shnum].add_or_renew_lease(lease_info)) |
---|
703 | + if new_length == 0: |
---|
704 | + d4.addCallback(lambda ign: self._clean_up_after_unlink()) |
---|
705 | + |
---|
706 | + d4.addCallback(lambda ign: (testv_is_good, read_data)) |
---|
707 | + return d4 |
---|
708 | + d3.addCallback(_do_writes) |
---|
709 | + return d3 |
---|
710 | + d2.addCallback(_gather) |
---|
711 | + return d2 |
---|
712 | + d.addCallback(_got_shares) |
---|
713 | + return d |
---|
714 | + |
---|
715 | + def readv(self, wanted_shnums, read_vector): |
---|
716 | + """ |
---|
717 | + Read a vector from the numbered shares in this shareset. An empty |
---|
718 | + shares list means to return data from all known shares. |
---|
719 | + |
---|
720 | + @param wanted_shnums=ListOf(int) |
---|
721 | + @param read_vector=ReadVector |
---|
722 | + @return DictOf(int, ReadData): shnum -> results, with one key per share |
---|
723 | + """ |
---|
724 | + shnums = [] |
---|
725 | + dreads = [] |
---|
726 | + d = self.get_shares() |
---|
727 | + def _got_shares( (shares, corrupted) ): |
---|
728 | + # We ignore corrupted shares. |
---|
729 | + for share in shares: |
---|
730 | + assert not isinstance(share, defer.Deferred), share |
---|
731 | + shnum = share.get_shnum() |
---|
732 | + if not wanted_shnums or shnum in wanted_shnums: |
---|
733 | + shnums.append(share.get_shnum()) |
---|
734 | + dreads.append(share.readv(read_vector)) |
---|
735 | + return gatherResults(dreads) |
---|
736 | + d.addCallback(_got_shares) |
---|
737 | + |
---|
738 | + def _got_reads(reads): |
---|
739 | + datavs = {} |
---|
740 | + for i in range(len(shnums)): |
---|
741 | + datavs[shnums[i]] = reads[i] |
---|
742 | + return datavs |
---|
743 | + d.addCallback(_got_reads) |
---|
744 | + return d |
---|
745 | + |
---|
746 | + |
---|
747 | +def testv_compare(a, op, b): |
---|
748 | + assert op in ("lt", "le", "eq", "ne", "ge", "gt") |
---|
749 | + if op == "lt": |
---|
750 | + return a < b |
---|
751 | + if op == "le": |
---|
752 | + return a <= b |
---|
753 | + if op == "eq": |
---|
754 | + return a == b |
---|
755 | + if op == "ne": |
---|
756 | + return a != b |
---|
757 | + if op == "ge": |
---|
758 | + return a >= b |
---|
759 | + if op == "gt": |
---|
760 | + return a > b |
---|
761 | + # never reached |
---|
762 | + |
---|
763 | + |
---|
764 | +def empty_check_testv(testv): |
---|
765 | + test_good = True |
---|
766 | + for (offset, length, operator, specimen) in testv: |
---|
767 | + data = "" |
---|
768 | + if not testv_compare(data, operator, specimen): |
---|
769 | + test_good = False |
---|
770 | + break |
---|
771 | + return test_good |
---|
772 | + |
---|
773 | addfile ./src/allmydata/storage/backends/disk/__init__.py |
---|
774 | addfile ./src/allmydata/storage/backends/disk/disk_backend.py |
---|
775 | hunk ./src/allmydata/storage/backends/disk/disk_backend.py 1 |
---|
776 | + |
---|
777 | +import re, struct |
---|
778 | + |
---|
779 | +from twisted.internet import defer |
---|
780 | + |
---|
781 | +from zope.interface import implements |
---|
782 | +from allmydata.interfaces import IStorageBackend, IShareSet |
---|
783 | +from allmydata.util import fileutil, log |
---|
784 | +from allmydata.storage.common import si_b2a, si_a2b, UnknownMutableContainerVersionError, \ |
---|
785 | + UnknownImmutableContainerVersionError |
---|
786 | +from allmydata.storage.bucket import BucketWriter |
---|
787 | +from allmydata.storage.backends.base import Backend, ShareSet |
---|
788 | +from allmydata.storage.backends.disk.immutable import load_immutable_disk_share, create_immutable_disk_share |
---|
789 | +from allmydata.storage.backends.disk.mutable import load_mutable_disk_share, create_mutable_disk_share |
---|
790 | +from allmydata.mutable.layout import MUTABLE_MAGIC |
---|
791 | + |
---|
792 | + |
---|
793 | +# storage/ |
---|
794 | +# storage/shares/incoming |
---|
795 | +# incoming/ holds temp dirs named $PREFIX/$STORAGEINDEX/$SHNUM which will |
---|
796 | +# be moved to storage/shares/$PREFIX/$STORAGEINDEX/$SHNUM upon success |
---|
797 | +# storage/shares/$PREFIX/$STORAGEINDEX |
---|
798 | +# storage/shares/$PREFIX/$STORAGEINDEX/$SHNUM |
---|
799 | + |
---|
800 | +# where "$PREFIX" denotes the first 10 bits worth of $STORAGEINDEX (that's 2 |
---|
801 | +# base-32 chars). |
---|
802 | +# $SHNUM matches this regex: |
---|
803 | +NUM_RE=re.compile("^[0-9]+$") |
---|
804 | + |
---|
805 | + |
---|
806 | +def si_si2dir(startfp, storageindex): |
---|
807 | + sia = si_b2a(storageindex) |
---|
808 | + newfp = startfp.child(sia[:2]) |
---|
809 | + return newfp.child(sia) |
---|
810 | + |
---|
811 | +def get_disk_share(home, storageindex=None, shnum=None): |
---|
812 | + f = home.open('rb') |
---|
813 | + try: |
---|
814 | + prefix = f.read(len(MUTABLE_MAGIC)) |
---|
815 | + finally: |
---|
816 | + f.close() |
---|
817 | + |
---|
818 | + if prefix == MUTABLE_MAGIC: |
---|
819 | + return load_mutable_disk_share(home, storageindex, shnum) |
---|
820 | + else: |
---|
821 | + # assume it's immutable |
---|
822 | + return load_immutable_disk_share(home, storageindex, shnum) |
---|
823 | + |
---|
824 | + |
---|
825 | +def configure_disk_backend(storedir, config): |
---|
826 | + readonly = config.get_config("storage", "readonly", False, boolean=True) |
---|
827 | + reserved_space = config.get_config_size("storage", "reserved_space", "0") |
---|
828 | + |
---|
829 | + return DiskBackend(storedir, readonly, reserved_space) |
---|
830 | + |
---|
831 | + |
---|
832 | +class DiskBackend(Backend): |
---|
833 | + implements(IStorageBackend) |
---|
834 | + |
---|
835 | + def __init__(self, storedir, readonly=False, reserved_space=0): |
---|
836 | + Backend.__init__(self) |
---|
837 | + self._setup_storage(storedir, readonly, reserved_space) |
---|
838 | + self._setup_corruption_advisory() |
---|
839 | + |
---|
840 | + def _setup_storage(self, storedir, readonly, reserved_space): |
---|
841 | + self._storedir = storedir |
---|
842 | + self._readonly = readonly |
---|
843 | + self._reserved_space = int(reserved_space) |
---|
844 | + self._sharedir = self._storedir.child("shares") |
---|
845 | + fileutil.fp_make_dirs(self._sharedir) |
---|
846 | + self._incomingdir = self._sharedir.child('incoming') |
---|
847 | + self._clean_incomplete() |
---|
848 | + if self._reserved_space and (self.get_available_space() is None): |
---|
849 | + log.msg("warning: [storage]reserved_space= is set, but this platform does not support an API to get disk statistics (statvfs(2) or GetDiskFreeSpaceEx), so this reservation cannot be honored", |
---|
850 | + umid="0wZ27w", level=log.UNUSUAL) |
---|
851 | + |
---|
852 | + def _clean_incomplete(self): |
---|
853 | + fileutil.fp_remove(self._incomingdir) |
---|
854 | + fileutil.fp_make_dirs(self._incomingdir) |
---|
855 | + |
---|
856 | + def _setup_corruption_advisory(self): |
---|
857 | + # we don't actually create the corruption-advisory dir until necessary |
---|
858 | + self._corruption_advisory_dir = self._storedir.child("corruption-advisories") |
---|
859 | + |
---|
860 | + def _make_shareset(self, sharehomedir): |
---|
861 | + return self.get_shareset(si_a2b(str(sharehomedir.basename()))) |
---|
862 | + |
---|
863 | + def supports_crawlers(self): |
---|
864 | + return True |
---|
865 | + |
---|
866 | + def get_sharesets_for_prefix(self, prefix): |
---|
867 | + prefixfp = self._sharedir.child(prefix) |
---|
868 | + sharesets = map(self._make_shareset, fileutil.fp_list(prefixfp)) |
---|
869 | + def _by_base32si(b): |
---|
870 | + return b.get_storage_index_string() |
---|
871 | + sharesets.sort(key=_by_base32si) |
---|
872 | + return sharesets |
---|
873 | + |
---|
874 | + def get_shareset(self, storageindex): |
---|
875 | + sharehomedir = si_si2dir(self._sharedir, storageindex) |
---|
876 | + incominghomedir = si_si2dir(self._incomingdir, storageindex) |
---|
877 | + return DiskShareSet(storageindex, sharehomedir, incominghomedir) |
---|
878 | + |
---|
879 | + def fill_in_space_stats(self, stats): |
---|
880 | + stats['storage_server.reserved_space'] = self._reserved_space |
---|
881 | + try: |
---|
882 | + disk = fileutil.get_disk_stats(self._sharedir, self._reserved_space) |
---|
883 | + writeable = disk['avail'] > 0 |
---|
884 | + |
---|
885 | + # spacetime predictors should use disk_avail / (d(disk_used)/dt) |
---|
886 | + stats['storage_server.disk_total'] = disk['total'] |
---|
887 | + stats['storage_server.disk_used'] = disk['used'] |
---|
888 | + stats['storage_server.disk_free_for_root'] = disk['free_for_root'] |
---|
889 | + stats['storage_server.disk_free_for_nonroot'] = disk['free_for_nonroot'] |
---|
890 | + stats['storage_server.disk_avail'] = disk['avail'] |
---|
891 | + except AttributeError: |
---|
892 | + writeable = True |
---|
893 | + except EnvironmentError: |
---|
894 | + log.msg("OS call to get disk statistics failed", level=log.UNUSUAL) |
---|
895 | + writeable = False |
---|
896 | + |
---|
897 | + if self._readonly: |
---|
898 | + stats['storage_server.disk_avail'] = 0 |
---|
899 | + writeable = False |
---|
900 | + |
---|
901 | + stats['storage_server.accepting_immutable_shares'] = int(writeable) |
---|
902 | + |
---|
903 | + def get_available_space(self): |
---|
904 | + if self._readonly: |
---|
905 | + return 0 |
---|
906 | + try: |
---|
907 | + return fileutil.get_available_space(self._sharedir, self._reserved_space) |
---|
908 | + except EnvironmentError: |
---|
909 | + return 0 |
---|
910 | + |
---|
911 | + |
---|
912 | +class DiskShareSet(ShareSet): |
---|
913 | + implements(IShareSet) |
---|
914 | + |
---|
915 | + def __init__(self, storageindex, sharehomedir, incominghomedir=None): |
---|
916 | + ShareSet.__init__(self, storageindex) |
---|
917 | + self._sharehomedir = sharehomedir |
---|
918 | + self._incominghomedir = incominghomedir |
---|
919 | + |
---|
920 | + def get_overhead(self): |
---|
921 | + return (fileutil.get_used_space(self._sharehomedir) + |
---|
922 | + fileutil.get_used_space(self._incominghomedir)) |
---|
923 | + |
---|
924 | + def get_shares_synchronous(self): |
---|
925 | + children = fileutil.fp_list(self._sharehomedir) |
---|
926 | + si = self.get_storage_index() |
---|
927 | + shares = {} |
---|
928 | + corrupted = set() |
---|
929 | + for fp in children: |
---|
930 | + shnumstr = str(fp.basename()) |
---|
931 | + if NUM_RE.match(shnumstr): |
---|
932 | + shnum = int(shnumstr) |
---|
933 | + try: |
---|
934 | + shares[shnum] = get_disk_share(fp, si, shnum) |
---|
935 | + except (UnknownMutableContainerVersionError, |
---|
936 | + UnknownImmutableContainerVersionError, |
---|
937 | + struct.error): |
---|
938 | + corrupted.add(shnum) |
---|
939 | + |
---|
940 | + return ([shares[shnum] for shnum in sorted(shares.keys())], corrupted) |
---|
941 | + |
---|
942 | + def get_shares(self): |
---|
943 | + return defer.succeed(self.get_shares_synchronous()) |
---|
944 | + |
---|
945 | + def get_share(self, shnum): |
---|
946 | + return get_disk_share(self._sharehomedir.child(str(shnum)), self.get_storage_index(), shnum) |
---|
947 | + |
---|
948 | + def has_incoming(self, shnum): |
---|
949 | + if self._incominghomedir is None: |
---|
950 | + return False |
---|
951 | + return self._incominghomedir.child(str(shnum)).exists() |
---|
952 | + |
---|
953 | + def renew_lease(self, renew_secret, new_expiration_time): |
---|
954 | + found_shares = False |
---|
955 | + (shares, corrupted) = self.get_shares_synchronous() |
---|
956 | + for share in shares: |
---|
957 | + found_shares = True |
---|
958 | + share.renew_lease(renew_secret, new_expiration_time) |
---|
959 | + |
---|
960 | + if not found_shares: |
---|
961 | + raise IndexError("no such lease to renew") |
---|
962 | + |
---|
963 | + def get_leases(self): |
---|
964 | + # Since all shares get the same lease data, we just grab the leases |
---|
965 | + # from the first share. |
---|
966 | + (shares, corrupted) = self.get_shares_synchronous() |
---|
967 | + if len(shares) > 0: |
---|
968 | + return shares[0].get_leases() |
---|
969 | + else: |
---|
970 | + return iter([]) |
---|
971 | + |
---|
972 | + def add_or_renew_lease(self, lease_info): |
---|
973 | + # This implementation assumes that lease data is duplicated in |
---|
974 | + # all shares of a shareset, which might not be true for all backends. |
---|
975 | + (shares, corrupted) = self.get_shares_synchronous() |
---|
976 | + for share in shares: |
---|
977 | + share.add_or_renew_lease(lease_info) |
---|
978 | + |
---|
979 | + def make_bucket_writer(self, storageserver, shnum, max_space_per_bucket, lease_info, canary): |
---|
980 | + finalhome = self._sharehomedir.child(str(shnum)) |
---|
981 | + incominghome = self._incominghomedir.child(str(shnum)) |
---|
982 | + immsh = create_immutable_disk_share(incominghome, finalhome, max_space_per_bucket, |
---|
983 | + self.get_storage_index(), shnum) |
---|
984 | + bw = BucketWriter(storageserver, immsh, lease_info, canary) |
---|
985 | + return bw |
---|
986 | + |
---|
987 | + def _create_mutable_share(self, storageserver, shnum, write_enabler): |
---|
988 | + fileutil.fp_make_dirs(self._sharehomedir) |
---|
989 | + sharehome = self._sharehomedir.child(str(shnum)) |
---|
990 | + serverid = storageserver.get_serverid() |
---|
991 | + return create_mutable_disk_share(sharehome, serverid, write_enabler, |
---|
992 | + self.get_storage_index(), shnum, parent=storageserver) |
---|
993 | + |
---|
994 | + def _clean_up_after_unlink(self): |
---|
995 | + fileutil.fp_rmdir_if_empty(self._sharehomedir) |
---|
996 | + |
---|
997 | + def _get_sharedir(self): |
---|
998 | + return self._sharehomedir |
---|
999 | addfile ./src/allmydata/storage/backends/null/__init__.py |
---|
1000 | addfile ./src/allmydata/storage/backends/null/null_backend.py |
---|
1001 | hunk ./src/allmydata/storage/backends/null/null_backend.py 1 |
---|
1002 | + |
---|
1003 | +from twisted.internet import defer |
---|
1004 | + |
---|
1005 | +from zope.interface import implements |
---|
1006 | +from allmydata.interfaces import IStorageBackend, IShareSet, IShareBase, \ |
---|
1007 | + IShareForReading, IShareForWriting, IMutableShare |
---|
1008 | + |
---|
1009 | +from allmydata.util.assertutil import precondition |
---|
1010 | +from allmydata.storage.backends.base import Backend, ShareSet, empty_check_testv |
---|
1011 | +from allmydata.storage.bucket import BucketWriter, BucketReader |
---|
1012 | +from allmydata.storage.common import si_b2a |
---|
1013 | + |
---|
1014 | + |
---|
1015 | +def configure_null_backend(storedir, config): |
---|
1016 | + return NullBackend() |
---|
1017 | + |
---|
1018 | + |
---|
1019 | +class NullBackend(Backend): |
---|
1020 | + implements(IStorageBackend) |
---|
1021 | + """ |
---|
1022 | + I am a test backend that records (in memory) which shares exist, but not their contents, leases, |
---|
1023 | + or write-enablers. |
---|
1024 | + """ |
---|
1025 | + |
---|
1026 | + def __init__(self): |
---|
1027 | + Backend.__init__(self) |
---|
1028 | + # mapping from storageindex to NullShareSet |
---|
1029 | + self._sharesets = {} |
---|
1030 | + |
---|
1031 | + def get_available_space(self): |
---|
1032 | + return None |
---|
1033 | + |
---|
1034 | + def get_sharesets_for_prefix(self, prefix): |
---|
1035 | + sharesets = [] |
---|
1036 | + for (si, shareset) in self._sharesets.iteritems(): |
---|
1037 | + if si_b2a(si).startswith(prefix): |
---|
1038 | + sharesets.append(shareset) |
---|
1039 | + |
---|
1040 | + def _by_base32si(b): |
---|
1041 | + return b.get_storage_index_string() |
---|
1042 | + sharesets.sort(key=_by_base32si) |
---|
1043 | + return sharesets |
---|
1044 | + |
---|
1045 | + def get_shareset(self, storageindex): |
---|
1046 | + shareset = self._sharesets.get(storageindex, None) |
---|
1047 | + if shareset is None: |
---|
1048 | + shareset = NullShareSet(storageindex) |
---|
1049 | + self._sharesets[storageindex] = shareset |
---|
1050 | + return shareset |
---|
1051 | + |
---|
1052 | + def fill_in_space_stats(self, stats): |
---|
1053 | + pass |
---|
1054 | + |
---|
1055 | + |
---|
1056 | +class NullShareSet(ShareSet): |
---|
1057 | + implements(IShareSet) |
---|
1058 | + |
---|
1059 | + def __init__(self, storageindex): |
---|
1060 | + self.storageindex = storageindex |
---|
1061 | + self._incoming_shnums = set() |
---|
1062 | + self._immutable_shnums = set() |
---|
1063 | + self._mutable_shnums = set() |
---|
1064 | + |
---|
1065 | + def close_shnum(self, shnum): |
---|
1066 | + self._incoming_shnums.remove(shnum) |
---|
1067 | + self._immutable_shnums.add(shnum) |
---|
1068 | + return defer.succeed(None) |
---|
1069 | + |
---|
1070 | + def unlink_shnum(self, shnum): |
---|
1071 | + if shnum in self._incoming_shnums: |
---|
1072 | + self._incoming_shnums.remove(shnum) |
---|
1073 | + if shnum in self._immutable_shnums: |
---|
1074 | + self._immutable_shnums.remove(shnum) |
---|
1075 | + if shnum in self._mutable_shnums: |
---|
1076 | + self._mutable_shnums.remove(shnum) |
---|
1077 | + return defer.succeed(None) |
---|
1078 | + |
---|
1079 | + def get_overhead(self): |
---|
1080 | + return 0 |
---|
1081 | + |
---|
1082 | + def get_shares(self): |
---|
1083 | + shares = {} |
---|
1084 | + for shnum in self._immutable_shnums: |
---|
1085 | + shares[shnum] = ImmutableNullShare(self, shnum) |
---|
1086 | + for shnum in self._mutable_shnums: |
---|
1087 | + shares[shnum] = MutableNullShare(self, shnum) |
---|
1088 | + # This backend never has any corrupt shares. |
---|
1089 | + return defer.succeed( ([shares[shnum] for shnum in sorted(shares.keys())], set()) ) |
---|
1090 | + |
---|
1091 | + def get_share(self, shnum): |
---|
1092 | + if shnum in self._immutable_shnums: |
---|
1093 | + return defer.succeed(ImmutableNullShare(self, shnum)) |
---|
1094 | + elif shnum in self._mutable_shnums: |
---|
1095 | + return defer.succeed(MutableNullShare(self, shnum)) |
---|
1096 | + else: |
---|
1097 | + def _not_found(): raise IndexError("no such share %d" % (shnum,)) |
---|
1098 | + return defer.execute(_not_found) |
---|
1099 | + |
---|
1100 | + def renew_lease(self, renew_secret, new_expiration_time): |
---|
1101 | + raise IndexError("no such lease to renew") |
---|
1102 | + |
---|
1103 | + def get_leases(self): |
---|
1104 | + pass |
---|
1105 | + |
---|
1106 | + def add_or_renew_lease(self, lease_info): |
---|
1107 | + pass |
---|
1108 | + |
---|
1109 | + def has_incoming(self, shnum): |
---|
1110 | + return shnum in self._incoming_shnums |
---|
1111 | + |
---|
1112 | + def get_storage_index(self): |
---|
1113 | + return self.storageindex |
---|
1114 | + |
---|
1115 | + def get_storage_index_string(self): |
---|
1116 | + return si_b2a(self.storageindex) |
---|
1117 | + |
---|
1118 | + def make_bucket_writer(self, storageserver, shnum, max_space_per_bucket, lease_info, canary): |
---|
1119 | + self._incoming_shnums.add(shnum) |
---|
1120 | + immutableshare = ImmutableNullShare(self, shnum) |
---|
1121 | + bw = BucketWriter(storageserver, immutableshare, lease_info, canary) |
---|
1122 | + bw.throw_out_all_data = True |
---|
1123 | + return bw |
---|
1124 | + |
---|
1125 | + def make_bucket_reader(self, storageserver, share): |
---|
1126 | + return BucketReader(storageserver, share) |
---|
1127 | + |
---|
1128 | + |
---|
1129 | +class NullShareBase(object): |
---|
1130 | + implements(IShareBase) |
---|
1131 | + |
---|
1132 | + def __init__(self, shareset, shnum): |
---|
1133 | + self.shareset = shareset |
---|
1134 | + self.shnum = shnum |
---|
1135 | + |
---|
1136 | + def get_storage_index(self): |
---|
1137 | + return self.shareset.get_storage_index() |
---|
1138 | + |
---|
1139 | + def get_storage_index_string(self): |
---|
1140 | + return self.shareset.get_storage_index_string() |
---|
1141 | + |
---|
1142 | + def get_shnum(self): |
---|
1143 | + return self.shnum |
---|
1144 | + |
---|
1145 | + def get_data_length(self): |
---|
1146 | + return 0 |
---|
1147 | + |
---|
1148 | + def get_size(self): |
---|
1149 | + return 0 |
---|
1150 | + |
---|
1151 | + def get_used_space(self): |
---|
1152 | + return 0 |
---|
1153 | + |
---|
1154 | + def unlink(self): |
---|
1155 | + return self.shareset.unlink_shnum(self.shnum) |
---|
1156 | + |
---|
1157 | + def readv(self, readv): |
---|
1158 | + datav = [] |
---|
1159 | + for (offset, length) in readv: |
---|
1160 | + datav.append("") |
---|
1161 | + return defer.succeed(datav) |
---|
1162 | + |
---|
1163 | + def get_leases(self): |
---|
1164 | + pass |
---|
1165 | + |
---|
1166 | + def add_lease(self, lease): |
---|
1167 | + pass |
---|
1168 | + |
---|
1169 | + def renew_lease(self, renew_secret, new_expire_time): |
---|
1170 | + raise IndexError("unable to renew non-existent lease") |
---|
1171 | + |
---|
1172 | + def add_or_renew_lease(self, lease_info): |
---|
1173 | + pass |
---|
1174 | + |
---|
1175 | + |
---|
1176 | +class ImmutableNullShare(NullShareBase): |
---|
1177 | + implements(IShareForReading, IShareForWriting) |
---|
1178 | + sharetype = "immutable" |
---|
1179 | + |
---|
1180 | + def read_share_data(self, offset, length): |
---|
1181 | + precondition(offset >= 0) |
---|
1182 | + return defer.succeed("") |
---|
1183 | + |
---|
1184 | + def get_allocated_size(self): |
---|
1185 | + return 0 |
---|
1186 | + |
---|
1187 | + def write_share_data(self, offset, data): |
---|
1188 | + return defer.succeed(None) |
---|
1189 | + |
---|
1190 | + def close(self): |
---|
1191 | + return self.shareset.close_shnum(self.shnum) |
---|
1192 | + |
---|
1193 | + |
---|
1194 | +class MutableNullShare(NullShareBase): |
---|
1195 | + implements(IMutableShare) |
---|
1196 | + sharetype = "mutable" |
---|
1197 | + |
---|
1198 | + def create(self, serverid, write_enabler): |
---|
1199 | + return defer.succeed(self) |
---|
1200 | + |
---|
1201 | + def check_write_enabler(self, write_enabler): |
---|
1202 | + # Null backend doesn't check write enablers. |
---|
1203 | + return defer.succeed(None) |
---|
1204 | + |
---|
1205 | + def check_testv(self, testv): |
---|
1206 | + return defer.succeed(empty_check_testv(testv)) |
---|
1207 | + |
---|
1208 | + def writev(self, datav, new_length): |
---|
1209 | + return defer.succeed(None) |
---|
1210 | addfile ./src/allmydata/storage/backends/s3/immutable.py |
---|
1211 | hunk ./src/allmydata/storage/backends/s3/immutable.py 1 |
---|
1212 | + |
---|
1213 | +import struct |
---|
1214 | +from cStringIO import StringIO |
---|
1215 | + |
---|
1216 | +from twisted.internet import defer |
---|
1217 | + |
---|
1218 | +from zope.interface import implements |
---|
1219 | +from allmydata.interfaces import IShareBase, IShareForReading, IShareForWriting |
---|
1220 | + |
---|
1221 | +from allmydata.util.assertutil import precondition |
---|
1222 | +from allmydata.storage.common import si_b2a, UnknownImmutableContainerVersionError, DataTooLargeError |
---|
1223 | +from allmydata.storage.backends.s3.s3_common import get_s3_share_key |
---|
1224 | + |
---|
1225 | + |
---|
1226 | +# Each share file (with key 'shares/$PREFIX/$STORAGEINDEX/$SHNUM') contains |
---|
1227 | +# lease information [currently inaccessible] and share data. The share data is |
---|
1228 | +# accessed by RIBucketWriter.write and RIBucketReader.read . |
---|
1229 | + |
---|
1230 | +# The share file has the following layout: |
---|
1231 | +# 0x00: share file version number, four bytes, current version is 1 |
---|
1232 | +# 0x04: always zero (was share data length prior to Tahoe-LAFS v1.3.0) |
---|
1233 | +# 0x08: number of leases, four bytes big-endian |
---|
1234 | +# 0x0c: beginning of share data (see immutable.layout.WriteBucketProxy) |
---|
1235 | +# data_length+0x0c: first lease. Each lease record is 72 bytes. |
---|
1236 | + |
---|
1237 | + |
---|
1238 | +class ImmutableS3ShareBase(object): |
---|
1239 | + implements(IShareBase) |
---|
1240 | + |
---|
1241 | + sharetype = "immutable" |
---|
1242 | + LEASE_SIZE = struct.calcsize(">L32s32sL") # for compatibility |
---|
1243 | + HEADER = ">LLL" |
---|
1244 | + HEADER_SIZE = struct.calcsize(HEADER) |
---|
1245 | + |
---|
1246 | + def __init__(self, s3bucket, storageindex, shnum): |
---|
1247 | + self._s3bucket = s3bucket |
---|
1248 | + self._storageindex = storageindex |
---|
1249 | + self._shnum = shnum |
---|
1250 | + self._key = get_s3_share_key(storageindex, shnum) |
---|
1251 | + |
---|
1252 | + def __repr__(self): |
---|
1253 | + return ("<%s at %r key %r>" % (self.__class__.__name__, self._s3bucket, self._key,)) |
---|
1254 | + |
---|
1255 | + def get_storage_index(self): |
---|
1256 | + return self._storageindex |
---|
1257 | + |
---|
1258 | + def get_storage_index_string(self): |
---|
1259 | + return si_b2a(self._storageindex) |
---|
1260 | + |
---|
1261 | + def get_shnum(self): |
---|
1262 | + return self._shnum |
---|
1263 | + |
---|
1264 | + def get_data_length(self): |
---|
1265 | + return self.get_size() - self.HEADER_SIZE |
---|
1266 | + |
---|
1267 | + def get_used_space(self): |
---|
1268 | + return self.get_size() |
---|
1269 | + |
---|
1270 | + def unlink(self): |
---|
1271 | + self._discard() |
---|
1272 | + try: |
---|
1273 | + return self._s3bucket.delete_object(self._key) |
---|
1274 | + except self._s3bucket.S3Error, e: |
---|
1275 | + if e.get_error_code() != 404: |
---|
1276 | + raise |
---|
1277 | + return defer.succeed(None) |
---|
1278 | + |
---|
1279 | + def get_size(self): |
---|
1280 | + # subclasses should implement |
---|
1281 | + raise NotImplementedError |
---|
1282 | + |
---|
1283 | + # XXX should these lease methods be necessary? |
---|
1284 | + |
---|
1285 | + def get_leases(self): |
---|
1286 | + pass |
---|
1287 | + |
---|
1288 | + def add_lease(self, lease_info): |
---|
1289 | + pass |
---|
1290 | + |
---|
1291 | + def renew_lease(self, renew_secret, new_expire_time): |
---|
1292 | + pass |
---|
1293 | + |
---|
1294 | + def add_or_renew_lease(self, lease_info): |
---|
1295 | + pass |
---|
1296 | + |
---|
1297 | + def cancel_lease(self, cancel_secret): |
---|
1298 | + pass |
---|
1299 | + |
---|
1300 | + def _get_filepath(self): |
---|
1301 | + # For use by tests, only with the mock S3 backend. |
---|
1302 | + # It is OK that _get_filepath doesn't exist on a real S3Bucket object. |
---|
1303 | + return self._s3bucket._get_filepath(self._key) |
---|
1304 | + |
---|
1305 | + |
---|
1306 | +class ImmutableS3ShareForWriting(ImmutableS3ShareBase): |
---|
1307 | + implements(IShareForWriting) |
---|
1308 | + |
---|
1309 | + def __init__(self, s3bucket, storageindex, shnum, max_size, incomingset): |
---|
1310 | + """ |
---|
1311 | + I won't allow more than max_size to be written to me. |
---|
1312 | + """ |
---|
1313 | + precondition(isinstance(max_size, (int, long)), max_size) |
---|
1314 | + ImmutableS3ShareBase.__init__(self, s3bucket, storageindex, shnum) |
---|
1315 | + self._max_size = max_size |
---|
1316 | + |
---|
1317 | + self._buf = StringIO() |
---|
1318 | + # The second field, which was the four-byte share data length in |
---|
1319 | + # Tahoe-LAFS versions prior to 1.3.0, is not used; we always write 0. |
---|
1320 | + # We also write 0 for the number of leases. |
---|
1321 | + self._buf.write(struct.pack(self.HEADER, 1, 0, 0) ) |
---|
1322 | + self._size = self._buf.tell() |
---|
1323 | + |
---|
1324 | + self._incomingset = incomingset |
---|
1325 | + self._incomingset.add( (storageindex, shnum) ) |
---|
1326 | + |
---|
1327 | + def get_size(self): |
---|
1328 | + return self._size |
---|
1329 | + |
---|
1330 | + def get_allocated_size(self): |
---|
1331 | + return self._max_size |
---|
1332 | + |
---|
1333 | + def write_share_data(self, offset, data): |
---|
1334 | + precondition(offset >= 0, offset) |
---|
1335 | + if offset+len(data) > self._max_size: |
---|
1336 | + raise DataTooLargeError(self._max_size, offset, len(data)) |
---|
1337 | + self._buf.seek(self.HEADER_SIZE+offset) |
---|
1338 | + self._buf.write(data) |
---|
1339 | + self._size = self._buf.tell() |
---|
1340 | + return defer.succeed(None) |
---|
1341 | + |
---|
1342 | + def close(self): |
---|
1343 | + # We really want to stream writes to S3, but txaws doesn't support |
---|
1344 | + # that yet (and neither does IS3Bucket, since that's a thin wrapper |
---|
1345 | + # over the txaws S3 API). See |
---|
1346 | + # https://bugs.launchpad.net/txaws/+bug/767205 and |
---|
1347 | + # https://bugs.launchpad.net/txaws/+bug/783801 |
---|
1348 | + data = self._buf.getvalue() |
---|
1349 | + self._discard() |
---|
1350 | + return self._s3bucket.put_object(self._key, data) |
---|
1351 | + |
---|
1352 | + def _discard(self): |
---|
1353 | + self._buf = None |
---|
1354 | + self._incomingset.discard( (self.get_storage_index(), self.get_shnum()) ) |
---|
1355 | + |
---|
1356 | + |
---|
1357 | +class ImmutableS3ShareForReading(ImmutableS3ShareBase): |
---|
1358 | + implements(IShareForReading) |
---|
1359 | + |
---|
1360 | + def __init__(self, s3bucket, storageindex, shnum, data): |
---|
1361 | + ImmutableS3ShareBase.__init__(self, s3bucket, storageindex, shnum) |
---|
1362 | + self._data = data |
---|
1363 | + |
---|
1364 | + header = self._data[:self.HEADER_SIZE] |
---|
1365 | + (version, unused, num_leases) = struct.unpack(self.HEADER, header) |
---|
1366 | + |
---|
1367 | + if version != 1: |
---|
1368 | + msg = "%r had version %d but we wanted 1" % (self, version) |
---|
1369 | + raise UnknownImmutableContainerVersionError(msg) |
---|
1370 | + |
---|
1371 | + # We cannot write leases in share files, but allow them to be present |
---|
1372 | + # in case a share file is copied from a disk backend, or in case we |
---|
1373 | + # need them in future. |
---|
1374 | + self._end_offset = len(self._data) - (num_leases * self.LEASE_SIZE) |
---|
1375 | + |
---|
1376 | + def get_size(self): |
---|
1377 | + return len(self._data) |
---|
1378 | + |
---|
1379 | + def readv(self, readv): |
---|
1380 | + datav = [] |
---|
1381 | + for (offset, length) in readv: |
---|
1382 | + datav.append(self.read_share_data(offset, length)) |
---|
1383 | + return defer.succeed(datav) |
---|
1384 | + |
---|
1385 | + def read_share_data(self, offset, length): |
---|
1386 | + precondition(offset >= 0) |
---|
1387 | + |
---|
1388 | + # Reads beyond the end of the data are truncated. Reads that start |
---|
1389 | + # beyond the end of the data return an empty string. |
---|
1390 | + seekpos = self.HEADER_SIZE+offset |
---|
1391 | + actuallength = max(0, min(length, self._end_offset-seekpos)) |
---|
1392 | + if actuallength == 0: |
---|
1393 | + return defer.succeed("") |
---|
1394 | + return defer.succeed(self._data[seekpos:seekpos+actuallength]) |
---|
1395 | + |
---|
1396 | + def _discard(self): |
---|
1397 | + pass |
---|
1398 | addfile ./src/allmydata/storage/backends/s3/mock_s3.py |
---|
1399 | hunk ./src/allmydata/storage/backends/s3/mock_s3.py 1 |
---|
1400 | + |
---|
1401 | +from twisted.internet import defer |
---|
1402 | + |
---|
1403 | +from zope.interface import implements |
---|
1404 | +from allmydata.storage.backends.s3.s3_common import IS3Bucket |
---|
1405 | +from allmydata.util.time_format import iso_utc |
---|
1406 | +from allmydata.util import fileutil |
---|
1407 | +from allmydata.util.deferredutil import async_iterate |
---|
1408 | + |
---|
1409 | + |
---|
1410 | +def configure_mock_s3_backend(storedir, config): |
---|
1411 | + from allmydata.storage.backends.s3.s3_backend import S3Backend |
---|
1412 | + |
---|
1413 | + corruption_advisory_dir = storedir.child("corruption-advisories") |
---|
1414 | + |
---|
1415 | + s3bucket = MockS3Bucket(storedir) |
---|
1416 | + return S3Backend(s3bucket, corruption_advisory_dir) |
---|
1417 | + |
---|
1418 | + |
---|
1419 | +MAX_KEYS = 1000 |
---|
1420 | + |
---|
1421 | +class MockS3Bucket(object): |
---|
1422 | + implements(IS3Bucket) |
---|
1423 | + """ |
---|
1424 | + I represent a mock S3 bucket that stores its data in the local filesystem, |
---|
1425 | + using a directory structure compatible with the disk backend. |
---|
1426 | + """ |
---|
1427 | + |
---|
1428 | + def __init__(self, storagedir): |
---|
1429 | + self._storagedir = storagedir |
---|
1430 | + self.bucketname = "bucket" |
---|
1431 | + self.model = MockS3Bucket.__module__ |
---|
1432 | + self.S3Error = MockS3Error |
---|
1433 | + |
---|
1434 | + def __repr__(self): |
---|
1435 | + return ("<%s at %r>" % (self.__class__.__name__, self._storagedir,)) |
---|
1436 | + |
---|
1437 | + def create(self): |
---|
1438 | + return defer.execute(self._not_implemented) |
---|
1439 | + |
---|
1440 | + def delete(self): |
---|
1441 | + return defer.execute(self._not_implemented) |
---|
1442 | + |
---|
1443 | + def _iterate_dirs(self): |
---|
1444 | + for prefixdir in fileutil.fp_list(self._storagedir.child("shares")): |
---|
1445 | + prefixstr = prefixdir.basename() |
---|
1446 | + prefixkey = "shares/%s" % (prefixstr,) |
---|
1447 | + for sidir in fileutil.fp_list(prefixdir): |
---|
1448 | + sistr = sidir.basename() |
---|
1449 | + sikey = "%s/%s" % (prefixkey, sistr) |
---|
1450 | + for sharefp in fileutil.fp_list(sidir): |
---|
1451 | + shnumstr = sharefp.basename() |
---|
1452 | + yield (sharefp, "%s/%s" % (sikey, shnumstr)) |
---|
1453 | + |
---|
1454 | + def list_all_objects(self): |
---|
1455 | + contents = [] |
---|
1456 | + def _next_share(res): |
---|
1457 | + if res is None: |
---|
1458 | + return |
---|
1459 | + (sharefp, sharekey) = res |
---|
1460 | + mtime_utc = iso_utc(sharefp.getmtime(), sep=' ')+'+00:00' |
---|
1461 | + item = BucketItem(key=sharekey, modification_date=mtime_utc, etag="", |
---|
1462 | + size=sharefp.getsize(), storage_class="STANDARD") |
---|
1463 | + contents.append(item) |
---|
1464 | + return len(contents) < MAX_KEYS |
---|
1465 | + |
---|
1466 | + d = async_iterate(_next_share, self._iterate_dirs()) |
---|
1467 | + d.addCallback(lambda completed: |
---|
1468 | + BucketListing(self.bucketname, '', '/', MAX_KEYS, |
---|
1469 | + is_truncated=not completed, contents=contents)) |
---|
1470 | + return d |
---|
1471 | + |
---|
1472 | + def _get_filepath(self, object_name, must_exist=False): |
---|
1473 | + # This method is also called by tests. |
---|
1474 | + sharefp = self._storagedir.preauthChild(object_name) |
---|
1475 | + if must_exist and not sharefp.exists(): |
---|
1476 | + raise MockS3Error(404, "not found") |
---|
1477 | + return sharefp |
---|
1478 | + |
---|
1479 | + def put_object(self, object_name, data, content_type=None, metadata={}): |
---|
1480 | + assert content_type is None, content_type |
---|
1481 | + assert metadata == {}, metadata |
---|
1482 | + sharefp = self._get_filepath(object_name) |
---|
1483 | + fileutil.fp_make_dirs(sharefp.parent()) |
---|
1484 | + sharefp.setContent(data) |
---|
1485 | + return defer.succeed(None) |
---|
1486 | + |
---|
1487 | + def get_object(self, object_name): |
---|
1488 | + return defer.succeed(self._get_filepath(object_name, must_exist=True).getContent()) |
---|
1489 | + |
---|
1490 | + def head_object(self, object_name): |
---|
1491 | + return defer.execute(self._not_implemented) |
---|
1492 | + |
---|
1493 | + def delete_object(self, object_name): |
---|
1494 | + self._get_filepath(object_name, must_exist=True).remove() |
---|
1495 | + return defer.succeed(None) |
---|
1496 | + |
---|
1497 | + def _not_implemented(self): |
---|
1498 | + raise NotImplementedError |
---|
1499 | + |
---|
1500 | + |
---|
1501 | +class MockS3Error(Exception): |
---|
1502 | + """ |
---|
1503 | + A error class providing custom methods on S3 errors. |
---|
1504 | + """ |
---|
1505 | + def __init__(self, error_code, error_message, request_id="", host_id=""): |
---|
1506 | + Exception.__init__(self, "%r: %r" % (error_code, error_message)) |
---|
1507 | + self.error_code = error_code |
---|
1508 | + self.error_message = error_message |
---|
1509 | + self.request_id = request_id |
---|
1510 | + self.host_id = host_id |
---|
1511 | + |
---|
1512 | + def get_error_code(self): |
---|
1513 | + return self.error_code |
---|
1514 | + |
---|
1515 | + def get_error_message(self): |
---|
1516 | + return self.error_message |
---|
1517 | + |
---|
1518 | + def parse(self, xml_bytes=""): |
---|
1519 | + raise NotImplementedError |
---|
1520 | + |
---|
1521 | + def has_error(self, errorString): |
---|
1522 | + raise NotImplementedError |
---|
1523 | + |
---|
1524 | + def get_error_codes(self): |
---|
1525 | + raise NotImplementedError |
---|
1526 | + |
---|
1527 | + def get_error_messages(self): |
---|
1528 | + raise NotImplementedError |
---|
1529 | + |
---|
1530 | + |
---|
1531 | +# Copied from txaws.s3.model. This ensures that we can test without needing to import txaws. |
---|
1532 | +# This code was under the MIT / Expat licence. |
---|
1533 | + |
---|
1534 | +class BucketItem(object): |
---|
1535 | + """ |
---|
1536 | + The contents of an Amazon S3 bucket. |
---|
1537 | + """ |
---|
1538 | + def __init__(self, key, modification_date, etag, size, storage_class, |
---|
1539 | + owner=None): |
---|
1540 | + self.key = key |
---|
1541 | + self.modification_date = modification_date |
---|
1542 | + self.etag = etag |
---|
1543 | + self.size = size |
---|
1544 | + self.storage_class = storage_class |
---|
1545 | + self.owner = owner |
---|
1546 | + |
---|
1547 | + |
---|
1548 | +class BucketListing(object): |
---|
1549 | + def __init__(self, name, prefix, marker, max_keys, is_truncated, |
---|
1550 | + contents=None, common_prefixes=None): |
---|
1551 | + self.name = name |
---|
1552 | + self.prefix = prefix |
---|
1553 | + self.marker = marker |
---|
1554 | + self.max_keys = max_keys |
---|
1555 | + self.is_truncated = is_truncated |
---|
1556 | + self.contents = contents |
---|
1557 | + self.common_prefixes = common_prefixes |
---|
1558 | addfile ./src/allmydata/storage/backends/s3/mutable.py |
---|
1559 | hunk ./src/allmydata/storage/backends/s3/mutable.py 1 |
---|
1560 | + |
---|
1561 | +import struct |
---|
1562 | +from cStringIO import StringIO |
---|
1563 | +from types import NoneType |
---|
1564 | + |
---|
1565 | +from twisted.internet import defer |
---|
1566 | + |
---|
1567 | +from zope.interface import implements |
---|
1568 | + |
---|
1569 | +from allmydata.interfaces import IMutableShare, BadWriteEnablerError |
---|
1570 | +from allmydata.util import idlib, log |
---|
1571 | +from allmydata.util.assertutil import precondition |
---|
1572 | +from allmydata.util.hashutil import constant_time_compare |
---|
1573 | +from allmydata.storage.common import si_b2a, UnknownMutableContainerVersionError, \ |
---|
1574 | + DataTooLargeError |
---|
1575 | +from allmydata.storage.backends.base import testv_compare |
---|
1576 | +from allmydata.mutable.layout import MUTABLE_MAGIC |
---|
1577 | +from allmydata.storage.backends.s3.s3_common import get_s3_share_key |
---|
1578 | + |
---|
1579 | + |
---|
1580 | +# The MutableS3Share is like the ImmutableS3Share, but used for mutable data. |
---|
1581 | +# It has a different layout. See docs/mutable.rst for more details. |
---|
1582 | + |
---|
1583 | +# # offset size name |
---|
1584 | +# 1 0 32 magic verstr "tahoe mutable container v1" plus binary |
---|
1585 | +# 2 32 20 write enabler's nodeid |
---|
1586 | +# 3 52 32 write enabler |
---|
1587 | +# 4 84 8 data size (actual share data present) (a) |
---|
1588 | +# 5 92 8 offset of (8) count of extra leases (after data) |
---|
1589 | +# 6 100 368 four leases, 92 bytes each, unused |
---|
1590 | +# 7 468 (a) data |
---|
1591 | +# 8 ?? 4 count of extra leases |
---|
1592 | +# 9 ?? n*92 extra leases |
---|
1593 | + |
---|
1594 | + |
---|
1595 | +# The struct module doc says that L's are 4 bytes in size, and that Q's are |
---|
1596 | +# 8 bytes in size. Since compatibility depends upon this, double-check it. |
---|
1597 | +assert struct.calcsize(">L") == 4, struct.calcsize(">L") |
---|
1598 | +assert struct.calcsize(">Q") == 8, struct.calcsize(">Q") |
---|
1599 | + |
---|
1600 | + |
---|
1601 | +class MutableS3Share(object): |
---|
1602 | + implements(IMutableShare) |
---|
1603 | + |
---|
1604 | + sharetype = "mutable" |
---|
1605 | + DATA_LENGTH_OFFSET = struct.calcsize(">32s20s32s") |
---|
1606 | + EXTRA_LEASE_OFFSET = DATA_LENGTH_OFFSET + 8 |
---|
1607 | + HEADER_SIZE = struct.calcsize(">32s20s32sQQ") # doesn't include leases |
---|
1608 | + LEASE_SIZE = struct.calcsize(">LL32s32s20s") |
---|
1609 | + assert LEASE_SIZE == 92 |
---|
1610 | + DATA_OFFSET = HEADER_SIZE + 4*LEASE_SIZE |
---|
1611 | + assert DATA_OFFSET == 468, DATA_OFFSET |
---|
1612 | + NUM_EXTRA_LEASES_SIZE = struct.calcsize(">L") |
---|
1613 | + |
---|
1614 | + MAGIC = MUTABLE_MAGIC |
---|
1615 | + assert len(MAGIC) == 32 |
---|
1616 | + MAX_SIZE = 2*1000*1000*1000 # 2GB, kind of arbitrary |
---|
1617 | + # TODO: decide upon a policy for max share size |
---|
1618 | + |
---|
1619 | + def __init__(self, s3bucket, data, storageindex, shnum, parent=None): |
---|
1620 | + """ |
---|
1621 | + Clients should use the load_mutable_s3_share and create_mutable_s3_share |
---|
1622 | + factory functions rather than creating instances directly. |
---|
1623 | + """ |
---|
1624 | + precondition(isinstance(data, (str, NoneType)), type(data)) |
---|
1625 | + precondition(isinstance(storageindex, str), storageindex=storageindex) |
---|
1626 | + precondition(isinstance(shnum, int), shnum=shnum) |
---|
1627 | + |
---|
1628 | + self._s3bucket = s3bucket |
---|
1629 | + self._storageindex = storageindex |
---|
1630 | + self._shnum = shnum |
---|
1631 | + self._key = get_s3_share_key(storageindex, shnum) |
---|
1632 | + |
---|
1633 | + # _buf is a file object containing a local copy of the share contents. |
---|
1634 | + self._buf = StringIO() |
---|
1635 | + if data is not None: |
---|
1636 | + (magic, write_enabler_nodeid, write_enabler, |
---|
1637 | + data_length, extra_lease_offset) = struct.unpack(">32s20s32sQQ", data[:self.HEADER_SIZE]) |
---|
1638 | + |
---|
1639 | + if magic != self.MAGIC: |
---|
1640 | + msg = "%r had magic %r but we wanted %r" % (self, magic, self.MAGIC) |
---|
1641 | + raise UnknownMutableContainerVersionError(msg) |
---|
1642 | + |
---|
1643 | + self._buf.write(data) |
---|
1644 | + self._data_length = data_length |
---|
1645 | + |
---|
1646 | + self.parent = parent # for logging |
---|
1647 | + |
---|
1648 | + def __repr__(self): |
---|
1649 | + return ("<%s at %r key %r>" % (self.__class__.__name__, self._s3bucket, self._key,)) |
---|
1650 | + |
---|
1651 | + def log(self, *args, **kwargs): |
---|
1652 | + if self.parent: |
---|
1653 | + return self.parent.log(*args, **kwargs) |
---|
1654 | + |
---|
1655 | + def create(self, serverid, write_enabler): |
---|
1656 | + # Unlike the disk backend, we don't check that the S3 object does not exist; |
---|
1657 | + # we assume that it does not because create was used, and no-one else should be |
---|
1658 | + # writing to the bucket. |
---|
1659 | + |
---|
1660 | + # There are no extra leases, but for compatibility, the offset they would have |
---|
1661 | + # still needs to be stored in the header. |
---|
1662 | + self._data_length = 0 |
---|
1663 | + num_extra_leases = 0 |
---|
1664 | + extra_lease_offset = self.DATA_OFFSET + self._data_length |
---|
1665 | + header = struct.pack(">32s20s32sQQ", |
---|
1666 | + self.MAGIC, serverid, write_enabler, |
---|
1667 | + self._data_length, extra_lease_offset, |
---|
1668 | + ) |
---|
1669 | + leases = ("\x00"*self.LEASE_SIZE) * 4 |
---|
1670 | + self._buf.write(header + leases) |
---|
1671 | + # data goes here, empty at creation |
---|
1672 | + self._buf.write(struct.pack(">L", num_extra_leases)) |
---|
1673 | + |
---|
1674 | + # As an optimization, we don't create empty share objects, we only write the |
---|
1675 | + # data when writev is called. Note that this depends on there being a call |
---|
1676 | + # to writev for shares of empty files, which needs a test. |
---|
1677 | + return self |
---|
1678 | + |
---|
1679 | + def get_storage_index(self): |
---|
1680 | + return self._storageindex |
---|
1681 | + |
---|
1682 | + def get_storage_index_string(self): |
---|
1683 | + return si_b2a(self._storageindex) |
---|
1684 | + |
---|
1685 | + def get_shnum(self): |
---|
1686 | + return self._shnum |
---|
1687 | + |
---|
1688 | + def get_size(self): |
---|
1689 | + self._buf.seek(0, 2) # 2 == os.SEEK_END in Python 2.5+ |
---|
1690 | + return self._buf.tell() |
---|
1691 | + |
---|
1692 | + def get_data_length(self): |
---|
1693 | + return self._data_length |
---|
1694 | + |
---|
1695 | + def get_used_space(self): |
---|
1696 | + # We're not charged for any per-object overheads in S3, so object data sizes are |
---|
1697 | + # what we're interested in for statistics and accounting. |
---|
1698 | + return self.get_size() |
---|
1699 | + |
---|
1700 | + def unlink(self): |
---|
1701 | + self._discard() |
---|
1702 | + try: |
---|
1703 | + return self._s3bucket.delete_object(self._key) |
---|
1704 | + except self._s3bucket.S3Error, e: |
---|
1705 | + if e.get_error_code() != 404: |
---|
1706 | + raise |
---|
1707 | + return defer.succeed(None) |
---|
1708 | + |
---|
1709 | + def _discard(self): |
---|
1710 | + self._buf = None |
---|
1711 | + |
---|
1712 | + def _read_share_data(self, offset, length): |
---|
1713 | + precondition(offset >= 0, offset=offset) |
---|
1714 | + if offset+length > self._data_length: |
---|
1715 | + # reads beyond the end of the data are truncated. Reads that |
---|
1716 | + # start beyond the end of the data return an empty string. |
---|
1717 | + length = max(0, self._data_length-offset) |
---|
1718 | + if length == 0: |
---|
1719 | + return "" |
---|
1720 | + precondition(offset+length <= self._data_length) |
---|
1721 | + self._buf.seek(self.DATA_OFFSET+offset) |
---|
1722 | + data = self._buf.read(length) |
---|
1723 | + return data |
---|
1724 | + |
---|
1725 | + def _write_share_data(self, offset, data): |
---|
1726 | + length = len(data) |
---|
1727 | + precondition(offset >= 0, offset=offset) |
---|
1728 | + precondition(offset+length < self.MAX_SIZE, offset=offset, length=length) |
---|
1729 | + |
---|
1730 | + self._buf.seek(self.DATA_OFFSET + offset) |
---|
1731 | + self._buf.write(data) |
---|
1732 | + if offset+length >= self._data_length: |
---|
1733 | + self._data_length = offset+length |
---|
1734 | + self._change_container_size() |
---|
1735 | + return defer.succeed(None) |
---|
1736 | + |
---|
1737 | + def _change_container_size(self): |
---|
1738 | + new_container_size = self.DATA_OFFSET + self._data_length + self.NUM_EXTRA_LEASES_SIZE |
---|
1739 | + |
---|
1740 | + self._buf.seek(self.DATA_LENGTH_OFFSET) |
---|
1741 | + self._buf.write(struct.pack(">Q", self._data_length)) |
---|
1742 | + |
---|
1743 | + extra_lease_offset = self.DATA_OFFSET + self._data_length |
---|
1744 | + self._buf.seek(self.EXTRA_LEASE_OFFSET) |
---|
1745 | + self._buf.write(struct.pack(">Q", extra_lease_offset)) |
---|
1746 | + |
---|
1747 | + # Just discard any extra leases. |
---|
1748 | + self._buf.seek(extra_lease_offset) |
---|
1749 | + self._buf.write(struct.pack(">L", 0)) |
---|
1750 | + assert self._buf.tell() == new_container_size |
---|
1751 | + self._buf.truncate(new_container_size) |
---|
1752 | + |
---|
1753 | + def readv(self, readv): |
---|
1754 | + datav = [] |
---|
1755 | + for (offset, length) in readv: |
---|
1756 | + datav.append(self._read_share_data(offset, length)) |
---|
1757 | + return defer.succeed(datav) |
---|
1758 | + |
---|
1759 | + def check_write_enabler(self, write_enabler): |
---|
1760 | + self._buf.seek(0) |
---|
1761 | + data = self._buf.read(self.HEADER_SIZE) |
---|
1762 | + (magic, write_enabler_nodeid, real_write_enabler, |
---|
1763 | + data_length, extra_least_offset) = struct.unpack(">32s20s32sQQ", data) |
---|
1764 | + assert magic == self.MAGIC |
---|
1765 | + |
---|
1766 | + # avoid a timing attack |
---|
1767 | + if not constant_time_compare(write_enabler, real_write_enabler): |
---|
1768 | + # accomodate share migration by reporting the nodeid used for the |
---|
1769 | + # old write enabler. |
---|
1770 | + self.log(format="bad write enabler on SI %(si)s," |
---|
1771 | + " recorded by nodeid %(nodeid)s", |
---|
1772 | + facility="tahoe.storage", |
---|
1773 | + level=log.WEIRD, umid="DF2fCR", |
---|
1774 | + si=self.get_storage_index_string(), |
---|
1775 | + nodeid=idlib.nodeid_b2a(write_enabler_nodeid)) |
---|
1776 | + msg = "The write enabler was recorded by nodeid '%s'." % \ |
---|
1777 | + (idlib.nodeid_b2a(write_enabler_nodeid),) |
---|
1778 | + raise BadWriteEnablerError(msg) |
---|
1779 | + return defer.succeed(None) |
---|
1780 | + |
---|
1781 | + def check_testv(self, testv): |
---|
1782 | + test_good = True |
---|
1783 | + for (offset, length, operator, specimen) in testv: |
---|
1784 | + data = self._read_share_data(offset, length) |
---|
1785 | + if not testv_compare(data, operator, specimen): |
---|
1786 | + test_good = False |
---|
1787 | + break |
---|
1788 | + return defer.succeed(test_good) |
---|
1789 | + |
---|
1790 | + def writev(self, datav, new_length): |
---|
1791 | + precondition(new_length is None or new_length >= 0, new_length=new_length) |
---|
1792 | + for (offset, data) in datav: |
---|
1793 | + precondition(offset >= 0, offset=offset) |
---|
1794 | + if offset+len(data) > self.MAX_SIZE: |
---|
1795 | + raise DataTooLargeError() |
---|
1796 | + |
---|
1797 | + for (offset, data) in datav: |
---|
1798 | + self._write_share_data(offset, data) |
---|
1799 | + |
---|
1800 | + # new_length can only be used to truncate, not extend. |
---|
1801 | + if new_length is not None and new_length < self._data_length: |
---|
1802 | + self._data_length = new_length |
---|
1803 | + self._change_container_size() |
---|
1804 | + |
---|
1805 | + # We really want to stream writes to S3, but txaws doesn't support |
---|
1806 | + # that yet (and neither does IS3Bucket, since that's a thin wrapper |
---|
1807 | + # over the txaws S3 API). See |
---|
1808 | + # https://bugs.launchpad.net/txaws/+bug/767205 and |
---|
1809 | + # https://bugs.launchpad.net/txaws/+bug/783801 |
---|
1810 | + data = self._buf.getvalue() |
---|
1811 | + return self._s3bucket.put_object(self._key, data) |
---|
1812 | + |
---|
1813 | + def close(self): |
---|
1814 | + self._discard() |
---|
1815 | + return defer.succeed(None) |
---|
1816 | + |
---|
1817 | + # XXX should these lease methods be necessary? |
---|
1818 | + |
---|
1819 | + def get_leases(self): |
---|
1820 | + pass |
---|
1821 | + |
---|
1822 | + def add_lease(self, lease_info): |
---|
1823 | + pass |
---|
1824 | + |
---|
1825 | + def renew_lease(self, renew_secret, new_expire_time): |
---|
1826 | + pass |
---|
1827 | + |
---|
1828 | + def add_or_renew_lease(self, lease_info): |
---|
1829 | + pass |
---|
1830 | + |
---|
1831 | + def cancel_lease(self, cancel_secret): |
---|
1832 | + pass |
---|
1833 | + |
---|
1834 | + def _get_filepath(self): |
---|
1835 | + # For use by tests, only with the mock S3 backend. |
---|
1836 | + # It is OK that _get_filepath doesn't exist on a real S3Bucket object. |
---|
1837 | + return self._s3bucket._get_filepath(self._key) |
---|
1838 | + |
---|
1839 | + |
---|
1840 | +def load_mutable_s3_share(s3bucket, data, storageindex=None, shnum=None, parent=None): |
---|
1841 | + return MutableS3Share(s3bucket, data, storageindex=storageindex, shnum=shnum, |
---|
1842 | + parent=parent) |
---|
1843 | + |
---|
1844 | +def create_mutable_s3_share(s3bucket, serverid, write_enabler, storageindex=None, shnum=None, parent=None): |
---|
1845 | + return MutableS3Share(s3bucket, None, storageindex=storageindex, shnum=shnum, |
---|
1846 | + parent=parent).create(serverid, write_enabler) |
---|
1847 | addfile ./src/allmydata/storage/backends/s3/s3_backend.py |
---|
1848 | hunk ./src/allmydata/storage/backends/s3/s3_backend.py 1 |
---|
1849 | + |
---|
1850 | +from zope.interface import implements |
---|
1851 | +from allmydata.interfaces import IStorageBackend, IShareSet |
---|
1852 | + |
---|
1853 | +from allmydata.node import InvalidValueError |
---|
1854 | +from allmydata.util.deferredutil import gatherResults |
---|
1855 | +from allmydata.storage.common import si_a2b |
---|
1856 | +from allmydata.storage.bucket import BucketWriter |
---|
1857 | +from allmydata.storage.backends.base import Backend, ShareSet |
---|
1858 | +from allmydata.storage.backends.s3.immutable import ImmutableS3ShareForReading, ImmutableS3ShareForWriting |
---|
1859 | +from allmydata.storage.backends.s3.mutable import load_mutable_s3_share, create_mutable_s3_share |
---|
1860 | +from allmydata.storage.backends.s3.s3_common import get_s3_share_key, list_objects, NUM_RE |
---|
1861 | +from allmydata.mutable.layout import MUTABLE_MAGIC |
---|
1862 | + |
---|
1863 | + |
---|
1864 | +def get_s3_share(s3bucket, storageindex, shnum): |
---|
1865 | + key = get_s3_share_key(storageindex, shnum) |
---|
1866 | + d = s3bucket.get_object(key) |
---|
1867 | + def _make_share(data): |
---|
1868 | + if data.startswith(MUTABLE_MAGIC): |
---|
1869 | + return load_mutable_s3_share(s3bucket, data, storageindex, shnum) |
---|
1870 | + else: |
---|
1871 | + # assume it's immutable |
---|
1872 | + return ImmutableS3ShareForReading(s3bucket, storageindex, shnum, data=data) |
---|
1873 | + d.addCallback(_make_share) |
---|
1874 | + return d |
---|
1875 | + |
---|
1876 | + |
---|
1877 | +def configure_s3_backend(storedir, config): |
---|
1878 | + from allmydata.storage.backends.s3.s3_bucket import S3Bucket |
---|
1879 | + |
---|
1880 | + if config.get_config("storage", "readonly", False, boolean=True): |
---|
1881 | + raise InvalidValueError("[storage]readonly is not supported by the S3 backend; " |
---|
1882 | + "make the S3 bucket read-only instead.") |
---|
1883 | + |
---|
1884 | + corruption_advisory_dir = storedir.child("corruption-advisories") |
---|
1885 | + |
---|
1886 | + accesskeyid = config.get_config("storage", "s3.access_key_id") |
---|
1887 | + secretkey = config.get_or_create_private_config("s3secret") |
---|
1888 | + usertoken = config.get_optional_private_config("s3usertoken") |
---|
1889 | + producttoken = config.get_optional_private_config("s3producttoken") |
---|
1890 | + if producttoken and not usertoken: |
---|
1891 | + raise InvalidValueError("If private/s3producttoken is present, private/s3usertoken must also be present.") |
---|
1892 | + url = config.get_config("storage", "s3.url", "http://s3.amazonaws.com") |
---|
1893 | + bucketname = config.get_config("storage", "s3.bucket") |
---|
1894 | + |
---|
1895 | + s3bucket = S3Bucket(accesskeyid, secretkey, url, bucketname, usertoken, producttoken) |
---|
1896 | + return S3Backend(s3bucket, corruption_advisory_dir) |
---|
1897 | + |
---|
1898 | + |
---|
1899 | +class S3Backend(Backend): |
---|
1900 | + implements(IStorageBackend) |
---|
1901 | + |
---|
1902 | + def __init__(self, s3bucket, corruption_advisory_dir=None): |
---|
1903 | + Backend.__init__(self) |
---|
1904 | + self._s3bucket = s3bucket |
---|
1905 | + |
---|
1906 | + # we don't actually create the corruption-advisory dir until necessary |
---|
1907 | + self._corruption_advisory_dir = corruption_advisory_dir |
---|
1908 | + |
---|
1909 | + # set of (storageindex, shnum) of incoming shares |
---|
1910 | + self._incomingset = set() |
---|
1911 | + |
---|
1912 | + def get_sharesets_for_prefix(self, prefix): |
---|
1913 | + d = list_objects(self._s3bucket, 'shares/%s/' % (prefix,)) |
---|
1914 | + def _get_sharesets(res): |
---|
1915 | + # XXX this enumerates all shares to get the set of SIs. |
---|
1916 | + # Is there a way to enumerate SIs more efficiently? |
---|
1917 | + si_strings = set() |
---|
1918 | + for item in res.contents: |
---|
1919 | + # XXX better error handling |
---|
1920 | + path = item.key.split('/') |
---|
1921 | + assert path[0:2] == ["shares", prefix] |
---|
1922 | + si_strings.add(path[2]) |
---|
1923 | + |
---|
1924 | + # XXX we want this to be deterministic, so we return the sharesets sorted |
---|
1925 | + # by their si_strings, but we shouldn't need to explicitly re-sort them |
---|
1926 | + # because list_objects returns a sorted list. |
---|
1927 | + return [S3ShareSet(si_a2b(s), self._s3bucket, self._incomingset) for s in sorted(si_strings)] |
---|
1928 | + d.addCallback(_get_sharesets) |
---|
1929 | + return d |
---|
1930 | + |
---|
1931 | + def get_shareset(self, storageindex): |
---|
1932 | + return S3ShareSet(storageindex, self._s3bucket, self._incomingset) |
---|
1933 | + |
---|
1934 | + def fill_in_space_stats(self, stats): |
---|
1935 | + # TODO: query space usage of S3 bucket |
---|
1936 | + # TODO: query whether the bucket is read-only and set |
---|
1937 | + # accepting_immutable_shares accordingly. |
---|
1938 | + stats['storage_server.accepting_immutable_shares'] = 1 |
---|
1939 | + |
---|
1940 | + def get_available_space(self): |
---|
1941 | + # TODO: query space usage of S3 bucket |
---|
1942 | + return 2**64 |
---|
1943 | + |
---|
1944 | + |
---|
1945 | +class S3ShareSet(ShareSet): |
---|
1946 | + implements(IShareSet) |
---|
1947 | + |
---|
1948 | + def __init__(self, storageindex, s3bucket, incomingset): |
---|
1949 | + ShareSet.__init__(self, storageindex) |
---|
1950 | + self._s3bucket = s3bucket |
---|
1951 | + self._incomingset = incomingset |
---|
1952 | + self._key = get_s3_share_key(storageindex) |
---|
1953 | + |
---|
1954 | + def get_overhead(self): |
---|
1955 | + return 0 |
---|
1956 | + |
---|
1957 | + def get_shares(self): |
---|
1958 | + d = list_objects(self._s3bucket, self._key) |
---|
1959 | + def _get_shares(res): |
---|
1960 | + si = self.get_storage_index() |
---|
1961 | + shnums = [] |
---|
1962 | + for item in res.contents: |
---|
1963 | + assert item.key.startswith(self._key), item.key |
---|
1964 | + path = item.key.split('/') |
---|
1965 | + if len(path) == 4: |
---|
1966 | + shnumstr = path[3] |
---|
1967 | + if NUM_RE.match(shnumstr): |
---|
1968 | + shnums.append(int(shnumstr)) |
---|
1969 | + |
---|
1970 | + return gatherResults([get_s3_share(self._s3bucket, si, shnum) |
---|
1971 | + for shnum in sorted(shnums)]) |
---|
1972 | + d.addCallback(_get_shares) |
---|
1973 | + # TODO: return information about corrupt shares. |
---|
1974 | + d.addCallback(lambda shares: (shares, set()) ) |
---|
1975 | + return d |
---|
1976 | + |
---|
1977 | + def get_share(self, shnum): |
---|
1978 | + return get_s3_share(self._s3bucket, self.get_storage_index(), shnum) |
---|
1979 | + |
---|
1980 | + def has_incoming(self, shnum): |
---|
1981 | + return (self.get_storage_index(), shnum) in self._incomingset |
---|
1982 | + |
---|
1983 | + def make_bucket_writer(self, storageserver, shnum, max_space_per_bucket, lease_info, canary): |
---|
1984 | + immsh = ImmutableS3ShareForWriting(self._s3bucket, self.get_storage_index(), shnum, |
---|
1985 | + max_space_per_bucket, self._incomingset) |
---|
1986 | + return BucketWriter(storageserver, immsh, lease_info, canary) |
---|
1987 | + |
---|
1988 | + def _create_mutable_share(self, storageserver, shnum, write_enabler): |
---|
1989 | + serverid = storageserver.get_serverid() |
---|
1990 | + return create_mutable_s3_share(self._s3bucket, serverid, write_enabler, |
---|
1991 | + self.get_storage_index(), shnum, parent=storageserver) |
---|
1992 | + |
---|
1993 | + def _clean_up_after_unlink(self): |
---|
1994 | + pass |
---|
1995 | + |
---|
1996 | + def _get_sharedir(self): |
---|
1997 | + # For use by tests, only with the mock S3 backend. |
---|
1998 | + # It is OK that _get_filepath doesn't exist on a real S3Bucket object. |
---|
1999 | + return self._s3bucket._get_filepath(self._key) |
---|
2000 | + |
---|
2001 | + def get_leases(self): |
---|
2002 | + raise NotImplementedError |
---|
2003 | + |
---|
2004 | + def add_or_renew_lease(self, lease_info): |
---|
2005 | + raise NotImplementedError |
---|
2006 | + |
---|
2007 | + def renew_lease(self, renew_secret, new_expiration_time): |
---|
2008 | + raise NotImplementedError |
---|
2009 | addfile ./src/allmydata/storage/backends/s3/s3_bucket.py |
---|
2010 | hunk ./src/allmydata/storage/backends/s3/s3_bucket.py 1 |
---|
2011 | + |
---|
2012 | +from twisted.internet.defer import maybeDeferred |
---|
2013 | + |
---|
2014 | +from zope.interface import implements |
---|
2015 | +from allmydata.storage.backends.s3.s3_common import IS3Bucket |
---|
2016 | + |
---|
2017 | + |
---|
2018 | +class S3Bucket(object): |
---|
2019 | + implements(IS3Bucket) |
---|
2020 | + """ |
---|
2021 | + I represent a real S3 bucket, accessed using the txaws library. |
---|
2022 | + """ |
---|
2023 | + |
---|
2024 | + def __init__(self, access_key, secret_key, url, bucketname, usertoken=None, producttoken=None): |
---|
2025 | + # We only depend on txaws when this class is actually instantiated. |
---|
2026 | + from txaws.credentials import AWSCredentials |
---|
2027 | + from txaws.service import AWSServiceEndpoint |
---|
2028 | + from txaws.s3.client import S3Client, Query |
---|
2029 | + from txaws.s3 import model |
---|
2030 | + from txaws.s3.exception import S3Error |
---|
2031 | + |
---|
2032 | + creds = AWSCredentials(access_key=access_key, secret_key=secret_key) |
---|
2033 | + endpoint = AWSServiceEndpoint(uri=url) |
---|
2034 | + |
---|
2035 | + query_factory = None |
---|
2036 | + if usertoken is not None: |
---|
2037 | + def make_query(*args, **kwargs): |
---|
2038 | + amz_headers = kwargs.get("amz_headers", {}) |
---|
2039 | + if producttoken is not None: |
---|
2040 | + amz_headers["security-token"] = (usertoken, producttoken) |
---|
2041 | + else: |
---|
2042 | + amz_headers["security-token"] = usertoken |
---|
2043 | + kwargs["amz_headers"] = amz_headers |
---|
2044 | + |
---|
2045 | + return Query(*args, **kwargs) |
---|
2046 | + query_factory = make_query |
---|
2047 | + |
---|
2048 | + self.client = S3Client(creds=creds, endpoint=endpoint, query_factory=query_factory) |
---|
2049 | + self.bucketname = bucketname |
---|
2050 | + self.model = model |
---|
2051 | + self.S3Error = S3Error |
---|
2052 | + |
---|
2053 | + def __repr__(self): |
---|
2054 | + return ("<%s %r>" % (self.__class__.__name__, self.bucketname,)) |
---|
2055 | + |
---|
2056 | + def create(self): |
---|
2057 | + return maybeDeferred(self.client.create, self.bucketname) |
---|
2058 | + |
---|
2059 | + def delete(self): |
---|
2060 | + return maybeDeferred(self.client.delete, self.bucketname) |
---|
2061 | + |
---|
2062 | + # We want to be able to do prefix queries, but txaws 0.2 doesn't implement that. |
---|
2063 | + def list_all_objects(self): |
---|
2064 | + return maybeDeferred(self.client.get_bucket, self.bucketname) |
---|
2065 | + |
---|
2066 | + def put_object(self, object_name, data, content_type=None, metadata={}): |
---|
2067 | + return maybeDeferred(self.client.put_object, self.bucketname, |
---|
2068 | + object_name, data, content_type, metadata) |
---|
2069 | + |
---|
2070 | + def get_object(self, object_name): |
---|
2071 | + return maybeDeferred(self.client.get_object, self.bucketname, object_name) |
---|
2072 | + |
---|
2073 | + def head_object(self, object_name): |
---|
2074 | + return maybeDeferred(self.client.head_object, self.bucketname, object_name) |
---|
2075 | + |
---|
2076 | + def delete_object(self, object_name): |
---|
2077 | + return maybeDeferred(self.client.delete_object, self.bucketname, object_name) |
---|
2078 | + |
---|
2079 | + def put_policy(self, policy): |
---|
2080 | + """ |
---|
2081 | + Set access control policy on a bucket. |
---|
2082 | + """ |
---|
2083 | + query = self.client.query_factory( |
---|
2084 | + action='PUT', creds=self.client.creds, endpoint=self.client.endpoint, |
---|
2085 | + bucket=self.bucketname, object_name='?policy', data=policy) |
---|
2086 | + return maybeDeferred(query.submit) |
---|
2087 | + |
---|
2088 | + def get_policy(self): |
---|
2089 | + query = self.client.query_factory( |
---|
2090 | + action='GET', creds=self.client.creds, endpoint=self.client.endpoint, |
---|
2091 | + bucket=self.bucketname, object_name='?policy') |
---|
2092 | + return maybeDeferred(query.submit) |
---|
2093 | + |
---|
2094 | + def delete_policy(self): |
---|
2095 | + query = self.client.query_factory( |
---|
2096 | + action='DELETE', creds=self.client.creds, endpoint=self.client.endpoint, |
---|
2097 | + bucket=self.bucketname, object_name='?policy') |
---|
2098 | + return maybeDeferred(query.submit) |
---|
2099 | addfile ./src/allmydata/storage/backends/s3/s3_common.py |
---|
2100 | hunk ./src/allmydata/storage/backends/s3/s3_common.py 1 |
---|
2101 | + |
---|
2102 | +import re |
---|
2103 | + |
---|
2104 | +from zope.interface import Interface |
---|
2105 | + |
---|
2106 | +from allmydata.storage.common import si_b2a |
---|
2107 | + |
---|
2108 | + |
---|
2109 | +# The S3 bucket has keys of the form shares/$PREFIX/$STORAGEINDEX/$SHNUM . |
---|
2110 | + |
---|
2111 | +def get_s3_share_key(si, shnum=None): |
---|
2112 | + sistr = si_b2a(si) |
---|
2113 | + if shnum is None: |
---|
2114 | + return "shares/%s/%s/" % (sistr[:2], sistr) |
---|
2115 | + else: |
---|
2116 | + return "shares/%s/%s/%d" % (sistr[:2], sistr, shnum) |
---|
2117 | + |
---|
2118 | +def list_objects(s3bucket, prefix, marker='/'): |
---|
2119 | + # XXX we want to be able to implement this in terms of a prefix query. Fake it for now. |
---|
2120 | + #d = self._s3bucket.list_objects('shares/%s/' % (prefix,), marker) |
---|
2121 | + d = s3bucket.list_all_objects() |
---|
2122 | + def _filter(res): |
---|
2123 | + res.contents = [item for item in res.contents if item.key.startswith(prefix)] |
---|
2124 | + return res |
---|
2125 | + d.addCallback(_filter) |
---|
2126 | + return d |
---|
2127 | + |
---|
2128 | +NUM_RE=re.compile("^[0-9]+$") |
---|
2129 | + |
---|
2130 | + |
---|
2131 | +class IS3Bucket(Interface): |
---|
2132 | + """ |
---|
2133 | + I represent an S3 bucket. |
---|
2134 | + """ |
---|
2135 | + def create(): |
---|
2136 | + """ |
---|
2137 | + Create this bucket. |
---|
2138 | + """ |
---|
2139 | + |
---|
2140 | + def delete(): |
---|
2141 | + """ |
---|
2142 | + Delete this bucket. |
---|
2143 | + The bucket must be empty before it can be deleted. |
---|
2144 | + """ |
---|
2145 | + |
---|
2146 | + def list_all_objects(): |
---|
2147 | + """ |
---|
2148 | + Get a BucketListing that lists all the objects in this bucket. |
---|
2149 | + """ |
---|
2150 | + |
---|
2151 | + def put_object(object_name, data, content_type=None, metadata={}): |
---|
2152 | + """ |
---|
2153 | + Put an object in this bucket. |
---|
2154 | + Any existing object of the same name will be replaced. |
---|
2155 | + """ |
---|
2156 | + |
---|
2157 | + def get_object(object_name): |
---|
2158 | + """ |
---|
2159 | + Get an object from this bucket. |
---|
2160 | + """ |
---|
2161 | + |
---|
2162 | + def head_object(object_name): |
---|
2163 | + """ |
---|
2164 | + Retrieve object metadata only. |
---|
2165 | + """ |
---|
2166 | + |
---|
2167 | + def delete_object(object_name): |
---|
2168 | + """ |
---|
2169 | + Delete an object from this bucket. |
---|
2170 | + Once deleted, there is no method to restore or undelete an object. |
---|
2171 | + """ |
---|
2172 | addfile ./src/allmydata/storage/bucket.py |
---|
2173 | hunk ./src/allmydata/storage/bucket.py 1 |
---|
2174 | + |
---|
2175 | +import time |
---|
2176 | + |
---|
2177 | +from foolscap.api import Referenceable |
---|
2178 | +from twisted.internet import defer |
---|
2179 | + |
---|
2180 | +from zope.interface import implements |
---|
2181 | +from allmydata.interfaces import RIBucketWriter, RIBucketReader |
---|
2182 | + |
---|
2183 | +from allmydata.util import base32, log |
---|
2184 | +from allmydata.util.assertutil import precondition |
---|
2185 | + |
---|
2186 | + |
---|
2187 | +class BucketWriter(Referenceable): |
---|
2188 | + implements(RIBucketWriter) |
---|
2189 | + |
---|
2190 | + def __init__(self, ss, immutableshare, lease_info, canary): |
---|
2191 | + self.ss = ss |
---|
2192 | + self._canary = canary |
---|
2193 | + self._disconnect_marker = canary.notifyOnDisconnect(self._disconnected) |
---|
2194 | + self.closed = False |
---|
2195 | + self.throw_out_all_data = False |
---|
2196 | + self._share = immutableshare |
---|
2197 | + # also, add our lease to the file now, so that other ones can be |
---|
2198 | + # added by simultaneous uploaders |
---|
2199 | + self._share.add_lease(lease_info) |
---|
2200 | + |
---|
2201 | + def allocated_size(self): |
---|
2202 | + return self._share.get_allocated_size() |
---|
2203 | + |
---|
2204 | + def _add_latency(self, res, name, start): |
---|
2205 | + self.ss.add_latency(name, time.time() - start) |
---|
2206 | + self.ss.count(name) |
---|
2207 | + return res |
---|
2208 | + |
---|
2209 | + def remote_write(self, offset, data): |
---|
2210 | + start = time.time() |
---|
2211 | + precondition(not self.closed) |
---|
2212 | + if self.throw_out_all_data: |
---|
2213 | + return defer.succeed(None) |
---|
2214 | + d = self._share.write_share_data(offset, data) |
---|
2215 | + d.addBoth(self._add_latency, "write", start) |
---|
2216 | + return d |
---|
2217 | + |
---|
2218 | + def remote_close(self): |
---|
2219 | + precondition(not self.closed) |
---|
2220 | + start = time.time() |
---|
2221 | + |
---|
2222 | + d = defer.succeed(None) |
---|
2223 | + d.addCallback(lambda ign: self._share.close()) |
---|
2224 | + # XXX should this be self._share.get_used_space() ? |
---|
2225 | + d.addCallback(lambda ign: self._share.get_size()) |
---|
2226 | + def _got_size(consumed_size): |
---|
2227 | + self._share = None |
---|
2228 | + self.closed = True |
---|
2229 | + self._canary.dontNotifyOnDisconnect(self._disconnect_marker) |
---|
2230 | + |
---|
2231 | + self.ss.bucket_writer_closed(self, consumed_size) |
---|
2232 | + d.addCallback(_got_size) |
---|
2233 | + d.addBoth(self._add_latency, "close", start) |
---|
2234 | + return d |
---|
2235 | + |
---|
2236 | + def _disconnected(self): |
---|
2237 | + if not self.closed: |
---|
2238 | + return self._abort() |
---|
2239 | + return defer.succeed(None) |
---|
2240 | + |
---|
2241 | + def remote_abort(self): |
---|
2242 | + log.msg("storage: aborting write to share %r" % self._share, |
---|
2243 | + facility="tahoe.storage", level=log.UNUSUAL) |
---|
2244 | + if not self.closed: |
---|
2245 | + self._canary.dontNotifyOnDisconnect(self._disconnect_marker) |
---|
2246 | + d = self._abort() |
---|
2247 | + def _count(ign): |
---|
2248 | + self.ss.count("abort") |
---|
2249 | + d.addBoth(_count) |
---|
2250 | + return d |
---|
2251 | + |
---|
2252 | + def _abort(self): |
---|
2253 | + d = defer.succeed(None) |
---|
2254 | + if self.closed: |
---|
2255 | + return d |
---|
2256 | + d.addCallback(lambda ign: self._share.unlink()) |
---|
2257 | + def _unlinked(ign): |
---|
2258 | + self._share = None |
---|
2259 | + |
---|
2260 | + # We are now considered closed for further writing. We must tell |
---|
2261 | + # the storage server about this so that it stops expecting us to |
---|
2262 | + # use the space it allocated for us earlier. |
---|
2263 | + self.closed = True |
---|
2264 | + self.ss.bucket_writer_closed(self, 0) |
---|
2265 | + d.addCallback(_unlinked) |
---|
2266 | + return d |
---|
2267 | + |
---|
2268 | + |
---|
2269 | +class BucketReader(Referenceable): |
---|
2270 | + implements(RIBucketReader) |
---|
2271 | + |
---|
2272 | + def __init__(self, ss, share): |
---|
2273 | + self.ss = ss |
---|
2274 | + self._share = share |
---|
2275 | + self.storageindex = share.get_storage_index() |
---|
2276 | + self.shnum = share.get_shnum() |
---|
2277 | + |
---|
2278 | + def __repr__(self): |
---|
2279 | + return "<%s %s %s>" % (self.__class__.__name__, |
---|
2280 | + base32.b2a_l(self.storageindex[:8], 60), |
---|
2281 | + self.shnum) |
---|
2282 | + |
---|
2283 | + def _add_latency(self, res, name, start): |
---|
2284 | + self.ss.add_latency(name, time.time() - start) |
---|
2285 | + self.ss.count(name) |
---|
2286 | + return res |
---|
2287 | + |
---|
2288 | + def remote_read(self, offset, length): |
---|
2289 | + start = time.time() |
---|
2290 | + d = self._share.read_share_data(offset, length) |
---|
2291 | + d.addBoth(self._add_latency, "read", start) |
---|
2292 | + return d |
---|
2293 | + |
---|
2294 | + def remote_advise_corrupt_share(self, reason): |
---|
2295 | + return self.ss.remote_advise_corrupt_share("immutable", |
---|
2296 | + self.storageindex, |
---|
2297 | + self.shnum, |
---|
2298 | + reason) |
---|
2299 | hunk ./src/allmydata/storage/shares.py 1 |
---|
2300 | -#! /usr/bin/python |
---|
2301 | - |
---|
2302 | -from allmydata.storage.mutable import MutableShareFile |
---|
2303 | -from allmydata.storage.immutable import ShareFile |
---|
2304 | - |
---|
2305 | -def get_share_file(filename): |
---|
2306 | - f = open(filename, "rb") |
---|
2307 | - prefix = f.read(32) |
---|
2308 | - f.close() |
---|
2309 | - if prefix == MutableShareFile.MAGIC: |
---|
2310 | - return MutableShareFile(filename) |
---|
2311 | - # otherwise assume it's immutable |
---|
2312 | - return ShareFile(filename) |
---|
2313 | - |
---|
2314 | rmfile ./src/allmydata/storage/shares.py |
---|
2315 | } |
---|
2316 | [Cosmetic changes in pluggable backends branch. refs #999, #1569 |
---|
2317 | david-sarah@jacaranda.org**20111216181207 |
---|
2318 | Ignore-this: ea6cf274dd733abba20032197ed17beb |
---|
2319 | ] { |
---|
2320 | hunk ./src/allmydata/client.py 225 |
---|
2321 | # searches. |
---|
2322 | seed = base32.b2a(self.nodeid) |
---|
2323 | else: |
---|
2324 | - # otherwise, we're free to use the more natural seed of our |
---|
2325 | - # pubkey-based serverid |
---|
2326 | + # Otherwise, we're free to use the more natural seed of our |
---|
2327 | + # pubkey-based serverid. |
---|
2328 | vk = self._server_key.get_verifying_key() |
---|
2329 | seed = vk.to_ascii(encoding="base32") |
---|
2330 | self.write_config("permutation-seed", seed+"\n") |
---|
2331 | hunk ./src/allmydata/client.py 233 |
---|
2332 | return seed.strip() |
---|
2333 | |
---|
2334 | def init_storage(self): |
---|
2335 | - # should we run a storage server (and publish it for others to use)? |
---|
2336 | + # Should we run a storage server (and publish it for others to use)? |
---|
2337 | if not self.get_config("storage", "enabled", True, boolean=True): |
---|
2338 | return |
---|
2339 | readonly = self.get_config("storage", "readonly", False, boolean=True) |
---|
2340 | hunk ./src/allmydata/immutable/offloaded.py 306 |
---|
2341 | if os.path.exists(self._encoding_file): |
---|
2342 | self.log("ciphertext already present, bypassing fetch", |
---|
2343 | level=log.UNUSUAL) |
---|
2344 | + # XXX the following comment is probably stale, since |
---|
2345 | + # LocalCiphertextReader.get_plaintext_hashtree_leaves does not exist. |
---|
2346 | + # |
---|
2347 | # we'll still need the plaintext hashes (when |
---|
2348 | # LocalCiphertextReader.get_plaintext_hashtree_leaves() is |
---|
2349 | # called), and currently the easiest way to get them is to ask |
---|
2350 | hunk ./src/allmydata/immutable/upload.py 765 |
---|
2351 | self._status.set_progress(1, progress) |
---|
2352 | return cryptdata |
---|
2353 | |
---|
2354 | - |
---|
2355 | def get_plaintext_hashtree_leaves(self, first, last, num_segments): |
---|
2356 | hunk ./src/allmydata/immutable/upload.py 766 |
---|
2357 | + """OBSOLETE; Get the leaf nodes of a merkle hash tree over the |
---|
2358 | + plaintext segments, i.e. get the tagged hashes of the given segments. |
---|
2359 | + The segment size is expected to be generated by the |
---|
2360 | + IEncryptedUploadable before any plaintext is read or ciphertext |
---|
2361 | + produced, so that the segment hashes can be generated with only a |
---|
2362 | + single pass. |
---|
2363 | + |
---|
2364 | + This returns a Deferred that fires with a sequence of hashes, using: |
---|
2365 | + |
---|
2366 | + tuple(segment_hashes[first:last]) |
---|
2367 | + |
---|
2368 | + 'num_segments' is used to assert that the number of segments that the |
---|
2369 | + IEncryptedUploadable handled matches the number of segments that the |
---|
2370 | + encoder was expecting. |
---|
2371 | + |
---|
2372 | + This method must not be called until the final byte has been read |
---|
2373 | + from read_encrypted(). Once this method is called, read_encrypted() |
---|
2374 | + can never be called again. |
---|
2375 | + """ |
---|
2376 | # this is currently unused, but will live again when we fix #453 |
---|
2377 | if len(self._plaintext_segment_hashes) < num_segments: |
---|
2378 | # close out the last one |
---|
2379 | hunk ./src/allmydata/immutable/upload.py 803 |
---|
2380 | return defer.succeed(tuple(self._plaintext_segment_hashes[first:last])) |
---|
2381 | |
---|
2382 | def get_plaintext_hash(self): |
---|
2383 | + """OBSOLETE; Get the hash of the whole plaintext. |
---|
2384 | + |
---|
2385 | + This returns a Deferred that fires with a tagged SHA-256 hash of the |
---|
2386 | + whole plaintext, obtained from hashutil.plaintext_hash(data). |
---|
2387 | + """ |
---|
2388 | + # this is currently unused, but will live again when we fix #453 |
---|
2389 | h = self._plaintext_hasher.digest() |
---|
2390 | return defer.succeed(h) |
---|
2391 | |
---|
2392 | hunk ./src/allmydata/interfaces.py 29 |
---|
2393 | Number = IntegerConstraint(8) # 2**(8*8) == 16EiB ~= 18e18 ~= 18 exabytes |
---|
2394 | Offset = Number |
---|
2395 | ReadSize = int # the 'int' constraint is 2**31 == 2Gib -- large files are processed in not-so-large increments |
---|
2396 | -WriteEnablerSecret = Hash # used to protect mutable bucket modifications |
---|
2397 | -LeaseRenewSecret = Hash # used to protect bucket lease renewal requests |
---|
2398 | -LeaseCancelSecret = Hash # used to protect bucket lease cancellation requests |
---|
2399 | +WriteEnablerSecret = Hash # used to protect mutable share modifications |
---|
2400 | +LeaseRenewSecret = Hash # used to protect lease renewal requests |
---|
2401 | +LeaseCancelSecret = Hash # formerly used to protect lease cancellation requests |
---|
2402 | |
---|
2403 | class RIStubClient(RemoteInterface): |
---|
2404 | """Each client publishes a service announcement for a dummy object called |
---|
2405 | hunk ./src/allmydata/interfaces.py 59 |
---|
2406 | """ |
---|
2407 | return None |
---|
2408 | |
---|
2409 | + |
---|
2410 | class RIBucketReader(RemoteInterface): |
---|
2411 | def read(offset=Offset, length=ReadSize): |
---|
2412 | return ShareData |
---|
2413 | hunk ./src/allmydata/interfaces.py 76 |
---|
2414 | documentation. |
---|
2415 | """ |
---|
2416 | |
---|
2417 | + |
---|
2418 | TestVector = ListOf(TupleOf(Offset, ReadSize, str, str)) |
---|
2419 | # elements are (offset, length, operator, specimen) |
---|
2420 | # operator is one of "lt, le, eq, ne, ge, gt" |
---|
2421 | hunk ./src/allmydata/interfaces.py 93 |
---|
2422 | ReadData = ListOf(ShareData) |
---|
2423 | # returns data[offset:offset+length] for each element of TestVector |
---|
2424 | |
---|
2425 | + |
---|
2426 | class RIStorageServer(RemoteInterface): |
---|
2427 | __remote_name__ = "RIStorageServer.tahoe.allmydata.com" |
---|
2428 | |
---|
2429 | hunk ./src/allmydata/interfaces.py 109 |
---|
2430 | sharenums=SetOf(int, maxLength=MAX_BUCKETS), |
---|
2431 | allocated_size=Offset, canary=Referenceable): |
---|
2432 | """ |
---|
2433 | - @param storage_index: the index of the bucket to be created or |
---|
2434 | + @param storage_index: the index of the shareset to be created or |
---|
2435 | increfed. |
---|
2436 | @param sharenums: these are the share numbers (probably between 0 and |
---|
2437 | 99) that the sender is proposing to store on this |
---|
2438 | hunk ./src/allmydata/interfaces.py 114 |
---|
2439 | server. |
---|
2440 | - @param renew_secret: This is the secret used to protect bucket refresh |
---|
2441 | + @param renew_secret: This is the secret used to protect lease renewal. |
---|
2442 | This secret is generated by the client and |
---|
2443 | stored for later comparison by the server. Each |
---|
2444 | server is given a different secret. |
---|
2445 | hunk ./src/allmydata/interfaces.py 118 |
---|
2446 | - @param cancel_secret: Like renew_secret, but protects bucket decref. |
---|
2447 | - @param canary: If the canary is lost before close(), the bucket is |
---|
2448 | + @param cancel_secret: ignored |
---|
2449 | + @param canary: If the canary is lost before close(), the allocation is |
---|
2450 | deleted. |
---|
2451 | @return: tuple of (alreadygot, allocated), where alreadygot is what we |
---|
2452 | already have and allocated is what we hereby agree to accept. |
---|
2453 | hunk ./src/allmydata/interfaces.py 132 |
---|
2454 | renew_secret=LeaseRenewSecret, |
---|
2455 | cancel_secret=LeaseCancelSecret): |
---|
2456 | """ |
---|
2457 | - Add a new lease on the given bucket. If the renew_secret matches an |
---|
2458 | + Add a new lease on the given shareset. If the renew_secret matches an |
---|
2459 | existing lease, that lease will be renewed instead. If there is no |
---|
2460 | hunk ./src/allmydata/interfaces.py 134 |
---|
2461 | - bucket for the given storage_index, return silently. (note that in |
---|
2462 | + shareset for the given storage_index, return silently. (Note that in |
---|
2463 | tahoe-1.3.0 and earlier, IndexError was raised if there was no |
---|
2464 | hunk ./src/allmydata/interfaces.py 136 |
---|
2465 | - bucket) |
---|
2466 | + shareset.) |
---|
2467 | """ |
---|
2468 | return Any() # returns None now, but future versions might change |
---|
2469 | |
---|
2470 | hunk ./src/allmydata/interfaces.py 142 |
---|
2471 | def renew_lease(storage_index=StorageIndex, renew_secret=LeaseRenewSecret): |
---|
2472 | """ |
---|
2473 | - Renew the lease on a given bucket, resetting the timer to 31 days. |
---|
2474 | - Some networks will use this, some will not. If there is no bucket for |
---|
2475 | + Renew the lease on a given shareset, resetting the timer to 31 days. |
---|
2476 | + Some networks will use this, some will not. If there is no shareset for |
---|
2477 | the given storage_index, IndexError will be raised. |
---|
2478 | |
---|
2479 | For mutable shares, if the given renew_secret does not match an |
---|
2480 | hunk ./src/allmydata/interfaces.py 149 |
---|
2481 | existing lease, IndexError will be raised with a note listing the |
---|
2482 | server-nodeids on the existing leases, so leases on migrated shares |
---|
2483 | - can be renewed or cancelled. For immutable shares, IndexError |
---|
2484 | - (without the note) will be raised. |
---|
2485 | + can be renewed. For immutable shares, IndexError (without the note) |
---|
2486 | + will be raised. |
---|
2487 | """ |
---|
2488 | return Any() |
---|
2489 | |
---|
2490 | hunk ./src/allmydata/interfaces.py 157 |
---|
2491 | def get_buckets(storage_index=StorageIndex): |
---|
2492 | return DictOf(int, RIBucketReader, maxKeys=MAX_BUCKETS) |
---|
2493 | |
---|
2494 | - |
---|
2495 | - |
---|
2496 | def slot_readv(storage_index=StorageIndex, |
---|
2497 | shares=ListOf(int), readv=ReadVector): |
---|
2498 | """Read a vector from the numbered shares associated with the given |
---|
2499 | hunk ./src/allmydata/interfaces.py 171 |
---|
2500 | tw_vectors=TestAndWriteVectorsForShares, |
---|
2501 | r_vector=ReadVector, |
---|
2502 | ): |
---|
2503 | - """General-purpose test-and-set operation for mutable slots. Perform |
---|
2504 | - a bunch of comparisons against the existing shares. If they all pass, |
---|
2505 | - then apply a bunch of write vectors to those shares. Then use the |
---|
2506 | - read vectors to extract data from all the shares and return the data. |
---|
2507 | + """ |
---|
2508 | + General-purpose atomic test-read-and-set operation for mutable slots. |
---|
2509 | + Perform a bunch of comparisons against the existing shares. If they |
---|
2510 | + all pass: use the read vectors to extract data from all the shares, |
---|
2511 | + then apply a bunch of write vectors to those shares. Return the read |
---|
2512 | + data, which does not include any modifications made by the writes. |
---|
2513 | |
---|
2514 | This method is, um, large. The goal is to allow clients to update all |
---|
2515 | the shares associated with a mutable file in a single round trip. |
---|
2516 | hunk ./src/allmydata/interfaces.py 181 |
---|
2517 | |
---|
2518 | - @param storage_index: the index of the bucket to be created or |
---|
2519 | + @param storage_index: the index of the shareset to be created or |
---|
2520 | increfed. |
---|
2521 | @param write_enabler: a secret that is stored along with the slot. |
---|
2522 | Writes are accepted from any caller who can |
---|
2523 | hunk ./src/allmydata/interfaces.py 187 |
---|
2524 | present the matching secret. A different secret |
---|
2525 | should be used for each slot*server pair. |
---|
2526 | - @param renew_secret: This is the secret used to protect bucket refresh |
---|
2527 | + @param renew_secret: This is the secret used to protect lease renewal. |
---|
2528 | This secret is generated by the client and |
---|
2529 | stored for later comparison by the server. Each |
---|
2530 | server is given a different secret. |
---|
2531 | hunk ./src/allmydata/interfaces.py 300 |
---|
2532 | @return: a Deferred that fires (with None) when the operation completes |
---|
2533 | """ |
---|
2534 | |
---|
2535 | - def put_crypttext_hashes(hashes=ListOf(Hash)): |
---|
2536 | + def put_crypttext_hashes(hashes): |
---|
2537 | """ |
---|
2538 | hunk ./src/allmydata/interfaces.py 302 |
---|
2539 | + @param hashes=ListOf(Hash) |
---|
2540 | @return: a Deferred that fires (with None) when the operation completes |
---|
2541 | """ |
---|
2542 | |
---|
2543 | hunk ./src/allmydata/interfaces.py 306 |
---|
2544 | - def put_block_hashes(blockhashes=ListOf(Hash)): |
---|
2545 | + def put_block_hashes(blockhashes): |
---|
2546 | """ |
---|
2547 | hunk ./src/allmydata/interfaces.py 308 |
---|
2548 | + @param blockhashes=ListOf(Hash) |
---|
2549 | @return: a Deferred that fires (with None) when the operation completes |
---|
2550 | """ |
---|
2551 | |
---|
2552 | hunk ./src/allmydata/interfaces.py 312 |
---|
2553 | - def put_share_hashes(sharehashes=ListOf(TupleOf(int, Hash))): |
---|
2554 | + def put_share_hashes(sharehashes): |
---|
2555 | """ |
---|
2556 | hunk ./src/allmydata/interfaces.py 314 |
---|
2557 | + @param sharehashes=ListOf(TupleOf(int, Hash)) |
---|
2558 | @return: a Deferred that fires (with None) when the operation completes |
---|
2559 | """ |
---|
2560 | |
---|
2561 | hunk ./src/allmydata/interfaces.py 318 |
---|
2562 | - def put_uri_extension(data=URIExtensionData): |
---|
2563 | + def put_uri_extension(data): |
---|
2564 | """This block of data contains integrity-checking information (hashes |
---|
2565 | of plaintext, crypttext, and shares), as well as encoding parameters |
---|
2566 | that are necessary to recover the data. This is a serialized dict |
---|
2567 | hunk ./src/allmydata/interfaces.py 323 |
---|
2568 | mapping strings to other strings. The hash of this data is kept in |
---|
2569 | - the URI and verified before any of the data is used. All buckets for |
---|
2570 | - a given file contain identical copies of this data. |
---|
2571 | + the URI and verified before any of the data is used. All share |
---|
2572 | + containers for a given file contain identical copies of this data. |
---|
2573 | |
---|
2574 | The serialization format is specified with the following pseudocode: |
---|
2575 | for k in sorted(dict.keys()): |
---|
2576 | hunk ./src/allmydata/interfaces.py 331 |
---|
2577 | assert re.match(r'^[a-zA-Z_\-]+$', k) |
---|
2578 | write(k + ':' + netstring(dict[k])) |
---|
2579 | |
---|
2580 | + @param data=URIExtensionData |
---|
2581 | @return: a Deferred that fires (with None) when the operation completes |
---|
2582 | """ |
---|
2583 | |
---|
2584 | hunk ./src/allmydata/interfaces.py 346 |
---|
2585 | |
---|
2586 | class IStorageBucketReader(Interface): |
---|
2587 | |
---|
2588 | - def get_block_data(blocknum=int, blocksize=int, size=int): |
---|
2589 | + def get_block_data(blocknum, blocksize, size): |
---|
2590 | """Most blocks will be the same size. The last block might be shorter |
---|
2591 | than the others. |
---|
2592 | |
---|
2593 | hunk ./src/allmydata/interfaces.py 350 |
---|
2594 | + @param blocknum=int |
---|
2595 | + @param blocksize=int |
---|
2596 | + @param size=int |
---|
2597 | @return: ShareData |
---|
2598 | """ |
---|
2599 | |
---|
2600 | hunk ./src/allmydata/interfaces.py 361 |
---|
2601 | @return: ListOf(Hash) |
---|
2602 | """ |
---|
2603 | |
---|
2604 | - def get_block_hashes(at_least_these=SetOf(int)): |
---|
2605 | + def get_block_hashes(at_least_these=()): |
---|
2606 | """ |
---|
2607 | hunk ./src/allmydata/interfaces.py 363 |
---|
2608 | + @param at_least_these=SetOf(int) |
---|
2609 | @return: ListOf(Hash) |
---|
2610 | """ |
---|
2611 | |
---|
2612 | hunk ./src/allmydata/interfaces.py 476 |
---|
2613 | Add the encrypted private key to the share. |
---|
2614 | """ |
---|
2615 | |
---|
2616 | - def put_blockhashes(blockhashes=list): |
---|
2617 | + def put_blockhashes(blockhashes): |
---|
2618 | """ |
---|
2619 | hunk ./src/allmydata/interfaces.py 478 |
---|
2620 | + @param blockhashes=list |
---|
2621 | Add the block hash tree to the share. |
---|
2622 | """ |
---|
2623 | |
---|
2624 | hunk ./src/allmydata/interfaces.py 482 |
---|
2625 | - def put_sharehashes(sharehashes=dict): |
---|
2626 | + def put_sharehashes(sharehashes): |
---|
2627 | """ |
---|
2628 | hunk ./src/allmydata/interfaces.py 484 |
---|
2629 | + @param sharehashes=dict |
---|
2630 | Add the share hash chain to the share. |
---|
2631 | """ |
---|
2632 | |
---|
2633 | hunk ./src/allmydata/interfaces.py 1572 |
---|
2634 | Block Hash, and the encoding parameters, both of which must be included |
---|
2635 | in the URI. |
---|
2636 | |
---|
2637 | - I do not choose shareholders, that is left to the IUploader. I must be |
---|
2638 | - given a dict of RemoteReferences to storage buckets that are ready and |
---|
2639 | - willing to receive data. |
---|
2640 | + I do not choose shareholders, that is left to the IUploader. |
---|
2641 | """ |
---|
2642 | |
---|
2643 | def set_size(size): |
---|
2644 | hunk ./src/allmydata/interfaces.py 1579 |
---|
2645 | """Specify the number of bytes that will be encoded. This must be |
---|
2646 | peformed before get_serialized_params() can be called. |
---|
2647 | """ |
---|
2648 | + |
---|
2649 | def set_params(params): |
---|
2650 | """Override the default encoding parameters. 'params' is a tuple of |
---|
2651 | (k,d,n), where 'k' is the number of required shares, 'd' is the |
---|
2652 | hunk ./src/allmydata/interfaces.py 1675 |
---|
2653 | download, validate, decode, and decrypt data from them, writing the |
---|
2654 | results to an output file. |
---|
2655 | |
---|
2656 | - I do not locate the shareholders, that is left to the IDownloader. I must |
---|
2657 | - be given a dict of RemoteReferences to storage buckets that are ready to |
---|
2658 | - send data. |
---|
2659 | + I do not locate the shareholders, that is left to the IDownloader. |
---|
2660 | """ |
---|
2661 | |
---|
2662 | def setup(outfile): |
---|
2663 | hunk ./src/allmydata/interfaces.py 2103 |
---|
2664 | |
---|
2665 | def get_storage_index(): |
---|
2666 | """Return a string with the (binary) storage index.""" |
---|
2667 | + |
---|
2668 | def get_storage_index_string(): |
---|
2669 | """Return a string with the (printable) abbreviated storage index.""" |
---|
2670 | hunk ./src/allmydata/interfaces.py 2106 |
---|
2671 | + |
---|
2672 | def get_uri(): |
---|
2673 | """Return the (string) URI of the object that was checked.""" |
---|
2674 | |
---|
2675 | hunk ./src/allmydata/interfaces.py 2201 |
---|
2676 | def get_report(): |
---|
2677 | """Return a list of strings with more detailed results.""" |
---|
2678 | |
---|
2679 | + |
---|
2680 | class ICheckAndRepairResults(Interface): |
---|
2681 | """I contain the detailed results of a check/verify/repair operation. |
---|
2682 | |
---|
2683 | hunk ./src/allmydata/interfaces.py 2211 |
---|
2684 | |
---|
2685 | def get_storage_index(): |
---|
2686 | """Return a string with the (binary) storage index.""" |
---|
2687 | + |
---|
2688 | def get_storage_index_string(): |
---|
2689 | """Return a string with the (printable) abbreviated storage index.""" |
---|
2690 | hunk ./src/allmydata/interfaces.py 2214 |
---|
2691 | + |
---|
2692 | def get_repair_attempted(): |
---|
2693 | """Return a boolean, True if a repair was attempted. We might not |
---|
2694 | attempt to repair the file because it was healthy, or healthy enough |
---|
2695 | hunk ./src/allmydata/interfaces.py 2220 |
---|
2696 | (i.e. some shares were missing but not enough to exceed some |
---|
2697 | threshold), or because we don't know how to repair this object.""" |
---|
2698 | + |
---|
2699 | def get_repair_successful(): |
---|
2700 | """Return a boolean, True if repair was attempted and the file/dir |
---|
2701 | was fully healthy afterwards. False if no repair was attempted or if |
---|
2702 | hunk ./src/allmydata/interfaces.py 2225 |
---|
2703 | a repair attempt failed.""" |
---|
2704 | + |
---|
2705 | def get_pre_repair_results(): |
---|
2706 | """Return an ICheckResults instance that describes the state of the |
---|
2707 | file/dir before any repair was attempted.""" |
---|
2708 | hunk ./src/allmydata/interfaces.py 2229 |
---|
2709 | + |
---|
2710 | def get_post_repair_results(): |
---|
2711 | """Return an ICheckResults instance that describes the state of the |
---|
2712 | file/dir after any repair was attempted. If no repair was attempted, |
---|
2713 | hunk ./src/allmydata/interfaces.py 2463 |
---|
2714 | (childnode, metadata_dict) tuples), the directory will be populated |
---|
2715 | with those children, otherwise it will be empty.""" |
---|
2716 | |
---|
2717 | + |
---|
2718 | class IClientStatus(Interface): |
---|
2719 | def list_all_uploads(): |
---|
2720 | """Return a list of uploader objects, one for each upload that |
---|
2721 | hunk ./src/allmydata/interfaces.py 2469 |
---|
2722 | currently has an object available (tracked with weakrefs). This is |
---|
2723 | intended for debugging purposes.""" |
---|
2724 | + |
---|
2725 | def list_active_uploads(): |
---|
2726 | """Return a list of active IUploadStatus objects.""" |
---|
2727 | hunk ./src/allmydata/interfaces.py 2472 |
---|
2728 | + |
---|
2729 | def list_recent_uploads(): |
---|
2730 | """Return a list of IUploadStatus objects for the most recently |
---|
2731 | started uploads.""" |
---|
2732 | hunk ./src/allmydata/interfaces.py 2481 |
---|
2733 | """Return a list of downloader objects, one for each download that |
---|
2734 | currently has an object available (tracked with weakrefs). This is |
---|
2735 | intended for debugging purposes.""" |
---|
2736 | + |
---|
2737 | def list_active_downloads(): |
---|
2738 | """Return a list of active IDownloadStatus objects.""" |
---|
2739 | hunk ./src/allmydata/interfaces.py 2484 |
---|
2740 | + |
---|
2741 | def list_recent_downloads(): |
---|
2742 | """Return a list of IDownloadStatus objects for the most recently |
---|
2743 | started downloads.""" |
---|
2744 | hunk ./src/allmydata/interfaces.py 2489 |
---|
2745 | |
---|
2746 | + |
---|
2747 | class IUploadStatus(Interface): |
---|
2748 | def get_started(): |
---|
2749 | """Return a timestamp (float with seconds since epoch) indicating |
---|
2750 | hunk ./src/allmydata/interfaces.py 2494 |
---|
2751 | when the operation was started.""" |
---|
2752 | + |
---|
2753 | def get_storage_index(): |
---|
2754 | """Return a string with the (binary) storage index in use on this |
---|
2755 | upload. Returns None if the storage index has not yet been |
---|
2756 | hunk ./src/allmydata/interfaces.py 2499 |
---|
2757 | calculated.""" |
---|
2758 | + |
---|
2759 | def get_size(): |
---|
2760 | """Return an integer with the number of bytes that will eventually |
---|
2761 | be uploaded for this file. Returns None if the size is not yet known. |
---|
2762 | hunk ./src/allmydata/interfaces.py 2504 |
---|
2763 | """ |
---|
2764 | + |
---|
2765 | def using_helper(): |
---|
2766 | """Return True if this upload is using a Helper, False if not.""" |
---|
2767 | hunk ./src/allmydata/interfaces.py 2507 |
---|
2768 | + |
---|
2769 | def get_status(): |
---|
2770 | """Return a string describing the current state of the upload |
---|
2771 | process.""" |
---|
2772 | hunk ./src/allmydata/interfaces.py 2511 |
---|
2773 | + |
---|
2774 | def get_progress(): |
---|
2775 | """Returns a tuple of floats, (chk, ciphertext, encode_and_push), |
---|
2776 | each from 0.0 to 1.0 . 'chk' describes how much progress has been |
---|
2777 | hunk ./src/allmydata/interfaces.py 2523 |
---|
2778 | process has finished: for helper uploads this is dependent upon the |
---|
2779 | helper providing progress reports. It might be reasonable to add all |
---|
2780 | three numbers and report the sum to the user.""" |
---|
2781 | + |
---|
2782 | def get_active(): |
---|
2783 | """Return True if the upload is currently active, False if not.""" |
---|
2784 | hunk ./src/allmydata/interfaces.py 2526 |
---|
2785 | + |
---|
2786 | def get_results(): |
---|
2787 | """Return an instance of UploadResults (which contains timing and |
---|
2788 | sharemap information). Might return None if the upload is not yet |
---|
2789 | hunk ./src/allmydata/interfaces.py 2531 |
---|
2790 | finished.""" |
---|
2791 | + |
---|
2792 | def get_counter(): |
---|
2793 | """Each upload status gets a unique number: this method returns that |
---|
2794 | number. This provides a handle to this particular upload, so a web |
---|
2795 | hunk ./src/allmydata/interfaces.py 2537 |
---|
2796 | page can generate a suitable hyperlink.""" |
---|
2797 | |
---|
2798 | + |
---|
2799 | class IDownloadStatus(Interface): |
---|
2800 | def get_started(): |
---|
2801 | """Return a timestamp (float with seconds since epoch) indicating |
---|
2802 | hunk ./src/allmydata/interfaces.py 2542 |
---|
2803 | when the operation was started.""" |
---|
2804 | + |
---|
2805 | def get_storage_index(): |
---|
2806 | """Return a string with the (binary) storage index in use on this |
---|
2807 | download. This may be None if there is no storage index (i.e. LIT |
---|
2808 | hunk ./src/allmydata/interfaces.py 2547 |
---|
2809 | files).""" |
---|
2810 | + |
---|
2811 | def get_size(): |
---|
2812 | """Return an integer with the number of bytes that will eventually be |
---|
2813 | retrieved for this file. Returns None if the size is not yet known. |
---|
2814 | hunk ./src/allmydata/interfaces.py 2552 |
---|
2815 | """ |
---|
2816 | + |
---|
2817 | def using_helper(): |
---|
2818 | """Return True if this download is using a Helper, False if not.""" |
---|
2819 | hunk ./src/allmydata/interfaces.py 2555 |
---|
2820 | + |
---|
2821 | def get_status(): |
---|
2822 | """Return a string describing the current state of the download |
---|
2823 | process.""" |
---|
2824 | hunk ./src/allmydata/interfaces.py 2559 |
---|
2825 | + |
---|
2826 | def get_progress(): |
---|
2827 | """Returns a float (from 0.0 to 1.0) describing the amount of the |
---|
2828 | download that has completed. This value will remain at 0.0 until the |
---|
2829 | hunk ./src/allmydata/interfaces.py 2564 |
---|
2830 | first byte of plaintext is pushed to the download target.""" |
---|
2831 | + |
---|
2832 | def get_active(): |
---|
2833 | """Return True if the download is currently active, False if not.""" |
---|
2834 | hunk ./src/allmydata/interfaces.py 2567 |
---|
2835 | + |
---|
2836 | def get_counter(): |
---|
2837 | """Each download status gets a unique number: this method returns |
---|
2838 | that number. This provides a handle to this particular download, so a |
---|
2839 | hunk ./src/allmydata/interfaces.py 2573 |
---|
2840 | web page can generate a suitable hyperlink.""" |
---|
2841 | |
---|
2842 | + |
---|
2843 | class IServermapUpdaterStatus(Interface): |
---|
2844 | pass |
---|
2845 | hunk ./src/allmydata/interfaces.py 2576 |
---|
2846 | + |
---|
2847 | + |
---|
2848 | class IPublishStatus(Interface): |
---|
2849 | pass |
---|
2850 | hunk ./src/allmydata/interfaces.py 2580 |
---|
2851 | + |
---|
2852 | + |
---|
2853 | class IRetrieveStatus(Interface): |
---|
2854 | pass |
---|
2855 | |
---|
2856 | hunk ./src/allmydata/interfaces.py 2585 |
---|
2857 | + |
---|
2858 | class NotCapableError(Exception): |
---|
2859 | """You have tried to write to a read-only node.""" |
---|
2860 | |
---|
2861 | hunk ./src/allmydata/interfaces.py 2589 |
---|
2862 | + |
---|
2863 | class BadWriteEnablerError(Exception): |
---|
2864 | pass |
---|
2865 | |
---|
2866 | hunk ./src/allmydata/interfaces.py 2649 |
---|
2867 | |
---|
2868 | return DictOf(str, float) |
---|
2869 | |
---|
2870 | + |
---|
2871 | UploadResults = Any() #DictOf(str, str) |
---|
2872 | |
---|
2873 | hunk ./src/allmydata/interfaces.py 2652 |
---|
2874 | + |
---|
2875 | class RIEncryptedUploadable(RemoteInterface): |
---|
2876 | __remote_name__ = "RIEncryptedUploadable.tahoe.allmydata.com" |
---|
2877 | |
---|
2878 | hunk ./src/allmydata/interfaces.py 2725 |
---|
2879 | """ |
---|
2880 | return DictOf(str, DictOf(str, ChoiceOf(float, int, long, None))) |
---|
2881 | |
---|
2882 | + |
---|
2883 | class RIStatsGatherer(RemoteInterface): |
---|
2884 | __remote_name__ = "RIStatsGatherer.tahoe.allmydata.com" |
---|
2885 | """ |
---|
2886 | hunk ./src/allmydata/interfaces.py 2765 |
---|
2887 | class FileTooLargeError(Exception): |
---|
2888 | pass |
---|
2889 | |
---|
2890 | + |
---|
2891 | class IValidatedThingProxy(Interface): |
---|
2892 | def start(): |
---|
2893 | """ Acquire a thing and validate it. Return a deferred that is |
---|
2894 | hunk ./src/allmydata/interfaces.py 2772 |
---|
2895 | eventually fired with self if the thing is valid or errbacked if it |
---|
2896 | can't be acquired or validated.""" |
---|
2897 | |
---|
2898 | + |
---|
2899 | class InsufficientVersionError(Exception): |
---|
2900 | def __init__(self, needed, got): |
---|
2901 | self.needed = needed |
---|
2902 | hunk ./src/allmydata/interfaces.py 2781 |
---|
2903 | return "InsufficientVersionError(need '%s', got %s)" % (self.needed, |
---|
2904 | self.got) |
---|
2905 | |
---|
2906 | + |
---|
2907 | class EmptyPathnameComponentError(Exception): |
---|
2908 | """The webapi disallows empty pathname components.""" |
---|
2909 | hunk ./src/allmydata/mutable/filenode.py 742 |
---|
2910 | self._writekey = writekey |
---|
2911 | self._serializer = defer.succeed(None) |
---|
2912 | |
---|
2913 | - |
---|
2914 | def get_sequence_number(self): |
---|
2915 | """ |
---|
2916 | Get the sequence number of the mutable version that I represent. |
---|
2917 | hunk ./src/allmydata/mutable/filenode.py 749 |
---|
2918 | return self._version[0] # verinfo[0] == the sequence number |
---|
2919 | |
---|
2920 | |
---|
2921 | - # TODO: Terminology? |
---|
2922 | def get_writekey(self): |
---|
2923 | """ |
---|
2924 | I return a writekey or None if I don't have a writekey. |
---|
2925 | hunk ./src/allmydata/mutable/filenode.py 755 |
---|
2926 | """ |
---|
2927 | return self._writekey |
---|
2928 | |
---|
2929 | - |
---|
2930 | def set_downloader_hints(self, hints): |
---|
2931 | """ |
---|
2932 | I set the downloader hints. |
---|
2933 | hunk ./src/allmydata/mutable/filenode.py 763 |
---|
2934 | |
---|
2935 | self._downloader_hints = hints |
---|
2936 | |
---|
2937 | - |
---|
2938 | def get_downloader_hints(self): |
---|
2939 | """ |
---|
2940 | I return the downloader hints. |
---|
2941 | hunk ./src/allmydata/mutable/filenode.py 769 |
---|
2942 | """ |
---|
2943 | return self._downloader_hints |
---|
2944 | |
---|
2945 | - |
---|
2946 | def overwrite(self, new_contents): |
---|
2947 | """ |
---|
2948 | I overwrite the contents of this mutable file version with the |
---|
2949 | hunk ./src/allmydata/mutable/filenode.py 778 |
---|
2950 | |
---|
2951 | return self._do_serialized(self._overwrite, new_contents) |
---|
2952 | |
---|
2953 | - |
---|
2954 | def _overwrite(self, new_contents): |
---|
2955 | assert IMutableUploadable.providedBy(new_contents) |
---|
2956 | assert self._servermap.get_last_update()[0] == MODE_WRITE |
---|
2957 | hunk ./src/allmydata/mutable/filenode.py 784 |
---|
2958 | |
---|
2959 | return self._upload(new_contents) |
---|
2960 | |
---|
2961 | - |
---|
2962 | def modify(self, modifier, backoffer=None): |
---|
2963 | """I use a modifier callback to apply a change to the mutable file. |
---|
2964 | I implement the following pseudocode:: |
---|
2965 | hunk ./src/allmydata/mutable/filenode.py 828 |
---|
2966 | |
---|
2967 | return self._do_serialized(self._modify, modifier, backoffer) |
---|
2968 | |
---|
2969 | - |
---|
2970 | def _modify(self, modifier, backoffer): |
---|
2971 | if backoffer is None: |
---|
2972 | backoffer = BackoffAgent().delay |
---|
2973 | hunk ./src/allmydata/mutable/filenode.py 833 |
---|
2974 | return self._modify_and_retry(modifier, backoffer, True) |
---|
2975 | |
---|
2976 | - |
---|
2977 | def _modify_and_retry(self, modifier, backoffer, first_time): |
---|
2978 | """ |
---|
2979 | I try to apply modifier to the contents of this version of the |
---|
2980 | hunk ./src/allmydata/mutable/filenode.py 865 |
---|
2981 | d.addErrback(_retry) |
---|
2982 | return d |
---|
2983 | |
---|
2984 | - |
---|
2985 | def _modify_once(self, modifier, first_time): |
---|
2986 | """ |
---|
2987 | I attempt to apply a modifier to the contents of the mutable |
---|
2988 | hunk ./src/allmydata/mutable/filenode.py 900 |
---|
2989 | d.addCallback(_apply) |
---|
2990 | return d |
---|
2991 | |
---|
2992 | - |
---|
2993 | def is_readonly(self): |
---|
2994 | """ |
---|
2995 | I return True if this MutableFileVersion provides no write |
---|
2996 | hunk ./src/allmydata/mutable/filenode.py 908 |
---|
2997 | """ |
---|
2998 | return self._writekey is None |
---|
2999 | |
---|
3000 | - |
---|
3001 | def is_mutable(self): |
---|
3002 | """ |
---|
3003 | I return True, since mutable files are always mutable by |
---|
3004 | hunk ./src/allmydata/mutable/filenode.py 915 |
---|
3005 | """ |
---|
3006 | return True |
---|
3007 | |
---|
3008 | - |
---|
3009 | def get_storage_index(self): |
---|
3010 | """ |
---|
3011 | I return the storage index of the reference that I encapsulate. |
---|
3012 | hunk ./src/allmydata/mutable/filenode.py 921 |
---|
3013 | """ |
---|
3014 | return self._storage_index |
---|
3015 | |
---|
3016 | - |
---|
3017 | def get_size(self): |
---|
3018 | """ |
---|
3019 | I return the length, in bytes, of this readable object. |
---|
3020 | hunk ./src/allmydata/mutable/filenode.py 927 |
---|
3021 | """ |
---|
3022 | return self._servermap.size_of_version(self._version) |
---|
3023 | |
---|
3024 | - |
---|
3025 | def download_to_data(self, fetch_privkey=False): |
---|
3026 | """ |
---|
3027 | I return a Deferred that fires with the contents of this |
---|
3028 | hunk ./src/allmydata/mutable/filenode.py 938 |
---|
3029 | d.addCallback(lambda mc: "".join(mc.chunks)) |
---|
3030 | return d |
---|
3031 | |
---|
3032 | - |
---|
3033 | def _try_to_download_data(self): |
---|
3034 | """ |
---|
3035 | I am an unserialized cousin of download_to_data; I am called |
---|
3036 | hunk ./src/allmydata/mutable/filenode.py 950 |
---|
3037 | d.addCallback(lambda mc: "".join(mc.chunks)) |
---|
3038 | return d |
---|
3039 | |
---|
3040 | - |
---|
3041 | def read(self, consumer, offset=0, size=None, fetch_privkey=False): |
---|
3042 | """ |
---|
3043 | I read a portion (possibly all) of the mutable file that I |
---|
3044 | hunk ./src/allmydata/mutable/filenode.py 958 |
---|
3045 | return self._do_serialized(self._read, consumer, offset, size, |
---|
3046 | fetch_privkey) |
---|
3047 | |
---|
3048 | - |
---|
3049 | def _read(self, consumer, offset=0, size=None, fetch_privkey=False): |
---|
3050 | """ |
---|
3051 | I am the serialized companion of read. |
---|
3052 | hunk ./src/allmydata/mutable/filenode.py 969 |
---|
3053 | d = r.download(consumer, offset, size) |
---|
3054 | return d |
---|
3055 | |
---|
3056 | - |
---|
3057 | def _do_serialized(self, cb, *args, **kwargs): |
---|
3058 | # note: to avoid deadlock, this callable is *not* allowed to invoke |
---|
3059 | # other serialized methods within this (or any other) |
---|
3060 | hunk ./src/allmydata/mutable/filenode.py 987 |
---|
3061 | self._serializer.addErrback(log.err) |
---|
3062 | return d |
---|
3063 | |
---|
3064 | - |
---|
3065 | def _upload(self, new_contents): |
---|
3066 | #assert self._pubkey, "update_servermap must be called before publish" |
---|
3067 | p = Publish(self._node, self._storage_broker, self._servermap) |
---|
3068 | hunk ./src/allmydata/mutable/filenode.py 997 |
---|
3069 | d.addCallback(self._did_upload, new_contents.get_size()) |
---|
3070 | return d |
---|
3071 | |
---|
3072 | - |
---|
3073 | def _did_upload(self, res, size): |
---|
3074 | self._most_recent_size = size |
---|
3075 | return res |
---|
3076 | hunk ./src/allmydata/mutable/filenode.py 1017 |
---|
3077 | """ |
---|
3078 | return self._do_serialized(self._update, data, offset) |
---|
3079 | |
---|
3080 | - |
---|
3081 | def _update(self, data, offset): |
---|
3082 | """ |
---|
3083 | I update the mutable file version represented by this particular |
---|
3084 | hunk ./src/allmydata/mutable/filenode.py 1046 |
---|
3085 | d.addCallback(self._build_uploadable_and_finish, data, offset) |
---|
3086 | return d |
---|
3087 | |
---|
3088 | - |
---|
3089 | def _do_modify_update(self, data, offset): |
---|
3090 | """ |
---|
3091 | I perform a file update by modifying the contents of the file |
---|
3092 | hunk ./src/allmydata/mutable/filenode.py 1061 |
---|
3093 | return new |
---|
3094 | return self._modify(m, None) |
---|
3095 | |
---|
3096 | - |
---|
3097 | def _do_update_update(self, data, offset): |
---|
3098 | """ |
---|
3099 | I start the Servermap update that gets us the data we need to |
---|
3100 | hunk ./src/allmydata/mutable/filenode.py 1096 |
---|
3101 | return self._update_servermap(update_range=(start_segment, |
---|
3102 | end_segment)) |
---|
3103 | |
---|
3104 | - |
---|
3105 | def _decode_and_decrypt_segments(self, ignored, data, offset): |
---|
3106 | """ |
---|
3107 | After the servermap update, I take the encrypted and encoded |
---|
3108 | hunk ./src/allmydata/mutable/filenode.py 1137 |
---|
3109 | d3 = defer.succeed(blockhashes) |
---|
3110 | return deferredutil.gatherResults([d1, d2, d3]) |
---|
3111 | |
---|
3112 | - |
---|
3113 | def _build_uploadable_and_finish(self, segments_and_bht, data, offset): |
---|
3114 | """ |
---|
3115 | After the process has the plaintext segments, I build the |
---|
3116 | hunk ./src/allmydata/mutable/filenode.py 1152 |
---|
3117 | p = Publish(self._node, self._storage_broker, self._servermap) |
---|
3118 | return p.update(u, offset, segments_and_bht[2], self._version) |
---|
3119 | |
---|
3120 | - |
---|
3121 | def _update_servermap(self, mode=MODE_WRITE, update_range=None): |
---|
3122 | """ |
---|
3123 | I update the servermap. I return a Deferred that fires when the |
---|
3124 | hunk ./src/allmydata/node.py 1 |
---|
3125 | + |
---|
3126 | import datetime, os.path, re, types, ConfigParser, tempfile |
---|
3127 | from base64 import b32decode, b32encode |
---|
3128 | |
---|
3129 | hunk ./src/allmydata/scripts/debug.py 791 |
---|
3130 | |
---|
3131 | elif struct.unpack(">L", prefix[:4]) == (1,): |
---|
3132 | # immutable |
---|
3133 | - |
---|
3134 | class ImmediateReadBucketProxy(ReadBucketProxy): |
---|
3135 | def __init__(self, sf): |
---|
3136 | self.sf = sf |
---|
3137 | hunk ./src/allmydata/scripts/debug.py 850 |
---|
3138 | sharedirs = listdir_unicode(abbrevdir) |
---|
3139 | for si_s in sorted(sharedirs): |
---|
3140 | si_dir = os.path.join(abbrevdir, si_s) |
---|
3141 | - catalog_shares_one_abbrevdir(si_s, si_dir, now, out,err) |
---|
3142 | + catalog_shares_one_abbrevdir(si_s, si_dir, now, out, err) |
---|
3143 | except: |
---|
3144 | print >>err, "Error processing %s" % quote_output(abbrevdir) |
---|
3145 | failure.Failure().printTraceback(err) |
---|
3146 | hunk ./src/allmydata/scripts/debug.py 871 |
---|
3147 | abs_sharefile = os.path.join(si_dir, shnum_s) |
---|
3148 | assert os.path.isfile(abs_sharefile) |
---|
3149 | try: |
---|
3150 | - describe_share(abs_sharefile, si_s, shnum_s, now, |
---|
3151 | - out) |
---|
3152 | + describe_share(abs_sharefile, si_s, shnum_s, now, out) |
---|
3153 | except: |
---|
3154 | print >>err, "Error processing %s" % quote_output(abs_sharefile) |
---|
3155 | failure.Failure().printTraceback(err) |
---|
3156 | hunk ./src/allmydata/scripts/debug.py 879 |
---|
3157 | print >>err, "Error processing %s" % quote_output(si_dir) |
---|
3158 | failure.Failure().printTraceback(err) |
---|
3159 | |
---|
3160 | + |
---|
3161 | class CorruptShareOptions(usage.Options): |
---|
3162 | def getSynopsis(self): |
---|
3163 | return "Usage: tahoe debug corrupt-share SHARE_FILENAME" |
---|
3164 | hunk ./src/allmydata/scripts/debug.py 903 |
---|
3165 | Obviously, this command should not be used in normal operation. |
---|
3166 | """ |
---|
3167 | return t |
---|
3168 | + |
---|
3169 | def parseArgs(self, filename): |
---|
3170 | self['filename'] = filename |
---|
3171 | |
---|
3172 | hunk ./src/allmydata/storage/backends/disk/immutable.py 14 |
---|
3173 | from allmydata.storage.common import UnknownImmutableContainerVersionError, \ |
---|
3174 | DataTooLargeError |
---|
3175 | |
---|
3176 | -# each share file (in storage/shares/$SI/$SHNUM) contains lease information |
---|
3177 | -# and share data. The share data is accessed by RIBucketWriter.write and |
---|
3178 | -# RIBucketReader.read . The lease information is not accessible through these |
---|
3179 | -# interfaces. |
---|
3180 | + |
---|
3181 | +# Each share file (in storage/shares/$PREFIX/$STORAGEINDEX/$SHNUM) contains |
---|
3182 | +# lease information and share data. The share data is accessed by |
---|
3183 | +# RIBucketWriter.write and RIBucketReader.read . The lease information is not |
---|
3184 | +# accessible through these remote interfaces. |
---|
3185 | |
---|
3186 | # The share file has the following layout: |
---|
3187 | # 0x00: share file version number, four bytes, current version is 1 |
---|
3188 | hunk ./src/allmydata/storage/backends/disk/immutable.py 86 |
---|
3189 | |
---|
3190 | def read_share_data(self, offset, length): |
---|
3191 | precondition(offset >= 0) |
---|
3192 | - # reads beyond the end of the data are truncated. Reads that start |
---|
3193 | + |
---|
3194 | + # Reads beyond the end of the data are truncated. Reads that start |
---|
3195 | # beyond the end of the data return an empty string. |
---|
3196 | seekpos = self._data_offset+offset |
---|
3197 | actuallength = max(0, min(length, self._lease_offset-seekpos)) |
---|
3198 | hunk ./src/allmydata/storage/backends/disk/immutable.py 164 |
---|
3199 | except IndexError: |
---|
3200 | self.add_lease(lease_info) |
---|
3201 | |
---|
3202 | - |
---|
3203 | def cancel_lease(self, cancel_secret): |
---|
3204 | """Remove a lease with the given cancel_secret. If the last lease is |
---|
3205 | cancelled, the file will be removed. Return the number of bytes that |
---|
3206 | hunk ./src/allmydata/storage/backends/disk/immutable.py 168 |
---|
3207 | were freed (by truncating the list of leases, and possibly by |
---|
3208 | - deleting the file. Raise IndexError if there was no lease with the |
---|
3209 | + deleting the file). Raise IndexError if there was no lease with the |
---|
3210 | given cancel_secret. |
---|
3211 | """ |
---|
3212 | |
---|
3213 | hunk ./src/allmydata/storage/backends/disk/immutable.py 174 |
---|
3214 | leases = list(self.get_leases()) |
---|
3215 | num_leases_removed = 0 |
---|
3216 | - for i,lease in enumerate(leases): |
---|
3217 | + for i, lease in enumerate(leases): |
---|
3218 | if constant_time_compare(lease.cancel_secret, cancel_secret): |
---|
3219 | leases[i] = None |
---|
3220 | num_leases_removed += 1 |
---|
3221 | hunk ./src/allmydata/storage/backends/disk/mutable.py 25 |
---|
3222 | # 4 4 expiration timestamp |
---|
3223 | # 8 32 renewal token |
---|
3224 | # 40 32 cancel token |
---|
3225 | -# 72 20 nodeid which accepted the tokens |
---|
3226 | +# 72 20 nodeid that accepted the tokens |
---|
3227 | # 7 468 (a) data |
---|
3228 | # 8 ?? 4 count of extra leases |
---|
3229 | # 9 ?? n*92 extra leases |
---|
3230 | hunk ./src/allmydata/storage/backends/disk/mutable.py 31 |
---|
3231 | |
---|
3232 | |
---|
3233 | -# The struct module doc says that L's are 4 bytes in size., and that Q's are |
---|
3234 | +# The struct module doc says that L's are 4 bytes in size, and that Q's are |
---|
3235 | # 8 bytes in size. Since compatibility depends upon this, double-check it. |
---|
3236 | assert struct.calcsize(">L") == 4, struct.calcsize(">L") |
---|
3237 | assert struct.calcsize(">Q") == 8, struct.calcsize(">Q") |
---|
3238 | hunk ./src/allmydata/storage/backends/disk/mutable.py 272 |
---|
3239 | try: |
---|
3240 | data = self._read_lease_record(f, i) |
---|
3241 | if data is not None: |
---|
3242 | - yield i,data |
---|
3243 | + yield i, data |
---|
3244 | except IndexError: |
---|
3245 | return |
---|
3246 | |
---|
3247 | hunk ./src/allmydata/storage/backends/disk/mutable.py 302 |
---|
3248 | accepting_nodeids.add(lease.nodeid) |
---|
3249 | f.close() |
---|
3250 | # Return the accepting_nodeids set, to give the client a chance to |
---|
3251 | - # update the leases on a share which has been migrated from its |
---|
3252 | + # update the leases on a share that has been migrated from its |
---|
3253 | # original server to a new one. |
---|
3254 | msg = ("Unable to renew non-existent lease. I have leases accepted by" |
---|
3255 | " nodeids: ") |
---|
3256 | hunk ./src/allmydata/storage/backends/disk/mutable.py 323 |
---|
3257 | """Remove any leases with the given cancel_secret. If the last lease |
---|
3258 | is cancelled, the file will be removed. Return the number of bytes |
---|
3259 | that were freed (by truncating the list of leases, and possibly by |
---|
3260 | - deleting the file. Raise IndexError if there was no lease with the |
---|
3261 | + deleting the file). Raise IndexError if there was no lease with the |
---|
3262 | given cancel_secret.""" |
---|
3263 | |
---|
3264 | accepting_nodeids = set() |
---|
3265 | hunk ./src/allmydata/storage/crawler.py 12 |
---|
3266 | class TimeSliceExceeded(Exception): |
---|
3267 | pass |
---|
3268 | |
---|
3269 | + |
---|
3270 | class ShareCrawler(service.MultiService): |
---|
3271 | """A ShareCrawler subclass is attached to a StorageServer, and |
---|
3272 | periodically walks all of its shares, processing each one in some |
---|
3273 | hunk ./src/allmydata/storage/crawler.py 29 |
---|
3274 | long enough to ensure that 'minimum_cycle_time' elapses between the start |
---|
3275 | of two consecutive cycles. |
---|
3276 | |
---|
3277 | - We assume that the normal upload/download/get_buckets traffic of a tahoe |
---|
3278 | + We assume that the normal upload/download/DYHB traffic of a Tahoe-LAFS |
---|
3279 | grid will cause the prefixdir contents to be mostly cached in the kernel, |
---|
3280 | hunk ./src/allmydata/storage/crawler.py 31 |
---|
3281 | - or that the number of buckets in each prefixdir will be small enough to |
---|
3282 | - load quickly. A 1TB allmydata.com server was measured to have 2.56M |
---|
3283 | - buckets, spread into the 1024 prefixdirs, with about 2500 buckets per |
---|
3284 | + or that the number of sharesets in each prefixdir will be small enough to |
---|
3285 | + load quickly. A 1TB allmydata.com server was measured to have 2.56 million |
---|
3286 | + sharesets, spread into the 1024 prefixdirs, with about 2500 sharesets per |
---|
3287 | prefix. On this server, each prefixdir took 130ms-200ms to list the first |
---|
3288 | time, and 17ms to list the second time. |
---|
3289 | |
---|
3290 | hunk ./src/allmydata/storage/crawler.py 143 |
---|
3291 | left = len(self.prefixes) - self.last_complete_prefix_index |
---|
3292 | remaining = left * self.last_prefix_elapsed_time |
---|
3293 | # TODO: remainder of this prefix: we need to estimate the |
---|
3294 | - # per-bucket time, probably by measuring the time spent on |
---|
3295 | - # this prefix so far, divided by the number of buckets we've |
---|
3296 | + # per-shareset time, probably by measuring the time spent on |
---|
3297 | + # this prefix so far, divided by the number of sharesets we've |
---|
3298 | # processed. |
---|
3299 | d["estimated-cycle-complete-time-left"] = remaining |
---|
3300 | # it's possible to call get_progress() from inside a crawler's |
---|
3301 | hunk ./src/allmydata/storage/crawler.py 177 |
---|
3302 | def load_state(self): |
---|
3303 | # we use this to store state for both the crawler's internals and |
---|
3304 | # anything the subclass-specific code needs. The state is stored |
---|
3305 | - # after each bucket is processed, after each prefixdir is processed, |
---|
3306 | + # after each shareset is processed, after each prefixdir is processed, |
---|
3307 | # and after a cycle is complete. The internal keys we use are: |
---|
3308 | # ["version"]: int, always 1 |
---|
3309 | # ["last-cycle-finished"]: int, or None if we have not yet finished |
---|
3310 | hunk ./src/allmydata/storage/crawler.py 191 |
---|
3311 | # are sleeping between cycles, or if we |
---|
3312 | # have not yet finished any prefixdir since |
---|
3313 | # a cycle was started |
---|
3314 | - # ["last-complete-bucket"]: str, base32 storage index bucket name |
---|
3315 | - # of the last bucket to be processed, or |
---|
3316 | - # None if we are sleeping between cycles |
---|
3317 | + # ["last-complete-bucket"]: str, base32 storage index of the last |
---|
3318 | + # shareset to be processed, or None if we |
---|
3319 | + # are sleeping between cycles |
---|
3320 | try: |
---|
3321 | f = open(self.statefile, "rb") |
---|
3322 | state = pickle.load(f) |
---|
3323 | hunk ./src/allmydata/storage/crawler.py 279 |
---|
3324 | sleep_time = (this_slice / self.allowed_cpu_percentage) - this_slice |
---|
3325 | # if the math gets weird, or a timequake happens, don't sleep |
---|
3326 | # forever. Note that this means that, while a cycle is running, we |
---|
3327 | - # will process at least one bucket every 5 minutes, no matter how |
---|
3328 | - # long that bucket takes. |
---|
3329 | + # will process at least one shareset every 5 minutes, no matter how |
---|
3330 | + # long that shareset takes. |
---|
3331 | sleep_time = max(0.0, min(sleep_time, 299)) |
---|
3332 | if finished_cycle: |
---|
3333 | # how long should we sleep between cycles? Don't run faster than |
---|
3334 | hunk ./src/allmydata/storage/crawler.py 352 |
---|
3335 | |
---|
3336 | You can override this if your crawler doesn't care about the actual |
---|
3337 | shares, for example a crawler which merely keeps track of how many |
---|
3338 | - buckets are being managed by this server. |
---|
3339 | + sharesets are being managed by this server. |
---|
3340 | |
---|
3341 | Subclasses which *do* care about actual bucket should leave this |
---|
3342 | method along, and implement process_bucket() instead. |
---|
3343 | hunk ./src/allmydata/storage/crawler.py 369 |
---|
3344 | # the remaining methods are explictly for subclasses to implement. |
---|
3345 | |
---|
3346 | def started_cycle(self, cycle): |
---|
3347 | - """Notify a subclass that the crawler is about to start a cycle. |
---|
3348 | + """ |
---|
3349 | + Notify a subclass that the crawler is about to start a cycle. |
---|
3350 | |
---|
3351 | This method is for subclasses to override. No upcall is necessary. |
---|
3352 | """ |
---|
3353 | hunk ./src/allmydata/storage/crawler.py 381 |
---|
3354 | to do to the shares therein, then update self.state as necessary. |
---|
3355 | |
---|
3356 | If the crawler is never interrupted by SIGKILL, this method will be |
---|
3357 | - called exactly once per share (per cycle). If it *is* interrupted, |
---|
3358 | + called exactly once per shareset (per cycle). If it *is* interrupted, |
---|
3359 | then the next time the node is started, some amount of work will be |
---|
3360 | duplicated, according to when self.save_state() was last called. By |
---|
3361 | default, save_state() is called at the end of each timeslice, and |
---|
3362 | hunk ./src/allmydata/storage/crawler.py 400 |
---|
3363 | pass |
---|
3364 | |
---|
3365 | def finished_prefix(self, cycle, prefix): |
---|
3366 | - """Notify a subclass that the crawler has just finished processing a |
---|
3367 | - prefix directory (all buckets with the same two-character/10bit |
---|
3368 | + """ |
---|
3369 | + Notify a subclass that the crawler has just finished processing a |
---|
3370 | + prefix directory (all sharesets with the same two-character/10-bit |
---|
3371 | prefix). To impose a limit on how much work might be duplicated by a |
---|
3372 | SIGKILL that occurs during a timeslice, you can call |
---|
3373 | self.save_state() here, but be aware that it may represent a |
---|
3374 | hunk ./src/allmydata/storage/crawler.py 413 |
---|
3375 | pass |
---|
3376 | |
---|
3377 | def finished_cycle(self, cycle): |
---|
3378 | - """Notify subclass that a cycle (one complete traversal of all |
---|
3379 | + """ |
---|
3380 | + Notify subclass that a cycle (one complete traversal of all |
---|
3381 | prefixdirs) has just finished. 'cycle' is the number of the cycle |
---|
3382 | that just finished. This method should perform summary work and |
---|
3383 | update self.state to publish information to status displays. |
---|
3384 | hunk ./src/allmydata/storage/crawler.py 431 |
---|
3385 | pass |
---|
3386 | |
---|
3387 | def yielding(self, sleep_time): |
---|
3388 | - """The crawler is about to sleep for 'sleep_time' seconds. This |
---|
3389 | + """ |
---|
3390 | + The crawler is about to sleep for 'sleep_time' seconds. This |
---|
3391 | method is mostly for the convenience of unit tests. |
---|
3392 | |
---|
3393 | This method is for subclasses to override. No upcall is necessary. |
---|
3394 | hunk ./src/allmydata/storage/crawler.py 469 |
---|
3395 | |
---|
3396 | def process_prefixdir(self, cycle, prefix, prefixdir, buckets, start_slice): |
---|
3397 | # we override process_prefixdir() because we don't want to look at |
---|
3398 | - # the individual buckets. We'll save state after each one. On my |
---|
3399 | + # the individual sharesets. We'll save state after each one. On my |
---|
3400 | # laptop, a mostly-empty storage server can process about 70 |
---|
3401 | # prefixdirs in a 1.0s slice. |
---|
3402 | if cycle not in self.state["bucket-counts"]: |
---|
3403 | hunk ./src/allmydata/storage/crawler.py 493 |
---|
3404 | old_cycle,buckets = self.state["storage-index-samples"][prefix] |
---|
3405 | if old_cycle != cycle: |
---|
3406 | del self.state["storage-index-samples"][prefix] |
---|
3407 | - |
---|
3408 | hunk ./src/allmydata/storage/expirer.py 15 |
---|
3409 | removed. |
---|
3410 | |
---|
3411 | I collect statistics on the leases and make these available to a web |
---|
3412 | - status page, including:: |
---|
3413 | + status page, including: |
---|
3414 | |
---|
3415 | Space recovered during this cycle-so-far: |
---|
3416 | actual (only if expiration_enabled=True): |
---|
3417 | hunk ./src/allmydata/storage/expirer.py 19 |
---|
3418 | - num-buckets, num-shares, sum of share sizes, real disk usage |
---|
3419 | + num-storage-indices, num-shares, sum of share sizes, real disk usage |
---|
3420 | ('real disk usage' means we use stat(fn).st_blocks*512 and include any |
---|
3421 | space used by the directory) |
---|
3422 | what it would have been with the original lease expiration time |
---|
3423 | hunk ./src/allmydata/storage/expirer.py 30 |
---|
3424 | |
---|
3425 | Space recovered during the last 10 cycles <-- saved in separate pickle |
---|
3426 | |
---|
3427 | - Shares/buckets examined: |
---|
3428 | + Shares/storage-indices examined: |
---|
3429 | this cycle-so-far |
---|
3430 | prediction of rest of cycle |
---|
3431 | during last 10 cycles <-- separate pickle |
---|
3432 | hunk ./src/allmydata/storage/expirer.py 40 |
---|
3433 | Histogram of leases-per-share: |
---|
3434 | this-cycle-to-date |
---|
3435 | last 10 cycles <-- separate pickle |
---|
3436 | - Histogram of lease ages, buckets = 1day |
---|
3437 | + Histogram of lease ages, storage-indices over 1 day |
---|
3438 | cycle-to-date |
---|
3439 | last 10 cycles <-- separate pickle |
---|
3440 | |
---|
3441 | hunk ./src/allmydata/storage/server.py 37 |
---|
3442 | |
---|
3443 | class StorageServer(service.MultiService, Referenceable): |
---|
3444 | implements(RIStorageServer, IStatsProducer) |
---|
3445 | + |
---|
3446 | name = 'storage' |
---|
3447 | LeaseCheckerClass = LeaseCheckingCrawler |
---|
3448 | |
---|
3449 | hunk ./src/allmydata/storage/server.py 268 |
---|
3450 | remaining_space = self.get_available_space() |
---|
3451 | limited = remaining_space is not None |
---|
3452 | if limited: |
---|
3453 | - # this is a bit conservative, since some of this allocated_size() |
---|
3454 | - # has already been written to disk, where it will show up in |
---|
3455 | + # This is a bit conservative, since some of this allocated_size() |
---|
3456 | + # has already been written to the backend, where it will show up in |
---|
3457 | # get_available_space. |
---|
3458 | remaining_space -= self.allocated_size() |
---|
3459 | # self.readonly_storage causes remaining_space <= 0 |
---|
3460 | hunk ./src/allmydata/storage/server.py 274 |
---|
3461 | |
---|
3462 | - # fill alreadygot with all shares that we have, not just the ones |
---|
3463 | + # Fill alreadygot with all shares that we have, not just the ones |
---|
3464 | # they asked about: this will save them a lot of work. Add or update |
---|
3465 | # leases for all of them: if they want us to hold shares for this |
---|
3466 | # file, they'll want us to hold leases for this file. |
---|
3467 | hunk ./src/allmydata/test/no_network.py 23 |
---|
3468 | from twisted.python.failure import Failure |
---|
3469 | from foolscap.api import Referenceable, fireEventually, RemoteException |
---|
3470 | from base64 import b32encode |
---|
3471 | + |
---|
3472 | from allmydata import uri as tahoe_uri |
---|
3473 | from allmydata.client import Client |
---|
3474 | from allmydata.storage.server import StorageServer, storage_index_to_dir |
---|
3475 | hunk ./src/allmydata/test/no_network.py 89 |
---|
3476 | return Failure(RemoteException(f)) |
---|
3477 | d.addErrback(_wrap_exception) |
---|
3478 | def _return_membrane(res): |
---|
3479 | - # rather than complete the difficult task of building a |
---|
3480 | + # Rather than complete the difficult task of building a |
---|
3481 | # fully-general Membrane (which would locate all Referenceable |
---|
3482 | # objects that cross the simulated wire and replace them with |
---|
3483 | # wrappers), we special-case certain methods that we happen to |
---|
3484 | hunk ./src/allmydata/test/no_network.py 156 |
---|
3485 | seed = server.get_permutation_seed() |
---|
3486 | return sha1(peer_selection_index + seed).digest() |
---|
3487 | return sorted(self.get_connected_servers(), key=_permuted) |
---|
3488 | + |
---|
3489 | def get_connected_servers(self): |
---|
3490 | return self.client._servers |
---|
3491 | hunk ./src/allmydata/test/no_network.py 159 |
---|
3492 | + |
---|
3493 | def get_nickname_for_serverid(self, serverid): |
---|
3494 | return None |
---|
3495 | |
---|
3496 | hunk ./src/allmydata/test/test_client.py 71 |
---|
3497 | def test_secrets(self): |
---|
3498 | basedir = "test_client.Basic.test_secrets" |
---|
3499 | os.mkdir(basedir) |
---|
3500 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
3501 | - BASECONFIG) |
---|
3502 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
3503 | + BASECONFIG) |
---|
3504 | c = client.Client(basedir) |
---|
3505 | secret_fname = os.path.join(basedir, "private", "secret") |
---|
3506 | self.failUnless(os.path.exists(secret_fname), secret_fname) |
---|
3507 | hunk ./src/allmydata/test/test_client.py 84 |
---|
3508 | def test_reserved_1(self): |
---|
3509 | basedir = "client.Basic.test_reserved_1" |
---|
3510 | os.mkdir(basedir) |
---|
3511 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
3512 | - BASECONFIG + \ |
---|
3513 | - "[storage]\n" + \ |
---|
3514 | - "enabled = true\n" + \ |
---|
3515 | - "reserved_space = 1000\n") |
---|
3516 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
3517 | + BASECONFIG + |
---|
3518 | + "[storage]\n" + |
---|
3519 | + "enabled = true\n" + |
---|
3520 | + "reserved_space = 1000\n") |
---|
3521 | c = client.Client(basedir) |
---|
3522 | self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 1000) |
---|
3523 | |
---|
3524 | hunk ./src/allmydata/test/test_client.py 95 |
---|
3525 | def test_reserved_2(self): |
---|
3526 | basedir = "client.Basic.test_reserved_2" |
---|
3527 | os.mkdir(basedir) |
---|
3528 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
3529 | - BASECONFIG + \ |
---|
3530 | - "[storage]\n" + \ |
---|
3531 | - "enabled = true\n" + \ |
---|
3532 | - "reserved_space = 10K\n") |
---|
3533 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
3534 | + BASECONFIG + |
---|
3535 | + "[storage]\n" + |
---|
3536 | + "enabled = true\n" + |
---|
3537 | + "reserved_space = 10K\n") |
---|
3538 | c = client.Client(basedir) |
---|
3539 | self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000) |
---|
3540 | |
---|
3541 | hunk ./src/allmydata/test/test_client.py 106 |
---|
3542 | def test_reserved_3(self): |
---|
3543 | basedir = "client.Basic.test_reserved_3" |
---|
3544 | os.mkdir(basedir) |
---|
3545 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
3546 | - BASECONFIG + \ |
---|
3547 | - "[storage]\n" + \ |
---|
3548 | - "enabled = true\n" + \ |
---|
3549 | - "reserved_space = 5mB\n") |
---|
3550 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
3551 | + BASECONFIG + |
---|
3552 | + "[storage]\n" + |
---|
3553 | + "enabled = true\n" + |
---|
3554 | + "reserved_space = 5mB\n") |
---|
3555 | c = client.Client(basedir) |
---|
3556 | self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, |
---|
3557 | 5*1000*1000) |
---|
3558 | hunk ./src/allmydata/test/test_crawler.py 19 |
---|
3559 | class BucketEnumeratingCrawler(ShareCrawler): |
---|
3560 | cpu_slice = 500 # make sure it can complete in a single slice |
---|
3561 | slow_start = 0 |
---|
3562 | + |
---|
3563 | def __init__(self, *args, **kwargs): |
---|
3564 | ShareCrawler.__init__(self, *args, **kwargs) |
---|
3565 | self.all_buckets = [] |
---|
3566 | hunk ./src/allmydata/test/test_crawler.py 29 |
---|
3567 | def finished_cycle(self, cycle): |
---|
3568 | eventually(self.finished_d.callback, None) |
---|
3569 | |
---|
3570 | + |
---|
3571 | class PacedCrawler(ShareCrawler): |
---|
3572 | cpu_slice = 500 # make sure it can complete in a single slice |
---|
3573 | slow_start = 0 |
---|
3574 | hunk ./src/allmydata/test/test_crawler.py 33 |
---|
3575 | + |
---|
3576 | def __init__(self, *args, **kwargs): |
---|
3577 | ShareCrawler.__init__(self, *args, **kwargs) |
---|
3578 | self.countdown = 6 |
---|
3579 | hunk ./src/allmydata/test/test_crawler.py 46 |
---|
3580 | if self.countdown == 0: |
---|
3581 | # force a timeout. We restore it in yielding() |
---|
3582 | self.cpu_slice = -1.0 |
---|
3583 | + |
---|
3584 | def yielding(self, sleep_time): |
---|
3585 | self.cpu_slice = 500 |
---|
3586 | if self.yield_cb: |
---|
3587 | hunk ./src/allmydata/test/test_crawler.py 51 |
---|
3588 | self.yield_cb() |
---|
3589 | + |
---|
3590 | def finished_cycle(self, cycle): |
---|
3591 | eventually(self.finished_d.callback, None) |
---|
3592 | |
---|
3593 | hunk ./src/allmydata/test/test_crawler.py 55 |
---|
3594 | + |
---|
3595 | class ConsumingCrawler(ShareCrawler): |
---|
3596 | cpu_slice = 0.5 |
---|
3597 | allowed_cpu_percentage = 0.5 |
---|
3598 | hunk ./src/allmydata/test/test_crawler.py 73 |
---|
3599 | elapsed = time.time() - start |
---|
3600 | self.accumulated += elapsed |
---|
3601 | self.last_yield += elapsed |
---|
3602 | + |
---|
3603 | def finished_cycle(self, cycle): |
---|
3604 | self.cycles += 1 |
---|
3605 | hunk ./src/allmydata/test/test_crawler.py 76 |
---|
3606 | + |
---|
3607 | def yielding(self, sleep_time): |
---|
3608 | self.last_yield = 0.0 |
---|
3609 | |
---|
3610 | hunk ./src/allmydata/test/test_crawler.py 80 |
---|
3611 | + |
---|
3612 | class OneShotCrawler(ShareCrawler): |
---|
3613 | cpu_slice = 500 # make sure it can complete in a single slice |
---|
3614 | slow_start = 0 |
---|
3615 | hunk ./src/allmydata/test/test_crawler.py 84 |
---|
3616 | + |
---|
3617 | def __init__(self, *args, **kwargs): |
---|
3618 | ShareCrawler.__init__(self, *args, **kwargs) |
---|
3619 | self.counter = 0 |
---|
3620 | hunk ./src/allmydata/test/test_crawler.py 91 |
---|
3621 | self.finished_d = defer.Deferred() |
---|
3622 | def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
3623 | self.counter += 1 |
---|
3624 | + |
---|
3625 | def finished_cycle(self, cycle): |
---|
3626 | self.finished_d.callback(None) |
---|
3627 | self.disownServiceParent() |
---|
3628 | hunk ./src/allmydata/test/test_crawler.py 96 |
---|
3629 | |
---|
3630 | + |
---|
3631 | class Basic(unittest.TestCase, StallMixin, pollmixin.PollMixin): |
---|
3632 | def setUp(self): |
---|
3633 | self.s = service.MultiService() |
---|
3634 | hunk ./src/allmydata/test/test_crawler.py 107 |
---|
3635 | |
---|
3636 | def si(self, i): |
---|
3637 | return hashutil.storage_index_hash(str(i)) |
---|
3638 | + |
---|
3639 | def rs(self, i, serverid): |
---|
3640 | return hashutil.bucket_renewal_secret_hash(str(i), serverid) |
---|
3641 | hunk ./src/allmydata/test/test_crawler.py 110 |
---|
3642 | + |
---|
3643 | def cs(self, i, serverid): |
---|
3644 | return hashutil.bucket_cancel_secret_hash(str(i), serverid) |
---|
3645 | |
---|
3646 | hunk ./src/allmydata/test/test_crawler.py 423 |
---|
3647 | d.addCallback(_done) |
---|
3648 | return d |
---|
3649 | |
---|
3650 | - |
---|
3651 | def test_oneshot(self): |
---|
3652 | self.basedir = "crawler/Basic/oneshot" |
---|
3653 | fileutil.make_dirs(self.basedir) |
---|
3654 | hunk ./src/allmydata/test/test_crawler.py 452 |
---|
3655 | self.failUnlessEqual(s["current-cycle"], None) |
---|
3656 | d.addCallback(_check) |
---|
3657 | return d |
---|
3658 | - |
---|
3659 | hunk ./src/allmydata/test/test_deepcheck.py 903 |
---|
3660 | d.addErrback(self.explain_error) |
---|
3661 | return d |
---|
3662 | |
---|
3663 | - |
---|
3664 | - |
---|
3665 | def set_up_damaged_tree(self): |
---|
3666 | # 6.4s |
---|
3667 | |
---|
3668 | hunk ./src/allmydata/test/test_deepcheck.py 1083 |
---|
3669 | |
---|
3670 | d.addCallback(lambda ign: _checkv("mutable-good", self.check_is_healthy)) |
---|
3671 | d.addCallback(lambda ign: _checkv("mutable-missing-shares", |
---|
3672 | - self.check_is_missing_shares)) |
---|
3673 | + self.check_is_missing_shares)) |
---|
3674 | d.addCallback(lambda ign: _checkv("mutable-corrupt-shares", |
---|
3675 | hunk ./src/allmydata/test/test_deepcheck.py 1085 |
---|
3676 | - self.check_has_corrupt_shares)) |
---|
3677 | + self.check_has_corrupt_shares)) |
---|
3678 | d.addCallback(lambda ign: _checkv("mutable-unrecoverable", |
---|
3679 | hunk ./src/allmydata/test/test_deepcheck.py 1087 |
---|
3680 | - self.check_is_unrecoverable)) |
---|
3681 | + self.check_is_unrecoverable)) |
---|
3682 | d.addCallback(lambda ign: _checkv("large-good", self.check_is_healthy)) |
---|
3683 | d.addCallback(lambda ign: _checkv("large-missing-shares", self.check_is_missing_shares)) |
---|
3684 | d.addCallback(lambda ign: _checkv("large-corrupt-shares", self.check_has_corrupt_shares)) |
---|
3685 | hunk ./src/allmydata/test/test_deepcheck.py 1092 |
---|
3686 | d.addCallback(lambda ign: _checkv("large-unrecoverable", |
---|
3687 | - self.check_is_unrecoverable)) |
---|
3688 | + self.check_is_unrecoverable)) |
---|
3689 | |
---|
3690 | return d |
---|
3691 | |
---|
3692 | hunk ./src/allmydata/test/test_deepcheck.py 1202 |
---|
3693 | d.addCallback(lambda ign: _checkv("mutable-good", |
---|
3694 | self.json_is_healthy)) |
---|
3695 | d.addCallback(lambda ign: _checkv("mutable-missing-shares", |
---|
3696 | - self.json_is_missing_shares)) |
---|
3697 | + self.json_is_missing_shares)) |
---|
3698 | d.addCallback(lambda ign: _checkv("mutable-corrupt-shares", |
---|
3699 | hunk ./src/allmydata/test/test_deepcheck.py 1204 |
---|
3700 | - self.json_has_corrupt_shares)) |
---|
3701 | + self.json_has_corrupt_shares)) |
---|
3702 | d.addCallback(lambda ign: _checkv("mutable-unrecoverable", |
---|
3703 | hunk ./src/allmydata/test/test_deepcheck.py 1206 |
---|
3704 | - self.json_is_unrecoverable)) |
---|
3705 | + self.json_is_unrecoverable)) |
---|
3706 | d.addCallback(lambda ign: _checkv("large-good", |
---|
3707 | self.json_is_healthy)) |
---|
3708 | d.addCallback(lambda ign: _checkv("large-missing-shares", self.json_is_missing_shares)) |
---|
3709 | hunk ./src/allmydata/test/test_deepcheck.py 1212 |
---|
3710 | d.addCallback(lambda ign: _checkv("large-corrupt-shares", self.json_has_corrupt_shares)) |
---|
3711 | d.addCallback(lambda ign: _checkv("large-unrecoverable", |
---|
3712 | - self.json_is_unrecoverable)) |
---|
3713 | + self.json_is_unrecoverable)) |
---|
3714 | |
---|
3715 | return d |
---|
3716 | |
---|
3717 | hunk ./src/allmydata/test/test_download.py 1002 |
---|
3718 | d.addCallback(_got_data) |
---|
3719 | return d |
---|
3720 | |
---|
3721 | - |
---|
3722 | d = self.c0.upload(u) |
---|
3723 | def _uploaded(ur): |
---|
3724 | imm_uri = ur.uri |
---|
3725 | hunk ./src/allmydata/test/test_download.py 1067 |
---|
3726 | d.addCallback(fireEventually) |
---|
3727 | return d |
---|
3728 | d.addCallback(_uploaded) |
---|
3729 | + |
---|
3730 | def _show_results(ign): |
---|
3731 | print |
---|
3732 | print ("of [0:%d], corruption ignored in %s" % |
---|
3733 | hunk ./src/allmydata/test/test_hung_server.py 20 |
---|
3734 | immutable_plaintext = "data" * 10000 |
---|
3735 | mutable_plaintext = "muta" * 10000 |
---|
3736 | |
---|
3737 | + |
---|
3738 | class HungServerDownloadTest(GridTestMixin, ShouldFailMixin, PollMixin, |
---|
3739 | unittest.TestCase): |
---|
3740 | # Many of these tests take around 60 seconds on François's ARM buildslave: |
---|
3741 | hunk ./src/allmydata/test/test_hung_server.py 159 |
---|
3742 | self._download_and_check) |
---|
3743 | else: |
---|
3744 | return self.shouldFail(NotEnoughSharesError, self.basedir, |
---|
3745 | - "ran out of shares", |
---|
3746 | + "ran out of shares", |
---|
3747 | self._download_and_check) |
---|
3748 | |
---|
3749 | |
---|
3750 | hunk ./src/allmydata/test/test_hung_server.py 268 |
---|
3751 | # stuck-but-not-overdue, and 4 live requests. All 4 live requests |
---|
3752 | # will retire before the download is complete and the ShareFinder |
---|
3753 | # is shut off. That will leave 4 OVERDUE and 1 |
---|
3754 | - # stuck-but-not-overdue, for a total of 5 requests in in |
---|
3755 | + # stuck-but-not-overdue, for a total of 5 requests in |
---|
3756 | # _sf.pending_requests |
---|
3757 | for t in self._sf.overdue_timers.values()[:4]: |
---|
3758 | t.reset(-1.0) |
---|
3759 | hunk ./src/allmydata/test/test_mutable.py 3542 |
---|
3760 | sdmf_old_shares[9] = "VGFob2UgbXV0YWJsZSBjb250YWluZXIgdjEKdQlEA47ESLbTdKdpLJXCpBxd5OH239tl5hvAiz1dvGdE5rIOpf8cbfxbPcwNF+Y5dM92uBVbmV6KAAAAAAAAB/wAAAAAAAAJ0AAAAAFOWSw7jSx7WXzaMpdleJYXwYsRCV82jNA5oex9m2YhXSnb2POh+vvC1LE1NAfRc9GOb2zQG84Xdsx1Jub2brEeKkyt0sRIttN0p2kslcKkHF3k4fbf22XmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABamJprL6ecrsOoFKdrXUmWveLq8nzEGDOjFnyK9detI3noX3uyK2MwSnFdAfyN0tuAwoAAAAAAAAAFQAAAAAAAAAVAAABjwAAAo8AAAMXAAADNwAAAAAAAAM+AAAAAAAAB/wwggEgMA0GCSqGSIb3DQEBAQUAA4IBDQAwggEIAoIBAQC1IkainlJF12IBXBQdpRK1zXB7a26vuEYqRmQM09YjC6sQjCs0F2ICk8n9m/2Kw4l16eIEboB2Au9pODCE+u/dEAakEFh4qidTMn61rbGUbsLK8xzuWNW22ezzz9/nPia0HDrulXt51/FYtfnnAuD1RJGXJv/8tDllE9FL/18TzlH4WuB6Fp8FTgv7QdbZAfWJHDGFIpVCJr1XxOCsSZNFJIqGwZnD2lsChiWw5OJDbKd8otqN1hIbfHyMyfMOJ/BzRzvZXaUt4Dv5nf93EmQDWClxShRwpuX/NkZ5B2K9OFonFTbOCexm/MjMAdCBqebKKaiHFkiknUCn9eJQpZ5bAgERgV50VKj+AVTDfgTpqfO2vfo4wrufi6ZBb8QV7hllhUFBjYogQ9C96dnS7skv0s+cqFuUjwMILr5/rsbEmEMGvl0T0ytyAbtlXuowEFVj/YORNknM4yjY72YUtEPTlMpk0Cis7aIgTvu5qWMPER26PMApZuRqiwRsGIkaJIvOVOTHHjFYe3/YzdMkc7OZtqRMfQLtwVl2/zKQQV8b/a9vaT6q3mRLRd4P3esaAFe/+7sR/t+9tmB+a8kxtKM6kmaVQJMbXJZ4aoHGfeLX0m35Rcvu2Bmph7QfSDjk/eaE3q55zYSoGWShmlhlw4Kwg84sMuhmcVhLvo0LovR8bKmbdgABUSzNKiMx0E91q51/WH6ASL0fDEOLef9oxuyBX5F5cpoABojmWkDX3k3FKfgNHIeptE3lxB8HHzxDfSD250psyfNCAAwGsKbMxbmI2NpdTozZ3SICrySwgGkatA1gsDOJmOnTzgAXVnLiODzHiLFAI/MsXcR71fmvb7UghLA1b8pq66KAyl+aopjsD29AKG5hrXt9hLIp6shvfrzaPGIid5C8IxYIrjgBj1YohGgDE0Wua7Lx6Bnad5n91qmHAnwSEJE5YIhQM634omd6cq9Wk4seJCUIn+ucoknrpxp0IR9QMxpKSMRHRUg2K8ZegnY3YqFunRZKCfsq9ufQEKgjZN12AFqi551KPBdn4/3V5HK6xTv0P4robSsE/BvuIfByvRf/W7ZrDx+CFC4EEcsBOACOZCrkhhqd5TkYKbe9RA+vs56+9N5qZGurkxcoKviiyEncxvTuShD65DK/6x6kMDMgQv/EdZDI3x9GtHTnRBYXwDGnPJ19w+q2zC3e2XarbxTGYQIPEC5mYx0gAA0sbjf018NGfwBhl6SB54iGsa8uLvR3jHv6OSRJgwxL6j7P0Ts4Hv2EtO12P0Lv21pwi3JC1O/WviSrKCvrQD5lMHL9Uym3hwFi2zu0mqwZvxOAbGy7kfOPXkLYKOHTZLthzKj3PsdjeceWBfYIvPGKYcd6wDr36d1aXSYS4IWeApTS2AQ2lu0DUcgSefAvsA8NkgOklvJY1cjTMSg6j6cxQo48Bvl8RAWGLbr4h2S/8KwDGxwLsSv0Gop/gnFc3GzCsmL0EkEyHHWkCA8YRXCghfW80KLDV495ff7yF5oiwK56GniqowZ3RG9Jxp5MXoJQgsLV1VMQFMAmsY69yz8eoxRH3wl9L0dMyndLulhWWzNwPMQ2I0yAWdzA/pksVmwTJTFenB3MHCiWc5rEwJ3yofe6NZZnZQrYyL9r1TNnVwfTwRUiykPiLSk4x9Mi6DX7RamDAxc8u3gDVfjPsTOTagBOEGUWlGAL54KE/E6sgCQ5DEAt12chk8AxbjBFLPgV+/idrzS0lZHOL+IVBI9D0i3Bq1yZcSIqcjZB0M3IbxbPm4gLAYOWEiTUN2ecsEHHg9nt6rhgffVoqSbCCFPbpC0xf7WOC3+BQORIZECOCC7cUAciXq3xn+GuxpFE40RWRJeKAK7bBQ21X89ABIXlQFkFddZ9kRvlZ2Pnl0oeF+2pjnZu0Yc2czNfZEQF2P7BKIdLrgMgxG89snxAY8qAYTCKyQw6xTG87wkjDcpy1wzsZLP3WsOuO7cAm7b27xU0jRKq8Cw4d1hDoyRG+RdS53F8RFJzVMaNNYgxU2tfRwUvXpTRXiOheeRVvh25+YGVnjakUXjx/dSDnOw4ETHGHD+7styDkeSfc3BdSZxswzc6OehgMI+xsCxeeRym15QUm9hxvg8X7Bfz/0WulgFwgzrm11TVynZYOmvyHpiZKoqQyQyKahIrfhwuchCr7lMsZ4a+umIkNkKxCLZnI+T7jd+eGFMgKItjz3kTTxRl3IhaJG3LbPmwRUJynMxQKdMi4Uf0qy0U7+i8hIJ9m50QXc+3tw2bwDSbx22XYJ9Wf14gxx5G5SPTb1JVCbhe4fxNt91xIxCow2zk62tzbYfRe6dfmDmgYHkv2PIEtMJZK8iKLDjFfu2ZUxsKT2A5g1q17og6o9MeXeuFS3mzJXJYFQZd+3UzlFR9qwkFkby9mg5y4XSeMvRLOHPt/H/r5SpEqBE6a9MadZYt61FBV152CUEzd43ihXtrAa0XH9HdsiySBcWI1SpM3mv9rRP0DiLjMUzHw/K1D8TE2f07zW4t/9kvE11tFj/NpICixQAAAAA=" |
---|
3761 | sdmf_old_cap = "URI:SSK:gmjgofw6gan57gwpsow6gtrz3e:5adm6fayxmu3e4lkmfvt6lkkfix34ai2wop2ioqr4bgvvhiol3kq" |
---|
3762 | sdmf_old_contents = "This is a test file.\n" |
---|
3763 | + |
---|
3764 | def copy_sdmf_shares(self): |
---|
3765 | # We'll basically be short-circuiting the upload process. |
---|
3766 | servernums = self.g.servers_by_number.keys() |
---|
3767 | hunk ./src/allmydata/test/test_mutable.py 3576 |
---|
3768 | d.addCallback(self.failUnlessEqual, self.sdmf_old_contents) |
---|
3769 | return d |
---|
3770 | |
---|
3771 | + |
---|
3772 | class DifferentEncoding(unittest.TestCase): |
---|
3773 | def setUp(self): |
---|
3774 | self._storage = s = FakeStorage() |
---|
3775 | hunk ./src/allmydata/test/test_no_network.py 10 |
---|
3776 | from allmydata.immutable.upload import Data |
---|
3777 | from allmydata.util.consumer import download_to_data |
---|
3778 | |
---|
3779 | + |
---|
3780 | class Harness(unittest.TestCase): |
---|
3781 | def setUp(self): |
---|
3782 | self.s = service.MultiService() |
---|
3783 | hunk ./src/allmydata/test/test_storage.py 6 |
---|
3784 | import mock |
---|
3785 | |
---|
3786 | from twisted.trial import unittest |
---|
3787 | - |
---|
3788 | from twisted.internet import defer |
---|
3789 | from twisted.application import service |
---|
3790 | from foolscap.api import fireEventually |
---|
3791 | hunk ./src/allmydata/test/test_storage.py 36 |
---|
3792 | from allmydata.test.no_network import NoNetworkServer |
---|
3793 | from allmydata.web.storage import StorageStatus, remove_prefix |
---|
3794 | |
---|
3795 | + |
---|
3796 | class Marker: |
---|
3797 | pass |
---|
3798 | hunk ./src/allmydata/test/test_storage.py 39 |
---|
3799 | + |
---|
3800 | + |
---|
3801 | class FakeCanary: |
---|
3802 | def __init__(self, ignore_disconnectors=False): |
---|
3803 | self.ignore = ignore_disconnectors |
---|
3804 | hunk ./src/allmydata/test/test_storage.py 56 |
---|
3805 | return |
---|
3806 | del self.disconnectors[marker] |
---|
3807 | |
---|
3808 | + |
---|
3809 | class FakeStatsProvider: |
---|
3810 | def count(self, name, delta=1): |
---|
3811 | pass |
---|
3812 | hunk ./src/allmydata/test/test_storage.py 63 |
---|
3813 | def register_producer(self, producer): |
---|
3814 | pass |
---|
3815 | |
---|
3816 | + |
---|
3817 | class Bucket(unittest.TestCase): |
---|
3818 | def make_workdir(self, name): |
---|
3819 | basedir = os.path.join("storage", "Bucket", name) |
---|
3820 | hunk ./src/allmydata/test/test_storage.py 292 |
---|
3821 | return d1 |
---|
3822 | |
---|
3823 | d.addCallback(_start_reading) |
---|
3824 | - |
---|
3825 | return d |
---|
3826 | |
---|
3827 | def test_readwrite_v1(self): |
---|
3828 | hunk ./src/allmydata/test/test_storage.py 1388 |
---|
3829 | # header. |
---|
3830 | self.salt_hash_tree_s = self.serialize_blockhashes(self.salt_hash_tree[1:]) |
---|
3831 | |
---|
3832 | - |
---|
3833 | def tearDown(self): |
---|
3834 | self.sparent.stopService() |
---|
3835 | shutil.rmtree(self.workdir("MDMFProxies storage test server")) |
---|
3836 | hunk ./src/allmydata/test/test_storage.py 1396 |
---|
3837 | def write_enabler(self, we_tag): |
---|
3838 | return hashutil.tagged_hash("we_blah", we_tag) |
---|
3839 | |
---|
3840 | - |
---|
3841 | def renew_secret(self, tag): |
---|
3842 | return hashutil.tagged_hash("renew_blah", str(tag)) |
---|
3843 | |
---|
3844 | hunk ./src/allmydata/test/test_storage.py 1399 |
---|
3845 | - |
---|
3846 | def cancel_secret(self, tag): |
---|
3847 | return hashutil.tagged_hash("cancel_blah", str(tag)) |
---|
3848 | |
---|
3849 | hunk ./src/allmydata/test/test_storage.py 1402 |
---|
3850 | - |
---|
3851 | def workdir(self, name): |
---|
3852 | basedir = os.path.join("storage", "MutableServer", name) |
---|
3853 | return basedir |
---|
3854 | hunk ./src/allmydata/test/test_storage.py 1413 |
---|
3855 | ss.setServiceParent(self.sparent) |
---|
3856 | return ss |
---|
3857 | |
---|
3858 | - |
---|
3859 | def build_test_mdmf_share(self, tail_segment=False, empty=False): |
---|
3860 | # Start with the checkstring |
---|
3861 | data = struct.pack(">BQ32s", |
---|
3862 | hunk ./src/allmydata/test/test_storage.py 1510 |
---|
3863 | data += self.block_hash_tree_s |
---|
3864 | return data |
---|
3865 | |
---|
3866 | - |
---|
3867 | def write_test_share_to_server(self, |
---|
3868 | storage_index, |
---|
3869 | tail_segment=False, |
---|
3870 | hunk ./src/allmydata/test/test_storage.py 1582 |
---|
3871 | self.offsets['EOF'] = eof_offset |
---|
3872 | return final_share |
---|
3873 | |
---|
3874 | - |
---|
3875 | def write_sdmf_share_to_server(self, |
---|
3876 | storage_index, |
---|
3877 | empty=False): |
---|
3878 | hunk ./src/allmydata/test/test_storage.py 1667 |
---|
3879 | self.failUnlessEqual(checkstring, checkstring)) |
---|
3880 | return d |
---|
3881 | |
---|
3882 | - |
---|
3883 | def test_read_with_different_tail_segment_size(self): |
---|
3884 | self.write_test_share_to_server("si1", tail_segment=True) |
---|
3885 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3886 | hunk ./src/allmydata/test/test_storage.py 1678 |
---|
3887 | d.addCallback(_check_tail_segment) |
---|
3888 | return d |
---|
3889 | |
---|
3890 | - |
---|
3891 | def test_get_block_with_invalid_segnum(self): |
---|
3892 | self.write_test_share_to_server("si1") |
---|
3893 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3894 | hunk ./src/allmydata/test/test_storage.py 1688 |
---|
3895 | mr.get_block_and_salt, 7)) |
---|
3896 | return d |
---|
3897 | |
---|
3898 | - |
---|
3899 | def test_get_encoding_parameters_first(self): |
---|
3900 | self.write_test_share_to_server("si1") |
---|
3901 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3902 | hunk ./src/allmydata/test/test_storage.py 1700 |
---|
3903 | d.addCallback(_check_encoding_parameters) |
---|
3904 | return d |
---|
3905 | |
---|
3906 | - |
---|
3907 | def test_get_seqnum_first(self): |
---|
3908 | self.write_test_share_to_server("si1") |
---|
3909 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3910 | hunk ./src/allmydata/test/test_storage.py 1708 |
---|
3911 | self.failUnlessEqual(seqnum, 0)) |
---|
3912 | return d |
---|
3913 | |
---|
3914 | - |
---|
3915 | def test_get_root_hash_first(self): |
---|
3916 | self.write_test_share_to_server("si1") |
---|
3917 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3918 | hunk ./src/allmydata/test/test_storage.py 1716 |
---|
3919 | self.failUnlessEqual(root_hash, self.root_hash)) |
---|
3920 | return d |
---|
3921 | |
---|
3922 | - |
---|
3923 | def test_get_checkstring_first(self): |
---|
3924 | self.write_test_share_to_server("si1") |
---|
3925 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
3926 | hunk ./src/allmydata/test/test_storage.py 1724 |
---|
3927 | self.failUnlessEqual(checkstring, self.checkstring)) |
---|
3928 | return d |
---|
3929 | |
---|
3930 | - |
---|
3931 | def test_write_read_vectors(self): |
---|
3932 | # When writing for us, the storage server will return to us a |
---|
3933 | # read vector, along with its result. If a write fails because |
---|
3934 | hunk ./src/allmydata/test/test_storage.py 1740 |
---|
3935 | mw.put_root_hash(self.root_hash) |
---|
3936 | mw.put_signature(self.signature) |
---|
3937 | mw.put_verification_key(self.verification_key) |
---|
3938 | + |
---|
3939 | d = mw.finish_publishing() |
---|
3940 | def _then(results): |
---|
3941 | self.failUnless(len(results), 2) |
---|
3942 | hunk ./src/allmydata/test/test_storage.py 1763 |
---|
3943 | # The checkstring remains the same for the rest of the process. |
---|
3944 | return d |
---|
3945 | |
---|
3946 | - |
---|
3947 | def test_private_key_after_share_hash_chain(self): |
---|
3948 | mw = self._make_new_mw("si1", 0) |
---|
3949 | d = defer.succeed(None) |
---|
3950 | hunk ./src/allmydata/test/test_storage.py 1781 |
---|
3951 | mw.put_encprivkey, self.encprivkey)) |
---|
3952 | return d |
---|
3953 | |
---|
3954 | - |
---|
3955 | def test_signature_after_verification_key(self): |
---|
3956 | mw = self._make_new_mw("si1", 0) |
---|
3957 | d = defer.succeed(None) |
---|
3958 | hunk ./src/allmydata/test/test_storage.py 1807 |
---|
3959 | mw.put_signature, self.signature)) |
---|
3960 | return d |
---|
3961 | |
---|
3962 | - |
---|
3963 | def test_uncoordinated_write(self): |
---|
3964 | # Make two mutable writers, both pointing to the same storage |
---|
3965 | # server, both at the same storage index, and try writing to the |
---|
3966 | hunk ./src/allmydata/test/test_storage.py 1839 |
---|
3967 | d.addCallback(_check_failure) |
---|
3968 | return d |
---|
3969 | |
---|
3970 | - |
---|
3971 | def test_invalid_salt_size(self): |
---|
3972 | # Salts need to be 16 bytes in size. Writes that attempt to |
---|
3973 | # write more or less than this should be rejected. |
---|
3974 | hunk ./src/allmydata/test/test_storage.py 1857 |
---|
3975 | another_invalid_salt)) |
---|
3976 | return d |
---|
3977 | |
---|
3978 | - |
---|
3979 | def test_write_test_vectors(self): |
---|
3980 | # If we give the write proxy a bogus test vector at |
---|
3981 | # any point during the process, it should fail to write when we |
---|
3982 | hunk ./src/allmydata/test/test_storage.py 1881 |
---|
3983 | mw.put_root_hash(self.root_hash) |
---|
3984 | mw.put_signature(self.signature) |
---|
3985 | mw.put_verification_key(self.verification_key) |
---|
3986 | + |
---|
3987 | d = mw.finish_publishing() |
---|
3988 | d.addCallback(_check_failure) |
---|
3989 | d.addCallback(lambda ignored: |
---|
3990 | hunk ./src/allmydata/test/test_storage.py 1891 |
---|
3991 | d.addCallback(_check_success) |
---|
3992 | return d |
---|
3993 | |
---|
3994 | - |
---|
3995 | def serialize_blockhashes(self, blockhashes): |
---|
3996 | return "".join(blockhashes) |
---|
3997 | |
---|
3998 | hunk ./src/allmydata/test/test_storage.py 1894 |
---|
3999 | - |
---|
4000 | def serialize_sharehashes(self, sharehashes): |
---|
4001 | ret = "".join([struct.pack(">H32s", i, sharehashes[i]) |
---|
4002 | for i in sorted(sharehashes.keys())]) |
---|
4003 | hunk ./src/allmydata/test/test_storage.py 1899 |
---|
4004 | return ret |
---|
4005 | |
---|
4006 | - |
---|
4007 | def test_write(self): |
---|
4008 | # This translates to a file with 6 6-byte segments, and with 2-byte |
---|
4009 | # blocks. |
---|
4010 | hunk ./src/allmydata/test/test_storage.py 1922 |
---|
4011 | mw.put_root_hash(self.root_hash) |
---|
4012 | mw.put_signature(self.signature) |
---|
4013 | mw.put_verification_key(self.verification_key) |
---|
4014 | + |
---|
4015 | d = mw.finish_publishing() |
---|
4016 | def _check_publish(results): |
---|
4017 | self.failUnlessEqual(len(results), 2) |
---|
4018 | hunk ./src/allmydata/test/test_storage.py 2031 |
---|
4019 | 6, datalength) |
---|
4020 | return mw |
---|
4021 | |
---|
4022 | - |
---|
4023 | def test_write_rejected_with_too_many_blocks(self): |
---|
4024 | mw = self._make_new_mw("si0", 0) |
---|
4025 | |
---|
4026 | hunk ./src/allmydata/test/test_storage.py 2035 |
---|
4027 | # Try writing too many blocks. We should not be able to write |
---|
4028 | - # more than 6 |
---|
4029 | - # blocks into each share. |
---|
4030 | + # more than 6 blocks into each share. |
---|
4031 | d = defer.succeed(None) |
---|
4032 | for i in xrange(6): |
---|
4033 | d.addCallback(lambda ignored, i=i: |
---|
4034 | hunk ./src/allmydata/test/test_storage.py 2046 |
---|
4035 | mw.put_block, self.block, 7, self.salt)) |
---|
4036 | return d |
---|
4037 | |
---|
4038 | - |
---|
4039 | def test_write_rejected_with_invalid_salt(self): |
---|
4040 | # Try writing an invalid salt. Salts are 16 bytes -- any more or |
---|
4041 | # less should cause an error. |
---|
4042 | hunk ./src/allmydata/test/test_storage.py 2057 |
---|
4043 | None, mw.put_block, self.block, 7, bad_salt)) |
---|
4044 | return d |
---|
4045 | |
---|
4046 | - |
---|
4047 | def test_write_rejected_with_invalid_root_hash(self): |
---|
4048 | # Try writing an invalid root hash. This should be SHA256d, and |
---|
4049 | # 32 bytes long as a result. |
---|
4050 | hunk ./src/allmydata/test/test_storage.py 2082 |
---|
4051 | None, mw.put_root_hash, invalid_root_hash)) |
---|
4052 | return d |
---|
4053 | |
---|
4054 | - |
---|
4055 | def test_write_rejected_with_invalid_blocksize(self): |
---|
4056 | # The blocksize implied by the writer that we get from |
---|
4057 | # _make_new_mw is 2bytes -- any more or any less than this |
---|
4058 | hunk ./src/allmydata/test/test_storage.py 2115 |
---|
4059 | mw.put_block(valid_block, 5, self.salt)) |
---|
4060 | return d |
---|
4061 | |
---|
4062 | - |
---|
4063 | def test_write_enforces_order_constraints(self): |
---|
4064 | # We require that the MDMFSlotWriteProxy be interacted with in a |
---|
4065 | # specific way. |
---|
4066 | hunk ./src/allmydata/test/test_storage.py 2200 |
---|
4067 | mw0.put_verification_key(self.verification_key)) |
---|
4068 | return d |
---|
4069 | |
---|
4070 | - |
---|
4071 | def test_end_to_end(self): |
---|
4072 | mw = self._make_new_mw("si1", 0) |
---|
4073 | # Write a share using the mutable writer, and make sure that the |
---|
4074 | hunk ./src/allmydata/test/test_storage.py 2283 |
---|
4075 | self.failUnlessEqual(checkstring, mw.get_checkstring())) |
---|
4076 | return d |
---|
4077 | |
---|
4078 | - |
---|
4079 | def test_is_sdmf(self): |
---|
4080 | # The MDMFSlotReadProxy should also know how to read SDMF files, |
---|
4081 | # since it will encounter them on the grid. Callers use the |
---|
4082 | hunk ./src/allmydata/test/test_storage.py 2294 |
---|
4083 | self.failUnless(issdmf)) |
---|
4084 | return d |
---|
4085 | |
---|
4086 | - |
---|
4087 | def test_reads_sdmf(self): |
---|
4088 | # The slot read proxy should, naturally, know how to tell us |
---|
4089 | # about data in the SDMF format |
---|
4090 | hunk ./src/allmydata/test/test_storage.py 2381 |
---|
4091 | mr.get_block_and_salt, 1)) |
---|
4092 | return d |
---|
4093 | |
---|
4094 | - |
---|
4095 | def test_read_with_prefetched_mdmf_data(self): |
---|
4096 | # The MDMFSlotReadProxy will prefill certain fields if you pass |
---|
4097 | # it data that you have already fetched. This is useful for |
---|
4098 | hunk ./src/allmydata/test/test_storage.py 2429 |
---|
4099 | self.failUnlessEqual(expected_prefix, prefix) |
---|
4100 | self.failUnlessEqual(self.rref.read_count, 0) |
---|
4101 | d.addCallback(_check_verinfo) |
---|
4102 | + |
---|
4103 | # This is not enough data to read a block and a share, so the |
---|
4104 | # wrapper should attempt to read this from the remote server. |
---|
4105 | d.addCallback(_make_mr, 123) |
---|
4106 | hunk ./src/allmydata/test/test_storage.py 2439 |
---|
4107 | self.failUnlessEqual(block, self.block) |
---|
4108 | self.failUnlessEqual(salt, self.salt) |
---|
4109 | self.failUnlessEqual(self.rref.read_count, 1) |
---|
4110 | + |
---|
4111 | # This should be enough data to read one block. |
---|
4112 | d.addCallback(_make_mr, 123 + PRIVATE_KEY_SIZE + SIGNATURE_SIZE + VERIFICATION_KEY_SIZE + SHARE_HASH_CHAIN_SIZE + 140) |
---|
4113 | d.addCallback(lambda mr: |
---|
4114 | hunk ./src/allmydata/test/test_storage.py 2447 |
---|
4115 | d.addCallback(_check_block_and_salt) |
---|
4116 | return d |
---|
4117 | |
---|
4118 | - |
---|
4119 | def test_read_with_prefetched_sdmf_data(self): |
---|
4120 | sdmf_data = self.build_test_sdmf_share() |
---|
4121 | self.write_sdmf_share_to_server("si1") |
---|
4122 | hunk ./src/allmydata/test/test_storage.py 2510 |
---|
4123 | d.addCallback(_check_block_and_salt) |
---|
4124 | return d |
---|
4125 | |
---|
4126 | - |
---|
4127 | def test_read_with_empty_mdmf_file(self): |
---|
4128 | # Some tests upload a file with no contents to test things |
---|
4129 | # unrelated to the actual handling of the content of the file. |
---|
4130 | hunk ./src/allmydata/test/test_storage.py 2564 |
---|
4131 | mr.get_block_and_salt, 0)) |
---|
4132 | return d |
---|
4133 | |
---|
4134 | - |
---|
4135 | def test_verinfo_with_sdmf_file(self): |
---|
4136 | self.write_sdmf_share_to_server("si1") |
---|
4137 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
4138 | hunk ./src/allmydata/test/test_storage.py 2604 |
---|
4139 | d.addCallback(_check_verinfo) |
---|
4140 | return d |
---|
4141 | |
---|
4142 | - |
---|
4143 | def test_verinfo_with_mdmf_file(self): |
---|
4144 | self.write_test_share_to_server("si1") |
---|
4145 | mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
4146 | hunk ./src/allmydata/test/test_storage.py 2642 |
---|
4147 | d.addCallback(_check_verinfo) |
---|
4148 | return d |
---|
4149 | |
---|
4150 | - |
---|
4151 | def test_sdmf_writer(self): |
---|
4152 | # Go through the motions of writing an SDMF share to the storage |
---|
4153 | # server. Then read the storage server to see that the share got |
---|
4154 | hunk ./src/allmydata/test/test_storage.py 2685 |
---|
4155 | d.addCallback(_then) |
---|
4156 | return d |
---|
4157 | |
---|
4158 | - |
---|
4159 | def test_sdmf_writer_preexisting_share(self): |
---|
4160 | data = self.build_test_sdmf_share() |
---|
4161 | self.write_sdmf_share_to_server("si1") |
---|
4162 | hunk ./src/allmydata/test/test_storage.py 2828 |
---|
4163 | self.failUnless(output["get"]["99_0_percentile"] is None, output) |
---|
4164 | self.failUnless(output["get"]["99_9_percentile"] is None, output) |
---|
4165 | |
---|
4166 | + |
---|
4167 | def remove_tags(s): |
---|
4168 | s = re.sub(r'<[^>]*>', ' ', s) |
---|
4169 | s = re.sub(r'\s+', ' ', s) |
---|
4170 | hunk ./src/allmydata/test/test_storage.py 2834 |
---|
4171 | return s |
---|
4172 | |
---|
4173 | + |
---|
4174 | class MyBucketCountingCrawler(BucketCountingCrawler): |
---|
4175 | def finished_prefix(self, cycle, prefix): |
---|
4176 | BucketCountingCrawler.finished_prefix(self, cycle, prefix) |
---|
4177 | hunk ./src/allmydata/test/test_storage.py 2960 |
---|
4178 | fileutil.make_dirs(basedir) |
---|
4179 | ss = MyStorageServer(basedir, "\x00" * 20) |
---|
4180 | ss.bucket_counter.slow_start = 0 |
---|
4181 | + |
---|
4182 | # these will be fired inside finished_prefix() |
---|
4183 | hooks = ss.bucket_counter.hook_ds = [defer.Deferred() for i in range(3)] |
---|
4184 | w = StorageStatus(ss) |
---|
4185 | hunk ./src/allmydata/test/test_storage.py 2994 |
---|
4186 | ss.setServiceParent(self.s) |
---|
4187 | return d |
---|
4188 | |
---|
4189 | + |
---|
4190 | class InstrumentedLeaseCheckingCrawler(LeaseCheckingCrawler): |
---|
4191 | stop_after_first_bucket = False |
---|
4192 | def process_bucket(self, *args, **kwargs): |
---|
4193 | hunk ./src/allmydata/test/test_storage.py 3742 |
---|
4194 | # expirer.py . This will have to change if/when the |
---|
4195 | # progress-measurer gets smart enough to count buckets (we'll |
---|
4196 | # have to interrupt it even earlier, before it's finished the |
---|
4197 | - # first bucket). |
---|
4198 | + # first shareset). |
---|
4199 | s = lc.get_state() |
---|
4200 | if "cycle-to-date" not in s: |
---|
4201 | d2 = fireEventually() |
---|
4202 | } |
---|
4203 | [All other changes in pluggable backends branch. refs #999, #1569 |
---|
4204 | david-sarah@jacaranda.org**20111216183651 |
---|
4205 | Ignore-this: c3957b0d5efc42dc2555ebd5e1567e16 |
---|
4206 | ] { |
---|
4207 | hunk ./src/allmydata/client.py 8 |
---|
4208 | from twisted.internet import reactor, defer |
---|
4209 | from twisted.application import service |
---|
4210 | from twisted.application.internet import TimerService |
---|
4211 | +from twisted.python.filepath import FilePath |
---|
4212 | from pycryptopp.publickey import rsa |
---|
4213 | |
---|
4214 | import allmydata |
---|
4215 | hunk ./src/allmydata/client.py 12 |
---|
4216 | +from allmydata.node import InvalidValueError |
---|
4217 | from allmydata.storage.server import StorageServer |
---|
4218 | hunk ./src/allmydata/client.py 14 |
---|
4219 | +from allmydata.storage.backends.null.null_backend import configure_null_backend |
---|
4220 | +from allmydata.storage.backends.disk.disk_backend import configure_disk_backend |
---|
4221 | +from allmydata.storage.backends.s3.s3_backend import configure_s3_backend |
---|
4222 | +from allmydata.storage.backends.s3.mock_s3 import configure_mock_s3_backend |
---|
4223 | from allmydata import storage_client |
---|
4224 | from allmydata.immutable.upload import Uploader |
---|
4225 | from allmydata.immutable.offloaded import Helper |
---|
4226 | hunk ./src/allmydata/client.py 23 |
---|
4227 | from allmydata.control import ControlServer |
---|
4228 | from allmydata.introducer.client import IntroducerClient |
---|
4229 | -from allmydata.util import hashutil, base32, pollmixin, log, keyutil |
---|
4230 | -from allmydata.util.encodingutil import get_filesystem_encoding |
---|
4231 | -from allmydata.util.abbreviate import parse_abbreviated_size |
---|
4232 | +from allmydata.util import hashutil, fileutil, keyutil, base32, pollmixin, log |
---|
4233 | +from allmydata.util.encodingutil import get_filesystem_encoding, quote_output |
---|
4234 | from allmydata.util.time_format import parse_duration, parse_date |
---|
4235 | from allmydata.stats import StatsProvider |
---|
4236 | from allmydata.history import History |
---|
4237 | hunk ./src/allmydata/client.py 217 |
---|
4238 | self._server_key = sk |
---|
4239 | |
---|
4240 | def _init_permutation_seed(self, ss): |
---|
4241 | - seed = self.get_config_from_file("permutation-seed") |
---|
4242 | + seed = self.get_optional_private_config("permutation-seed") |
---|
4243 | if not seed: |
---|
4244 | hunk ./src/allmydata/client.py 219 |
---|
4245 | - have_shares = ss.have_shares() |
---|
4246 | - if have_shares: |
---|
4247 | - # if the server has shares but not a recorded |
---|
4248 | + # quick test to decide if we need to commit to an implicit |
---|
4249 | + # permutation-seed or if we should use a new one |
---|
4250 | + if self._have_disk_shares: |
---|
4251 | + # If the server has shares but not a recorded |
---|
4252 | # permutation-seed, then it has been around since pre-#466 |
---|
4253 | # days, and the clients who uploaded those shares used our |
---|
4254 | # TubID as a permutation-seed. We should keep using that same |
---|
4255 | hunk ./src/allmydata/client.py 242 |
---|
4256 | # Should we run a storage server (and publish it for others to use)? |
---|
4257 | if not self.get_config("storage", "enabled", True, boolean=True): |
---|
4258 | return |
---|
4259 | - readonly = self.get_config("storage", "readonly", False, boolean=True) |
---|
4260 | |
---|
4261 | self._maybe_create_server_key() |
---|
4262 | |
---|
4263 | hunk ./src/allmydata/client.py 245 |
---|
4264 | - storedir = os.path.join(self.basedir, self.STOREDIR) |
---|
4265 | + storedir = FilePath(self.basedir).child(self.STOREDIR) |
---|
4266 | |
---|
4267 | hunk ./src/allmydata/client.py 247 |
---|
4268 | - data = self.get_config("storage", "reserved_space", None) |
---|
4269 | - reserved = None |
---|
4270 | - try: |
---|
4271 | - reserved = parse_abbreviated_size(data) |
---|
4272 | - except ValueError: |
---|
4273 | - log.msg("[storage]reserved_space= contains unparseable value %s" |
---|
4274 | - % data) |
---|
4275 | - if reserved is None: |
---|
4276 | - reserved = 0 |
---|
4277 | - discard = self.get_config("storage", "debug_discard", False, |
---|
4278 | - boolean=True) |
---|
4279 | + # Record whether we have stored shares as a disk backend. |
---|
4280 | + # (This should be true if there are shares on disk even if we're not currently |
---|
4281 | + # configured as a disk backend.) |
---|
4282 | + self._have_disk_shares = bool([True for child in fileutil.fp_list(storedir.child("shares")) |
---|
4283 | + if child.basename() != "incoming"]) |
---|
4284 | + |
---|
4285 | + # What sort of backend? |
---|
4286 | + backendtype = self.get_config("storage", "backend", "disk") |
---|
4287 | + |
---|
4288 | + backend_configurators = { |
---|
4289 | + 'disk': configure_disk_backend, |
---|
4290 | + 's3': configure_s3_backend, |
---|
4291 | + 'mock_s3': configure_mock_s3_backend, |
---|
4292 | + 'debug_discard': configure_null_backend, |
---|
4293 | + } |
---|
4294 | + |
---|
4295 | + if backendtype not in backend_configurators: |
---|
4296 | + raise InvalidValueError("[storage]backend= is required to be one of %s, but was %s" |
---|
4297 | + % (backend_configurators.keys(), quote_output(backendtype)) ) |
---|
4298 | + |
---|
4299 | + backend = backend_configurators[backendtype](storedir, self) |
---|
4300 | |
---|
4301 | expire = self.get_config("storage", "expire.enabled", False, boolean=True) |
---|
4302 | if expire: |
---|
4303 | hunk ./src/allmydata/client.py 289 |
---|
4304 | sharetypes.append("immutable") |
---|
4305 | if self.get_config("storage", "expire.mutable", True, boolean=True): |
---|
4306 | sharetypes.append("mutable") |
---|
4307 | - expiration_sharetypes = tuple(sharetypes) |
---|
4308 | |
---|
4309 | hunk ./src/allmydata/client.py 290 |
---|
4310 | - ss = StorageServer(storedir, self.nodeid, |
---|
4311 | - reserved_space=reserved, |
---|
4312 | - discard_storage=discard, |
---|
4313 | - readonly_storage=readonly, |
---|
4314 | + expiration_policy = { |
---|
4315 | + 'enabled': expire, |
---|
4316 | + 'mode': mode, |
---|
4317 | + 'override_lease_duration': o_l_d, |
---|
4318 | + 'cutoff_date': cutoff_date, |
---|
4319 | + 'sharetypes': tuple(sharetypes), |
---|
4320 | + } |
---|
4321 | + |
---|
4322 | + statedir = storedir |
---|
4323 | + ss = StorageServer(self.nodeid, backend, statedir, |
---|
4324 | stats_provider=self.stats_provider, |
---|
4325 | hunk ./src/allmydata/client.py 301 |
---|
4326 | - expiration_enabled=expire, |
---|
4327 | - expiration_mode=mode, |
---|
4328 | - expiration_override_lease_duration=o_l_d, |
---|
4329 | - expiration_cutoff_date=cutoff_date, |
---|
4330 | - expiration_sharetypes=expiration_sharetypes) |
---|
4331 | + expiration_policy=expiration_policy) |
---|
4332 | self.add_service(ss) |
---|
4333 | |
---|
4334 | d = self.when_tub_ready() |
---|
4335 | hunk ./src/allmydata/immutable/layout.py 340 |
---|
4336 | return self._read(0, 0x44) |
---|
4337 | |
---|
4338 | def _parse_offsets(self, data): |
---|
4339 | - precondition(len(data) >= 0x4) |
---|
4340 | + precondition(len(data) >= 0x4, len(data)) |
---|
4341 | self._offsets = {} |
---|
4342 | (version,) = struct.unpack(">L", data[0:4]) |
---|
4343 | if version != 1 and version != 2: |
---|
4344 | hunk ./src/allmydata/interfaces.py 33 |
---|
4345 | LeaseRenewSecret = Hash # used to protect lease renewal requests |
---|
4346 | LeaseCancelSecret = Hash # formerly used to protect lease cancellation requests |
---|
4347 | |
---|
4348 | -class RIStubClient(RemoteInterface): |
---|
4349 | - """Each client publishes a service announcement for a dummy object called |
---|
4350 | - the StubClient. This object doesn't actually offer any services, but the |
---|
4351 | - announcement helps the Introducer keep track of which clients are |
---|
4352 | - subscribed (so the grid admin can keep track of things like the size of |
---|
4353 | - the grid and the client versions in use. This is the (empty) |
---|
4354 | - RemoteInterface for the StubClient.""" |
---|
4355 | |
---|
4356 | class RIBucketWriter(RemoteInterface): |
---|
4357 | """ Objects of this kind live on the server side. """ |
---|
4358 | hunk ./src/allmydata/interfaces.py 184 |
---|
4359 | This secret is generated by the client and |
---|
4360 | stored for later comparison by the server. Each |
---|
4361 | server is given a different secret. |
---|
4362 | - @param cancel_secret: Like renew_secret, but protects bucket decref. |
---|
4363 | + @param cancel_secret: This no longer allows lease cancellation, but |
---|
4364 | + must still be a unique value identifying the |
---|
4365 | + lease. XXX stop relying on it to be unique. |
---|
4366 | |
---|
4367 | hunk ./src/allmydata/interfaces.py 188 |
---|
4368 | - The 'secrets' argument is a tuple of (write_enabler, renew_secret, |
---|
4369 | - cancel_secret). The first is required to perform any write. The |
---|
4370 | - latter two are used when allocating new shares. To simply acquire a |
---|
4371 | - new lease on existing shares, use an empty testv and an empty writev. |
---|
4372 | + The 'secrets' argument is a tuple with (write_enabler, renew_secret). |
---|
4373 | + The write_enabler is required to perform any write. The renew_secret |
---|
4374 | + is used when allocating new shares. |
---|
4375 | |
---|
4376 | Each share can have a separate test vector (i.e. a list of |
---|
4377 | comparisons to perform). If all vectors for all shares pass, then all |
---|
4378 | hunk ./src/allmydata/interfaces.py 279 |
---|
4379 | store that on disk. |
---|
4380 | """ |
---|
4381 | |
---|
4382 | -class IStorageBucketWriter(Interface): |
---|
4383 | + |
---|
4384 | +class IStorageBackend(Interface): |
---|
4385 | """ |
---|
4386 | hunk ./src/allmydata/interfaces.py 282 |
---|
4387 | - Objects of this kind live on the client side. |
---|
4388 | + Objects of this kind live on the server side and are used by the |
---|
4389 | + storage server object. |
---|
4390 | """ |
---|
4391 | hunk ./src/allmydata/interfaces.py 285 |
---|
4392 | - def put_block(segmentnum=int, data=ShareData): |
---|
4393 | - """@param data: For most segments, this data will be 'blocksize' |
---|
4394 | - bytes in length. The last segment might be shorter. |
---|
4395 | - @return: a Deferred that fires (with None) when the operation completes |
---|
4396 | + def supports_crawlers(): |
---|
4397 | + """ |
---|
4398 | + Returns True if this backend is able to support crawlers, |
---|
4399 | + otherwise False. |
---|
4400 | + """ |
---|
4401 | + |
---|
4402 | + def get_available_space(): |
---|
4403 | + """ |
---|
4404 | + Returns available space for share storage in bytes, or |
---|
4405 | + None if this information is not available or if the available |
---|
4406 | + space is unlimited. |
---|
4407 | + |
---|
4408 | + If the backend is configured for read-only mode then this will |
---|
4409 | + return 0. |
---|
4410 | + """ |
---|
4411 | + |
---|
4412 | + def get_sharesets_for_prefix(prefix): |
---|
4413 | + """ |
---|
4414 | + Return an iterable containing IShareSet objects for all storage |
---|
4415 | + indices matching the given base-32 prefix, for which this backend |
---|
4416 | + holds shares. |
---|
4417 | + XXX This will probably need to return a Deferred, but for now it |
---|
4418 | + is synchronous. |
---|
4419 | + """ |
---|
4420 | + |
---|
4421 | + def get_shareset(storageindex): |
---|
4422 | + """ |
---|
4423 | + Get an IShareSet object for the given storage index. |
---|
4424 | + This method is synchronous. |
---|
4425 | + """ |
---|
4426 | + |
---|
4427 | + def fill_in_space_stats(stats): |
---|
4428 | + """ |
---|
4429 | + Fill in the 'stats' dict with space statistics for this backend, in |
---|
4430 | + 'storage_server.*' keys. |
---|
4431 | + """ |
---|
4432 | + |
---|
4433 | + def advise_corrupt_share(storageindex, sharetype, shnum, reason): |
---|
4434 | + """ |
---|
4435 | + Clients who discover hash failures in shares that they have |
---|
4436 | + downloaded from me will use this method to inform me about the |
---|
4437 | + failures. I will record their concern so that my operator can |
---|
4438 | + manually inspect the shares in question. This method is synchronous. |
---|
4439 | + |
---|
4440 | + 'sharetype' is either 'mutable' or 'immutable'. 'shnum' is the integer |
---|
4441 | + share number. 'reason' is a human-readable explanation of the problem, |
---|
4442 | + probably including some expected hash values and the computed ones |
---|
4443 | + that did not match. Corruption advisories for mutable shares should |
---|
4444 | + include a hash of the public key (the same value that appears in the |
---|
4445 | + mutable-file verify-cap), since the current share format does not |
---|
4446 | + store that on disk. |
---|
4447 | + |
---|
4448 | + @param storageindex=str |
---|
4449 | + @param sharetype=str |
---|
4450 | + @param shnum=int |
---|
4451 | + @param reason=str |
---|
4452 | + """ |
---|
4453 | + |
---|
4454 | + |
---|
4455 | +class IShareSet(Interface): |
---|
4456 | + def get_storage_index(): |
---|
4457 | + """ |
---|
4458 | + Returns the storage index for this shareset. |
---|
4459 | + """ |
---|
4460 | + |
---|
4461 | + def get_storage_index_string(): |
---|
4462 | + """ |
---|
4463 | + Returns the base32-encoded storage index for this shareset. |
---|
4464 | + """ |
---|
4465 | + |
---|
4466 | + def get_overhead(): |
---|
4467 | + """ |
---|
4468 | + Returns an estimate of the storage overhead, in bytes, of this shareset |
---|
4469 | + (exclusive of the space used by its shares). |
---|
4470 | + """ |
---|
4471 | + |
---|
4472 | + def get_shares(): |
---|
4473 | + """ |
---|
4474 | + Returns a Deferred that fires with a pair |
---|
4475 | + (list of IShareBase objects, set of corrupted shnums). |
---|
4476 | + The share objects include only completed shares in this shareset. |
---|
4477 | + """ |
---|
4478 | + # XXX rename to get_shares_and_corrupted? |
---|
4479 | + |
---|
4480 | + def get_shares_synchronous(): |
---|
4481 | + """ |
---|
4482 | + A synchronous version of get_shares() that returns a pair |
---|
4483 | + (list of IShareBase objects, set of corrupted shnums). |
---|
4484 | + This is only available on sharesets from a backend that supports_crawlers(). |
---|
4485 | + """ |
---|
4486 | + |
---|
4487 | + def get_share(shnum): |
---|
4488 | + """ |
---|
4489 | + Returns a Deferred that fires with an IShareBase object if the given |
---|
4490 | + share exists, or fails with IndexError otherwise. |
---|
4491 | + """ |
---|
4492 | + |
---|
4493 | + def has_incoming(shnum): |
---|
4494 | + """ |
---|
4495 | + Returns True if this shareset has an incoming (partial) share with this |
---|
4496 | + number, otherwise False. |
---|
4497 | + """ |
---|
4498 | + |
---|
4499 | + def make_bucket_writer(storageserver, shnum, max_space_per_bucket, lease_info, canary): |
---|
4500 | + """ |
---|
4501 | + Create a bucket writer that can be used to write data to a given share. |
---|
4502 | + |
---|
4503 | + @param storageserver=RIStorageServer |
---|
4504 | + @param shnum=int: A share number in this shareset |
---|
4505 | + @param max_space_per_bucket=int: The maximum space allocated for the |
---|
4506 | + share, in bytes |
---|
4507 | + @param lease_info=LeaseInfo: The initial lease information |
---|
4508 | + @param canary=Referenceable: If the canary is lost before close(), the |
---|
4509 | + bucket is deleted. |
---|
4510 | + @return an IStorageBucketWriter for the given share |
---|
4511 | """ |
---|
4512 | |
---|
4513 | hunk ./src/allmydata/interfaces.py 402 |
---|
4514 | - def put_plaintext_hashes(hashes=ListOf(Hash)): |
---|
4515 | + def make_bucket_reader(storageserver, share): |
---|
4516 | + """ |
---|
4517 | + Create a bucket reader that can be used to read data from a given share. |
---|
4518 | + |
---|
4519 | + @param storageserver=RIStorageServer |
---|
4520 | + @param share=IStoredShare |
---|
4521 | + @return an IStorageBucketReader for the given share |
---|
4522 | + """ |
---|
4523 | + |
---|
4524 | + def readv(wanted_shnums, read_vector): |
---|
4525 | + """ |
---|
4526 | + Read a vector from the numbered shares in this shareset. An empty |
---|
4527 | + wanted_shnums list means to return data from all known shares. |
---|
4528 | + Return a Deferred that fires with a dict mapping the share number |
---|
4529 | + to the corresponding ReadData. |
---|
4530 | + |
---|
4531 | + @param wanted_shnums=ListOf(int) |
---|
4532 | + @param read_vector=ReadVector |
---|
4533 | + @return DeferredOf(DictOf(int, ReadData)): shnum -> results, with one key per share |
---|
4534 | + """ |
---|
4535 | + |
---|
4536 | + def testv_and_readv_and_writev(storageserver, secrets, test_and_write_vectors, read_vector, expiration_time): |
---|
4537 | + """ |
---|
4538 | + General-purpose atomic test-read-and-set operation for mutable slots. |
---|
4539 | + Perform a bunch of comparisons against the existing shares in this |
---|
4540 | + shareset. If they all pass: use the read vectors to extract data from |
---|
4541 | + all the shares, then apply a bunch of write vectors to those shares. |
---|
4542 | + Return a Deferred that fires with a pair consisting of a boolean that is |
---|
4543 | + True iff the test vectors passed, and a dict mapping the share number |
---|
4544 | + to the corresponding ReadData. Reads do not include any modifications |
---|
4545 | + made by the writes. |
---|
4546 | + |
---|
4547 | + See the similar method in RIStorageServer for more detail. |
---|
4548 | + |
---|
4549 | + @param storageserver=RIStorageServer |
---|
4550 | + @param secrets=TupleOf(WriteEnablerSecret, LeaseRenewSecret[, ...]) |
---|
4551 | + @param test_and_write_vectors=TestAndWriteVectorsForShares |
---|
4552 | + @param read_vector=ReadVector |
---|
4553 | + @param expiration_time=int |
---|
4554 | + @return DeferredOf(TupleOf(bool, DictOf(int, ReadData))) |
---|
4555 | """ |
---|
4556 | hunk ./src/allmydata/interfaces.py 443 |
---|
4557 | + |
---|
4558 | + def get_leases(): |
---|
4559 | + """ |
---|
4560 | + Yield a LeaseInfo instance for each lease on this shareset. |
---|
4561 | + """ |
---|
4562 | + |
---|
4563 | + def add_or_renew_lease(lease_info): |
---|
4564 | + """ |
---|
4565 | + Add a new lease on the shares in this shareset. If the renew_secret |
---|
4566 | + matches an existing lease, that lease will be renewed instead. If |
---|
4567 | + there are no shares in this shareset, return silently. |
---|
4568 | + |
---|
4569 | + @param lease_info=LeaseInfo |
---|
4570 | + """ |
---|
4571 | + |
---|
4572 | + def renew_lease(renew_secret, new_expiration_time): |
---|
4573 | + """ |
---|
4574 | + Renew a lease on the shares in this shareset, resetting the timer |
---|
4575 | + to 31 days. Some grids will use this, some will not. If there are no |
---|
4576 | + shares in this shareset, IndexError will be raised. |
---|
4577 | + |
---|
4578 | + For mutable shares, if the given renew_secret does not match an |
---|
4579 | + existing lease, IndexError will be raised with a note listing the |
---|
4580 | + server-nodeids on the existing leases, so leases on migrated shares |
---|
4581 | + can be renewed. For immutable shares, IndexError (without the note) |
---|
4582 | + will be raised. |
---|
4583 | + |
---|
4584 | + @param renew_secret=LeaseRenewSecret |
---|
4585 | + """ |
---|
4586 | + |
---|
4587 | + |
---|
4588 | +class IShareBase(Interface): |
---|
4589 | + """ |
---|
4590 | + I represent an immutable or mutable share stored by a particular backend. |
---|
4591 | + I may hold some, all, or none of the share data in memory. |
---|
4592 | + |
---|
4593 | + XXX should this interface also include lease operations? |
---|
4594 | + """ |
---|
4595 | + def get_storage_index(): |
---|
4596 | + """ |
---|
4597 | + Returns the storage index. |
---|
4598 | + """ |
---|
4599 | + |
---|
4600 | + def get_storage_index_string(): |
---|
4601 | + """ |
---|
4602 | + Returns the base32-encoded storage index. |
---|
4603 | + """ |
---|
4604 | + |
---|
4605 | + def get_shnum(): |
---|
4606 | + """ |
---|
4607 | + Returns the share number. |
---|
4608 | + """ |
---|
4609 | + |
---|
4610 | + def get_data_length(): |
---|
4611 | + """ |
---|
4612 | + Returns the data length in bytes. |
---|
4613 | + """ |
---|
4614 | + |
---|
4615 | + def get_size(): |
---|
4616 | + """ |
---|
4617 | + Returns the size of the share in bytes. |
---|
4618 | + """ |
---|
4619 | + |
---|
4620 | + def get_used_space(): |
---|
4621 | + """ |
---|
4622 | + Returns the amount of backend storage including overhead (which may |
---|
4623 | + have to be estimated), in bytes, used by this share. |
---|
4624 | + """ |
---|
4625 | + |
---|
4626 | + def unlink(): |
---|
4627 | + """ |
---|
4628 | + Signal that this share can be removed from the backend storage. This does |
---|
4629 | + not guarantee that the share data will be immediately inaccessible, or |
---|
4630 | + that it will be securely erased. |
---|
4631 | + Returns a Deferred that fires after the share has been removed. |
---|
4632 | + |
---|
4633 | + This may be called on a share that is being written and is not closed. |
---|
4634 | + """ |
---|
4635 | + |
---|
4636 | + |
---|
4637 | +class IShareForReading(IShareBase): |
---|
4638 | + """ |
---|
4639 | + I represent an immutable share that can be read from. |
---|
4640 | + """ |
---|
4641 | + def read_share_data(offset, length): |
---|
4642 | + """ |
---|
4643 | + Return a Deferred that fires with the read result. |
---|
4644 | + """ |
---|
4645 | + |
---|
4646 | + def readv(read_vector): |
---|
4647 | + """ |
---|
4648 | + Given a list of (offset, length) pairs, return a Deferred that fires with |
---|
4649 | + a list of read results. |
---|
4650 | + """ |
---|
4651 | + |
---|
4652 | + |
---|
4653 | +class IShareForWriting(IShareBase): |
---|
4654 | + """ |
---|
4655 | + I represent an immutable share that is being written. |
---|
4656 | + """ |
---|
4657 | + def get_allocated_size(): |
---|
4658 | + """ |
---|
4659 | + Returns the allocated size of the share (not including header) in bytes. |
---|
4660 | + This is the maximum amount of data that can be written. |
---|
4661 | + """ |
---|
4662 | + |
---|
4663 | + def write_share_data(offset, data): |
---|
4664 | + """ |
---|
4665 | + Write data at the given offset. Return a Deferred that fires when we |
---|
4666 | + are ready to accept the next write. |
---|
4667 | + |
---|
4668 | + XXX should we require that data is written with no backtracking (i.e. that |
---|
4669 | + offset must not be before the previous end-of-data)? |
---|
4670 | + """ |
---|
4671 | + |
---|
4672 | + def close(): |
---|
4673 | + """ |
---|
4674 | + Complete writing to this share. |
---|
4675 | + """ |
---|
4676 | + |
---|
4677 | + |
---|
4678 | +class IMutableShare(IShareBase): |
---|
4679 | + """ |
---|
4680 | + I represent a mutable share. |
---|
4681 | + """ |
---|
4682 | + def create(serverid, write_enabler): |
---|
4683 | + """ |
---|
4684 | + Create an empty mutable share with the given serverid and write enabler. |
---|
4685 | + Return a Deferred that fires when the share has been created. |
---|
4686 | + """ |
---|
4687 | + |
---|
4688 | + def check_write_enabler(write_enabler): |
---|
4689 | + """ |
---|
4690 | + XXX |
---|
4691 | + """ |
---|
4692 | + |
---|
4693 | + def check_testv(test_vector): |
---|
4694 | + """ |
---|
4695 | + XXX |
---|
4696 | + """ |
---|
4697 | + |
---|
4698 | + def writev(datav, new_length): |
---|
4699 | + """ |
---|
4700 | + XXX |
---|
4701 | + """ |
---|
4702 | + |
---|
4703 | + |
---|
4704 | +class IStorageBucketWriter(Interface): |
---|
4705 | + """ |
---|
4706 | + Objects of this kind live on the client side. |
---|
4707 | + """ |
---|
4708 | + def put_block(segmentnum, data): |
---|
4709 | + """ |
---|
4710 | + @param segmentnum=int |
---|
4711 | + @param data=ShareData: For most segments, this data will be 'blocksize' |
---|
4712 | + bytes in length. The last segment might be shorter. |
---|
4713 | @return: a Deferred that fires (with None) when the operation completes |
---|
4714 | """ |
---|
4715 | |
---|
4716 | hunk ./src/allmydata/interfaces.py 669 |
---|
4717 | @return: ListOf(Hash) |
---|
4718 | """ |
---|
4719 | |
---|
4720 | - def get_share_hashes(at_least_these=SetOf(int)): |
---|
4721 | + def get_share_hashes(): |
---|
4722 | """ |
---|
4723 | @return: ListOf(TupleOf(int, Hash)) |
---|
4724 | """ |
---|
4725 | hunk ./src/allmydata/interfaces.py 701 |
---|
4726 | @return: unicode nickname, or None |
---|
4727 | """ |
---|
4728 | |
---|
4729 | - # methods moved from IntroducerClient, need review |
---|
4730 | - def get_all_connections(): |
---|
4731 | - """Return a frozenset of (nodeid, service_name, rref) tuples, one for |
---|
4732 | - each active connection we've established to a remote service. This is |
---|
4733 | - mostly useful for unit tests that need to wait until a certain number |
---|
4734 | - of connections have been made.""" |
---|
4735 | - |
---|
4736 | - def get_all_connectors(): |
---|
4737 | - """Return a dict that maps from (nodeid, service_name) to a |
---|
4738 | - RemoteServiceConnector instance for all services that we are actively |
---|
4739 | - trying to connect to. Each RemoteServiceConnector has the following |
---|
4740 | - public attributes:: |
---|
4741 | - |
---|
4742 | - service_name: the type of service provided, like 'storage' |
---|
4743 | - announcement_time: when we first heard about this service |
---|
4744 | - last_connect_time: when we last established a connection |
---|
4745 | - last_loss_time: when we last lost a connection |
---|
4746 | - |
---|
4747 | - version: the peer's version, from the most recent connection |
---|
4748 | - oldest_supported: the peer's oldest supported version, same |
---|
4749 | - |
---|
4750 | - rref: the RemoteReference, if connected, otherwise None |
---|
4751 | - remote_host: the IAddress, if connected, otherwise None |
---|
4752 | - |
---|
4753 | - This method is intended for monitoring interfaces, such as a web page |
---|
4754 | - that describes connecting and connected peers. |
---|
4755 | - """ |
---|
4756 | - |
---|
4757 | - def get_all_peerids(): |
---|
4758 | - """Return a frozenset of all peerids to whom we have a connection (to |
---|
4759 | - one or more services) established. Mostly useful for unit tests.""" |
---|
4760 | - |
---|
4761 | - def get_all_connections_for(service_name): |
---|
4762 | - """Return a frozenset of (nodeid, service_name, rref) tuples, one |
---|
4763 | - for each active connection that provides the given SERVICE_NAME.""" |
---|
4764 | - |
---|
4765 | - def get_permuted_peers(service_name, key): |
---|
4766 | - """Returns an ordered list of (peerid, rref) tuples, selecting from |
---|
4767 | - the connections that provide SERVICE_NAME, using a hash-based |
---|
4768 | - permutation keyed by KEY. This randomizes the service list in a |
---|
4769 | - repeatable way, to distribute load over many peers. |
---|
4770 | - """ |
---|
4771 | - |
---|
4772 | |
---|
4773 | class IMutableSlotWriter(Interface): |
---|
4774 | """ |
---|
4775 | hunk ./src/allmydata/interfaces.py 706 |
---|
4776 | The interface for a writer around a mutable slot on a remote server. |
---|
4777 | """ |
---|
4778 | - def set_checkstring(checkstring, *args): |
---|
4779 | + def set_checkstring(seqnum_or_checkstring, root_hash=None, salt=None): |
---|
4780 | """ |
---|
4781 | Set the checkstring that I will pass to the remote server when |
---|
4782 | writing. |
---|
4783 | hunk ./src/allmydata/interfaces.py 730 |
---|
4784 | Add a block and salt to the share. |
---|
4785 | """ |
---|
4786 | |
---|
4787 | - def put_encprivkey(encprivkey): |
---|
4788 | + def put_encprivkey(encrypted_privkey): |
---|
4789 | """ |
---|
4790 | Add the encrypted private key to the share. |
---|
4791 | """ |
---|
4792 | hunk ./src/allmydata/interfaces.py 964 |
---|
4793 | writer-visible data using this writekey. |
---|
4794 | """ |
---|
4795 | |
---|
4796 | - # TODO: Can this be overwrite instead of replace? |
---|
4797 | - def replace(new_contents): |
---|
4798 | - """Replace the contents of the mutable file, provided that no other |
---|
4799 | + def overwrite(new_contents): |
---|
4800 | + """Overwrite the contents of the mutable file, provided that no other |
---|
4801 | node has published (or is attempting to publish, concurrently) a |
---|
4802 | newer version of the file than this one. |
---|
4803 | |
---|
4804 | hunk ./src/allmydata/interfaces.py 1431 |
---|
4805 | is empty, the metadata will be an empty dictionary. |
---|
4806 | """ |
---|
4807 | |
---|
4808 | - def set_uri(name, writecap, readcap=None, metadata=None, overwrite=True): |
---|
4809 | + def set_uri(name, writecap, readcap, metadata=None, overwrite=True): |
---|
4810 | """I add a child (by writecap+readcap) at the specific name. I return |
---|
4811 | a Deferred that fires when the operation finishes. If overwrite= is |
---|
4812 | True, I will replace any existing child of the same name, otherwise |
---|
4813 | hunk ./src/allmydata/interfaces.py 2035 |
---|
4814 | resuming an interrupted upload (where we need to compute the |
---|
4815 | plaintext hashes, but don't need the redundant encrypted data).""" |
---|
4816 | |
---|
4817 | - def get_plaintext_hashtree_leaves(first, last, num_segments): |
---|
4818 | - """OBSOLETE; Get the leaf nodes of a merkle hash tree over the |
---|
4819 | - plaintext segments, i.e. get the tagged hashes of the given segments. |
---|
4820 | - The segment size is expected to be generated by the |
---|
4821 | - IEncryptedUploadable before any plaintext is read or ciphertext |
---|
4822 | - produced, so that the segment hashes can be generated with only a |
---|
4823 | - single pass. |
---|
4824 | - |
---|
4825 | - This returns a Deferred that fires with a sequence of hashes, using: |
---|
4826 | - |
---|
4827 | - tuple(segment_hashes[first:last]) |
---|
4828 | - |
---|
4829 | - 'num_segments' is used to assert that the number of segments that the |
---|
4830 | - IEncryptedUploadable handled matches the number of segments that the |
---|
4831 | - encoder was expecting. |
---|
4832 | - |
---|
4833 | - This method must not be called until the final byte has been read |
---|
4834 | - from read_encrypted(). Once this method is called, read_encrypted() |
---|
4835 | - can never be called again. |
---|
4836 | - """ |
---|
4837 | - |
---|
4838 | - def get_plaintext_hash(): |
---|
4839 | - """OBSOLETE; Get the hash of the whole plaintext. |
---|
4840 | - |
---|
4841 | - This returns a Deferred that fires with a tagged SHA-256 hash of the |
---|
4842 | - whole plaintext, obtained from hashutil.plaintext_hash(data). |
---|
4843 | - """ |
---|
4844 | - |
---|
4845 | def close(): |
---|
4846 | """Just like IUploadable.close().""" |
---|
4847 | |
---|
4848 | hunk ./src/allmydata/interfaces.py 2229 |
---|
4849 | returns a Deferred that fires with an IUploadResults instance, from |
---|
4850 | which the URI of the file can be obtained as results.uri .""" |
---|
4851 | |
---|
4852 | - def upload_ssk(write_capability, new_version, uploadable): |
---|
4853 | - """TODO: how should this work?""" |
---|
4854 | - |
---|
4855 | class ICheckable(Interface): |
---|
4856 | def check(monitor, verify=False, add_lease=False): |
---|
4857 | """Check up on my health, optionally repairing any problems. |
---|
4858 | hunk ./src/allmydata/interfaces.py 2598 |
---|
4859 | |
---|
4860 | class IRepairResults(Interface): |
---|
4861 | """I contain the results of a repair operation.""" |
---|
4862 | - def get_successful(self): |
---|
4863 | + def get_successful(): |
---|
4864 | """Returns a boolean: True if the repair made the file healthy, False |
---|
4865 | if not. Repair failure generally indicates a file that has been |
---|
4866 | damaged beyond repair.""" |
---|
4867 | hunk ./src/allmydata/interfaces.py 2670 |
---|
4868 | Tahoe process will typically have a single NodeMaker, but unit tests may |
---|
4869 | create simplified/mocked forms for testing purposes. |
---|
4870 | """ |
---|
4871 | - def create_from_cap(writecap, readcap=None, **kwargs): |
---|
4872 | + def create_from_cap(writecap, readcap=None, deep_immutable=False, name=u"<unknown name>"): |
---|
4873 | """I create an IFilesystemNode from the given writecap/readcap. I can |
---|
4874 | only provide nodes for existing file/directory objects: use my other |
---|
4875 | methods to create new objects. I return synchronously.""" |
---|
4876 | hunk ./src/allmydata/interfaces.py 2820 |
---|
4877 | class BadWriteEnablerError(Exception): |
---|
4878 | pass |
---|
4879 | |
---|
4880 | -class RIControlClient(RemoteInterface): |
---|
4881 | |
---|
4882 | hunk ./src/allmydata/interfaces.py 2821 |
---|
4883 | +class RIControlClient(RemoteInterface): |
---|
4884 | def wait_for_client_connections(num_clients=int): |
---|
4885 | """Do not return until we have connections to at least NUM_CLIENTS |
---|
4886 | storage servers. |
---|
4887 | hunk ./src/allmydata/monitor.py 30 |
---|
4888 | |
---|
4889 | # the following methods are provided for the operation code |
---|
4890 | |
---|
4891 | - def is_cancelled(self): |
---|
4892 | + def is_cancelled(): |
---|
4893 | """Returns True if the operation has been cancelled. If True, |
---|
4894 | operation code should stop creating new work, and attempt to stop any |
---|
4895 | work already in progress.""" |
---|
4896 | hunk ./src/allmydata/monitor.py 35 |
---|
4897 | |
---|
4898 | - def raise_if_cancelled(self): |
---|
4899 | + def raise_if_cancelled(): |
---|
4900 | """Raise OperationCancelledError if the operation has been cancelled. |
---|
4901 | Operation code that has a robust error-handling path can simply call |
---|
4902 | this periodically.""" |
---|
4903 | hunk ./src/allmydata/monitor.py 40 |
---|
4904 | |
---|
4905 | - def set_status(self, status): |
---|
4906 | + def set_status(status): |
---|
4907 | """Sets the Monitor's 'status' object to an arbitrary value. |
---|
4908 | Different operations will store different sorts of status information |
---|
4909 | here. Operation code should use get+modify+set sequences to update |
---|
4910 | hunk ./src/allmydata/monitor.py 46 |
---|
4911 | this.""" |
---|
4912 | |
---|
4913 | - def get_status(self): |
---|
4914 | + def get_status(): |
---|
4915 | """Return the status object. If the operation failed, this will be a |
---|
4916 | Failure instance.""" |
---|
4917 | |
---|
4918 | hunk ./src/allmydata/monitor.py 50 |
---|
4919 | - def finish(self, status): |
---|
4920 | + def finish(status): |
---|
4921 | """Call this when the operation is done, successful or not. The |
---|
4922 | Monitor's lifetime is influenced by the completion of the operation |
---|
4923 | it is monitoring. The Monitor's 'status' value will be set with the |
---|
4924 | hunk ./src/allmydata/monitor.py 63 |
---|
4925 | |
---|
4926 | # the following methods are provided for the initiator of the operation |
---|
4927 | |
---|
4928 | - def is_finished(self): |
---|
4929 | + def is_finished(): |
---|
4930 | """Return a boolean, True if the operation is done (whether |
---|
4931 | successful or failed), False if it is still running.""" |
---|
4932 | |
---|
4933 | hunk ./src/allmydata/monitor.py 67 |
---|
4934 | - def when_done(self): |
---|
4935 | + def when_done(): |
---|
4936 | """Return a Deferred that fires when the operation is complete. It |
---|
4937 | will fire with the operation status, the same value as returned by |
---|
4938 | get_status().""" |
---|
4939 | hunk ./src/allmydata/monitor.py 72 |
---|
4940 | |
---|
4941 | - def cancel(self): |
---|
4942 | + def cancel(): |
---|
4943 | """Cancel the operation as soon as possible. is_cancelled() will |
---|
4944 | start returning True after this is called.""" |
---|
4945 | |
---|
4946 | hunk ./src/allmydata/mutable/filenode.py 748 |
---|
4947 | """ |
---|
4948 | return self._version[0] # verinfo[0] == the sequence number |
---|
4949 | |
---|
4950 | + def get_servermap(self): |
---|
4951 | + return self._servermap |
---|
4952 | |
---|
4953 | def get_writekey(self): |
---|
4954 | """ |
---|
4955 | hunk ./src/allmydata/mutable/layout.py 76 |
---|
4956 | OFFSETS = ">LLLLQQ" |
---|
4957 | OFFSETS_LENGTH = struct.calcsize(OFFSETS) |
---|
4958 | |
---|
4959 | +# our sharefiles share with a recognizable string, plus some random |
---|
4960 | +# binary data to reduce the chance that a regular text file will look |
---|
4961 | +# like a sharefile. |
---|
4962 | +MUTABLE_MAGIC = "Tahoe mutable container v1\n" + "\x75\x09\x44\x03\x8e" |
---|
4963 | + |
---|
4964 | # These are still used for some tests. |
---|
4965 | def unpack_header(data): |
---|
4966 | o = {} |
---|
4967 | hunk ./src/allmydata/mutable/layout.py 1250 |
---|
4968 | |
---|
4969 | |
---|
4970 | def _process_encoding_parameters(self, encoding_parameters): |
---|
4971 | - assert self.shnum in encoding_parameters |
---|
4972 | + assert self.shnum in encoding_parameters, (self.shnum, encoding_parameters) |
---|
4973 | encoding_parameters = encoding_parameters[self.shnum][0] |
---|
4974 | # The first byte is the version number. It will tell us what |
---|
4975 | # to do next. |
---|
4976 | hunk ./src/allmydata/mutable/layout.py 1395 |
---|
4977 | d.addCallback(_then) |
---|
4978 | d.addCallback(lambda readvs: self._read(readvs)) |
---|
4979 | def _process_results(results): |
---|
4980 | - assert self.shnum in results |
---|
4981 | + assert self.shnum in results, (self.shnum, results) |
---|
4982 | if self._version_number == 0: |
---|
4983 | # We only read the share data, but we know the salt from |
---|
4984 | # when we fetched the header |
---|
4985 | hunk ./src/allmydata/mutable/publish.py 872 |
---|
4986 | |
---|
4987 | |
---|
4988 | def _record_verinfo(self): |
---|
4989 | - self.versioninfo = self.writers.values()[0].get_verinfo() |
---|
4990 | + writers = self.writers.values() |
---|
4991 | + if len(writers) > 0: |
---|
4992 | + self.versioninfo = writers[0].get_verinfo() |
---|
4993 | |
---|
4994 | |
---|
4995 | def _connection_problem(self, f, writer): |
---|
4996 | hunk ./src/allmydata/node.py 6 |
---|
4997 | from base64 import b32decode, b32encode |
---|
4998 | |
---|
4999 | from twisted.python import log as twlog |
---|
5000 | +from twisted.python.filepath import FilePath |
---|
5001 | from twisted.application import service |
---|
5002 | from twisted.internet import defer, reactor |
---|
5003 | from foolscap.api import Tub, eventually, app_versions |
---|
5004 | hunk ./src/allmydata/node.py 16 |
---|
5005 | from allmydata.util import fileutil, iputil, observer |
---|
5006 | from allmydata.util.assertutil import precondition, _assert |
---|
5007 | from allmydata.util.fileutil import abspath_expanduser_unicode |
---|
5008 | -from allmydata.util.encodingutil import get_filesystem_encoding, quote_output |
---|
5009 | +from allmydata.util.encodingutil import get_filesystem_encoding, quote_output, quote_filepath |
---|
5010 | +from allmydata.util.abbreviate import parse_abbreviated_size |
---|
5011 | + |
---|
5012 | |
---|
5013 | # Add our application versions to the data that Foolscap's LogPublisher |
---|
5014 | # reports. |
---|
5015 | hunk ./src/allmydata/node.py 44 |
---|
5016 | are set to disallow users other than its owner from reading the contents of |
---|
5017 | the files. See the 'configuration.rst' documentation file for details.""" |
---|
5018 | |
---|
5019 | -class _None: # used as a marker in get_config() |
---|
5020 | +class _None: # used as a marker in get_config() and get_or_create_private_config() |
---|
5021 | pass |
---|
5022 | |
---|
5023 | hunk ./src/allmydata/node.py 47 |
---|
5024 | +class InvalidValueError(Exception): |
---|
5025 | + """ The configured value was not valid. """ |
---|
5026 | + |
---|
5027 | class MissingConfigEntry(Exception): |
---|
5028 | """ A required config entry was not found. """ |
---|
5029 | |
---|
5030 | hunk ./src/allmydata/node.py 120 |
---|
5031 | % (quote_output(fn), section, option)) |
---|
5032 | return default |
---|
5033 | |
---|
5034 | + def get_config_size(self, section, option, default=_None): |
---|
5035 | + data = self.get_config(section, option, default) |
---|
5036 | + if data is None: |
---|
5037 | + return None |
---|
5038 | + try: |
---|
5039 | + return parse_abbreviated_size(data) |
---|
5040 | + except ValueError: |
---|
5041 | + raise InvalidValueError("[%s]%s= contains unparseable size value %s" |
---|
5042 | + % (section, option, quote_output(data)) ) |
---|
5043 | + |
---|
5044 | def set_config(self, section, option, value): |
---|
5045 | if not self.config.has_section(section): |
---|
5046 | self.config.add_section(section) |
---|
5047 | hunk ./src/allmydata/node.py 212 |
---|
5048 | # TODO: merge this with allmydata.get_package_versions |
---|
5049 | return dict(app_versions.versions) |
---|
5050 | |
---|
5051 | - def get_config_from_file(self, name, required=False): |
---|
5052 | - """Get the (string) contents of a config file, or None if the file |
---|
5053 | - did not exist. If required=True, raise an exception rather than |
---|
5054 | - returning None. Any leading or trailing whitespace will be stripped |
---|
5055 | - from the data.""" |
---|
5056 | - fn = os.path.join(self.basedir, name) |
---|
5057 | + def _get_private_config_filepath(self, name): |
---|
5058 | + return FilePath(self.basedir).child("private").child(name) |
---|
5059 | + |
---|
5060 | + def get_optional_private_config(self, name): |
---|
5061 | + """Try to get the (string) contents of a private config file (which |
---|
5062 | + is a config file that resides within the subdirectory named |
---|
5063 | + 'private'), and return it. Any leading or trailing whitespace will be |
---|
5064 | + stripped from the data. If the file does not exist, return None. |
---|
5065 | + """ |
---|
5066 | + priv_fp = self._get_private_config_filepath(name) |
---|
5067 | try: |
---|
5068 | hunk ./src/allmydata/node.py 223 |
---|
5069 | - return fileutil.read(fn).strip() |
---|
5070 | + value = priv_fp.getContent() |
---|
5071 | except EnvironmentError: |
---|
5072 | hunk ./src/allmydata/node.py 225 |
---|
5073 | - if not required: |
---|
5074 | - return None |
---|
5075 | - raise |
---|
5076 | + if priv_fp.exists(): |
---|
5077 | + raise |
---|
5078 | + return None |
---|
5079 | + return value.strip() |
---|
5080 | |
---|
5081 | def write_private_config(self, name, value): |
---|
5082 | """Write the (string) contents of a private config file (which is a |
---|
5083 | hunk ./src/allmydata/node.py 236 |
---|
5084 | return it. Any leading or trailing whitespace will be stripped from |
---|
5085 | the data. |
---|
5086 | """ |
---|
5087 | - privname = os.path.join(self.basedir, "private", name) |
---|
5088 | - open(privname, "w").write(value.strip()) |
---|
5089 | + self._get_private_config_filepath(name).setContent(value.strip()) |
---|
5090 | |
---|
5091 | hunk ./src/allmydata/node.py 238 |
---|
5092 | - def get_or_create_private_config(self, name, default): |
---|
5093 | + def get_or_create_private_config(self, name, default=_None): |
---|
5094 | """Try to get the (string) contents of a private config file (which |
---|
5095 | is a config file that resides within the subdirectory named |
---|
5096 | 'private'), and return it. Any leading or trailing whitespace will be |
---|
5097 | hunk ./src/allmydata/node.py 244 |
---|
5098 | stripped from the data. |
---|
5099 | |
---|
5100 | - If the file does not exist, try to create it using default, and |
---|
5101 | - then return the value that was written. If 'default' is a string, |
---|
5102 | - use it as a default value. If not, treat it as a 0-argument callable |
---|
5103 | - which is expected to return a string. |
---|
5104 | + If the file does not exist, and default is not given, report an error. |
---|
5105 | + If the file does not exist and a default is specified, try to create |
---|
5106 | + it using that default, and then return the value that was written. |
---|
5107 | + If 'default' is a string, use it as a default value. If not, treat it |
---|
5108 | + as a zero-argument callable that is expected to return a string. |
---|
5109 | """ |
---|
5110 | hunk ./src/allmydata/node.py 250 |
---|
5111 | - privname = os.path.join(self.basedir, "private", name) |
---|
5112 | - try: |
---|
5113 | - value = fileutil.read(privname) |
---|
5114 | - except EnvironmentError: |
---|
5115 | - if isinstance(default, basestring): |
---|
5116 | - value = default |
---|
5117 | + value = self.get_optional_private_config(name) |
---|
5118 | + if value is None: |
---|
5119 | + priv_fp = self._get_private_config_filepath(name) |
---|
5120 | + if default is _None: |
---|
5121 | + raise MissingConfigEntry("The required configuration file %s is missing." |
---|
5122 | + % (quote_filepath(priv_fp),)) |
---|
5123 | + elif isinstance(default, basestring): |
---|
5124 | + value = default.strip() |
---|
5125 | else: |
---|
5126 | hunk ./src/allmydata/node.py 259 |
---|
5127 | - value = default() |
---|
5128 | - fileutil.write(privname, value) |
---|
5129 | - return value.strip() |
---|
5130 | + value = default().strip() |
---|
5131 | + priv_fp.setContent(value) |
---|
5132 | + return value |
---|
5133 | |
---|
5134 | def write_config(self, name, value, mode="w"): |
---|
5135 | """Write a string to a config file.""" |
---|
5136 | hunk ./src/allmydata/scripts/debug.py 8 |
---|
5137 | from twisted.python import usage, failure |
---|
5138 | from twisted.internet import defer |
---|
5139 | from twisted.scripts import trial as twisted_trial |
---|
5140 | +from twisted.python.filepath import FilePath |
---|
5141 | |
---|
5142 | |
---|
5143 | class DumpOptions(usage.Options): |
---|
5144 | hunk ./src/allmydata/scripts/debug.py 38 |
---|
5145 | self['filename'] = argv_to_abspath(filename) |
---|
5146 | |
---|
5147 | def dump_share(options): |
---|
5148 | - from allmydata.storage.mutable import MutableShareFile |
---|
5149 | + from allmydata.storage.backends.disk.disk_backend import get_disk_share |
---|
5150 | from allmydata.util.encodingutil import quote_output |
---|
5151 | |
---|
5152 | out = options.stdout |
---|
5153 | hunk ./src/allmydata/scripts/debug.py 42 |
---|
5154 | + filename = options['filename'] |
---|
5155 | |
---|
5156 | # check the version, to see if we have a mutable or immutable share |
---|
5157 | hunk ./src/allmydata/scripts/debug.py 45 |
---|
5158 | - print >>out, "share filename: %s" % quote_output(options['filename']) |
---|
5159 | + print >>out, "share filename: %s" % quote_output(filename) |
---|
5160 | |
---|
5161 | hunk ./src/allmydata/scripts/debug.py 47 |
---|
5162 | - f = open(options['filename'], "rb") |
---|
5163 | - prefix = f.read(32) |
---|
5164 | - f.close() |
---|
5165 | - if prefix == MutableShareFile.MAGIC: |
---|
5166 | - return dump_mutable_share(options) |
---|
5167 | - # otherwise assume it's immutable |
---|
5168 | - return dump_immutable_share(options) |
---|
5169 | + share = get_disk_share(FilePath(filename)) |
---|
5170 | |
---|
5171 | hunk ./src/allmydata/scripts/debug.py 49 |
---|
5172 | -def dump_immutable_share(options): |
---|
5173 | - from allmydata.storage.immutable import ShareFile |
---|
5174 | + if share.sharetype == "mutable": |
---|
5175 | + return dump_mutable_share(options, share) |
---|
5176 | + else: |
---|
5177 | + assert share.sharetype == "immutable", share.sharetype |
---|
5178 | + return dump_immutable_share(options, share) |
---|
5179 | |
---|
5180 | hunk ./src/allmydata/scripts/debug.py 55 |
---|
5181 | +def dump_immutable_share(options, share): |
---|
5182 | out = options.stdout |
---|
5183 | hunk ./src/allmydata/scripts/debug.py 57 |
---|
5184 | - f = ShareFile(options['filename']) |
---|
5185 | if not options["leases-only"]: |
---|
5186 | hunk ./src/allmydata/scripts/debug.py 58 |
---|
5187 | - dump_immutable_chk_share(f, out, options) |
---|
5188 | - dump_immutable_lease_info(f, out) |
---|
5189 | + dump_immutable_chk_share(share, out, options) |
---|
5190 | + dump_immutable_lease_info(share, out) |
---|
5191 | print >>out |
---|
5192 | return 0 |
---|
5193 | |
---|
5194 | hunk ./src/allmydata/scripts/debug.py 63 |
---|
5195 | -def dump_immutable_chk_share(f, out, options): |
---|
5196 | +def dump_immutable_chk_share(share, out, options): |
---|
5197 | from allmydata import uri |
---|
5198 | from allmydata.util import base32 |
---|
5199 | from allmydata.immutable.layout import ReadBucketProxy |
---|
5200 | hunk ./src/allmydata/scripts/debug.py 71 |
---|
5201 | |
---|
5202 | # use a ReadBucketProxy to parse the bucket and find the uri extension |
---|
5203 | bp = ReadBucketProxy(None, None, '') |
---|
5204 | - offsets = bp._parse_offsets(f.read_share_data(0, 0x44)) |
---|
5205 | + f = share._get_filepath().open("rb") |
---|
5206 | + # XXX yuck, private API |
---|
5207 | + def read_share_data(offset, length): |
---|
5208 | + return share._read_share_data(f, offset, length) |
---|
5209 | + |
---|
5210 | + offsets = bp._parse_offsets(read_share_data(0, 0x44)) |
---|
5211 | print >>out, "%20s: %d" % ("version", bp._version) |
---|
5212 | seek = offsets['uri_extension'] |
---|
5213 | length = struct.unpack(bp._fieldstruct, |
---|
5214 | hunk ./src/allmydata/scripts/debug.py 80 |
---|
5215 | - f.read_share_data(seek, bp._fieldsize))[0] |
---|
5216 | + read_share_data(seek, bp._fieldsize))[0] |
---|
5217 | seek += bp._fieldsize |
---|
5218 | hunk ./src/allmydata/scripts/debug.py 82 |
---|
5219 | - UEB_data = f.read_share_data(seek, length) |
---|
5220 | + UEB_data = read_share_data(seek, length) |
---|
5221 | |
---|
5222 | unpacked = uri.unpack_extension_readable(UEB_data) |
---|
5223 | keys1 = ("size", "num_segments", "segment_size", |
---|
5224 | hunk ./src/allmydata/scripts/debug.py 142 |
---|
5225 | if options['offsets']: |
---|
5226 | print >>out |
---|
5227 | print >>out, " Section Offsets:" |
---|
5228 | - print >>out, "%20s: %s" % ("share data", f._data_offset) |
---|
5229 | + print >>out, "%20s: %s" % ("share data", share._data_offset) |
---|
5230 | for k in ["data", "plaintext_hash_tree", "crypttext_hash_tree", |
---|
5231 | "block_hashes", "share_hashes", "uri_extension"]: |
---|
5232 | name = {"data": "block data"}.get(k,k) |
---|
5233 | hunk ./src/allmydata/scripts/debug.py 146 |
---|
5234 | - offset = f._data_offset + offsets[k] |
---|
5235 | + offset = share._data_offset + offsets[k] |
---|
5236 | print >>out, " %20s: %s (0x%x)" % (name, offset, offset) |
---|
5237 | hunk ./src/allmydata/scripts/debug.py 148 |
---|
5238 | - print >>out, "%20s: %s" % ("leases", f._lease_offset) |
---|
5239 | + print >>out, "%20s: %s" % ("leases", share._lease_offset) |
---|
5240 | |
---|
5241 | def dump_immutable_lease_info(f, out): |
---|
5242 | # display lease information too |
---|
5243 | hunk ./src/allmydata/scripts/debug.py 173 |
---|
5244 | return when |
---|
5245 | |
---|
5246 | |
---|
5247 | -def dump_mutable_share(options): |
---|
5248 | - from allmydata.storage.mutable import MutableShareFile |
---|
5249 | +def dump_mutable_share(options, m): |
---|
5250 | from allmydata.util import base32, idlib |
---|
5251 | out = options.stdout |
---|
5252 | hunk ./src/allmydata/scripts/debug.py 176 |
---|
5253 | - m = MutableShareFile(options['filename']) |
---|
5254 | f = open(options['filename'], "rb") |
---|
5255 | WE, nodeid = m._read_write_enabler_and_nodeid(f) |
---|
5256 | num_extra_leases = m._read_num_extra_leases(f) |
---|
5257 | hunk ./src/allmydata/scripts/debug.py 286 |
---|
5258 | |
---|
5259 | if options['offsets']: |
---|
5260 | # NOTE: this offset-calculation code is fragile, and needs to be |
---|
5261 | - # merged with MutableShareFile's internals. |
---|
5262 | + # merged with MutableDiskShare's internals. |
---|
5263 | print >>out |
---|
5264 | print >>out, " Section Offsets:" |
---|
5265 | def printoffset(name, value, shift=0): |
---|
5266 | hunk ./src/allmydata/scripts/debug.py 380 |
---|
5267 | |
---|
5268 | if options['offsets']: |
---|
5269 | # NOTE: this offset-calculation code is fragile, and needs to be |
---|
5270 | - # merged with MutableShareFile's internals. |
---|
5271 | + # merged with MutableDiskShare's internals. |
---|
5272 | |
---|
5273 | print >>out |
---|
5274 | print >>out, " Section Offsets:" |
---|
5275 | hunk ./src/allmydata/scripts/debug.py 647 |
---|
5276 | /home/warner/testnet/node-1/storage/shares/44k/44kai1tui348689nrw8fjegc8c/9 |
---|
5277 | /home/warner/testnet/node-2/storage/shares/44k/44kai1tui348689nrw8fjegc8c/2 |
---|
5278 | """ |
---|
5279 | - from allmydata.storage.server import si_a2b, storage_index_to_dir |
---|
5280 | - from allmydata.util.encodingutil import listdir_unicode |
---|
5281 | + from allmydata.storage.server import si_a2b |
---|
5282 | + from allmydata.storage.backends.disk.disk_backend import si_si2dir |
---|
5283 | + from allmydata.util.encodingutil import quote_filepath |
---|
5284 | |
---|
5285 | out = options.stdout |
---|
5286 | hunk ./src/allmydata/scripts/debug.py 652 |
---|
5287 | - sharedir = storage_index_to_dir(si_a2b(options.si_s)) |
---|
5288 | - for d in options.nodedirs: |
---|
5289 | - d = os.path.join(d, "storage/shares", sharedir) |
---|
5290 | - if os.path.exists(d): |
---|
5291 | - for shnum in listdir_unicode(d): |
---|
5292 | - print >>out, os.path.join(d, shnum) |
---|
5293 | + si = si_a2b(options.si_s) |
---|
5294 | + for nodedir in options.nodedirs: |
---|
5295 | + sharedir = si_si2dir(FilePath(nodedir).child("storage").child("shares"), si) |
---|
5296 | + if sharedir.exists(): |
---|
5297 | + for sharefp in sharedir.children(): |
---|
5298 | + print >>out, quote_filepath(sharefp, quotemarks=False) |
---|
5299 | |
---|
5300 | return 0 |
---|
5301 | |
---|
5302 | hunk ./src/allmydata/scripts/debug.py 710 |
---|
5303 | |
---|
5304 | def describe_share(abs_sharefile, si_s, shnum_s, now, out): |
---|
5305 | from allmydata import uri |
---|
5306 | - from allmydata.storage.mutable import MutableShareFile |
---|
5307 | - from allmydata.storage.immutable import ShareFile |
---|
5308 | + from allmydata.storage.backends.disk.disk_backend import get_disk_share |
---|
5309 | + from allmydata.storage.common import UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError |
---|
5310 | from allmydata.mutable.layout import unpack_share |
---|
5311 | from allmydata.mutable.common import NeedMoreDataError |
---|
5312 | from allmydata.immutable.layout import ReadBucketProxy |
---|
5313 | hunk ./src/allmydata/scripts/debug.py 717 |
---|
5314 | from allmydata.util import base32 |
---|
5315 | from allmydata.util.encodingutil import quote_output |
---|
5316 | - import struct |
---|
5317 | |
---|
5318 | hunk ./src/allmydata/scripts/debug.py 718 |
---|
5319 | - f = open(abs_sharefile, "rb") |
---|
5320 | - prefix = f.read(32) |
---|
5321 | + sharefp = FilePath(abs_sharefile) |
---|
5322 | + try: |
---|
5323 | + share = get_disk_share(sharefp) |
---|
5324 | + except UnknownMutableContainerVersionError: |
---|
5325 | + print >>out, "UNKNOWN mutable %s" % quote_output(abs_sharefile) |
---|
5326 | + return |
---|
5327 | + except UnknownImmutableContainerVersionError: |
---|
5328 | + print >>out, "UNKNOWN really-unknown %s" % quote_output(abs_sharefile) |
---|
5329 | + return |
---|
5330 | + |
---|
5331 | + f = sharefp.open("rb") |
---|
5332 | |
---|
5333 | hunk ./src/allmydata/scripts/debug.py 730 |
---|
5334 | - if prefix == MutableShareFile.MAGIC: |
---|
5335 | - # mutable share |
---|
5336 | - m = MutableShareFile(abs_sharefile) |
---|
5337 | - WE, nodeid = m._read_write_enabler_and_nodeid(f) |
---|
5338 | - data_length = m._read_data_length(f) |
---|
5339 | - expiration_time = min( [lease.expiration_time |
---|
5340 | - for (i,lease) in m._enumerate_leases(f)] ) |
---|
5341 | + leases = list(share.get_leases()) |
---|
5342 | + if len(leases) > 0: |
---|
5343 | + expiration_time = min( [lease.expiration_time for lease in leases] ) |
---|
5344 | expiration = max(0, expiration_time - now) |
---|
5345 | hunk ./src/allmydata/scripts/debug.py 734 |
---|
5346 | + else: |
---|
5347 | + expiration = None |
---|
5348 | + |
---|
5349 | + if share.sharetype == "mutable": |
---|
5350 | + WE, nodeid = share._read_write_enabler_and_nodeid(f) |
---|
5351 | + data_length = share._read_data_length(f) |
---|
5352 | |
---|
5353 | share_type = "unknown" |
---|
5354 | hunk ./src/allmydata/scripts/debug.py 742 |
---|
5355 | - f.seek(m.DATA_OFFSET) |
---|
5356 | + f.seek(share.DATA_OFFSET) |
---|
5357 | version = f.read(1) |
---|
5358 | if version == "\x00": |
---|
5359 | # this slot contains an SMDF share |
---|
5360 | hunk ./src/allmydata/scripts/debug.py 751 |
---|
5361 | share_type = "MDMF" |
---|
5362 | |
---|
5363 | if share_type == "SDMF": |
---|
5364 | - f.seek(m.DATA_OFFSET) |
---|
5365 | + f.seek(share.DATA_OFFSET) |
---|
5366 | data = f.read(min(data_length, 2000)) |
---|
5367 | |
---|
5368 | try: |
---|
5369 | hunk ./src/allmydata/scripts/debug.py 759 |
---|
5370 | except NeedMoreDataError, e: |
---|
5371 | # retry once with the larger size |
---|
5372 | size = e.needed_bytes |
---|
5373 | - f.seek(m.DATA_OFFSET) |
---|
5374 | + f.seek(share.DATA_OFFSET) |
---|
5375 | data = f.read(min(data_length, size)) |
---|
5376 | pieces = unpack_share(data) |
---|
5377 | (seqnum, root_hash, IV, k, N, segsize, datalen, |
---|
5378 | hunk ./src/allmydata/scripts/debug.py 766 |
---|
5379 | pubkey, signature, share_hash_chain, block_hash_tree, |
---|
5380 | share_data, enc_privkey) = pieces |
---|
5381 | |
---|
5382 | - print >>out, "SDMF %s %d/%d %d #%d:%s %d %s" % \ |
---|
5383 | + print >>out, "SDMF %s %d/%d %d #%d:%s %r %s" % \ |
---|
5384 | (si_s, k, N, datalen, |
---|
5385 | seqnum, base32.b2a(root_hash), |
---|
5386 | expiration, quote_output(abs_sharefile)) |
---|
5387 | hunk ./src/allmydata/scripts/debug.py 778 |
---|
5388 | def _read(self, readvs, force_remote=False, queue=False): |
---|
5389 | data = [] |
---|
5390 | for (where,length) in readvs: |
---|
5391 | - f.seek(m.DATA_OFFSET+where) |
---|
5392 | + f.seek(share.DATA_OFFSET+where) |
---|
5393 | data.append(f.read(length)) |
---|
5394 | return defer.succeed({fake_shnum: data}) |
---|
5395 | |
---|
5396 | hunk ./src/allmydata/scripts/debug.py 795 |
---|
5397 | verinfo = extract(p.get_verinfo) |
---|
5398 | (seqnum, root_hash, salt_to_use, segsize, datalen, k, N, prefix, |
---|
5399 | offsets) = verinfo |
---|
5400 | - print >>out, "MDMF %s %d/%d %d #%d:%s %d %s" % \ |
---|
5401 | + print >>out, "MDMF %s %d/%d %d #%d:%s %r %s" % \ |
---|
5402 | (si_s, k, N, datalen, |
---|
5403 | seqnum, base32.b2a(root_hash), |
---|
5404 | expiration, quote_output(abs_sharefile)) |
---|
5405 | hunk ./src/allmydata/scripts/debug.py 802 |
---|
5406 | else: |
---|
5407 | print >>out, "UNKNOWN mutable %s" % quote_output(abs_sharefile) |
---|
5408 | |
---|
5409 | - elif struct.unpack(">L", prefix[:4]) == (1,): |
---|
5410 | + else: |
---|
5411 | # immutable |
---|
5412 | class ImmediateReadBucketProxy(ReadBucketProxy): |
---|
5413 | hunk ./src/allmydata/scripts/debug.py 805 |
---|
5414 | - def __init__(self, sf): |
---|
5415 | - self.sf = sf |
---|
5416 | + def __init__(self, share): |
---|
5417 | + self.share = share |
---|
5418 | ReadBucketProxy.__init__(self, None, None, "") |
---|
5419 | def __repr__(self): |
---|
5420 | return "<ImmediateReadBucketProxy>" |
---|
5421 | hunk ./src/allmydata/scripts/debug.py 811 |
---|
5422 | def _read(self, offset, size): |
---|
5423 | - return defer.succeed(sf.read_share_data(offset, size)) |
---|
5424 | + return defer.maybeDeferred(self.share.read_share_data, offset, size) |
---|
5425 | |
---|
5426 | # use a ReadBucketProxy to parse the bucket and find the uri extension |
---|
5427 | hunk ./src/allmydata/scripts/debug.py 814 |
---|
5428 | - sf = ShareFile(abs_sharefile) |
---|
5429 | - bp = ImmediateReadBucketProxy(sf) |
---|
5430 | - |
---|
5431 | - expiration_time = min( [lease.expiration_time |
---|
5432 | - for lease in sf.get_leases()] ) |
---|
5433 | - expiration = max(0, expiration_time - now) |
---|
5434 | + bp = ImmediateReadBucketProxy(share) |
---|
5435 | |
---|
5436 | UEB_data = call(bp.get_uri_extension) |
---|
5437 | unpacked = uri.unpack_extension_readable(UEB_data) |
---|
5438 | hunk ./src/allmydata/scripts/debug.py 824 |
---|
5439 | filesize = unpacked["size"] |
---|
5440 | ueb_hash = unpacked["UEB_hash"] |
---|
5441 | |
---|
5442 | - print >>out, "CHK %s %d/%d %d %s %d %s" % (si_s, k, N, filesize, |
---|
5443 | + print >>out, "CHK %s %d/%d %d %s %r %s" % (si_s, k, N, filesize, |
---|
5444 | ueb_hash, expiration, |
---|
5445 | quote_output(abs_sharefile)) |
---|
5446 | |
---|
5447 | hunk ./src/allmydata/scripts/debug.py 828 |
---|
5448 | - else: |
---|
5449 | - print >>out, "UNKNOWN really-unknown %s" % quote_output(abs_sharefile) |
---|
5450 | - |
---|
5451 | f.close() |
---|
5452 | |
---|
5453 | def catalog_shares(options): |
---|
5454 | hunk ./src/allmydata/scripts/debug.py 913 |
---|
5455 | self['filename'] = filename |
---|
5456 | |
---|
5457 | def corrupt_share(options): |
---|
5458 | + do_corrupt_share(options.stdout, FilePath(options['filename']), options['offset']) |
---|
5459 | + |
---|
5460 | +def do_corrupt_share(out, fp, offset="block-random"): |
---|
5461 | import random |
---|
5462 | hunk ./src/allmydata/scripts/debug.py 917 |
---|
5463 | - from allmydata.storage.mutable import MutableShareFile |
---|
5464 | - from allmydata.storage.immutable import ShareFile |
---|
5465 | + from allmydata.storage.backends.disk.disk_backend import get_disk_share |
---|
5466 | from allmydata.mutable.layout import unpack_header |
---|
5467 | from allmydata.immutable.layout import ReadBucketProxy |
---|
5468 | hunk ./src/allmydata/scripts/debug.py 920 |
---|
5469 | - out = options.stdout |
---|
5470 | - fn = options['filename'] |
---|
5471 | - assert options["offset"] == "block-random", "other offsets not implemented" |
---|
5472 | - # first, what kind of share is it? |
---|
5473 | + |
---|
5474 | + assert offset == "block-random", "other offsets not implemented" |
---|
5475 | |
---|
5476 | def flip_bit(start, end): |
---|
5477 | offset = random.randrange(start, end) |
---|
5478 | hunk ./src/allmydata/scripts/debug.py 927 |
---|
5479 | bit = random.randrange(0, 8) |
---|
5480 | print >>out, "[%d..%d): %d.b%d" % (start, end, offset, bit) |
---|
5481 | - f = open(fn, "rb+") |
---|
5482 | - f.seek(offset) |
---|
5483 | - d = f.read(1) |
---|
5484 | - d = chr(ord(d) ^ 0x01) |
---|
5485 | - f.seek(offset) |
---|
5486 | - f.write(d) |
---|
5487 | - f.close() |
---|
5488 | + f = fp.open("rb+") |
---|
5489 | + try: |
---|
5490 | + f.seek(offset) |
---|
5491 | + d = f.read(1) |
---|
5492 | + d = chr(ord(d) ^ 0x01) |
---|
5493 | + f.seek(offset) |
---|
5494 | + f.write(d) |
---|
5495 | + finally: |
---|
5496 | + f.close() |
---|
5497 | |
---|
5498 | hunk ./src/allmydata/scripts/debug.py 937 |
---|
5499 | - f = open(fn, "rb") |
---|
5500 | - prefix = f.read(32) |
---|
5501 | - f.close() |
---|
5502 | - if prefix == MutableShareFile.MAGIC: |
---|
5503 | - # mutable |
---|
5504 | - m = MutableShareFile(fn) |
---|
5505 | - f = open(fn, "rb") |
---|
5506 | - f.seek(m.DATA_OFFSET) |
---|
5507 | - data = f.read(2000) |
---|
5508 | - # make sure this slot contains an SMDF share |
---|
5509 | - assert data[0] == "\x00", "non-SDMF mutable shares not supported" |
---|
5510 | - f.close() |
---|
5511 | + # what kind of share is it? |
---|
5512 | + |
---|
5513 | + share = get_disk_share(fp) |
---|
5514 | + if share.sharetype == "mutable": |
---|
5515 | + f = fp.open("rb") |
---|
5516 | + try: |
---|
5517 | + f.seek(share.DATA_OFFSET) |
---|
5518 | + data = f.read(2000) |
---|
5519 | + # make sure this slot contains an SMDF share |
---|
5520 | + assert data[0] == "\x00", "non-SDMF mutable shares not supported" |
---|
5521 | + finally: |
---|
5522 | + f.close() |
---|
5523 | |
---|
5524 | (version, ig_seqnum, ig_roothash, ig_IV, ig_k, ig_N, ig_segsize, |
---|
5525 | ig_datalen, offsets) = unpack_header(data) |
---|
5526 | hunk ./src/allmydata/scripts/debug.py 954 |
---|
5527 | |
---|
5528 | assert version == 0, "we only handle v0 SDMF files" |
---|
5529 | - start = m.DATA_OFFSET + offsets["share_data"] |
---|
5530 | - end = m.DATA_OFFSET + offsets["enc_privkey"] |
---|
5531 | + start = share.DATA_OFFSET + offsets["share_data"] |
---|
5532 | + end = share.DATA_OFFSET + offsets["enc_privkey"] |
---|
5533 | flip_bit(start, end) |
---|
5534 | else: |
---|
5535 | # otherwise assume it's immutable |
---|
5536 | hunk ./src/allmydata/scripts/debug.py 959 |
---|
5537 | - f = ShareFile(fn) |
---|
5538 | bp = ReadBucketProxy(None, None, '') |
---|
5539 | hunk ./src/allmydata/scripts/debug.py 960 |
---|
5540 | - offsets = bp._parse_offsets(f.read_share_data(0, 0x24)) |
---|
5541 | - start = f._data_offset + offsets["data"] |
---|
5542 | - end = f._data_offset + offsets["plaintext_hash_tree"] |
---|
5543 | + f = fp.open("rb") |
---|
5544 | + try: |
---|
5545 | + # XXX yuck, private API |
---|
5546 | + header = share._read_share_data(f, 0, 0x24) |
---|
5547 | + finally: |
---|
5548 | + f.close() |
---|
5549 | + offsets = bp._parse_offsets(header) |
---|
5550 | + start = share._data_offset + offsets["data"] |
---|
5551 | + end = share._data_offset + offsets["plaintext_hash_tree"] |
---|
5552 | flip_bit(start, end) |
---|
5553 | |
---|
5554 | |
---|
5555 | hunk ./src/allmydata/storage/backends/disk/immutable.py 1 |
---|
5556 | -import os, stat, struct, time |
---|
5557 | |
---|
5558 | hunk ./src/allmydata/storage/backends/disk/immutable.py 2 |
---|
5559 | -from foolscap.api import Referenceable |
---|
5560 | +import struct |
---|
5561 | + |
---|
5562 | +from twisted.internet import defer |
---|
5563 | |
---|
5564 | from zope.interface import implements |
---|
5565 | hunk ./src/allmydata/storage/backends/disk/immutable.py 7 |
---|
5566 | -from allmydata.interfaces import RIBucketWriter, RIBucketReader |
---|
5567 | -from allmydata.util import base32, fileutil, log |
---|
5568 | +from allmydata.interfaces import IShareForReading, IShareForWriting |
---|
5569 | + |
---|
5570 | +from allmydata.util import fileutil |
---|
5571 | from allmydata.util.assertutil import precondition |
---|
5572 | hunk ./src/allmydata/storage/backends/disk/immutable.py 11 |
---|
5573 | +from allmydata.util.fileutil import fp_make_dirs |
---|
5574 | from allmydata.util.hashutil import constant_time_compare |
---|
5575 | hunk ./src/allmydata/storage/backends/disk/immutable.py 13 |
---|
5576 | +from allmydata.util.encodingutil import quote_filepath |
---|
5577 | +from allmydata.storage.common import si_b2a, UnknownImmutableContainerVersionError, DataTooLargeError |
---|
5578 | from allmydata.storage.lease import LeaseInfo |
---|
5579 | hunk ./src/allmydata/storage/backends/disk/immutable.py 16 |
---|
5580 | -from allmydata.storage.common import UnknownImmutableContainerVersionError, \ |
---|
5581 | - DataTooLargeError |
---|
5582 | |
---|
5583 | |
---|
5584 | # Each share file (in storage/shares/$PREFIX/$STORAGEINDEX/$SHNUM) contains |
---|
5585 | hunk ./src/allmydata/storage/backends/disk/immutable.py 43 |
---|
5586 | # then the value stored in this field will be the actual share data length |
---|
5587 | # modulo 2**32. |
---|
5588 | |
---|
5589 | -class ShareFile: |
---|
5590 | - LEASE_SIZE = struct.calcsize(">L32s32sL") |
---|
5591 | +class ImmutableDiskShare(object): |
---|
5592 | + implements(IShareForReading, IShareForWriting) |
---|
5593 | + |
---|
5594 | sharetype = "immutable" |
---|
5595 | hunk ./src/allmydata/storage/backends/disk/immutable.py 47 |
---|
5596 | + LEASE_SIZE = struct.calcsize(">L32s32sL") |
---|
5597 | + HEADER = ">LLL" |
---|
5598 | + HEADER_SIZE = struct.calcsize(HEADER) |
---|
5599 | |
---|
5600 | hunk ./src/allmydata/storage/backends/disk/immutable.py 51 |
---|
5601 | - def __init__(self, filename, max_size=None, create=False): |
---|
5602 | - """ If max_size is not None then I won't allow more than max_size to be written to me. If create=True and max_size must not be None. """ |
---|
5603 | - precondition((max_size is not None) or (not create), max_size, create) |
---|
5604 | - self.home = filename |
---|
5605 | + def __init__(self, home, storageindex, shnum, finalhome=None, max_size=None): |
---|
5606 | + """ |
---|
5607 | + If max_size is not None then I won't allow more than max_size to be written to me. |
---|
5608 | + If finalhome is not None (meaning that we are creating the share) then max_size |
---|
5609 | + must not be None. |
---|
5610 | + |
---|
5611 | + Clients should use the load_immutable_disk_share and create_immutable_disk_share |
---|
5612 | + factory functions rather than creating instances directly. |
---|
5613 | + """ |
---|
5614 | + precondition((max_size is not None) or (finalhome is None), max_size, finalhome) |
---|
5615 | + self._storageindex = storageindex |
---|
5616 | self._max_size = max_size |
---|
5617 | hunk ./src/allmydata/storage/backends/disk/immutable.py 63 |
---|
5618 | - if create: |
---|
5619 | - # touch the file, so later callers will see that we're working on |
---|
5620 | + |
---|
5621 | + # If we are creating the share, _finalhome refers to the final path and |
---|
5622 | + # _home to the incoming path. Otherwise, _finalhome is None. |
---|
5623 | + self._finalhome = finalhome |
---|
5624 | + self._home = home |
---|
5625 | + self._shnum = shnum |
---|
5626 | + |
---|
5627 | + if self._finalhome is not None: |
---|
5628 | + # Touch the file, so later callers will see that we're working on |
---|
5629 | # it. Also construct the metadata. |
---|
5630 | hunk ./src/allmydata/storage/backends/disk/immutable.py 73 |
---|
5631 | - assert not os.path.exists(self.home) |
---|
5632 | - fileutil.make_dirs(os.path.dirname(self.home)) |
---|
5633 | - f = open(self.home, 'wb') |
---|
5634 | + assert not self._finalhome.exists() |
---|
5635 | + fp_make_dirs(self._home.parent()) |
---|
5636 | # The second field -- the four-byte share data length -- is no |
---|
5637 | # longer used as of Tahoe v1.3.0, but we continue to write it in |
---|
5638 | # there in case someone downgrades a storage server from >= |
---|
5639 | hunk ./src/allmydata/storage/backends/disk/immutable.py 84 |
---|
5640 | # the largest length that can fit into the field. That way, even |
---|
5641 | # if this does happen, the old < v1.3.0 server will still allow |
---|
5642 | # clients to read the first part of the share. |
---|
5643 | - f.write(struct.pack(">LLL", 1, min(2**32-1, max_size), 0)) |
---|
5644 | - f.close() |
---|
5645 | - self._lease_offset = max_size + 0x0c |
---|
5646 | + self._home.setContent(struct.pack(self.HEADER, 1, min(2**32-1, max_size), 0) ) |
---|
5647 | + self._lease_offset = self.HEADER_SIZE + max_size |
---|
5648 | self._num_leases = 0 |
---|
5649 | else: |
---|
5650 | hunk ./src/allmydata/storage/backends/disk/immutable.py 88 |
---|
5651 | - f = open(self.home, 'rb') |
---|
5652 | - filesize = os.path.getsize(self.home) |
---|
5653 | - (version, unused, num_leases) = struct.unpack(">LLL", f.read(0xc)) |
---|
5654 | - f.close() |
---|
5655 | + f = self._home.open(mode='rb') |
---|
5656 | + try: |
---|
5657 | + (version, unused, num_leases) = struct.unpack(self.HEADER, f.read(self.HEADER_SIZE)) |
---|
5658 | + finally: |
---|
5659 | + f.close() |
---|
5660 | if version != 1: |
---|
5661 | msg = "sharefile %s had version %d but we wanted 1" % \ |
---|
5662 | hunk ./src/allmydata/storage/backends/disk/immutable.py 95 |
---|
5663 | - (filename, version) |
---|
5664 | + (self._home, version) |
---|
5665 | raise UnknownImmutableContainerVersionError(msg) |
---|
5666 | hunk ./src/allmydata/storage/backends/disk/immutable.py 97 |
---|
5667 | + |
---|
5668 | + filesize = self._home.getsize() |
---|
5669 | self._num_leases = num_leases |
---|
5670 | self._lease_offset = filesize - (num_leases * self.LEASE_SIZE) |
---|
5671 | hunk ./src/allmydata/storage/backends/disk/immutable.py 101 |
---|
5672 | - self._data_offset = 0xc |
---|
5673 | + self._data_offset = self.HEADER_SIZE |
---|
5674 | + |
---|
5675 | + def __repr__(self): |
---|
5676 | + return ("<ImmutableDiskShare %s:%r at %s>" |
---|
5677 | + % (si_b2a(self._storageindex or ""), self._shnum, quote_filepath(self._home))) |
---|
5678 | + |
---|
5679 | + def close(self): |
---|
5680 | + fileutil.fp_make_dirs(self._finalhome.parent()) |
---|
5681 | + self._home.moveTo(self._finalhome) |
---|
5682 | + |
---|
5683 | + # self._home is like storage/shares/incoming/ab/abcde/4 . |
---|
5684 | + # We try to delete the parent (.../ab/abcde) to avoid leaving |
---|
5685 | + # these directories lying around forever, but the delete might |
---|
5686 | + # fail if we're working on another share for the same storage |
---|
5687 | + # index (like ab/abcde/5). The alternative approach would be to |
---|
5688 | + # use a hierarchy of objects (PrefixHolder, BucketHolder, |
---|
5689 | + # ShareWriter), each of which is responsible for a single |
---|
5690 | + # directory on disk, and have them use reference counting of |
---|
5691 | + # their children to know when they should do the rmdir. This |
---|
5692 | + # approach is simpler, but relies on os.rmdir (used by |
---|
5693 | + # fp_rmdir_if_empty) refusing to delete a non-empty directory. |
---|
5694 | + # Do *not* use fileutil.fp_remove() here! |
---|
5695 | + parent = self._home.parent() |
---|
5696 | + fileutil.fp_rmdir_if_empty(parent) |
---|
5697 | + |
---|
5698 | + # we also delete the grandparent (prefix) directory, .../ab , |
---|
5699 | + # again to avoid leaving directories lying around. This might |
---|
5700 | + # fail if there is another bucket open that shares a prefix (like |
---|
5701 | + # ab/abfff). |
---|
5702 | + fileutil.fp_rmdir_if_empty(parent.parent()) |
---|
5703 | + |
---|
5704 | + # we leave the great-grandparent (incoming/) directory in place. |
---|
5705 | + |
---|
5706 | + # allow lease changes after closing. |
---|
5707 | + self._home = self._finalhome |
---|
5708 | + self._finalhome = None |
---|
5709 | + return defer.succeed(None) |
---|
5710 | + |
---|
5711 | + def get_used_space(self): |
---|
5712 | + return (fileutil.get_used_space(self._finalhome) + |
---|
5713 | + fileutil.get_used_space(self._home)) |
---|
5714 | + |
---|
5715 | + def get_storage_index(self): |
---|
5716 | + return self._storageindex |
---|
5717 | + |
---|
5718 | + def get_storage_index_string(self): |
---|
5719 | + return si_b2a(self._storageindex) |
---|
5720 | + |
---|
5721 | + def get_shnum(self): |
---|
5722 | + return self._shnum |
---|
5723 | |
---|
5724 | def unlink(self): |
---|
5725 | hunk ./src/allmydata/storage/backends/disk/immutable.py 153 |
---|
5726 | - os.unlink(self.home) |
---|
5727 | + fileutil.fp_remove(self._home) |
---|
5728 | + return defer.succeed(None) |
---|
5729 | |
---|
5730 | hunk ./src/allmydata/storage/backends/disk/immutable.py 156 |
---|
5731 | - def read_share_data(self, offset, length): |
---|
5732 | + def get_allocated_size(self): |
---|
5733 | + return self._max_size |
---|
5734 | + |
---|
5735 | + def get_size(self): |
---|
5736 | + return self._home.getsize() |
---|
5737 | + |
---|
5738 | + def get_data_length(self): |
---|
5739 | + return self._lease_offset - self._data_offset |
---|
5740 | + |
---|
5741 | + def readv(self, readv): |
---|
5742 | + datav = [] |
---|
5743 | + f = self._home.open('rb') |
---|
5744 | + try: |
---|
5745 | + for (offset, length) in readv: |
---|
5746 | + datav.append(self._read_share_data(f, offset, length)) |
---|
5747 | + finally: |
---|
5748 | + f.close() |
---|
5749 | + return defer.succeed(datav) |
---|
5750 | + |
---|
5751 | + def _get_filepath(self): |
---|
5752 | + return self._home |
---|
5753 | + |
---|
5754 | + def _read_share_data(self, f, offset, length): |
---|
5755 | precondition(offset >= 0) |
---|
5756 | |
---|
5757 | # Reads beyond the end of the data are truncated. Reads that start |
---|
5758 | hunk ./src/allmydata/storage/backends/disk/immutable.py 187 |
---|
5759 | actuallength = max(0, min(length, self._lease_offset-seekpos)) |
---|
5760 | if actuallength == 0: |
---|
5761 | return "" |
---|
5762 | - f = open(self.home, 'rb') |
---|
5763 | f.seek(seekpos) |
---|
5764 | return f.read(actuallength) |
---|
5765 | |
---|
5766 | hunk ./src/allmydata/storage/backends/disk/immutable.py 190 |
---|
5767 | + def read_share_data(self, offset, length): |
---|
5768 | + f = self._home.open(mode='rb') |
---|
5769 | + try: |
---|
5770 | + return defer.succeed(self._read_share_data(f, offset, length)) |
---|
5771 | + finally: |
---|
5772 | + f.close() |
---|
5773 | + |
---|
5774 | def write_share_data(self, offset, data): |
---|
5775 | length = len(data) |
---|
5776 | precondition(offset >= 0, offset) |
---|
5777 | hunk ./src/allmydata/storage/backends/disk/immutable.py 202 |
---|
5778 | if self._max_size is not None and offset+length > self._max_size: |
---|
5779 | raise DataTooLargeError(self._max_size, offset, length) |
---|
5780 | - f = open(self.home, 'rb+') |
---|
5781 | - real_offset = self._data_offset+offset |
---|
5782 | - f.seek(real_offset) |
---|
5783 | - assert f.tell() == real_offset |
---|
5784 | - f.write(data) |
---|
5785 | - f.close() |
---|
5786 | + f = self._home.open(mode='rb+') |
---|
5787 | + try: |
---|
5788 | + real_offset = self._data_offset+offset |
---|
5789 | + f.seek(real_offset) |
---|
5790 | + assert f.tell() == real_offset |
---|
5791 | + f.write(data) |
---|
5792 | + return defer.succeed(None) |
---|
5793 | + finally: |
---|
5794 | + f.close() |
---|
5795 | |
---|
5796 | def _write_lease_record(self, f, lease_number, lease_info): |
---|
5797 | offset = self._lease_offset + lease_number * self.LEASE_SIZE |
---|
5798 | hunk ./src/allmydata/storage/backends/disk/immutable.py 220 |
---|
5799 | |
---|
5800 | def _read_num_leases(self, f): |
---|
5801 | f.seek(0x08) |
---|
5802 | - (num_leases,) = struct.unpack(">L", f.read(4)) |
---|
5803 | + ro = f.read(4) |
---|
5804 | + (num_leases,) = struct.unpack(">L", ro) |
---|
5805 | return num_leases |
---|
5806 | |
---|
5807 | def _write_num_leases(self, f, num_leases): |
---|
5808 | hunk ./src/allmydata/storage/backends/disk/immutable.py 231 |
---|
5809 | def _truncate_leases(self, f, num_leases): |
---|
5810 | f.truncate(self._lease_offset + num_leases * self.LEASE_SIZE) |
---|
5811 | |
---|
5812 | + # These lease operations are intended for use by disk_backend.py. |
---|
5813 | + # Other clients should not depend on the fact that the disk backend |
---|
5814 | + # stores leases in share files. |
---|
5815 | + # XXX BucketWriter in bucket.py also relies on add_lease. |
---|
5816 | + |
---|
5817 | def get_leases(self): |
---|
5818 | """Yields a LeaseInfo instance for all leases.""" |
---|
5819 | hunk ./src/allmydata/storage/backends/disk/immutable.py 238 |
---|
5820 | - f = open(self.home, 'rb') |
---|
5821 | - (version, unused, num_leases) = struct.unpack(">LLL", f.read(0xc)) |
---|
5822 | - f.seek(self._lease_offset) |
---|
5823 | - for i in range(num_leases): |
---|
5824 | - data = f.read(self.LEASE_SIZE) |
---|
5825 | - if data: |
---|
5826 | - yield LeaseInfo().from_immutable_data(data) |
---|
5827 | + f = self._home.open(mode='rb') |
---|
5828 | + try: |
---|
5829 | + (version, unused, num_leases) = struct.unpack(self.HEADER, f.read(self.HEADER_SIZE)) |
---|
5830 | + f.seek(self._lease_offset) |
---|
5831 | + for i in range(num_leases): |
---|
5832 | + data = f.read(self.LEASE_SIZE) |
---|
5833 | + if data: |
---|
5834 | + yield LeaseInfo().from_immutable_data(data) |
---|
5835 | + finally: |
---|
5836 | + f.close() |
---|
5837 | |
---|
5838 | def add_lease(self, lease_info): |
---|
5839 | hunk ./src/allmydata/storage/backends/disk/immutable.py 250 |
---|
5840 | - f = open(self.home, 'rb+') |
---|
5841 | - num_leases = self._read_num_leases(f) |
---|
5842 | - self._write_lease_record(f, num_leases, lease_info) |
---|
5843 | - self._write_num_leases(f, num_leases+1) |
---|
5844 | - f.close() |
---|
5845 | + f = self._home.open(mode='rb+') |
---|
5846 | + try: |
---|
5847 | + num_leases = self._read_num_leases(f) |
---|
5848 | + self._write_lease_record(f, num_leases, lease_info) |
---|
5849 | + self._write_num_leases(f, num_leases+1) |
---|
5850 | + finally: |
---|
5851 | + f.close() |
---|
5852 | |
---|
5853 | def renew_lease(self, renew_secret, new_expire_time): |
---|
5854 | hunk ./src/allmydata/storage/backends/disk/immutable.py 259 |
---|
5855 | - for i,lease in enumerate(self.get_leases()): |
---|
5856 | - if constant_time_compare(lease.renew_secret, renew_secret): |
---|
5857 | - # yup. See if we need to update the owner time. |
---|
5858 | - if new_expire_time > lease.expiration_time: |
---|
5859 | - # yes |
---|
5860 | - lease.expiration_time = new_expire_time |
---|
5861 | - f = open(self.home, 'rb+') |
---|
5862 | - self._write_lease_record(f, i, lease) |
---|
5863 | - f.close() |
---|
5864 | - return |
---|
5865 | + try: |
---|
5866 | + for i, lease in enumerate(self.get_leases()): |
---|
5867 | + if constant_time_compare(lease.renew_secret, renew_secret): |
---|
5868 | + # yup. See if we need to update the owner time. |
---|
5869 | + if new_expire_time > lease.expiration_time: |
---|
5870 | + # yes |
---|
5871 | + lease.expiration_time = new_expire_time |
---|
5872 | + f = self._home.open('rb+') |
---|
5873 | + try: |
---|
5874 | + self._write_lease_record(f, i, lease) |
---|
5875 | + finally: |
---|
5876 | + f.close() |
---|
5877 | + return |
---|
5878 | + except IndexError, e: |
---|
5879 | + raise Exception("IndexError: %s" % (e,)) |
---|
5880 | raise IndexError("unable to renew non-existent lease") |
---|
5881 | |
---|
5882 | def add_or_renew_lease(self, lease_info): |
---|
5883 | hunk ./src/allmydata/storage/backends/disk/immutable.py 299 |
---|
5884 | num_leases_removed += 1 |
---|
5885 | if not num_leases_removed: |
---|
5886 | raise IndexError("unable to find matching lease to cancel") |
---|
5887 | + |
---|
5888 | + space_freed = 0 |
---|
5889 | if num_leases_removed: |
---|
5890 | # pack and write out the remaining leases. We write these out in |
---|
5891 | # the same order as they were added, so that if we crash while |
---|
5892 | hunk ./src/allmydata/storage/backends/disk/immutable.py 306 |
---|
5893 | # doing this, we won't lose any non-cancelled leases. |
---|
5894 | leases = [l for l in leases if l] # remove the cancelled leases |
---|
5895 | - f = open(self.home, 'rb+') |
---|
5896 | - for i,lease in enumerate(leases): |
---|
5897 | - self._write_lease_record(f, i, lease) |
---|
5898 | - self._write_num_leases(f, len(leases)) |
---|
5899 | - self._truncate_leases(f, len(leases)) |
---|
5900 | - f.close() |
---|
5901 | - space_freed = self.LEASE_SIZE * num_leases_removed |
---|
5902 | - if not len(leases): |
---|
5903 | - space_freed += os.stat(self.home)[stat.ST_SIZE] |
---|
5904 | - self.unlink() |
---|
5905 | + if len(leases) > 0: |
---|
5906 | + f = self._home.open('rb+') |
---|
5907 | + try: |
---|
5908 | + for i, lease in enumerate(leases): |
---|
5909 | + self._write_lease_record(f, i, lease) |
---|
5910 | + self._write_num_leases(f, len(leases)) |
---|
5911 | + self._truncate_leases(f, len(leases)) |
---|
5912 | + finally: |
---|
5913 | + f.close() |
---|
5914 | + space_freed = self.LEASE_SIZE * num_leases_removed |
---|
5915 | + else: |
---|
5916 | + space_freed = fileutil.get_used_space(self._home) |
---|
5917 | + self.unlink() |
---|
5918 | return space_freed |
---|
5919 | |
---|
5920 | |
---|
5921 | hunk ./src/allmydata/storage/backends/disk/immutable.py 322 |
---|
5922 | -class BucketWriter(Referenceable): |
---|
5923 | - implements(RIBucketWriter) |
---|
5924 | - |
---|
5925 | - def __init__(self, ss, incominghome, finalhome, max_size, lease_info, canary): |
---|
5926 | - self.ss = ss |
---|
5927 | - self.incominghome = incominghome |
---|
5928 | - self.finalhome = finalhome |
---|
5929 | - self._max_size = max_size # don't allow the client to write more than this |
---|
5930 | - self._canary = canary |
---|
5931 | - self._disconnect_marker = canary.notifyOnDisconnect(self._disconnected) |
---|
5932 | - self.closed = False |
---|
5933 | - self.throw_out_all_data = False |
---|
5934 | - self._sharefile = ShareFile(incominghome, create=True, max_size=max_size) |
---|
5935 | - # also, add our lease to the file now, so that other ones can be |
---|
5936 | - # added by simultaneous uploaders |
---|
5937 | - self._sharefile.add_lease(lease_info) |
---|
5938 | - |
---|
5939 | - def allocated_size(self): |
---|
5940 | - return self._max_size |
---|
5941 | - |
---|
5942 | - def remote_write(self, offset, data): |
---|
5943 | - start = time.time() |
---|
5944 | - precondition(not self.closed) |
---|
5945 | - if self.throw_out_all_data: |
---|
5946 | - return |
---|
5947 | - self._sharefile.write_share_data(offset, data) |
---|
5948 | - self.ss.add_latency("write", time.time() - start) |
---|
5949 | - self.ss.count("write") |
---|
5950 | - |
---|
5951 | - def remote_close(self): |
---|
5952 | - precondition(not self.closed) |
---|
5953 | - start = time.time() |
---|
5954 | - |
---|
5955 | - fileutil.make_dirs(os.path.dirname(self.finalhome)) |
---|
5956 | - fileutil.rename(self.incominghome, self.finalhome) |
---|
5957 | - try: |
---|
5958 | - # self.incominghome is like storage/shares/incoming/ab/abcde/4 . |
---|
5959 | - # We try to delete the parent (.../ab/abcde) to avoid leaving |
---|
5960 | - # these directories lying around forever, but the delete might |
---|
5961 | - # fail if we're working on another share for the same storage |
---|
5962 | - # index (like ab/abcde/5). The alternative approach would be to |
---|
5963 | - # use a hierarchy of objects (PrefixHolder, BucketHolder, |
---|
5964 | - # ShareWriter), each of which is responsible for a single |
---|
5965 | - # directory on disk, and have them use reference counting of |
---|
5966 | - # their children to know when they should do the rmdir. This |
---|
5967 | - # approach is simpler, but relies on os.rmdir refusing to delete |
---|
5968 | - # a non-empty directory. Do *not* use fileutil.rm_dir() here! |
---|
5969 | - os.rmdir(os.path.dirname(self.incominghome)) |
---|
5970 | - # we also delete the grandparent (prefix) directory, .../ab , |
---|
5971 | - # again to avoid leaving directories lying around. This might |
---|
5972 | - # fail if there is another bucket open that shares a prefix (like |
---|
5973 | - # ab/abfff). |
---|
5974 | - os.rmdir(os.path.dirname(os.path.dirname(self.incominghome))) |
---|
5975 | - # we leave the great-grandparent (incoming/) directory in place. |
---|
5976 | - except EnvironmentError: |
---|
5977 | - # ignore the "can't rmdir because the directory is not empty" |
---|
5978 | - # exceptions, those are normal consequences of the |
---|
5979 | - # above-mentioned conditions. |
---|
5980 | - pass |
---|
5981 | - self._sharefile = None |
---|
5982 | - self.closed = True |
---|
5983 | - self._canary.dontNotifyOnDisconnect(self._disconnect_marker) |
---|
5984 | - |
---|
5985 | - filelen = os.stat(self.finalhome)[stat.ST_SIZE] |
---|
5986 | - self.ss.bucket_writer_closed(self, filelen) |
---|
5987 | - self.ss.add_latency("close", time.time() - start) |
---|
5988 | - self.ss.count("close") |
---|
5989 | - |
---|
5990 | - def _disconnected(self): |
---|
5991 | - if not self.closed: |
---|
5992 | - self._abort() |
---|
5993 | - |
---|
5994 | - def remote_abort(self): |
---|
5995 | - log.msg("storage: aborting sharefile %s" % self.incominghome, |
---|
5996 | - facility="tahoe.storage", level=log.UNUSUAL) |
---|
5997 | - if not self.closed: |
---|
5998 | - self._canary.dontNotifyOnDisconnect(self._disconnect_marker) |
---|
5999 | - self._abort() |
---|
6000 | - self.ss.count("abort") |
---|
6001 | - |
---|
6002 | - def _abort(self): |
---|
6003 | - if self.closed: |
---|
6004 | - return |
---|
6005 | - |
---|
6006 | - os.remove(self.incominghome) |
---|
6007 | - # if we were the last share to be moved, remove the incoming/ |
---|
6008 | - # directory that was our parent |
---|
6009 | - parentdir = os.path.split(self.incominghome)[0] |
---|
6010 | - if not os.listdir(parentdir): |
---|
6011 | - os.rmdir(parentdir) |
---|
6012 | - self._sharefile = None |
---|
6013 | - |
---|
6014 | - # We are now considered closed for further writing. We must tell |
---|
6015 | - # the storage server about this so that it stops expecting us to |
---|
6016 | - # use the space it allocated for us earlier. |
---|
6017 | - self.closed = True |
---|
6018 | - self.ss.bucket_writer_closed(self, 0) |
---|
6019 | - |
---|
6020 | - |
---|
6021 | -class BucketReader(Referenceable): |
---|
6022 | - implements(RIBucketReader) |
---|
6023 | - |
---|
6024 | - def __init__(self, ss, sharefname, storage_index=None, shnum=None): |
---|
6025 | - self.ss = ss |
---|
6026 | - self._share_file = ShareFile(sharefname) |
---|
6027 | - self.storage_index = storage_index |
---|
6028 | - self.shnum = shnum |
---|
6029 | - |
---|
6030 | - def __repr__(self): |
---|
6031 | - return "<%s %s %s>" % (self.__class__.__name__, |
---|
6032 | - base32.b2a_l(self.storage_index[:8], 60), |
---|
6033 | - self.shnum) |
---|
6034 | - |
---|
6035 | - def remote_read(self, offset, length): |
---|
6036 | - start = time.time() |
---|
6037 | - data = self._share_file.read_share_data(offset, length) |
---|
6038 | - self.ss.add_latency("read", time.time() - start) |
---|
6039 | - self.ss.count("read") |
---|
6040 | - return data |
---|
6041 | +def load_immutable_disk_share(home, storageindex=None, shnum=None): |
---|
6042 | + return ImmutableDiskShare(home, storageindex=storageindex, shnum=shnum) |
---|
6043 | |
---|
6044 | hunk ./src/allmydata/storage/backends/disk/immutable.py 325 |
---|
6045 | - def remote_advise_corrupt_share(self, reason): |
---|
6046 | - return self.ss.remote_advise_corrupt_share("immutable", |
---|
6047 | - self.storage_index, |
---|
6048 | - self.shnum, |
---|
6049 | - reason) |
---|
6050 | +def create_immutable_disk_share(home, finalhome, max_size, storageindex=None, shnum=None): |
---|
6051 | + return ImmutableDiskShare(home, finalhome=finalhome, max_size=max_size, |
---|
6052 | + storageindex=storageindex, shnum=shnum) |
---|
6053 | hunk ./src/allmydata/storage/backends/disk/mutable.py 1 |
---|
6054 | -import os, stat, struct |
---|
6055 | |
---|
6056 | hunk ./src/allmydata/storage/backends/disk/mutable.py 2 |
---|
6057 | -from allmydata.interfaces import BadWriteEnablerError |
---|
6058 | -from allmydata.util import idlib, log |
---|
6059 | +import struct |
---|
6060 | + |
---|
6061 | +from twisted.internet import defer |
---|
6062 | + |
---|
6063 | +from zope.interface import implements |
---|
6064 | +from allmydata.interfaces import IMutableShare, BadWriteEnablerError |
---|
6065 | + |
---|
6066 | +from allmydata.util import fileutil, idlib, log |
---|
6067 | from allmydata.util.assertutil import precondition |
---|
6068 | from allmydata.util.hashutil import constant_time_compare |
---|
6069 | hunk ./src/allmydata/storage/backends/disk/mutable.py 12 |
---|
6070 | -from allmydata.storage.lease import LeaseInfo |
---|
6071 | -from allmydata.storage.common import UnknownMutableContainerVersionError, \ |
---|
6072 | +from allmydata.util.encodingutil import quote_filepath |
---|
6073 | +from allmydata.storage.common import si_b2a, UnknownMutableContainerVersionError, \ |
---|
6074 | DataTooLargeError |
---|
6075 | hunk ./src/allmydata/storage/backends/disk/mutable.py 15 |
---|
6076 | +from allmydata.storage.lease import LeaseInfo |
---|
6077 | +from allmydata.storage.backends.base import testv_compare |
---|
6078 | +from allmydata.mutable.layout import MUTABLE_MAGIC |
---|
6079 | + |
---|
6080 | |
---|
6081 | hunk ./src/allmydata/storage/backends/disk/mutable.py 20 |
---|
6082 | -# the MutableShareFile is like the ShareFile, but used for mutable data. It |
---|
6083 | -# has a different layout. See docs/mutable.txt for more details. |
---|
6084 | +# The MutableDiskShare is like the ImmutableDiskShare, but used for mutable data. |
---|
6085 | +# It has a different layout. See docs/mutable.rst for more details. |
---|
6086 | |
---|
6087 | # # offset size name |
---|
6088 | # 1 0 32 magic verstr "tahoe mutable container v1" plus binary |
---|
6089 | hunk ./src/allmydata/storage/backends/disk/mutable.py 45 |
---|
6090 | assert struct.calcsize(">L") == 4, struct.calcsize(">L") |
---|
6091 | assert struct.calcsize(">Q") == 8, struct.calcsize(">Q") |
---|
6092 | |
---|
6093 | -class MutableShareFile: |
---|
6094 | + |
---|
6095 | +class MutableDiskShare(object): |
---|
6096 | + implements(IMutableShare) |
---|
6097 | |
---|
6098 | sharetype = "mutable" |
---|
6099 | DATA_LENGTH_OFFSET = struct.calcsize(">32s20s32s") |
---|
6100 | hunk ./src/allmydata/storage/backends/disk/mutable.py 57 |
---|
6101 | assert LEASE_SIZE == 92 |
---|
6102 | DATA_OFFSET = HEADER_SIZE + 4*LEASE_SIZE |
---|
6103 | assert DATA_OFFSET == 468, DATA_OFFSET |
---|
6104 | - # our sharefiles share with a recognizable string, plus some random |
---|
6105 | - # binary data to reduce the chance that a regular text file will look |
---|
6106 | - # like a sharefile. |
---|
6107 | - MAGIC = "Tahoe mutable container v1\n" + "\x75\x09\x44\x03\x8e" |
---|
6108 | + |
---|
6109 | + MAGIC = MUTABLE_MAGIC |
---|
6110 | assert len(MAGIC) == 32 |
---|
6111 | MAX_SIZE = 2*1000*1000*1000 # 2GB, kind of arbitrary |
---|
6112 | # TODO: decide upon a policy for max share size |
---|
6113 | hunk ./src/allmydata/storage/backends/disk/mutable.py 63 |
---|
6114 | |
---|
6115 | - def __init__(self, filename, parent=None): |
---|
6116 | - self.home = filename |
---|
6117 | - if os.path.exists(self.home): |
---|
6118 | + def __init__(self, home, storageindex, shnum, parent=None): |
---|
6119 | + """ |
---|
6120 | + Clients should use the load_mutable_disk_share and create_mutable_disk_share |
---|
6121 | + factory functions rather than creating instances directly. |
---|
6122 | + """ |
---|
6123 | + self._storageindex = storageindex |
---|
6124 | + self._shnum = shnum |
---|
6125 | + self._home = home |
---|
6126 | + if self._home.exists(): |
---|
6127 | # we don't cache anything, just check the magic |
---|
6128 | hunk ./src/allmydata/storage/backends/disk/mutable.py 73 |
---|
6129 | - f = open(self.home, 'rb') |
---|
6130 | - data = f.read(self.HEADER_SIZE) |
---|
6131 | - (magic, |
---|
6132 | - write_enabler_nodeid, write_enabler, |
---|
6133 | - data_length, extra_least_offset) = \ |
---|
6134 | - struct.unpack(">32s20s32sQQ", data) |
---|
6135 | - if magic != self.MAGIC: |
---|
6136 | - msg = "sharefile %s had magic '%r' but we wanted '%r'" % \ |
---|
6137 | - (filename, magic, self.MAGIC) |
---|
6138 | - raise UnknownMutableContainerVersionError(msg) |
---|
6139 | + f = self._home.open('rb') |
---|
6140 | + try: |
---|
6141 | + data = f.read(self.HEADER_SIZE) |
---|
6142 | + (magic, |
---|
6143 | + write_enabler_nodeid, write_enabler, |
---|
6144 | + data_length, extra_lease_offset) = \ |
---|
6145 | + struct.unpack(">32s20s32sQQ", data) |
---|
6146 | + if magic != self.MAGIC: |
---|
6147 | + msg = "sharefile %s had magic '%r' but we wanted '%r'" % \ |
---|
6148 | + (quote_filepath(self._home), magic, self.MAGIC) |
---|
6149 | + raise UnknownMutableContainerVersionError(msg) |
---|
6150 | + finally: |
---|
6151 | + f.close() |
---|
6152 | self.parent = parent # for logging |
---|
6153 | |
---|
6154 | def log(self, *args, **kwargs): |
---|
6155 | hunk ./src/allmydata/storage/backends/disk/mutable.py 89 |
---|
6156 | - return self.parent.log(*args, **kwargs) |
---|
6157 | + if self.parent: |
---|
6158 | + return self.parent.log(*args, **kwargs) |
---|
6159 | |
---|
6160 | hunk ./src/allmydata/storage/backends/disk/mutable.py 92 |
---|
6161 | - def create(self, my_nodeid, write_enabler): |
---|
6162 | - assert not os.path.exists(self.home) |
---|
6163 | + def create(self, serverid, write_enabler): |
---|
6164 | + assert not self._home.exists(), "%r already exists and should not" % (self._home,) |
---|
6165 | data_length = 0 |
---|
6166 | extra_lease_offset = (self.HEADER_SIZE |
---|
6167 | + 4 * self.LEASE_SIZE |
---|
6168 | hunk ./src/allmydata/storage/backends/disk/mutable.py 100 |
---|
6169 | + data_length) |
---|
6170 | assert extra_lease_offset == self.DATA_OFFSET # true at creation |
---|
6171 | num_extra_leases = 0 |
---|
6172 | - f = open(self.home, 'wb') |
---|
6173 | - header = struct.pack(">32s20s32sQQ", |
---|
6174 | - self.MAGIC, my_nodeid, write_enabler, |
---|
6175 | - data_length, extra_lease_offset, |
---|
6176 | - ) |
---|
6177 | - leases = ("\x00"*self.LEASE_SIZE) * 4 |
---|
6178 | - f.write(header + leases) |
---|
6179 | - # data goes here, empty after creation |
---|
6180 | - f.write(struct.pack(">L", num_extra_leases)) |
---|
6181 | - # extra leases go here, none at creation |
---|
6182 | - f.close() |
---|
6183 | + f = self._home.open('wb') |
---|
6184 | + try: |
---|
6185 | + header = struct.pack(">32s20s32sQQ", |
---|
6186 | + self.MAGIC, serverid, write_enabler, |
---|
6187 | + data_length, extra_lease_offset, |
---|
6188 | + ) |
---|
6189 | + leases = ("\x00"*self.LEASE_SIZE) * 4 |
---|
6190 | + f.write(header + leases) |
---|
6191 | + # data goes here, empty after creation |
---|
6192 | + f.write(struct.pack(">L", num_extra_leases)) |
---|
6193 | + # extra leases go here, none at creation |
---|
6194 | + finally: |
---|
6195 | + f.close() |
---|
6196 | + return self |
---|
6197 | + |
---|
6198 | + def __repr__(self): |
---|
6199 | + return ("<MutableDiskShare %s:%r at %s>" |
---|
6200 | + % (si_b2a(self._storageindex or ""), self._shnum, quote_filepath(self._home))) |
---|
6201 | + |
---|
6202 | + def get_used_space(self): |
---|
6203 | + return fileutil.get_used_space(self._home) |
---|
6204 | + |
---|
6205 | + def get_storage_index(self): |
---|
6206 | + return self._storageindex |
---|
6207 | + |
---|
6208 | + def get_storage_index_string(self): |
---|
6209 | + return si_b2a(self._storageindex) |
---|
6210 | + |
---|
6211 | + def get_shnum(self): |
---|
6212 | + return self._shnum |
---|
6213 | |
---|
6214 | def unlink(self): |
---|
6215 | hunk ./src/allmydata/storage/backends/disk/mutable.py 132 |
---|
6216 | - os.unlink(self.home) |
---|
6217 | + fileutil.fp_remove(self._home) |
---|
6218 | + return defer.succeed(None) |
---|
6219 | + |
---|
6220 | + def _get_filepath(self): |
---|
6221 | + return self._home |
---|
6222 | |
---|
6223 | def _read_data_length(self, f): |
---|
6224 | f.seek(self.DATA_LENGTH_OFFSET) |
---|
6225 | hunk ./src/allmydata/storage/backends/disk/mutable.py 148 |
---|
6226 | f.write(struct.pack(">Q", data_length)) |
---|
6227 | |
---|
6228 | def _read_share_data(self, f, offset, length): |
---|
6229 | - precondition(offset >= 0) |
---|
6230 | + precondition(offset >= 0, offset=offset) |
---|
6231 | data_length = self._read_data_length(f) |
---|
6232 | if offset+length > data_length: |
---|
6233 | # reads beyond the end of the data are truncated. Reads that |
---|
6234 | hunk ./src/allmydata/storage/backends/disk/mutable.py 181 |
---|
6235 | f.seek(extra_lease_offset) |
---|
6236 | f.write(struct.pack(">L", num_leases)) |
---|
6237 | |
---|
6238 | - def _change_container_size(self, f, new_container_size): |
---|
6239 | - if new_container_size > self.MAX_SIZE: |
---|
6240 | + def _change_container_size(self, f, new_data_length): |
---|
6241 | + if new_data_length > self.MAX_SIZE: |
---|
6242 | raise DataTooLargeError() |
---|
6243 | old_extra_lease_offset = self._read_extra_lease_offset(f) |
---|
6244 | hunk ./src/allmydata/storage/backends/disk/mutable.py 185 |
---|
6245 | - new_extra_lease_offset = self.DATA_OFFSET + new_container_size |
---|
6246 | + new_extra_lease_offset = self.DATA_OFFSET + new_data_length |
---|
6247 | if new_extra_lease_offset < old_extra_lease_offset: |
---|
6248 | # TODO: allow containers to shrink. For now they remain large. |
---|
6249 | return |
---|
6250 | hunk ./src/allmydata/storage/backends/disk/mutable.py 208 |
---|
6251 | |
---|
6252 | def _write_share_data(self, f, offset, data): |
---|
6253 | length = len(data) |
---|
6254 | - precondition(offset >= 0) |
---|
6255 | + precondition(offset >= 0, offset=offset) |
---|
6256 | + precondition(offset+length < self.MAX_SIZE, offset=offset, length=length) |
---|
6257 | + |
---|
6258 | data_length = self._read_data_length(f) |
---|
6259 | extra_lease_offset = self._read_extra_lease_offset(f) |
---|
6260 | |
---|
6261 | hunk ./src/allmydata/storage/backends/disk/mutable.py 306 |
---|
6262 | |
---|
6263 | def get_leases(self): |
---|
6264 | """Yields a LeaseInfo instance for all leases.""" |
---|
6265 | - f = open(self.home, 'rb') |
---|
6266 | - for i, lease in self._enumerate_leases(f): |
---|
6267 | - yield lease |
---|
6268 | - f.close() |
---|
6269 | + f = self._home.open('rb') |
---|
6270 | + try: |
---|
6271 | + for i, lease in self._enumerate_leases(f): |
---|
6272 | + yield lease |
---|
6273 | + finally: |
---|
6274 | + f.close() |
---|
6275 | |
---|
6276 | def _enumerate_leases(self, f): |
---|
6277 | for i in range(self._get_num_lease_slots(f)): |
---|
6278 | hunk ./src/allmydata/storage/backends/disk/mutable.py 322 |
---|
6279 | except IndexError: |
---|
6280 | return |
---|
6281 | |
---|
6282 | + # These lease operations are intended for use by disk_backend.py. |
---|
6283 | + # Other non-test clients should not depend on the fact that the disk |
---|
6284 | + # backend stores leases in share files. |
---|
6285 | + |
---|
6286 | def add_lease(self, lease_info): |
---|
6287 | precondition(lease_info.owner_num != 0) # 0 means "no lease here" |
---|
6288 | hunk ./src/allmydata/storage/backends/disk/mutable.py 328 |
---|
6289 | - f = open(self.home, 'rb+') |
---|
6290 | - num_lease_slots = self._get_num_lease_slots(f) |
---|
6291 | - empty_slot = self._get_first_empty_lease_slot(f) |
---|
6292 | - if empty_slot is not None: |
---|
6293 | - self._write_lease_record(f, empty_slot, lease_info) |
---|
6294 | - else: |
---|
6295 | - self._write_lease_record(f, num_lease_slots, lease_info) |
---|
6296 | - f.close() |
---|
6297 | + f = self._home.open('rb+') |
---|
6298 | + try: |
---|
6299 | + num_lease_slots = self._get_num_lease_slots(f) |
---|
6300 | + empty_slot = self._get_first_empty_lease_slot(f) |
---|
6301 | + if empty_slot is not None: |
---|
6302 | + self._write_lease_record(f, empty_slot, lease_info) |
---|
6303 | + else: |
---|
6304 | + self._write_lease_record(f, num_lease_slots, lease_info) |
---|
6305 | + finally: |
---|
6306 | + f.close() |
---|
6307 | |
---|
6308 | def renew_lease(self, renew_secret, new_expire_time): |
---|
6309 | accepting_nodeids = set() |
---|
6310 | hunk ./src/allmydata/storage/backends/disk/mutable.py 341 |
---|
6311 | - f = open(self.home, 'rb+') |
---|
6312 | - for (leasenum,lease) in self._enumerate_leases(f): |
---|
6313 | - if constant_time_compare(lease.renew_secret, renew_secret): |
---|
6314 | - # yup. See if we need to update the owner time. |
---|
6315 | - if new_expire_time > lease.expiration_time: |
---|
6316 | - # yes |
---|
6317 | - lease.expiration_time = new_expire_time |
---|
6318 | - self._write_lease_record(f, leasenum, lease) |
---|
6319 | - f.close() |
---|
6320 | - return |
---|
6321 | - accepting_nodeids.add(lease.nodeid) |
---|
6322 | - f.close() |
---|
6323 | + f = self._home.open('rb+') |
---|
6324 | + try: |
---|
6325 | + for (leasenum, lease) in self._enumerate_leases(f): |
---|
6326 | + if constant_time_compare(lease.renew_secret, renew_secret): |
---|
6327 | + # yup. See if we need to update the owner time. |
---|
6328 | + if new_expire_time > lease.expiration_time: |
---|
6329 | + # yes |
---|
6330 | + lease.expiration_time = new_expire_time |
---|
6331 | + self._write_lease_record(f, leasenum, lease) |
---|
6332 | + return |
---|
6333 | + accepting_nodeids.add(lease.nodeid) |
---|
6334 | + finally: |
---|
6335 | + f.close() |
---|
6336 | # Return the accepting_nodeids set, to give the client a chance to |
---|
6337 | # update the leases on a share that has been migrated from its |
---|
6338 | # original server to a new one. |
---|
6339 | hunk ./src/allmydata/storage/backends/disk/mutable.py 379 |
---|
6340 | deleting the file). Raise IndexError if there was no lease with the |
---|
6341 | given cancel_secret.""" |
---|
6342 | |
---|
6343 | + # XXX can this be more like ImmutableDiskShare.cancel_lease? |
---|
6344 | + |
---|
6345 | accepting_nodeids = set() |
---|
6346 | modified = 0 |
---|
6347 | remaining = 0 |
---|
6348 | hunk ./src/allmydata/storage/backends/disk/mutable.py 389 |
---|
6349 | cancel_secret="\x00"*32, |
---|
6350 | expiration_time=0, |
---|
6351 | nodeid="\x00"*20) |
---|
6352 | - f = open(self.home, 'rb+') |
---|
6353 | - for (leasenum,lease) in self._enumerate_leases(f): |
---|
6354 | - accepting_nodeids.add(lease.nodeid) |
---|
6355 | - if constant_time_compare(lease.cancel_secret, cancel_secret): |
---|
6356 | - self._write_lease_record(f, leasenum, blank_lease) |
---|
6357 | - modified += 1 |
---|
6358 | - else: |
---|
6359 | - remaining += 1 |
---|
6360 | - if modified: |
---|
6361 | - freed_space = self._pack_leases(f) |
---|
6362 | + f = self._home.open('rb+') |
---|
6363 | + try: |
---|
6364 | + for (leasenum, lease) in self._enumerate_leases(f): |
---|
6365 | + accepting_nodeids.add(lease.nodeid) |
---|
6366 | + if constant_time_compare(lease.cancel_secret, cancel_secret): |
---|
6367 | + self._write_lease_record(f, leasenum, blank_lease) |
---|
6368 | + modified += 1 |
---|
6369 | + else: |
---|
6370 | + remaining += 1 |
---|
6371 | + if modified: |
---|
6372 | + freed_space = self._pack_leases(f) |
---|
6373 | + finally: |
---|
6374 | f.close() |
---|
6375 | hunk ./src/allmydata/storage/backends/disk/mutable.py 402 |
---|
6376 | - if not remaining: |
---|
6377 | - freed_space += os.stat(self.home)[stat.ST_SIZE] |
---|
6378 | + |
---|
6379 | + if modified > 0: |
---|
6380 | + if remaining == 0: |
---|
6381 | + freed_space = fileutil.get_used_space(self._home) |
---|
6382 | self.unlink() |
---|
6383 | return freed_space |
---|
6384 | |
---|
6385 | hunk ./src/allmydata/storage/backends/disk/mutable.py 432 |
---|
6386 | |
---|
6387 | def readv(self, readv): |
---|
6388 | datav = [] |
---|
6389 | - f = open(self.home, 'rb') |
---|
6390 | - for (offset, length) in readv: |
---|
6391 | - datav.append(self._read_share_data(f, offset, length)) |
---|
6392 | - f.close() |
---|
6393 | - return datav |
---|
6394 | + f = self._home.open('rb') |
---|
6395 | + try: |
---|
6396 | + for (offset, length) in readv: |
---|
6397 | + datav.append(self._read_share_data(f, offset, length)) |
---|
6398 | + finally: |
---|
6399 | + f.close() |
---|
6400 | + return defer.succeed(datav) |
---|
6401 | |
---|
6402 | hunk ./src/allmydata/storage/backends/disk/mutable.py 440 |
---|
6403 | -# def remote_get_length(self): |
---|
6404 | -# f = open(self.home, 'rb') |
---|
6405 | -# data_length = self._read_data_length(f) |
---|
6406 | -# f.close() |
---|
6407 | -# return data_length |
---|
6408 | + def get_size(self): |
---|
6409 | + return self._home.getsize() |
---|
6410 | |
---|
6411 | hunk ./src/allmydata/storage/backends/disk/mutable.py 443 |
---|
6412 | - def check_write_enabler(self, write_enabler, si_s): |
---|
6413 | - f = open(self.home, 'rb+') |
---|
6414 | - (real_write_enabler, write_enabler_nodeid) = \ |
---|
6415 | - self._read_write_enabler_and_nodeid(f) |
---|
6416 | - f.close() |
---|
6417 | + def get_data_length(self): |
---|
6418 | + f = self._home.open('rb') |
---|
6419 | + try: |
---|
6420 | + data_length = self._read_data_length(f) |
---|
6421 | + finally: |
---|
6422 | + f.close() |
---|
6423 | + return data_length |
---|
6424 | + |
---|
6425 | + def check_write_enabler(self, write_enabler): |
---|
6426 | + f = self._home.open('rb+') |
---|
6427 | + try: |
---|
6428 | + (real_write_enabler, write_enabler_nodeid) = self._read_write_enabler_and_nodeid(f) |
---|
6429 | + finally: |
---|
6430 | + f.close() |
---|
6431 | # avoid a timing attack |
---|
6432 | hunk ./src/allmydata/storage/backends/disk/mutable.py 458 |
---|
6433 | - #if write_enabler != real_write_enabler: |
---|
6434 | if not constant_time_compare(write_enabler, real_write_enabler): |
---|
6435 | # accomodate share migration by reporting the nodeid used for the |
---|
6436 | # old write enabler. |
---|
6437 | hunk ./src/allmydata/storage/backends/disk/mutable.py 465 |
---|
6438 | " recorded by nodeid %(nodeid)s", |
---|
6439 | facility="tahoe.storage", |
---|
6440 | level=log.WEIRD, umid="cE1eBQ", |
---|
6441 | - si=si_s, nodeid=idlib.nodeid_b2a(write_enabler_nodeid)) |
---|
6442 | + si=self.get_storage_index_string(), |
---|
6443 | + nodeid=idlib.nodeid_b2a(write_enabler_nodeid)) |
---|
6444 | msg = "The write enabler was recorded by nodeid '%s'." % \ |
---|
6445 | (idlib.nodeid_b2a(write_enabler_nodeid),) |
---|
6446 | raise BadWriteEnablerError(msg) |
---|
6447 | hunk ./src/allmydata/storage/backends/disk/mutable.py 470 |
---|
6448 | + return defer.succeed(None) |
---|
6449 | |
---|
6450 | def check_testv(self, testv): |
---|
6451 | test_good = True |
---|
6452 | hunk ./src/allmydata/storage/backends/disk/mutable.py 474 |
---|
6453 | - f = open(self.home, 'rb+') |
---|
6454 | - for (offset, length, operator, specimen) in testv: |
---|
6455 | - data = self._read_share_data(f, offset, length) |
---|
6456 | - if not testv_compare(data, operator, specimen): |
---|
6457 | - test_good = False |
---|
6458 | - break |
---|
6459 | - f.close() |
---|
6460 | - return test_good |
---|
6461 | + f = self._home.open('rb+') |
---|
6462 | + try: |
---|
6463 | + for (offset, length, operator, specimen) in testv: |
---|
6464 | + data = self._read_share_data(f, offset, length) |
---|
6465 | + if not testv_compare(data, operator, specimen): |
---|
6466 | + test_good = False |
---|
6467 | + break |
---|
6468 | + finally: |
---|
6469 | + f.close() |
---|
6470 | + return defer.succeed(test_good) |
---|
6471 | |
---|
6472 | def writev(self, datav, new_length): |
---|
6473 | hunk ./src/allmydata/storage/backends/disk/mutable.py 486 |
---|
6474 | - f = open(self.home, 'rb+') |
---|
6475 | + precondition(new_length is None or new_length >= 0, new_length=new_length) |
---|
6476 | for (offset, data) in datav: |
---|
6477 | hunk ./src/allmydata/storage/backends/disk/mutable.py 488 |
---|
6478 | - self._write_share_data(f, offset, data) |
---|
6479 | - if new_length is not None: |
---|
6480 | - cur_length = self._read_data_length(f) |
---|
6481 | - if new_length < cur_length: |
---|
6482 | - self._write_data_length(f, new_length) |
---|
6483 | - # TODO: if we're going to shrink the share file when the |
---|
6484 | - # share data has shrunk, then call |
---|
6485 | - # self._change_container_size() here. |
---|
6486 | - f.close() |
---|
6487 | + precondition(offset >= 0, offset=offset) |
---|
6488 | + if offset+len(data) > self.MAX_SIZE: |
---|
6489 | + raise DataTooLargeError() |
---|
6490 | |
---|
6491 | hunk ./src/allmydata/storage/backends/disk/mutable.py 492 |
---|
6492 | -def testv_compare(a, op, b): |
---|
6493 | - assert op in ("lt", "le", "eq", "ne", "ge", "gt") |
---|
6494 | - if op == "lt": |
---|
6495 | - return a < b |
---|
6496 | - if op == "le": |
---|
6497 | - return a <= b |
---|
6498 | - if op == "eq": |
---|
6499 | - return a == b |
---|
6500 | - if op == "ne": |
---|
6501 | - return a != b |
---|
6502 | - if op == "ge": |
---|
6503 | - return a >= b |
---|
6504 | - if op == "gt": |
---|
6505 | - return a > b |
---|
6506 | - # never reached |
---|
6507 | + f = self._home.open('rb+') |
---|
6508 | + try: |
---|
6509 | + for (offset, data) in datav: |
---|
6510 | + self._write_share_data(f, offset, data) |
---|
6511 | + if new_length is not None: |
---|
6512 | + cur_length = self._read_data_length(f) |
---|
6513 | + if new_length < cur_length: |
---|
6514 | + self._write_data_length(f, new_length) |
---|
6515 | + # TODO: if we're going to shrink the share file when the |
---|
6516 | + # share data has shrunk, then call |
---|
6517 | + # self._change_container_size() here. |
---|
6518 | + finally: |
---|
6519 | + f.close() |
---|
6520 | + return defer.succeed(None) |
---|
6521 | |
---|
6522 | hunk ./src/allmydata/storage/backends/disk/mutable.py 507 |
---|
6523 | -class EmptyShare: |
---|
6524 | + def close(self): |
---|
6525 | + return defer.succeed(None) |
---|
6526 | |
---|
6527 | hunk ./src/allmydata/storage/backends/disk/mutable.py 510 |
---|
6528 | - def check_testv(self, testv): |
---|
6529 | - test_good = True |
---|
6530 | - for (offset, length, operator, specimen) in testv: |
---|
6531 | - data = "" |
---|
6532 | - if not testv_compare(data, operator, specimen): |
---|
6533 | - test_good = False |
---|
6534 | - break |
---|
6535 | - return test_good |
---|
6536 | |
---|
6537 | hunk ./src/allmydata/storage/backends/disk/mutable.py 511 |
---|
6538 | -def create_mutable_sharefile(filename, my_nodeid, write_enabler, parent): |
---|
6539 | - ms = MutableShareFile(filename, parent) |
---|
6540 | - ms.create(my_nodeid, write_enabler) |
---|
6541 | - del ms |
---|
6542 | - return MutableShareFile(filename, parent) |
---|
6543 | +def load_mutable_disk_share(home, storageindex=None, shnum=None, parent=None): |
---|
6544 | + return MutableDiskShare(home, storageindex, shnum, parent) |
---|
6545 | |
---|
6546 | hunk ./src/allmydata/storage/backends/disk/mutable.py 514 |
---|
6547 | +def create_mutable_disk_share(home, serverid, write_enabler, storageindex=None, shnum=None, parent=None): |
---|
6548 | + ms = MutableDiskShare(home, storageindex, shnum, parent) |
---|
6549 | + return ms.create(serverid, write_enabler) |
---|
6550 | hunk ./src/allmydata/storage/common.py 1 |
---|
6551 | - |
---|
6552 | -import os.path |
---|
6553 | from allmydata.util import base32 |
---|
6554 | |
---|
6555 | class DataTooLargeError(Exception): |
---|
6556 | hunk ./src/allmydata/storage/common.py 5 |
---|
6557 | pass |
---|
6558 | -class UnknownMutableContainerVersionError(Exception): |
---|
6559 | + |
---|
6560 | +class UnknownContainerVersionError(Exception): |
---|
6561 | + pass |
---|
6562 | + |
---|
6563 | +class UnknownMutableContainerVersionError(UnknownContainerVersionError): |
---|
6564 | pass |
---|
6565 | hunk ./src/allmydata/storage/common.py 11 |
---|
6566 | -class UnknownImmutableContainerVersionError(Exception): |
---|
6567 | + |
---|
6568 | +class UnknownImmutableContainerVersionError(UnknownContainerVersionError): |
---|
6569 | pass |
---|
6570 | |
---|
6571 | |
---|
6572 | hunk ./src/allmydata/storage/common.py 21 |
---|
6573 | |
---|
6574 | def si_a2b(ascii_storageindex): |
---|
6575 | return base32.a2b(ascii_storageindex) |
---|
6576 | - |
---|
6577 | -def storage_index_to_dir(storageindex): |
---|
6578 | - sia = si_b2a(storageindex) |
---|
6579 | - return os.path.join(sia[:2], sia) |
---|
6580 | hunk ./src/allmydata/storage/crawler.py 2 |
---|
6581 | |
---|
6582 | -import os, time, struct |
---|
6583 | -import cPickle as pickle |
---|
6584 | +import pickle, struct |
---|
6585 | from twisted.internet import reactor |
---|
6586 | from twisted.application import service |
---|
6587 | hunk ./src/allmydata/storage/crawler.py 5 |
---|
6588 | + |
---|
6589 | +from allmydata.util.assertutil import precondition |
---|
6590 | +from allmydata.interfaces import IStorageBackend |
---|
6591 | from allmydata.storage.common import si_b2a |
---|
6592 | hunk ./src/allmydata/storage/crawler.py 9 |
---|
6593 | -from allmydata.util import fileutil |
---|
6594 | + |
---|
6595 | |
---|
6596 | class TimeSliceExceeded(Exception): |
---|
6597 | pass |
---|
6598 | hunk ./src/allmydata/storage/crawler.py 16 |
---|
6599 | |
---|
6600 | |
---|
6601 | class ShareCrawler(service.MultiService): |
---|
6602 | - """A ShareCrawler subclass is attached to a StorageServer, and |
---|
6603 | - periodically walks all of its shares, processing each one in some |
---|
6604 | - fashion. This crawl is rate-limited, to reduce the IO burden on the host, |
---|
6605 | - since large servers can easily have a terabyte of shares, in several |
---|
6606 | - million files, which can take hours or days to read. |
---|
6607 | + """ |
---|
6608 | + An instance of a subclass of ShareCrawler is attached to a storage |
---|
6609 | + backend, and periodically walks the backend's shares, processing them |
---|
6610 | + in some fashion. This crawl is rate-limited to reduce the I/O burden on |
---|
6611 | + the host, since large servers can easily have a terabyte of shares in |
---|
6612 | + several million files, which can take hours or days to read. |
---|
6613 | |
---|
6614 | Once the crawler starts a cycle, it will proceed at a rate limited by the |
---|
6615 | allowed_cpu_percentage= and cpu_slice= parameters: yielding the reactor |
---|
6616 | hunk ./src/allmydata/storage/crawler.py 40 |
---|
6617 | prefix. On this server, each prefixdir took 130ms-200ms to list the first |
---|
6618 | time, and 17ms to list the second time. |
---|
6619 | |
---|
6620 | - To use a crawler, create a subclass which implements the process_bucket() |
---|
6621 | - method. It will be called with a prefixdir and a base32 storage index |
---|
6622 | - string. process_bucket() must run synchronously. Any keys added to |
---|
6623 | - self.state will be preserved. Override add_initial_state() to set up |
---|
6624 | - initial state keys. Override finished_cycle() to perform additional |
---|
6625 | - processing when the cycle is complete. Any status that the crawler |
---|
6626 | - produces should be put in the self.state dictionary. Status renderers |
---|
6627 | - (like a web page which describes the accomplishments of your crawler) |
---|
6628 | - will use crawler.get_state() to retrieve this dictionary; they can |
---|
6629 | - present the contents as they see fit. |
---|
6630 | + To implement a crawler, create a subclass that implements the |
---|
6631 | + process_shareset() method. It will be called with a prefixdir and an |
---|
6632 | + object providing the IShareSet interface. process_shareset() must run |
---|
6633 | + synchronously. Any keys added to self.state will be preserved. Override |
---|
6634 | + add_initial_state() to set up initial state keys. Override |
---|
6635 | + finished_cycle() to perform additional processing when the cycle is |
---|
6636 | + complete. Any status that the crawler produces should be put in the |
---|
6637 | + self.state dictionary. Status renderers (like a web page describing the |
---|
6638 | + accomplishments of your crawler) will use crawler.get_state() to retrieve |
---|
6639 | + this dictionary; they can present the contents as they see fit. |
---|
6640 | |
---|
6641 | hunk ./src/allmydata/storage/crawler.py 51 |
---|
6642 | - Then create an instance, with a reference to a StorageServer and a |
---|
6643 | - filename where it can store persistent state. The statefile is used to |
---|
6644 | - keep track of how far around the ring the process has travelled, as well |
---|
6645 | - as timing history to allow the pace to be predicted and controlled. The |
---|
6646 | - statefile will be updated and written to disk after each time slice (just |
---|
6647 | - before the crawler yields to the reactor), and also after each cycle is |
---|
6648 | - finished, and also when stopService() is called. Note that this means |
---|
6649 | - that a crawler which is interrupted with SIGKILL while it is in the |
---|
6650 | - middle of a time slice will lose progress: the next time the node is |
---|
6651 | - started, the crawler will repeat some unknown amount of work. |
---|
6652 | + Then create an instance, with a reference to a backend object providing |
---|
6653 | + the IStorageBackend interface, and a filename where it can store |
---|
6654 | + persistent state. The statefile is used to keep track of how far around |
---|
6655 | + the ring the process has travelled, as well as timing history to allow |
---|
6656 | + the pace to be predicted and controlled. The statefile will be updated |
---|
6657 | + and written to disk after each time slice (just before the crawler yields |
---|
6658 | + to the reactor), and also after each cycle is finished, and also when |
---|
6659 | + stopService() is called. Note that this means that a crawler that is |
---|
6660 | + interrupted with SIGKILL while it is in the middle of a time slice will |
---|
6661 | + lose progress: the next time the node is started, the crawler will repeat |
---|
6662 | + some unknown amount of work. |
---|
6663 | |
---|
6664 | The crawler instance must be started with startService() before it will |
---|
6665 | hunk ./src/allmydata/storage/crawler.py 64 |
---|
6666 | - do any work. To make it stop doing work, call stopService(). |
---|
6667 | + do any work. To make it stop doing work, call stopService(). A crawler |
---|
6668 | + is usually a child service of a StorageServer, although it should not |
---|
6669 | + depend on that. |
---|
6670 | + |
---|
6671 | + For historical reasons, some dictionary key names use the term "bucket" |
---|
6672 | + for what is now preferably called a "shareset" (the set of shares that a |
---|
6673 | + server holds under a given storage index). |
---|
6674 | + |
---|
6675 | + Subclasses should measure time using self.clock.seconds(), rather than |
---|
6676 | + time.time(), in order to make themselves deterministically testable. |
---|
6677 | """ |
---|
6678 | |
---|
6679 | slow_start = 300 # don't start crawling for 5 minutes after startup |
---|
6680 | hunk ./src/allmydata/storage/crawler.py 82 |
---|
6681 | cpu_slice = 1.0 # use up to 1.0 seconds before yielding |
---|
6682 | minimum_cycle_time = 300 # don't run a cycle faster than this |
---|
6683 | |
---|
6684 | - def __init__(self, server, statefile, allowed_cpu_percentage=None): |
---|
6685 | + def __init__(self, backend, statefp, allowed_cpu_percentage=None, clock=None): |
---|
6686 | + precondition(IStorageBackend.providedBy(backend), backend) |
---|
6687 | + assert backend.supports_crawlers(), backend |
---|
6688 | service.MultiService.__init__(self) |
---|
6689 | hunk ./src/allmydata/storage/crawler.py 86 |
---|
6690 | + self.backend = backend |
---|
6691 | + self.statefp = statefp |
---|
6692 | if allowed_cpu_percentage is not None: |
---|
6693 | self.allowed_cpu_percentage = allowed_cpu_percentage |
---|
6694 | hunk ./src/allmydata/storage/crawler.py 90 |
---|
6695 | - self.server = server |
---|
6696 | - self.sharedir = server.sharedir |
---|
6697 | - self.statefile = statefile |
---|
6698 | + self.clock = clock or reactor |
---|
6699 | self.prefixes = [si_b2a(struct.pack(">H", i << (16-10)))[:2] |
---|
6700 | for i in range(2**10)] |
---|
6701 | self.prefixes.sort() |
---|
6702 | hunk ./src/allmydata/storage/crawler.py 95 |
---|
6703 | self.timer = None |
---|
6704 | - self.bucket_cache = (None, []) |
---|
6705 | + self.shareset_cache = (None, []) |
---|
6706 | self.current_sleep_time = None |
---|
6707 | self.next_wake_time = None |
---|
6708 | self.last_prefix_finished_time = None |
---|
6709 | hunk ./src/allmydata/storage/crawler.py 148 |
---|
6710 | d["cycle-in-progress"] = False |
---|
6711 | d["next-crawl-time"] = self.next_wake_time |
---|
6712 | d["remaining-wait-time"] = self.minus_or_none(self.next_wake_time, |
---|
6713 | - time.time()) |
---|
6714 | + self.clock.seconds()) |
---|
6715 | else: |
---|
6716 | d["cycle-in-progress"] = True |
---|
6717 | pct = 100.0 * self.last_complete_prefix_index / len(self.prefixes) |
---|
6718 | hunk ./src/allmydata/storage/crawler.py 165 |
---|
6719 | # it's possible to call get_progress() from inside a crawler's |
---|
6720 | # finished_prefix() function |
---|
6721 | d["remaining-sleep-time"] = self.minus_or_none(self.next_wake_time, |
---|
6722 | - time.time()) |
---|
6723 | + self.clock.seconds()) |
---|
6724 | per_cycle = None |
---|
6725 | if self.last_cycle_elapsed_time is not None: |
---|
6726 | per_cycle = self.last_cycle_elapsed_time |
---|
6727 | hunk ./src/allmydata/storage/crawler.py 179 |
---|
6728 | state dictionary. |
---|
6729 | |
---|
6730 | If we are not currently sleeping (i.e. get_state() was called from |
---|
6731 | - inside the process_prefixdir, process_bucket, or finished_cycle() |
---|
6732 | + inside the process_prefixdir, process_shareset, or finished_cycle() |
---|
6733 | methods, or if startService has not yet been called on this crawler), |
---|
6734 | these two keys will be None. |
---|
6735 | |
---|
6736 | hunk ./src/allmydata/storage/crawler.py 210 |
---|
6737 | # shareset to be processed, or None if we |
---|
6738 | # are sleeping between cycles |
---|
6739 | try: |
---|
6740 | - f = open(self.statefile, "rb") |
---|
6741 | - state = pickle.load(f) |
---|
6742 | - f.close() |
---|
6743 | + pickled = self.statefp.getContent() |
---|
6744 | except EnvironmentError: |
---|
6745 | hunk ./src/allmydata/storage/crawler.py 212 |
---|
6746 | + if self.statefp.exists(): |
---|
6747 | + raise |
---|
6748 | state = {"version": 1, |
---|
6749 | "last-cycle-finished": None, |
---|
6750 | "current-cycle": None, |
---|
6751 | hunk ./src/allmydata/storage/crawler.py 220 |
---|
6752 | "last-complete-prefix": None, |
---|
6753 | "last-complete-bucket": None, |
---|
6754 | } |
---|
6755 | - state.setdefault("current-cycle-start-time", time.time()) # approximate |
---|
6756 | + else: |
---|
6757 | + state = pickle.loads(pickled) |
---|
6758 | + |
---|
6759 | + state.setdefault("current-cycle-start-time", self.clock.seconds()) # approximate |
---|
6760 | self.state = state |
---|
6761 | lcp = state["last-complete-prefix"] |
---|
6762 | if lcp == None: |
---|
6763 | hunk ./src/allmydata/storage/crawler.py 251 |
---|
6764 | else: |
---|
6765 | last_complete_prefix = self.prefixes[lcpi] |
---|
6766 | self.state["last-complete-prefix"] = last_complete_prefix |
---|
6767 | - tmpfile = self.statefile + ".tmp" |
---|
6768 | - f = open(tmpfile, "wb") |
---|
6769 | - pickle.dump(self.state, f) |
---|
6770 | - f.close() |
---|
6771 | - fileutil.move_into_place(tmpfile, self.statefile) |
---|
6772 | + pickled = pickle.dumps(self.state) |
---|
6773 | + self.statefp.setContent(pickled) |
---|
6774 | |
---|
6775 | def startService(self): |
---|
6776 | # arrange things to look like we were just sleeping, so |
---|
6777 | hunk ./src/allmydata/storage/crawler.py 259 |
---|
6778 | # status/progress values work correctly |
---|
6779 | self.sleeping_between_cycles = True |
---|
6780 | self.current_sleep_time = self.slow_start |
---|
6781 | - self.next_wake_time = time.time() + self.slow_start |
---|
6782 | - self.timer = reactor.callLater(self.slow_start, self.start_slice) |
---|
6783 | + self.next_wake_time = self.clock.seconds() + self.slow_start |
---|
6784 | + self.timer = self.clock.callLater(self.slow_start, self.start_slice) |
---|
6785 | service.MultiService.startService(self) |
---|
6786 | |
---|
6787 | def stopService(self): |
---|
6788 | hunk ./src/allmydata/storage/crawler.py 271 |
---|
6789 | return service.MultiService.stopService(self) |
---|
6790 | |
---|
6791 | def start_slice(self): |
---|
6792 | - start_slice = time.time() |
---|
6793 | + start_slice = self.clock.seconds() |
---|
6794 | self.timer = None |
---|
6795 | self.sleeping_between_cycles = False |
---|
6796 | self.current_sleep_time = None |
---|
6797 | hunk ./src/allmydata/storage/crawler.py 286 |
---|
6798 | # someone might have used stopService() to shut us down |
---|
6799 | return |
---|
6800 | # either we finished a whole cycle, or we ran out of time |
---|
6801 | - now = time.time() |
---|
6802 | + now = self.clock.seconds() |
---|
6803 | this_slice = now - start_slice |
---|
6804 | # this_slice/(this_slice+sleep_time) = percentage |
---|
6805 | # this_slice/percentage = this_slice+sleep_time |
---|
6806 | hunk ./src/allmydata/storage/crawler.py 308 |
---|
6807 | self.current_sleep_time = sleep_time # for status page |
---|
6808 | self.next_wake_time = now + sleep_time |
---|
6809 | self.yielding(sleep_time) |
---|
6810 | - self.timer = reactor.callLater(sleep_time, self.start_slice) |
---|
6811 | + self.timer = self.clock.callLater(sleep_time, self.start_slice) |
---|
6812 | |
---|
6813 | def start_current_prefix(self, start_slice): |
---|
6814 | state = self.state |
---|
6815 | hunk ./src/allmydata/storage/crawler.py 313 |
---|
6816 | if state["current-cycle"] is None: |
---|
6817 | - self.last_cycle_started_time = time.time() |
---|
6818 | + self.last_cycle_started_time = self.clock.seconds() |
---|
6819 | state["current-cycle-start-time"] = self.last_cycle_started_time |
---|
6820 | if state["last-cycle-finished"] is None: |
---|
6821 | state["current-cycle"] = 0 |
---|
6822 | hunk ./src/allmydata/storage/crawler.py 325 |
---|
6823 | for i in range(self.last_complete_prefix_index+1, len(self.prefixes)): |
---|
6824 | # if we want to yield earlier, just raise TimeSliceExceeded() |
---|
6825 | prefix = self.prefixes[i] |
---|
6826 | - prefixdir = os.path.join(self.sharedir, prefix) |
---|
6827 | - if i == self.bucket_cache[0]: |
---|
6828 | - buckets = self.bucket_cache[1] |
---|
6829 | + if i == self.shareset_cache[0]: |
---|
6830 | + sharesets = self.shareset_cache[1] |
---|
6831 | else: |
---|
6832 | hunk ./src/allmydata/storage/crawler.py 328 |
---|
6833 | - try: |
---|
6834 | - buckets = os.listdir(prefixdir) |
---|
6835 | - buckets.sort() |
---|
6836 | - except EnvironmentError: |
---|
6837 | - buckets = [] |
---|
6838 | - self.bucket_cache = (i, buckets) |
---|
6839 | - self.process_prefixdir(cycle, prefix, prefixdir, |
---|
6840 | - buckets, start_slice) |
---|
6841 | + sharesets = self.backend.get_sharesets_for_prefix(prefix) |
---|
6842 | + self.shareset_cache = (i, sharesets) |
---|
6843 | + self.process_prefixdir(cycle, prefix, sharesets, start_slice) |
---|
6844 | self.last_complete_prefix_index = i |
---|
6845 | |
---|
6846 | hunk ./src/allmydata/storage/crawler.py 333 |
---|
6847 | - now = time.time() |
---|
6848 | + now = self.clock.seconds() |
---|
6849 | if self.last_prefix_finished_time is not None: |
---|
6850 | elapsed = now - self.last_prefix_finished_time |
---|
6851 | self.last_prefix_elapsed_time = elapsed |
---|
6852 | hunk ./src/allmydata/storage/crawler.py 340 |
---|
6853 | self.last_prefix_finished_time = now |
---|
6854 | |
---|
6855 | self.finished_prefix(cycle, prefix) |
---|
6856 | - if time.time() >= start_slice + self.cpu_slice: |
---|
6857 | + if self.clock.seconds() >= start_slice + self.cpu_slice: |
---|
6858 | raise TimeSliceExceeded() |
---|
6859 | |
---|
6860 | # yay! we finished the whole cycle |
---|
6861 | hunk ./src/allmydata/storage/crawler.py 346 |
---|
6862 | self.last_complete_prefix_index = -1 |
---|
6863 | self.last_prefix_finished_time = None # don't include the sleep |
---|
6864 | - now = time.time() |
---|
6865 | + now = self.clock.seconds() |
---|
6866 | if self.last_cycle_started_time is not None: |
---|
6867 | self.last_cycle_elapsed_time = now - self.last_cycle_started_time |
---|
6868 | state["last-complete-bucket"] = None |
---|
6869 | hunk ./src/allmydata/storage/crawler.py 355 |
---|
6870 | self.finished_cycle(cycle) |
---|
6871 | self.save_state() |
---|
6872 | |
---|
6873 | - def process_prefixdir(self, cycle, prefix, prefixdir, buckets, start_slice): |
---|
6874 | - """This gets a list of bucket names (i.e. storage index strings, |
---|
6875 | + def process_prefixdir(self, cycle, prefix, sharesets, start_slice): |
---|
6876 | + """ |
---|
6877 | + This gets a list of shareset names (i.e. storage index strings, |
---|
6878 | base32-encoded) in sorted order. |
---|
6879 | |
---|
6880 | You can override this if your crawler doesn't care about the actual |
---|
6881 | hunk ./src/allmydata/storage/crawler.py 364 |
---|
6882 | shares, for example a crawler which merely keeps track of how many |
---|
6883 | sharesets are being managed by this server. |
---|
6884 | |
---|
6885 | - Subclasses which *do* care about actual bucket should leave this |
---|
6886 | - method along, and implement process_bucket() instead. |
---|
6887 | + Subclasses which *do* care about actual shareset should leave this |
---|
6888 | + method alone, and implement process_shareset() instead. |
---|
6889 | """ |
---|
6890 | hunk ./src/allmydata/storage/crawler.py 367 |
---|
6891 | - |
---|
6892 | - for bucket in buckets: |
---|
6893 | - if bucket <= self.state["last-complete-bucket"]: |
---|
6894 | + for shareset in sharesets: |
---|
6895 | + base32si = shareset.get_storage_index_string() |
---|
6896 | + if base32si <= self.state["last-complete-bucket"]: |
---|
6897 | continue |
---|
6898 | hunk ./src/allmydata/storage/crawler.py 371 |
---|
6899 | - self.process_bucket(cycle, prefix, prefixdir, bucket) |
---|
6900 | - self.state["last-complete-bucket"] = bucket |
---|
6901 | - if time.time() >= start_slice + self.cpu_slice: |
---|
6902 | + self.process_shareset(cycle, prefix, shareset) |
---|
6903 | + self.state["last-complete-bucket"] = base32si |
---|
6904 | + if self.clock.seconds() >= start_slice + self.cpu_slice: |
---|
6905 | raise TimeSliceExceeded() |
---|
6906 | |
---|
6907 | # the remaining methods are explictly for subclasses to implement. |
---|
6908 | hunk ./src/allmydata/storage/crawler.py 386 |
---|
6909 | """ |
---|
6910 | pass |
---|
6911 | |
---|
6912 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
6913 | - """Examine a single bucket. Subclasses should do whatever they want |
---|
6914 | + def process_shareset(self, cycle, prefix, shareset): |
---|
6915 | + """ |
---|
6916 | + Examine a single shareset. Subclasses should do whatever they want |
---|
6917 | to do to the shares therein, then update self.state as necessary. |
---|
6918 | |
---|
6919 | If the crawler is never interrupted by SIGKILL, this method will be |
---|
6920 | hunk ./src/allmydata/storage/crawler.py 400 |
---|
6921 | |
---|
6922 | To reduce the chance of duplicate work (i.e. to avoid adding multiple |
---|
6923 | records to a database), you can call save_state() at the end of your |
---|
6924 | - process_bucket() method. This will reduce the maximum duplicated work |
---|
6925 | - to one bucket per SIGKILL. It will also add overhead, probably 1-20ms |
---|
6926 | - per bucket (and some disk writes), which will count against your |
---|
6927 | - allowed_cpu_percentage, and which may be considerable if |
---|
6928 | - process_bucket() runs quickly. |
---|
6929 | + process_shareset() method. This will reduce the maximum duplicated |
---|
6930 | + work to one shareset per SIGKILL. It will also add overhead, probably |
---|
6931 | + 1-20ms per shareset (and some disk writes), which will count against |
---|
6932 | + your allowed_cpu_percentage, and which may be considerable if |
---|
6933 | + process_shareset() runs quickly. |
---|
6934 | |
---|
6935 | This method is for subclasses to override. No upcall is necessary. |
---|
6936 | """ |
---|
6937 | hunk ./src/allmydata/storage/crawler.py 452 |
---|
6938 | |
---|
6939 | |
---|
6940 | class BucketCountingCrawler(ShareCrawler): |
---|
6941 | - """I keep track of how many buckets are being managed by this server. |
---|
6942 | - This is equivalent to the number of distributed files and directories for |
---|
6943 | - which I am providing storage. The actual number of files+directories in |
---|
6944 | - the full grid is probably higher (especially when there are more servers |
---|
6945 | - than 'N', the number of generated shares), because some files+directories |
---|
6946 | - will have shares on other servers instead of me. Also note that the |
---|
6947 | - number of buckets will differ from the number of shares in small grids, |
---|
6948 | - when more than one share is placed on a single server. |
---|
6949 | + """ |
---|
6950 | + I keep track of how many sharesets, each corresponding to a storage index, |
---|
6951 | + are being managed by this server. This is equivalent to the number of |
---|
6952 | + distributed files and directories for which I am providing storage. The |
---|
6953 | + actual number of files and directories in the full grid is probably higher |
---|
6954 | + (especially when there are more servers than 'N', the number of generated |
---|
6955 | + shares), because some files and directories will have shares on other |
---|
6956 | + servers instead of me. Also note that the number of sharesets will differ |
---|
6957 | + from the number of shares in small grids, when more than one share is |
---|
6958 | + placed on a single server. |
---|
6959 | """ |
---|
6960 | |
---|
6961 | minimum_cycle_time = 60*60 # we don't need this more than once an hour |
---|
6962 | hunk ./src/allmydata/storage/crawler.py 466 |
---|
6963 | |
---|
6964 | - def __init__(self, server, statefile, num_sample_prefixes=1): |
---|
6965 | - ShareCrawler.__init__(self, server, statefile) |
---|
6966 | + def __init__(self, backend, statefp, num_sample_prefixes=1, **kwargs): |
---|
6967 | + ShareCrawler.__init__(self, backend, statefp, **kwargs) |
---|
6968 | self.num_sample_prefixes = num_sample_prefixes |
---|
6969 | |
---|
6970 | def add_initial_state(self): |
---|
6971 | hunk ./src/allmydata/storage/crawler.py 480 |
---|
6972 | self.state.setdefault("last-complete-bucket-count", None) |
---|
6973 | self.state.setdefault("storage-index-samples", {}) |
---|
6974 | |
---|
6975 | - def process_prefixdir(self, cycle, prefix, prefixdir, buckets, start_slice): |
---|
6976 | + def process_prefixdir(self, cycle, prefix, sharesets, start_slice): |
---|
6977 | # we override process_prefixdir() because we don't want to look at |
---|
6978 | # the individual sharesets. We'll save state after each one. On my |
---|
6979 | # laptop, a mostly-empty storage server can process about 70 |
---|
6980 | hunk ./src/allmydata/storage/crawler.py 487 |
---|
6981 | # prefixdirs in a 1.0s slice. |
---|
6982 | if cycle not in self.state["bucket-counts"]: |
---|
6983 | self.state["bucket-counts"][cycle] = {} |
---|
6984 | - self.state["bucket-counts"][cycle][prefix] = len(buckets) |
---|
6985 | + self.state["bucket-counts"][cycle][prefix] = len(sharesets) |
---|
6986 | if prefix in self.prefixes[:self.num_sample_prefixes]: |
---|
6987 | hunk ./src/allmydata/storage/crawler.py 489 |
---|
6988 | - self.state["storage-index-samples"][prefix] = (cycle, buckets) |
---|
6989 | + si_strings = [shareset.get_storage_index_string() for shareset in sharesets] |
---|
6990 | + self.state["storage-index-samples"][prefix] = (cycle, si_strings) |
---|
6991 | |
---|
6992 | def finished_cycle(self, cycle): |
---|
6993 | last_counts = self.state["bucket-counts"].get(cycle, []) |
---|
6994 | hunk ./src/allmydata/storage/crawler.py 496 |
---|
6995 | if len(last_counts) == len(self.prefixes): |
---|
6996 | # great, we have a whole cycle. |
---|
6997 | - num_buckets = sum(last_counts.values()) |
---|
6998 | - self.state["last-complete-bucket-count"] = num_buckets |
---|
6999 | + num_sharesets = sum(last_counts.values()) |
---|
7000 | + self.state["last-complete-bucket-count"] = num_sharesets |
---|
7001 | # get rid of old counts |
---|
7002 | for old_cycle in list(self.state["bucket-counts"].keys()): |
---|
7003 | if old_cycle != cycle: |
---|
7004 | hunk ./src/allmydata/storage/crawler.py 504 |
---|
7005 | del self.state["bucket-counts"][old_cycle] |
---|
7006 | # get rid of old samples too |
---|
7007 | for prefix in list(self.state["storage-index-samples"].keys()): |
---|
7008 | - old_cycle,buckets = self.state["storage-index-samples"][prefix] |
---|
7009 | + old_cycle, storage_indices = self.state["storage-index-samples"][prefix] |
---|
7010 | if old_cycle != cycle: |
---|
7011 | del self.state["storage-index-samples"][prefix] |
---|
7012 | hunk ./src/allmydata/storage/expirer.py 1 |
---|
7013 | -import time, os, pickle, struct |
---|
7014 | + |
---|
7015 | +import pickle, struct |
---|
7016 | +from twisted.python import log as twlog |
---|
7017 | + |
---|
7018 | from allmydata.storage.crawler import ShareCrawler |
---|
7019 | hunk ./src/allmydata/storage/expirer.py 6 |
---|
7020 | -from allmydata.storage.shares import get_share_file |
---|
7021 | from allmydata.storage.common import UnknownMutableContainerVersionError, \ |
---|
7022 | UnknownImmutableContainerVersionError |
---|
7023 | hunk ./src/allmydata/storage/expirer.py 8 |
---|
7024 | -from twisted.python import log as twlog |
---|
7025 | + |
---|
7026 | |
---|
7027 | class LeaseCheckingCrawler(ShareCrawler): |
---|
7028 | """I examine the leases on all shares, determining which are still valid |
---|
7029 | hunk ./src/allmydata/storage/expirer.py 53 |
---|
7030 | slow_start = 360 # wait 6 minutes after startup |
---|
7031 | minimum_cycle_time = 12*60*60 # not more than twice per day |
---|
7032 | |
---|
7033 | - def __init__(self, server, statefile, historyfile, |
---|
7034 | - expiration_enabled, mode, |
---|
7035 | - override_lease_duration, # used if expiration_mode=="age" |
---|
7036 | - cutoff_date, # used if expiration_mode=="cutoff-date" |
---|
7037 | - sharetypes): |
---|
7038 | - self.historyfile = historyfile |
---|
7039 | - self.expiration_enabled = expiration_enabled |
---|
7040 | - self.mode = mode |
---|
7041 | + def __init__(self, backend, statefp, historyfp, expiration_policy, clock=None): |
---|
7042 | + # ShareCrawler.__init__ will call add_initial_state, so self.historyfp has to be set first. |
---|
7043 | + self.historyfp = historyfp |
---|
7044 | + ShareCrawler.__init__(self, backend, statefp, clock=clock) |
---|
7045 | + |
---|
7046 | + self.expiration_enabled = expiration_policy['enabled'] |
---|
7047 | + self.mode = expiration_policy['mode'] |
---|
7048 | self.override_lease_duration = None |
---|
7049 | self.cutoff_date = None |
---|
7050 | if self.mode == "age": |
---|
7051 | hunk ./src/allmydata/storage/expirer.py 63 |
---|
7052 | - assert isinstance(override_lease_duration, (int, type(None))) |
---|
7053 | - self.override_lease_duration = override_lease_duration # seconds |
---|
7054 | + assert isinstance(expiration_policy['override_lease_duration'], (int, type(None))) |
---|
7055 | + self.override_lease_duration = expiration_policy['override_lease_duration'] # seconds |
---|
7056 | elif self.mode == "cutoff-date": |
---|
7057 | hunk ./src/allmydata/storage/expirer.py 66 |
---|
7058 | - assert isinstance(cutoff_date, int) # seconds-since-epoch |
---|
7059 | - assert cutoff_date is not None |
---|
7060 | - self.cutoff_date = cutoff_date |
---|
7061 | + assert isinstance(expiration_policy['cutoff_date'], int) # seconds-since-epoch |
---|
7062 | + self.cutoff_date = expiration_policy['cutoff_date'] |
---|
7063 | else: |
---|
7064 | hunk ./src/allmydata/storage/expirer.py 69 |
---|
7065 | - raise ValueError("GC mode '%s' must be 'age' or 'cutoff-date'" % mode) |
---|
7066 | - self.sharetypes_to_expire = sharetypes |
---|
7067 | - ShareCrawler.__init__(self, server, statefile) |
---|
7068 | + raise ValueError("GC mode '%s' must be 'age' or 'cutoff-date'" % expiration_policy['mode']) |
---|
7069 | + self.sharetypes_to_expire = expiration_policy['sharetypes'] |
---|
7070 | |
---|
7071 | def add_initial_state(self): |
---|
7072 | # we fill ["cycle-to-date"] here (even though they will be reset in |
---|
7073 | hunk ./src/allmydata/storage/expirer.py 84 |
---|
7074 | self.state["cycle-to-date"].setdefault(k, so_far[k]) |
---|
7075 | |
---|
7076 | # initialize history |
---|
7077 | - if not os.path.exists(self.historyfile): |
---|
7078 | + if not self.historyfp.exists(): |
---|
7079 | history = {} # cyclenum -> dict |
---|
7080 | hunk ./src/allmydata/storage/expirer.py 86 |
---|
7081 | - f = open(self.historyfile, "wb") |
---|
7082 | - pickle.dump(history, f) |
---|
7083 | - f.close() |
---|
7084 | + pickled = pickle.dumps(history) |
---|
7085 | + self.historyfp.setContent(pickled) |
---|
7086 | |
---|
7087 | def create_empty_cycle_dict(self): |
---|
7088 | recovered = self.create_empty_recovered_dict() |
---|
7089 | hunk ./src/allmydata/storage/expirer.py 100 |
---|
7090 | |
---|
7091 | def create_empty_recovered_dict(self): |
---|
7092 | recovered = {} |
---|
7093 | + # "buckets" is ambiguous; here it means the number of sharesets (one per storage index per server) |
---|
7094 | for a in ("actual", "original", "configured", "examined"): |
---|
7095 | for b in ("buckets", "shares", "sharebytes", "diskbytes"): |
---|
7096 | recovered[a+"-"+b] = 0 |
---|
7097 | hunk ./src/allmydata/storage/expirer.py 111 |
---|
7098 | def started_cycle(self, cycle): |
---|
7099 | self.state["cycle-to-date"] = self.create_empty_cycle_dict() |
---|
7100 | |
---|
7101 | - def stat(self, fn): |
---|
7102 | - return os.stat(fn) |
---|
7103 | + def _process_corrupt_share(self, si, shnum): |
---|
7104 | + twlog.msg("lease-checker error processing share %r:%r" % (si, shnum)) |
---|
7105 | + self.state["cycle-to-date"]["corrupt-shares"].append( (si, shnum) ) |
---|
7106 | + return (1, 1, 1, "unknown") |
---|
7107 | |
---|
7108 | hunk ./src/allmydata/storage/expirer.py 116 |
---|
7109 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
7110 | - bucketdir = os.path.join(prefixdir, storage_index_b32) |
---|
7111 | - s = self.stat(bucketdir) |
---|
7112 | + def process_shareset(self, cycle, prefix, shareset): |
---|
7113 | would_keep_shares = [] |
---|
7114 | wks = None |
---|
7115 | hunk ./src/allmydata/storage/expirer.py 119 |
---|
7116 | + si = shareset.get_storage_index_string() |
---|
7117 | |
---|
7118 | hunk ./src/allmydata/storage/expirer.py 121 |
---|
7119 | - for fn in os.listdir(bucketdir): |
---|
7120 | - try: |
---|
7121 | - shnum = int(fn) |
---|
7122 | - except ValueError: |
---|
7123 | - continue # non-numeric means not a sharefile |
---|
7124 | - sharefile = os.path.join(bucketdir, fn) |
---|
7125 | + (shares, corrupted) = shareset.get_shares_synchronous() |
---|
7126 | + for share in shares: |
---|
7127 | try: |
---|
7128 | hunk ./src/allmydata/storage/expirer.py 124 |
---|
7129 | - wks = self.process_share(sharefile) |
---|
7130 | + wks = self.process_share(share) |
---|
7131 | except (UnknownMutableContainerVersionError, |
---|
7132 | UnknownImmutableContainerVersionError, |
---|
7133 | struct.error): |
---|
7134 | hunk ./src/allmydata/storage/expirer.py 128 |
---|
7135 | - twlog.msg("lease-checker error processing %s" % sharefile) |
---|
7136 | + wks = self._process_corrupt_share(si, share.get_shnum()) |
---|
7137 | twlog.err() |
---|
7138 | hunk ./src/allmydata/storage/expirer.py 130 |
---|
7139 | - which = (storage_index_b32, shnum) |
---|
7140 | - self.state["cycle-to-date"]["corrupt-shares"].append(which) |
---|
7141 | - wks = (1, 1, 1, "unknown") |
---|
7142 | would_keep_shares.append(wks) |
---|
7143 | |
---|
7144 | hunk ./src/allmydata/storage/expirer.py 132 |
---|
7145 | - sharetype = None |
---|
7146 | + for shnum in sorted(corrupted): |
---|
7147 | + wks = self._process_corrupt_share(si, shnum) |
---|
7148 | + would_keep_shares.append(wks) |
---|
7149 | + |
---|
7150 | + shareset_type = None |
---|
7151 | if wks: |
---|
7152 | hunk ./src/allmydata/storage/expirer.py 138 |
---|
7153 | - # use the last share's sharetype as the buckettype |
---|
7154 | - sharetype = wks[3] |
---|
7155 | + # use the last share's type as the shareset type |
---|
7156 | + shareset_type = wks[3] |
---|
7157 | rec = self.state["cycle-to-date"]["space-recovered"] |
---|
7158 | self.increment(rec, "examined-buckets", 1) |
---|
7159 | hunk ./src/allmydata/storage/expirer.py 142 |
---|
7160 | - if sharetype: |
---|
7161 | - self.increment(rec, "examined-buckets-"+sharetype, 1) |
---|
7162 | + if shareset_type: |
---|
7163 | + self.increment(rec, "examined-buckets-"+shareset_type, 1) |
---|
7164 | + |
---|
7165 | + shareset_diskbytes = shareset.get_overhead() |
---|
7166 | |
---|
7167 | hunk ./src/allmydata/storage/expirer.py 147 |
---|
7168 | - try: |
---|
7169 | - bucket_diskbytes = s.st_blocks * 512 |
---|
7170 | - except AttributeError: |
---|
7171 | - bucket_diskbytes = 0 # no stat().st_blocks on windows |
---|
7172 | if sum([wks[0] for wks in would_keep_shares]) == 0: |
---|
7173 | hunk ./src/allmydata/storage/expirer.py 148 |
---|
7174 | - self.increment_bucketspace("original", bucket_diskbytes, sharetype) |
---|
7175 | + self.increment_shareset_space("original", shareset_diskbytes, shareset_type) |
---|
7176 | if sum([wks[1] for wks in would_keep_shares]) == 0: |
---|
7177 | hunk ./src/allmydata/storage/expirer.py 150 |
---|
7178 | - self.increment_bucketspace("configured", bucket_diskbytes, sharetype) |
---|
7179 | + self.increment_shareset_space("configured", shareset_diskbytes, shareset_type) |
---|
7180 | if sum([wks[2] for wks in would_keep_shares]) == 0: |
---|
7181 | hunk ./src/allmydata/storage/expirer.py 152 |
---|
7182 | - self.increment_bucketspace("actual", bucket_diskbytes, sharetype) |
---|
7183 | + self.increment_shareset_space("actual", shareset_diskbytes, shareset_type) |
---|
7184 | |
---|
7185 | hunk ./src/allmydata/storage/expirer.py 154 |
---|
7186 | - def process_share(self, sharefilename): |
---|
7187 | - # first, find out what kind of a share it is |
---|
7188 | - sf = get_share_file(sharefilename) |
---|
7189 | - sharetype = sf.sharetype |
---|
7190 | - now = time.time() |
---|
7191 | - s = self.stat(sharefilename) |
---|
7192 | + def process_share(self, share): |
---|
7193 | + sharetype = share.sharetype |
---|
7194 | + now = self.clock.seconds() |
---|
7195 | + sharebytes = share.get_size() |
---|
7196 | + diskbytes = share.get_used_space() |
---|
7197 | |
---|
7198 | num_leases = 0 |
---|
7199 | num_valid_leases_original = 0 |
---|
7200 | hunk ./src/allmydata/storage/expirer.py 165 |
---|
7201 | num_valid_leases_configured = 0 |
---|
7202 | expired_leases_configured = [] |
---|
7203 | |
---|
7204 | - for li in sf.get_leases(): |
---|
7205 | + for li in share.get_leases(): |
---|
7206 | num_leases += 1 |
---|
7207 | original_expiration_time = li.get_expiration_time() |
---|
7208 | grant_renew_time = li.get_grant_renew_time_time() |
---|
7209 | hunk ./src/allmydata/storage/expirer.py 178 |
---|
7210 | |
---|
7211 | # expired-or-not according to our configured age limit |
---|
7212 | expired = False |
---|
7213 | - if self.mode == "age": |
---|
7214 | - age_limit = original_expiration_time |
---|
7215 | - if self.override_lease_duration is not None: |
---|
7216 | - age_limit = self.override_lease_duration |
---|
7217 | - if age > age_limit: |
---|
7218 | - expired = True |
---|
7219 | - else: |
---|
7220 | - assert self.mode == "cutoff-date" |
---|
7221 | - if grant_renew_time < self.cutoff_date: |
---|
7222 | - expired = True |
---|
7223 | - if sharetype not in self.sharetypes_to_expire: |
---|
7224 | - expired = False |
---|
7225 | + if sharetype in self.sharetypes_to_expire: |
---|
7226 | + if self.mode == "age": |
---|
7227 | + age_limit = original_expiration_time |
---|
7228 | + if self.override_lease_duration is not None: |
---|
7229 | + age_limit = self.override_lease_duration |
---|
7230 | + if age > age_limit: |
---|
7231 | + expired = True |
---|
7232 | + else: |
---|
7233 | + assert self.mode == "cutoff-date" |
---|
7234 | + if grant_renew_time < self.cutoff_date: |
---|
7235 | + expired = True |
---|
7236 | |
---|
7237 | if expired: |
---|
7238 | expired_leases_configured.append(li) |
---|
7239 | hunk ./src/allmydata/storage/expirer.py 197 |
---|
7240 | |
---|
7241 | so_far = self.state["cycle-to-date"] |
---|
7242 | self.increment(so_far["leases-per-share-histogram"], num_leases, 1) |
---|
7243 | - self.increment_space("examined", s, sharetype) |
---|
7244 | + self.increment_space("examined", sharebytes, diskbytes, sharetype) |
---|
7245 | |
---|
7246 | would_keep_share = [1, 1, 1, sharetype] |
---|
7247 | |
---|
7248 | hunk ./src/allmydata/storage/expirer.py 203 |
---|
7249 | if self.expiration_enabled: |
---|
7250 | for li in expired_leases_configured: |
---|
7251 | - sf.cancel_lease(li.cancel_secret) |
---|
7252 | + share.cancel_lease(li.cancel_secret) |
---|
7253 | |
---|
7254 | if num_valid_leases_original == 0: |
---|
7255 | would_keep_share[0] = 0 |
---|
7256 | hunk ./src/allmydata/storage/expirer.py 207 |
---|
7257 | - self.increment_space("original", s, sharetype) |
---|
7258 | + self.increment_space("original", sharebytes, diskbytes, sharetype) |
---|
7259 | |
---|
7260 | if num_valid_leases_configured == 0: |
---|
7261 | would_keep_share[1] = 0 |
---|
7262 | hunk ./src/allmydata/storage/expirer.py 211 |
---|
7263 | - self.increment_space("configured", s, sharetype) |
---|
7264 | + self.increment_space("configured", sharebytes, diskbytes, sharetype) |
---|
7265 | if self.expiration_enabled: |
---|
7266 | would_keep_share[2] = 0 |
---|
7267 | hunk ./src/allmydata/storage/expirer.py 214 |
---|
7268 | - self.increment_space("actual", s, sharetype) |
---|
7269 | + self.increment_space("actual", sharebytes, diskbytes, sharetype) |
---|
7270 | |
---|
7271 | return would_keep_share |
---|
7272 | |
---|
7273 | hunk ./src/allmydata/storage/expirer.py 218 |
---|
7274 | - def increment_space(self, a, s, sharetype): |
---|
7275 | - sharebytes = s.st_size |
---|
7276 | - try: |
---|
7277 | - # note that stat(2) says that st_blocks is 512 bytes, and that |
---|
7278 | - # st_blksize is "optimal file sys I/O ops blocksize", which is |
---|
7279 | - # independent of the block-size that st_blocks uses. |
---|
7280 | - diskbytes = s.st_blocks * 512 |
---|
7281 | - except AttributeError: |
---|
7282 | - # the docs say that st_blocks is only on linux. I also see it on |
---|
7283 | - # MacOS. But it isn't available on windows. |
---|
7284 | - diskbytes = sharebytes |
---|
7285 | + def increment_space(self, a, sharebytes, diskbytes, sharetype): |
---|
7286 | so_far_sr = self.state["cycle-to-date"]["space-recovered"] |
---|
7287 | self.increment(so_far_sr, a+"-shares", 1) |
---|
7288 | self.increment(so_far_sr, a+"-sharebytes", sharebytes) |
---|
7289 | hunk ./src/allmydata/storage/expirer.py 228 |
---|
7290 | self.increment(so_far_sr, a+"-sharebytes-"+sharetype, sharebytes) |
---|
7291 | self.increment(so_far_sr, a+"-diskbytes-"+sharetype, diskbytes) |
---|
7292 | |
---|
7293 | - def increment_bucketspace(self, a, bucket_diskbytes, sharetype): |
---|
7294 | + def increment_shareset_space(self, a, shareset_diskbytes, shareset_type): |
---|
7295 | rec = self.state["cycle-to-date"]["space-recovered"] |
---|
7296 | hunk ./src/allmydata/storage/expirer.py 230 |
---|
7297 | - self.increment(rec, a+"-diskbytes", bucket_diskbytes) |
---|
7298 | + self.increment(rec, a+"-diskbytes", shareset_diskbytes) |
---|
7299 | self.increment(rec, a+"-buckets", 1) |
---|
7300 | hunk ./src/allmydata/storage/expirer.py 232 |
---|
7301 | - if sharetype: |
---|
7302 | - self.increment(rec, a+"-diskbytes-"+sharetype, bucket_diskbytes) |
---|
7303 | - self.increment(rec, a+"-buckets-"+sharetype, 1) |
---|
7304 | + if shareset_type: |
---|
7305 | + self.increment(rec, a+"-diskbytes-"+shareset_type, shareset_diskbytes) |
---|
7306 | + self.increment(rec, a+"-buckets-"+shareset_type, 1) |
---|
7307 | |
---|
7308 | def increment(self, d, k, delta=1): |
---|
7309 | if k not in d: |
---|
7310 | hunk ./src/allmydata/storage/expirer.py 264 |
---|
7311 | h = {} |
---|
7312 | |
---|
7313 | start = self.state["current-cycle-start-time"] |
---|
7314 | - now = time.time() |
---|
7315 | + now = self.clock.seconds() |
---|
7316 | h["cycle-start-finish-times"] = (start, now) |
---|
7317 | h["expiration-enabled"] = self.expiration_enabled |
---|
7318 | h["configured-expiration-mode"] = (self.mode, |
---|
7319 | hunk ./src/allmydata/storage/expirer.py 288 |
---|
7320 | # copy() needs to become a deepcopy |
---|
7321 | h["space-recovered"] = s["space-recovered"].copy() |
---|
7322 | |
---|
7323 | - history = pickle.load(open(self.historyfile, "rb")) |
---|
7324 | + pickled = self.historyfp.getContent() |
---|
7325 | + history = pickle.loads(pickled) |
---|
7326 | history[cycle] = h |
---|
7327 | while len(history) > 10: |
---|
7328 | oldcycles = sorted(history.keys()) |
---|
7329 | hunk ./src/allmydata/storage/expirer.py 294 |
---|
7330 | del history[oldcycles[0]] |
---|
7331 | - f = open(self.historyfile, "wb") |
---|
7332 | - pickle.dump(history, f) |
---|
7333 | - f.close() |
---|
7334 | + repickled = pickle.dumps(history) |
---|
7335 | + self.historyfp.setContent(repickled) |
---|
7336 | |
---|
7337 | def get_state(self): |
---|
7338 | """In addition to the crawler state described in |
---|
7339 | hunk ./src/allmydata/storage/expirer.py 364 |
---|
7340 | progress = self.get_progress() |
---|
7341 | |
---|
7342 | state = ShareCrawler.get_state(self) # does a shallow copy |
---|
7343 | - history = pickle.load(open(self.historyfile, "rb")) |
---|
7344 | + pickled = self.historyfp.getContent() |
---|
7345 | + history = pickle.loads(pickled) |
---|
7346 | state["history"] = history |
---|
7347 | |
---|
7348 | if not progress["cycle-in-progress"]: |
---|
7349 | hunk ./src/allmydata/storage/server.py 1 |
---|
7350 | -import os, re, weakref, struct, time |
---|
7351 | +import weakref |
---|
7352 | |
---|
7353 | from foolscap.api import Referenceable |
---|
7354 | from twisted.application import service |
---|
7355 | hunk ./src/allmydata/storage/server.py 5 |
---|
7356 | +from twisted.internet import defer, reactor |
---|
7357 | |
---|
7358 | from zope.interface import implements |
---|
7359 | hunk ./src/allmydata/storage/server.py 8 |
---|
7360 | -from allmydata.interfaces import RIStorageServer, IStatsProducer |
---|
7361 | -from allmydata.util import fileutil, idlib, log, time_format |
---|
7362 | +from allmydata.interfaces import RIStorageServer, IStatsProducer, IStorageBackend |
---|
7363 | +from allmydata.util.assertutil import precondition |
---|
7364 | +from allmydata.util import idlib, log, fileutil |
---|
7365 | import allmydata # for __full_version__ |
---|
7366 | |
---|
7367 | hunk ./src/allmydata/storage/server.py 13 |
---|
7368 | -from allmydata.storage.common import si_b2a, si_a2b, storage_index_to_dir |
---|
7369 | -_pyflakes_hush = [si_b2a, si_a2b, storage_index_to_dir] # re-exported |
---|
7370 | +from allmydata.storage.common import si_a2b, si_b2a |
---|
7371 | +[si_a2b] # hush pyflakes |
---|
7372 | from allmydata.storage.lease import LeaseInfo |
---|
7373 | hunk ./src/allmydata/storage/server.py 16 |
---|
7374 | -from allmydata.storage.mutable import MutableShareFile, EmptyShare, \ |
---|
7375 | - create_mutable_sharefile |
---|
7376 | -from allmydata.storage.immutable import ShareFile, BucketWriter, BucketReader |
---|
7377 | -from allmydata.storage.crawler import BucketCountingCrawler |
---|
7378 | from allmydata.storage.expirer import LeaseCheckingCrawler |
---|
7379 | hunk ./src/allmydata/storage/server.py 17 |
---|
7380 | - |
---|
7381 | -# storage/ |
---|
7382 | -# storage/shares/incoming |
---|
7383 | -# incoming/ holds temp dirs named $START/$STORAGEINDEX/$SHARENUM which will |
---|
7384 | -# be moved to storage/shares/$START/$STORAGEINDEX/$SHARENUM upon success |
---|
7385 | -# storage/shares/$START/$STORAGEINDEX |
---|
7386 | -# storage/shares/$START/$STORAGEINDEX/$SHARENUM |
---|
7387 | - |
---|
7388 | -# Where "$START" denotes the first 10 bits worth of $STORAGEINDEX (that's 2 |
---|
7389 | -# base-32 chars). |
---|
7390 | - |
---|
7391 | -# $SHARENUM matches this regex: |
---|
7392 | -NUM_RE=re.compile("^[0-9]+$") |
---|
7393 | - |
---|
7394 | +from allmydata.storage.crawler import BucketCountingCrawler |
---|
7395 | |
---|
7396 | |
---|
7397 | class StorageServer(service.MultiService, Referenceable): |
---|
7398 | hunk ./src/allmydata/storage/server.py 25 |
---|
7399 | |
---|
7400 | name = 'storage' |
---|
7401 | LeaseCheckerClass = LeaseCheckingCrawler |
---|
7402 | + BucketCounterClass = BucketCountingCrawler |
---|
7403 | + DEFAULT_EXPIRATION_POLICY = { |
---|
7404 | + 'enabled': False, |
---|
7405 | + 'mode': 'age', |
---|
7406 | + 'override_lease_duration': None, |
---|
7407 | + 'cutoff_date': None, |
---|
7408 | + 'sharetypes': ('mutable', 'immutable'), |
---|
7409 | + } |
---|
7410 | |
---|
7411 | hunk ./src/allmydata/storage/server.py 34 |
---|
7412 | - def __init__(self, storedir, nodeid, reserved_space=0, |
---|
7413 | - discard_storage=False, readonly_storage=False, |
---|
7414 | + def __init__(self, serverid, backend, statedir, |
---|
7415 | stats_provider=None, |
---|
7416 | hunk ./src/allmydata/storage/server.py 36 |
---|
7417 | - expiration_enabled=False, |
---|
7418 | - expiration_mode="age", |
---|
7419 | - expiration_override_lease_duration=None, |
---|
7420 | - expiration_cutoff_date=None, |
---|
7421 | - expiration_sharetypes=("mutable", "immutable")): |
---|
7422 | + expiration_policy=None, |
---|
7423 | + clock=None): |
---|
7424 | service.MultiService.__init__(self) |
---|
7425 | hunk ./src/allmydata/storage/server.py 39 |
---|
7426 | - assert isinstance(nodeid, str) |
---|
7427 | - assert len(nodeid) == 20 |
---|
7428 | - self.my_nodeid = nodeid |
---|
7429 | - self.storedir = storedir |
---|
7430 | - sharedir = os.path.join(storedir, "shares") |
---|
7431 | - fileutil.make_dirs(sharedir) |
---|
7432 | - self.sharedir = sharedir |
---|
7433 | - # we don't actually create the corruption-advisory dir until necessary |
---|
7434 | - self.corruption_advisory_dir = os.path.join(storedir, |
---|
7435 | - "corruption-advisories") |
---|
7436 | - self.reserved_space = int(reserved_space) |
---|
7437 | - self.no_storage = discard_storage |
---|
7438 | - self.readonly_storage = readonly_storage |
---|
7439 | + precondition(IStorageBackend.providedBy(backend), backend) |
---|
7440 | + precondition(isinstance(serverid, str), serverid) |
---|
7441 | + precondition(len(serverid) == 20, serverid) |
---|
7442 | + |
---|
7443 | + self._serverid = serverid |
---|
7444 | + self.clock = clock or reactor |
---|
7445 | self.stats_provider = stats_provider |
---|
7446 | if self.stats_provider: |
---|
7447 | self.stats_provider.register_producer(self) |
---|
7448 | hunk ./src/allmydata/storage/server.py 48 |
---|
7449 | - self.incomingdir = os.path.join(sharedir, 'incoming') |
---|
7450 | - self._clean_incomplete() |
---|
7451 | - fileutil.make_dirs(self.incomingdir) |
---|
7452 | self._active_writers = weakref.WeakKeyDictionary() |
---|
7453 | hunk ./src/allmydata/storage/server.py 49 |
---|
7454 | + self.backend = backend |
---|
7455 | + self.backend.setServiceParent(self) |
---|
7456 | + self._statedir = statedir |
---|
7457 | + fileutil.fp_make_dirs(self._statedir) |
---|
7458 | log.msg("StorageServer created", facility="tahoe.storage") |
---|
7459 | |
---|
7460 | hunk ./src/allmydata/storage/server.py 55 |
---|
7461 | - if reserved_space: |
---|
7462 | - if self.get_available_space() is None: |
---|
7463 | - log.msg("warning: [storage]reserved_space= is set, but this platform does not support an API to get disk statistics (statvfs(2) or GetDiskFreeSpaceEx), so this reservation cannot be honored", |
---|
7464 | - umin="0wZ27w", level=log.UNUSUAL) |
---|
7465 | - |
---|
7466 | self.latencies = {"allocate": [], # immutable |
---|
7467 | "write": [], |
---|
7468 | "close": [], |
---|
7469 | hunk ./src/allmydata/storage/server.py 66 |
---|
7470 | "renew": [], |
---|
7471 | "cancel": [], |
---|
7472 | } |
---|
7473 | - self.add_bucket_counter() |
---|
7474 | |
---|
7475 | hunk ./src/allmydata/storage/server.py 67 |
---|
7476 | - statefile = os.path.join(self.storedir, "lease_checker.state") |
---|
7477 | - historyfile = os.path.join(self.storedir, "lease_checker.history") |
---|
7478 | - klass = self.LeaseCheckerClass |
---|
7479 | - self.lease_checker = klass(self, statefile, historyfile, |
---|
7480 | - expiration_enabled, expiration_mode, |
---|
7481 | - expiration_override_lease_duration, |
---|
7482 | - expiration_cutoff_date, |
---|
7483 | - expiration_sharetypes) |
---|
7484 | - self.lease_checker.setServiceParent(self) |
---|
7485 | + self.bucket_counter = None |
---|
7486 | + self.lease_checker = None |
---|
7487 | + if backend.supports_crawlers(): |
---|
7488 | + self._setup_bucket_counter() |
---|
7489 | + self._setup_lease_checker(expiration_policy or self.DEFAULT_EXPIRATION_POLICY) |
---|
7490 | |
---|
7491 | def __repr__(self): |
---|
7492 | hunk ./src/allmydata/storage/server.py 74 |
---|
7493 | - return "<StorageServer %s>" % (idlib.shortnodeid_b2a(self.my_nodeid),) |
---|
7494 | + return "<StorageServer %s>" % (idlib.shortnodeid_b2a(self._serverid),) |
---|
7495 | |
---|
7496 | hunk ./src/allmydata/storage/server.py 76 |
---|
7497 | - def have_shares(self): |
---|
7498 | - # quick test to decide if we need to commit to an implicit |
---|
7499 | - # permutation-seed or if we should use a new one |
---|
7500 | - return bool(set(os.listdir(self.sharedir)) - set(["incoming"])) |
---|
7501 | - |
---|
7502 | - def add_bucket_counter(self): |
---|
7503 | - statefile = os.path.join(self.storedir, "bucket_counter.state") |
---|
7504 | - self.bucket_counter = BucketCountingCrawler(self, statefile) |
---|
7505 | + def _setup_bucket_counter(self): |
---|
7506 | + statefp = self._statedir.child("bucket_counter.state") |
---|
7507 | + self.bucket_counter = self.BucketCounterClass(self.backend, statefp, |
---|
7508 | + clock=self.clock) |
---|
7509 | self.bucket_counter.setServiceParent(self) |
---|
7510 | |
---|
7511 | hunk ./src/allmydata/storage/server.py 82 |
---|
7512 | + def _setup_lease_checker(self, expiration_policy): |
---|
7513 | + statefp = self._statedir.child("lease_checker.state") |
---|
7514 | + historyfp = self._statedir.child("lease_checker.history") |
---|
7515 | + self.lease_checker = self.LeaseCheckerClass(self.backend, statefp, historyfp, expiration_policy, |
---|
7516 | + clock=self.clock) |
---|
7517 | + self.lease_checker.setServiceParent(self) |
---|
7518 | + |
---|
7519 | def count(self, name, delta=1): |
---|
7520 | if self.stats_provider: |
---|
7521 | self.stats_provider.count("storage_server." + name, delta) |
---|
7522 | hunk ./src/allmydata/storage/server.py 103 |
---|
7523 | """Return a dict, indexed by category, that contains a dict of |
---|
7524 | latency numbers for each category. If there are sufficient samples |
---|
7525 | for unambiguous interpretation, each dict will contain the |
---|
7526 | - following keys: mean, 01_0_percentile, 10_0_percentile, |
---|
7527 | + following keys: samplesize, mean, 01_0_percentile, 10_0_percentile, |
---|
7528 | 50_0_percentile (median), 90_0_percentile, 95_0_percentile, |
---|
7529 | 99_0_percentile, 99_9_percentile. If there are insufficient |
---|
7530 | samples for a given percentile to be interpreted unambiguously |
---|
7531 | hunk ./src/allmydata/storage/server.py 125 |
---|
7532 | else: |
---|
7533 | stats["mean"] = None |
---|
7534 | |
---|
7535 | - orderstatlist = [(0.01, "01_0_percentile", 100), (0.1, "10_0_percentile", 10),\ |
---|
7536 | - (0.50, "50_0_percentile", 10), (0.90, "90_0_percentile", 10),\ |
---|
7537 | - (0.95, "95_0_percentile", 20), (0.99, "99_0_percentile", 100),\ |
---|
7538 | + orderstatlist = [(0.1, "10_0_percentile", 10), (0.5, "50_0_percentile", 10), \ |
---|
7539 | + (0.9, "90_0_percentile", 10), (0.95, "95_0_percentile", 20), \ |
---|
7540 | + (0.01, "01_0_percentile", 100), (0.99, "99_0_percentile", 100),\ |
---|
7541 | (0.999, "99_9_percentile", 1000)] |
---|
7542 | |
---|
7543 | for percentile, percentilestring, minnumtoobserve in orderstatlist: |
---|
7544 | hunk ./src/allmydata/storage/server.py 144 |
---|
7545 | kwargs["facility"] = "tahoe.storage" |
---|
7546 | return log.msg(*args, **kwargs) |
---|
7547 | |
---|
7548 | - def _clean_incomplete(self): |
---|
7549 | - fileutil.rm_dir(self.incomingdir) |
---|
7550 | + def get_serverid(self): |
---|
7551 | + return self._serverid |
---|
7552 | |
---|
7553 | def get_stats(self): |
---|
7554 | # remember: RIStatsProvider requires that our return dict |
---|
7555 | hunk ./src/allmydata/storage/server.py 149 |
---|
7556 | - # contains numeric values. |
---|
7557 | + # contains numeric, or None values. |
---|
7558 | stats = { 'storage_server.allocated': self.allocated_size(), } |
---|
7559 | hunk ./src/allmydata/storage/server.py 151 |
---|
7560 | - stats['storage_server.reserved_space'] = self.reserved_space |
---|
7561 | for category,ld in self.get_latencies().items(): |
---|
7562 | for name,v in ld.items(): |
---|
7563 | stats['storage_server.latencies.%s.%s' % (category, name)] = v |
---|
7564 | hunk ./src/allmydata/storage/server.py 155 |
---|
7565 | |
---|
7566 | - try: |
---|
7567 | - disk = fileutil.get_disk_stats(self.sharedir, self.reserved_space) |
---|
7568 | - writeable = disk['avail'] > 0 |
---|
7569 | - |
---|
7570 | - # spacetime predictors should use disk_avail / (d(disk_used)/dt) |
---|
7571 | - stats['storage_server.disk_total'] = disk['total'] |
---|
7572 | - stats['storage_server.disk_used'] = disk['used'] |
---|
7573 | - stats['storage_server.disk_free_for_root'] = disk['free_for_root'] |
---|
7574 | - stats['storage_server.disk_free_for_nonroot'] = disk['free_for_nonroot'] |
---|
7575 | - stats['storage_server.disk_avail'] = disk['avail'] |
---|
7576 | - except AttributeError: |
---|
7577 | - writeable = True |
---|
7578 | - except EnvironmentError: |
---|
7579 | - log.msg("OS call to get disk statistics failed", level=log.UNUSUAL) |
---|
7580 | - writeable = False |
---|
7581 | + self.backend.fill_in_space_stats(stats) |
---|
7582 | |
---|
7583 | hunk ./src/allmydata/storage/server.py 157 |
---|
7584 | - if self.readonly_storage: |
---|
7585 | - stats['storage_server.disk_avail'] = 0 |
---|
7586 | - writeable = False |
---|
7587 | - |
---|
7588 | - stats['storage_server.accepting_immutable_shares'] = int(writeable) |
---|
7589 | - s = self.bucket_counter.get_state() |
---|
7590 | - bucket_count = s.get("last-complete-bucket-count") |
---|
7591 | - if bucket_count: |
---|
7592 | - stats['storage_server.total_bucket_count'] = bucket_count |
---|
7593 | + if self.bucket_counter: |
---|
7594 | + s = self.bucket_counter.get_state() |
---|
7595 | + bucket_count = s.get("last-complete-bucket-count") |
---|
7596 | + if bucket_count: |
---|
7597 | + stats['storage_server.total_bucket_count'] = bucket_count |
---|
7598 | return stats |
---|
7599 | |
---|
7600 | def get_available_space(self): |
---|
7601 | hunk ./src/allmydata/storage/server.py 165 |
---|
7602 | - """Returns available space for share storage in bytes, or None if no |
---|
7603 | - API to get this information is available.""" |
---|
7604 | - |
---|
7605 | - if self.readonly_storage: |
---|
7606 | - return 0 |
---|
7607 | - return fileutil.get_available_space(self.sharedir, self.reserved_space) |
---|
7608 | + return self.backend.get_available_space() |
---|
7609 | |
---|
7610 | def allocated_size(self): |
---|
7611 | space = 0 |
---|
7612 | hunk ./src/allmydata/storage/server.py 174 |
---|
7613 | return space |
---|
7614 | |
---|
7615 | def remote_get_version(self): |
---|
7616 | - remaining_space = self.get_available_space() |
---|
7617 | + remaining_space = self.backend.get_available_space() |
---|
7618 | if remaining_space is None: |
---|
7619 | # We're on a platform that has no API to get disk stats. |
---|
7620 | remaining_space = 2**64 |
---|
7621 | hunk ./src/allmydata/storage/server.py 185 |
---|
7622 | "delete-mutable-shares-with-zero-length-writev": True, |
---|
7623 | "fills-holes-with-zero-bytes": True, |
---|
7624 | "prevents-read-past-end-of-share-data": True, |
---|
7625 | + "has-immutable-readv": True, |
---|
7626 | }, |
---|
7627 | "application-version": str(allmydata.__full_version__), |
---|
7628 | } |
---|
7629 | hunk ./src/allmydata/storage/server.py 191 |
---|
7630 | return version |
---|
7631 | |
---|
7632 | - def remote_allocate_buckets(self, storage_index, |
---|
7633 | + def _add_latency(self, res, name, start): |
---|
7634 | + self.add_latency(name, self.clock.seconds() - start) |
---|
7635 | + return res |
---|
7636 | + |
---|
7637 | + def remote_allocate_buckets(self, storageindex, |
---|
7638 | renew_secret, cancel_secret, |
---|
7639 | sharenums, allocated_size, |
---|
7640 | canary, owner_num=0): |
---|
7641 | hunk ./src/allmydata/storage/server.py 200 |
---|
7642 | # owner_num is not for clients to set, but rather it should be |
---|
7643 | - # curried into the PersonalStorageServer instance that is dedicated |
---|
7644 | - # to a particular owner. |
---|
7645 | - start = time.time() |
---|
7646 | + # curried into a StorageServer instance dedicated to a particular |
---|
7647 | + # owner. |
---|
7648 | + start = self.clock.seconds() |
---|
7649 | self.count("allocate") |
---|
7650 | hunk ./src/allmydata/storage/server.py 204 |
---|
7651 | - alreadygot = set() |
---|
7652 | bucketwriters = {} # k: shnum, v: BucketWriter |
---|
7653 | hunk ./src/allmydata/storage/server.py 205 |
---|
7654 | - si_dir = storage_index_to_dir(storage_index) |
---|
7655 | - si_s = si_b2a(storage_index) |
---|
7656 | |
---|
7657 | hunk ./src/allmydata/storage/server.py 206 |
---|
7658 | + si_s = si_b2a(storageindex) |
---|
7659 | log.msg("storage: allocate_buckets %s" % si_s) |
---|
7660 | |
---|
7661 | hunk ./src/allmydata/storage/server.py 209 |
---|
7662 | - # in this implementation, the lease information (including secrets) |
---|
7663 | - # goes into the share files themselves. It could also be put into a |
---|
7664 | - # separate database. Note that the lease should not be added until |
---|
7665 | - # the BucketWriter has been closed. |
---|
7666 | - expire_time = time.time() + 31*24*60*60 |
---|
7667 | - lease_info = LeaseInfo(owner_num, |
---|
7668 | - renew_secret, cancel_secret, |
---|
7669 | - expire_time, self.my_nodeid) |
---|
7670 | + # Note that the lease should not be added until the BucketWriter |
---|
7671 | + # has been closed. |
---|
7672 | + expire_time = start + 31*24*60*60 |
---|
7673 | + lease_info = LeaseInfo(owner_num, renew_secret, cancel_secret, |
---|
7674 | + expire_time, self._serverid) |
---|
7675 | |
---|
7676 | max_space_per_bucket = allocated_size |
---|
7677 | |
---|
7678 | hunk ./src/allmydata/storage/server.py 217 |
---|
7679 | - remaining_space = self.get_available_space() |
---|
7680 | + remaining_space = self.backend.get_available_space() |
---|
7681 | limited = remaining_space is not None |
---|
7682 | if limited: |
---|
7683 | # This is a bit conservative, since some of this allocated_size() |
---|
7684 | hunk ./src/allmydata/storage/server.py 224 |
---|
7685 | # has already been written to the backend, where it will show up in |
---|
7686 | # get_available_space. |
---|
7687 | remaining_space -= self.allocated_size() |
---|
7688 | - # self.readonly_storage causes remaining_space <= 0 |
---|
7689 | + # If the backend is read-only, remaining_space will be <= 0. |
---|
7690 | + |
---|
7691 | + shareset = self.backend.get_shareset(storageindex) |
---|
7692 | |
---|
7693 | # Fill alreadygot with all shares that we have, not just the ones |
---|
7694 | # they asked about: this will save them a lot of work. Add or update |
---|
7695 | hunk ./src/allmydata/storage/server.py 231 |
---|
7696 | # leases for all of them: if they want us to hold shares for this |
---|
7697 | - # file, they'll want us to hold leases for this file. |
---|
7698 | - for (shnum, fn) in self._get_bucket_shares(storage_index): |
---|
7699 | - alreadygot.add(shnum) |
---|
7700 | - sf = ShareFile(fn) |
---|
7701 | - sf.add_or_renew_lease(lease_info) |
---|
7702 | + # file, they'll want us to hold leases for all the shares of it. |
---|
7703 | + # |
---|
7704 | + # XXX should we be making the assumption here that lease info is |
---|
7705 | + # duplicated in all shares? |
---|
7706 | + alreadygot = set() |
---|
7707 | + d = shareset.get_shares() |
---|
7708 | + def _got_shares( (shares, corrupted) ): |
---|
7709 | + remaining = remaining_space |
---|
7710 | + for share in shares: |
---|
7711 | + share.add_or_renew_lease(lease_info) |
---|
7712 | + alreadygot.add(share.get_shnum()) |
---|
7713 | |
---|
7714 | hunk ./src/allmydata/storage/server.py 243 |
---|
7715 | - for shnum in sharenums: |
---|
7716 | - incominghome = os.path.join(self.incomingdir, si_dir, "%d" % shnum) |
---|
7717 | - finalhome = os.path.join(self.sharedir, si_dir, "%d" % shnum) |
---|
7718 | - if os.path.exists(finalhome): |
---|
7719 | - # great! we already have it. easy. |
---|
7720 | - pass |
---|
7721 | - elif os.path.exists(incominghome): |
---|
7722 | - # Note that we don't create BucketWriters for shnums that |
---|
7723 | - # have a partial share (in incoming/), so if a second upload |
---|
7724 | - # occurs while the first is still in progress, the second |
---|
7725 | - # uploader will use different storage servers. |
---|
7726 | - pass |
---|
7727 | - elif (not limited) or (remaining_space >= max_space_per_bucket): |
---|
7728 | - # ok! we need to create the new share file. |
---|
7729 | - bw = BucketWriter(self, incominghome, finalhome, |
---|
7730 | - max_space_per_bucket, lease_info, canary) |
---|
7731 | - if self.no_storage: |
---|
7732 | - bw.throw_out_all_data = True |
---|
7733 | - bucketwriters[shnum] = bw |
---|
7734 | - self._active_writers[bw] = 1 |
---|
7735 | - if limited: |
---|
7736 | - remaining_space -= max_space_per_bucket |
---|
7737 | - else: |
---|
7738 | - # bummer! not enough space to accept this bucket |
---|
7739 | - pass |
---|
7740 | + d2 = defer.succeed(None) |
---|
7741 | |
---|
7742 | hunk ./src/allmydata/storage/server.py 245 |
---|
7743 | - if bucketwriters: |
---|
7744 | - fileutil.make_dirs(os.path.join(self.sharedir, si_dir)) |
---|
7745 | + # We only want BucketWriters for the shares we're going to write. |
---|
7746 | |
---|
7747 | hunk ./src/allmydata/storage/server.py 247 |
---|
7748 | - self.add_latency("allocate", time.time() - start) |
---|
7749 | - return alreadygot, bucketwriters |
---|
7750 | + # Currently we don't create BucketWriters for shnums where we have a |
---|
7751 | + # share that is corrupted. Is that right, or should we allow the corrupted |
---|
7752 | + # share to be clobbered? Note that currently the disk share classes |
---|
7753 | + # have assertions that prevent them from clobbering existing files. |
---|
7754 | + for shnum in set(sharenums) - alreadygot - corrupted: |
---|
7755 | + if shareset.has_incoming(shnum): |
---|
7756 | + # Note that we don't create BucketWriters for shnums that |
---|
7757 | + # have an incoming share, so if a second upload occurs while |
---|
7758 | + # the first is still in progress, the second uploader will |
---|
7759 | + # use different storage servers. |
---|
7760 | + pass |
---|
7761 | + elif (not limited) or (remaining >= max_space_per_bucket): |
---|
7762 | + if limited: |
---|
7763 | + remaining -= max_space_per_bucket |
---|
7764 | |
---|
7765 | hunk ./src/allmydata/storage/server.py 262 |
---|
7766 | - def _iter_share_files(self, storage_index): |
---|
7767 | - for shnum, filename in self._get_bucket_shares(storage_index): |
---|
7768 | - f = open(filename, 'rb') |
---|
7769 | - header = f.read(32) |
---|
7770 | - f.close() |
---|
7771 | - if header[:32] == MutableShareFile.MAGIC: |
---|
7772 | - sf = MutableShareFile(filename, self) |
---|
7773 | - # note: if the share has been migrated, the renew_lease() |
---|
7774 | - # call will throw an exception, with information to help the |
---|
7775 | - # client update the lease. |
---|
7776 | - elif header[:4] == struct.pack(">L", 1): |
---|
7777 | - sf = ShareFile(filename) |
---|
7778 | - else: |
---|
7779 | - continue # non-sharefile |
---|
7780 | - yield sf |
---|
7781 | + d2.addCallback(lambda ign, shnum=shnum: |
---|
7782 | + shareset.make_bucket_writer(self, shnum, max_space_per_bucket, |
---|
7783 | + lease_info, canary)) |
---|
7784 | + def _record_writer(bw, shnum=shnum): |
---|
7785 | + bucketwriters[shnum] = bw |
---|
7786 | + self._active_writers[bw] = 1 |
---|
7787 | + d2.addCallback(_record_writer) |
---|
7788 | + else: |
---|
7789 | + # Bummer not enough space to accept this share. |
---|
7790 | + pass |
---|
7791 | + |
---|
7792 | + d2.addCallback(lambda ign: (alreadygot, bucketwriters)) |
---|
7793 | + return d2 |
---|
7794 | + d.addCallback(_got_shares) |
---|
7795 | + d.addBoth(self._add_latency, "allocate", start) |
---|
7796 | + return d |
---|
7797 | |
---|
7798 | hunk ./src/allmydata/storage/server.py 279 |
---|
7799 | - def remote_add_lease(self, storage_index, renew_secret, cancel_secret, |
---|
7800 | + def remote_add_lease(self, storageindex, renew_secret, cancel_secret, |
---|
7801 | owner_num=1): |
---|
7802 | hunk ./src/allmydata/storage/server.py 281 |
---|
7803 | - start = time.time() |
---|
7804 | + start = self.clock.seconds() |
---|
7805 | self.count("add-lease") |
---|
7806 | hunk ./src/allmydata/storage/server.py 283 |
---|
7807 | - new_expire_time = time.time() + 31*24*60*60 |
---|
7808 | - lease_info = LeaseInfo(owner_num, |
---|
7809 | - renew_secret, cancel_secret, |
---|
7810 | - new_expire_time, self.my_nodeid) |
---|
7811 | - for sf in self._iter_share_files(storage_index): |
---|
7812 | - sf.add_or_renew_lease(lease_info) |
---|
7813 | - self.add_latency("add-lease", time.time() - start) |
---|
7814 | - return None |
---|
7815 | + new_expire_time = start + 31*24*60*60 |
---|
7816 | + lease_info = LeaseInfo(owner_num, renew_secret, cancel_secret, |
---|
7817 | + new_expire_time, self._serverid) |
---|
7818 | + |
---|
7819 | + try: |
---|
7820 | + shareset = self.backend.get_shareset(storageindex) |
---|
7821 | + shareset.add_or_renew_lease(lease_info) |
---|
7822 | + finally: |
---|
7823 | + self.add_latency("add-lease", self.clock.seconds() - start) |
---|
7824 | |
---|
7825 | hunk ./src/allmydata/storage/server.py 293 |
---|
7826 | - def remote_renew_lease(self, storage_index, renew_secret): |
---|
7827 | - start = time.time() |
---|
7828 | + def remote_renew_lease(self, storageindex, renew_secret): |
---|
7829 | + start = self.clock.seconds() |
---|
7830 | self.count("renew") |
---|
7831 | hunk ./src/allmydata/storage/server.py 296 |
---|
7832 | - new_expire_time = time.time() + 31*24*60*60 |
---|
7833 | - found_buckets = False |
---|
7834 | - for sf in self._iter_share_files(storage_index): |
---|
7835 | - found_buckets = True |
---|
7836 | - sf.renew_lease(renew_secret, new_expire_time) |
---|
7837 | - self.add_latency("renew", time.time() - start) |
---|
7838 | - if not found_buckets: |
---|
7839 | - raise IndexError("no such lease to renew") |
---|
7840 | + |
---|
7841 | + try: |
---|
7842 | + shareset = self.backend.get_shareset(storageindex) |
---|
7843 | + new_expiration_time = start + 31*24*60*60 # one month from now |
---|
7844 | + shareset.renew_lease(renew_secret, new_expiration_time) |
---|
7845 | + finally: |
---|
7846 | + self.add_latency("renew", self.clock.seconds() - start) |
---|
7847 | |
---|
7848 | def bucket_writer_closed(self, bw, consumed_size): |
---|
7849 | if self.stats_provider: |
---|
7850 | hunk ./src/allmydata/storage/server.py 309 |
---|
7851 | self.stats_provider.count('storage_server.bytes_added', consumed_size) |
---|
7852 | del self._active_writers[bw] |
---|
7853 | |
---|
7854 | - def _get_bucket_shares(self, storage_index): |
---|
7855 | - """Return a list of (shnum, pathname) tuples for files that hold |
---|
7856 | - shares for this storage_index. In each tuple, 'shnum' will always be |
---|
7857 | - the integer form of the last component of 'pathname'.""" |
---|
7858 | - storagedir = os.path.join(self.sharedir, storage_index_to_dir(storage_index)) |
---|
7859 | - try: |
---|
7860 | - for f in os.listdir(storagedir): |
---|
7861 | - if NUM_RE.match(f): |
---|
7862 | - filename = os.path.join(storagedir, f) |
---|
7863 | - yield (int(f), filename) |
---|
7864 | - except OSError: |
---|
7865 | - # Commonly caused by there being no buckets at all. |
---|
7866 | - pass |
---|
7867 | - |
---|
7868 | - def remote_get_buckets(self, storage_index): |
---|
7869 | - start = time.time() |
---|
7870 | + def remote_get_buckets(self, storageindex): |
---|
7871 | + start = self.clock.seconds() |
---|
7872 | self.count("get") |
---|
7873 | hunk ./src/allmydata/storage/server.py 312 |
---|
7874 | - si_s = si_b2a(storage_index) |
---|
7875 | + si_s = si_b2a(storageindex) |
---|
7876 | log.msg("storage: get_buckets %s" % si_s) |
---|
7877 | bucketreaders = {} # k: sharenum, v: BucketReader |
---|
7878 | hunk ./src/allmydata/storage/server.py 315 |
---|
7879 | - for shnum, filename in self._get_bucket_shares(storage_index): |
---|
7880 | - bucketreaders[shnum] = BucketReader(self, filename, |
---|
7881 | - storage_index, shnum) |
---|
7882 | - self.add_latency("get", time.time() - start) |
---|
7883 | - return bucketreaders |
---|
7884 | |
---|
7885 | hunk ./src/allmydata/storage/server.py 316 |
---|
7886 | - def get_leases(self, storage_index): |
---|
7887 | - """Provide an iterator that yields all of the leases attached to this |
---|
7888 | - bucket. Each lease is returned as a LeaseInfo instance. |
---|
7889 | + shareset = self.backend.get_shareset(storageindex) |
---|
7890 | + d = shareset.get_shares() |
---|
7891 | + def _make_readers( (shares, corrupted) ): |
---|
7892 | + # We don't create BucketReaders for corrupted shares. |
---|
7893 | + for share in shares: |
---|
7894 | + assert not isinstance(share, defer.Deferred), share |
---|
7895 | + bucketreaders[share.get_shnum()] = shareset.make_bucket_reader(self, share) |
---|
7896 | + return bucketreaders |
---|
7897 | + d.addCallback(_make_readers) |
---|
7898 | + d.addBoth(self._add_latency, "get", start) |
---|
7899 | + return d |
---|
7900 | |
---|
7901 | hunk ./src/allmydata/storage/server.py 328 |
---|
7902 | - This method is not for client use. |
---|
7903 | + def get_leases(self, storageindex): |
---|
7904 | """ |
---|
7905 | hunk ./src/allmydata/storage/server.py 330 |
---|
7906 | + Provide an iterator that yields all of the leases attached to this |
---|
7907 | + bucket. Each lease is returned as a LeaseInfo instance. |
---|
7908 | |
---|
7909 | hunk ./src/allmydata/storage/server.py 333 |
---|
7910 | - # since all shares get the same lease data, we just grab the leases |
---|
7911 | - # from the first share |
---|
7912 | - try: |
---|
7913 | - shnum, filename = self._get_bucket_shares(storage_index).next() |
---|
7914 | - sf = ShareFile(filename) |
---|
7915 | - return sf.get_leases() |
---|
7916 | - except StopIteration: |
---|
7917 | - return iter([]) |
---|
7918 | + This method is not for client use. XXX do we need it at all? |
---|
7919 | + For the time being this is synchronous. |
---|
7920 | + """ |
---|
7921 | + return self.backend.get_shareset(storageindex).get_leases() |
---|
7922 | |
---|
7923 | hunk ./src/allmydata/storage/server.py 338 |
---|
7924 | - def remote_slot_testv_and_readv_and_writev(self, storage_index, |
---|
7925 | + def remote_slot_testv_and_readv_and_writev(self, storageindex, |
---|
7926 | secrets, |
---|
7927 | test_and_write_vectors, |
---|
7928 | read_vector): |
---|
7929 | hunk ./src/allmydata/storage/server.py 342 |
---|
7930 | - start = time.time() |
---|
7931 | + start = self.clock.seconds() |
---|
7932 | self.count("writev") |
---|
7933 | hunk ./src/allmydata/storage/server.py 344 |
---|
7934 | - si_s = si_b2a(storage_index) |
---|
7935 | + si_s = si_b2a(storageindex) |
---|
7936 | log.msg("storage: slot_writev %s" % si_s) |
---|
7937 | hunk ./src/allmydata/storage/server.py 346 |
---|
7938 | - si_dir = storage_index_to_dir(storage_index) |
---|
7939 | - (write_enabler, renew_secret, cancel_secret) = secrets |
---|
7940 | - # shares exist if there is a file for them |
---|
7941 | - bucketdir = os.path.join(self.sharedir, si_dir) |
---|
7942 | - shares = {} |
---|
7943 | - if os.path.isdir(bucketdir): |
---|
7944 | - for sharenum_s in os.listdir(bucketdir): |
---|
7945 | - try: |
---|
7946 | - sharenum = int(sharenum_s) |
---|
7947 | - except ValueError: |
---|
7948 | - continue |
---|
7949 | - filename = os.path.join(bucketdir, sharenum_s) |
---|
7950 | - msf = MutableShareFile(filename, self) |
---|
7951 | - msf.check_write_enabler(write_enabler, si_s) |
---|
7952 | - shares[sharenum] = msf |
---|
7953 | - # write_enabler is good for all existing shares. |
---|
7954 | - |
---|
7955 | - # Now evaluate test vectors. |
---|
7956 | - testv_is_good = True |
---|
7957 | - for sharenum in test_and_write_vectors: |
---|
7958 | - (testv, datav, new_length) = test_and_write_vectors[sharenum] |
---|
7959 | - if sharenum in shares: |
---|
7960 | - if not shares[sharenum].check_testv(testv): |
---|
7961 | - self.log("testv failed: [%d]: %r" % (sharenum, testv)) |
---|
7962 | - testv_is_good = False |
---|
7963 | - break |
---|
7964 | - else: |
---|
7965 | - # compare the vectors against an empty share, in which all |
---|
7966 | - # reads return empty strings. |
---|
7967 | - if not EmptyShare().check_testv(testv): |
---|
7968 | - self.log("testv failed (empty): [%d] %r" % (sharenum, |
---|
7969 | - testv)) |
---|
7970 | - testv_is_good = False |
---|
7971 | - break |
---|
7972 | |
---|
7973 | hunk ./src/allmydata/storage/server.py 347 |
---|
7974 | - # now gather the read vectors, before we do any writes |
---|
7975 | - read_data = {} |
---|
7976 | - for sharenum, share in shares.items(): |
---|
7977 | - read_data[sharenum] = share.readv(read_vector) |
---|
7978 | - |
---|
7979 | - ownerid = 1 # TODO |
---|
7980 | - expire_time = time.time() + 31*24*60*60 # one month |
---|
7981 | - lease_info = LeaseInfo(ownerid, |
---|
7982 | - renew_secret, cancel_secret, |
---|
7983 | - expire_time, self.my_nodeid) |
---|
7984 | - |
---|
7985 | - if testv_is_good: |
---|
7986 | - # now apply the write vectors |
---|
7987 | - for sharenum in test_and_write_vectors: |
---|
7988 | - (testv, datav, new_length) = test_and_write_vectors[sharenum] |
---|
7989 | - if new_length == 0: |
---|
7990 | - if sharenum in shares: |
---|
7991 | - shares[sharenum].unlink() |
---|
7992 | - else: |
---|
7993 | - if sharenum not in shares: |
---|
7994 | - # allocate a new share |
---|
7995 | - allocated_size = 2000 # arbitrary, really |
---|
7996 | - share = self._allocate_slot_share(bucketdir, secrets, |
---|
7997 | - sharenum, |
---|
7998 | - allocated_size, |
---|
7999 | - owner_num=0) |
---|
8000 | - shares[sharenum] = share |
---|
8001 | - shares[sharenum].writev(datav, new_length) |
---|
8002 | - # and update the lease |
---|
8003 | - shares[sharenum].add_or_renew_lease(lease_info) |
---|
8004 | + shareset = self.backend.get_shareset(storageindex) |
---|
8005 | + expiration_time = start + 31*24*60*60 # one month from now |
---|
8006 | |
---|
8007 | hunk ./src/allmydata/storage/server.py 350 |
---|
8008 | - if new_length == 0: |
---|
8009 | - # delete empty bucket directories |
---|
8010 | - if not os.listdir(bucketdir): |
---|
8011 | - os.rmdir(bucketdir) |
---|
8012 | + d = shareset.testv_and_readv_and_writev(self, secrets, test_and_write_vectors, |
---|
8013 | + read_vector, expiration_time) |
---|
8014 | + d.addBoth(self._add_latency, "writev", start) |
---|
8015 | + return d |
---|
8016 | |
---|
8017 | hunk ./src/allmydata/storage/server.py 355 |
---|
8018 | - |
---|
8019 | - # all done |
---|
8020 | - self.add_latency("writev", time.time() - start) |
---|
8021 | - return (testv_is_good, read_data) |
---|
8022 | - |
---|
8023 | - def _allocate_slot_share(self, bucketdir, secrets, sharenum, |
---|
8024 | - allocated_size, owner_num=0): |
---|
8025 | - (write_enabler, renew_secret, cancel_secret) = secrets |
---|
8026 | - my_nodeid = self.my_nodeid |
---|
8027 | - fileutil.make_dirs(bucketdir) |
---|
8028 | - filename = os.path.join(bucketdir, "%d" % sharenum) |
---|
8029 | - share = create_mutable_sharefile(filename, my_nodeid, write_enabler, |
---|
8030 | - self) |
---|
8031 | - return share |
---|
8032 | - |
---|
8033 | - def remote_slot_readv(self, storage_index, shares, readv): |
---|
8034 | - start = time.time() |
---|
8035 | + def remote_slot_readv(self, storageindex, shares, readv): |
---|
8036 | + start = self.clock.seconds() |
---|
8037 | self.count("readv") |
---|
8038 | hunk ./src/allmydata/storage/server.py 358 |
---|
8039 | - si_s = si_b2a(storage_index) |
---|
8040 | - lp = log.msg("storage: slot_readv %s %s" % (si_s, shares), |
---|
8041 | - facility="tahoe.storage", level=log.OPERATIONAL) |
---|
8042 | - si_dir = storage_index_to_dir(storage_index) |
---|
8043 | - # shares exist if there is a file for them |
---|
8044 | - bucketdir = os.path.join(self.sharedir, si_dir) |
---|
8045 | - if not os.path.isdir(bucketdir): |
---|
8046 | - self.add_latency("readv", time.time() - start) |
---|
8047 | - return {} |
---|
8048 | - datavs = {} |
---|
8049 | - for sharenum_s in os.listdir(bucketdir): |
---|
8050 | - try: |
---|
8051 | - sharenum = int(sharenum_s) |
---|
8052 | - except ValueError: |
---|
8053 | - continue |
---|
8054 | - if sharenum in shares or not shares: |
---|
8055 | - filename = os.path.join(bucketdir, sharenum_s) |
---|
8056 | - msf = MutableShareFile(filename, self) |
---|
8057 | - datavs[sharenum] = msf.readv(readv) |
---|
8058 | - log.msg("returning shares %s" % (datavs.keys(),), |
---|
8059 | - facility="tahoe.storage", level=log.NOISY, parent=lp) |
---|
8060 | - self.add_latency("readv", time.time() - start) |
---|
8061 | - return datavs |
---|
8062 | + si_s = si_b2a(storageindex) |
---|
8063 | + log.msg("storage: slot_readv %s %s" % (si_s, shares), |
---|
8064 | + facility="tahoe.storage", level=log.OPERATIONAL) |
---|
8065 | + |
---|
8066 | + shareset = self.backend.get_shareset(storageindex) |
---|
8067 | + d = shareset.readv(shares, readv) |
---|
8068 | + d.addBoth(self._add_latency, "readv", start) |
---|
8069 | + return d |
---|
8070 | |
---|
8071 | hunk ./src/allmydata/storage/server.py 367 |
---|
8072 | - def remote_advise_corrupt_share(self, share_type, storage_index, shnum, |
---|
8073 | - reason): |
---|
8074 | - fileutil.make_dirs(self.corruption_advisory_dir) |
---|
8075 | - now = time_format.iso_utc(sep="T") |
---|
8076 | - si_s = si_b2a(storage_index) |
---|
8077 | - # windows can't handle colons in the filename |
---|
8078 | - fn = os.path.join(self.corruption_advisory_dir, |
---|
8079 | - "%s--%s-%d" % (now, si_s, shnum)).replace(":","") |
---|
8080 | - f = open(fn, "w") |
---|
8081 | - f.write("report: Share Corruption\n") |
---|
8082 | - f.write("type: %s\n" % share_type) |
---|
8083 | - f.write("storage_index: %s\n" % si_s) |
---|
8084 | - f.write("share_number: %d\n" % shnum) |
---|
8085 | - f.write("\n") |
---|
8086 | - f.write(reason) |
---|
8087 | - f.write("\n") |
---|
8088 | - f.close() |
---|
8089 | - log.msg(format=("client claims corruption in (%(share_type)s) " + |
---|
8090 | - "%(si)s-%(shnum)d: %(reason)s"), |
---|
8091 | - share_type=share_type, si=si_s, shnum=shnum, reason=reason, |
---|
8092 | - level=log.SCARY, umid="SGx2fA") |
---|
8093 | - return None |
---|
8094 | + def remote_advise_corrupt_share(self, share_type, storage_index, shnum, reason): |
---|
8095 | + self.backend.advise_corrupt_share(share_type, storage_index, shnum, reason) |
---|
8096 | hunk ./src/allmydata/test/common.py 19 |
---|
8097 | DeepCheckResults, DeepCheckAndRepairResults |
---|
8098 | from allmydata.mutable.layout import unpack_header |
---|
8099 | from allmydata.mutable.publish import MutableData |
---|
8100 | -from allmydata.storage.mutable import MutableShareFile |
---|
8101 | +from allmydata.storage.backends.disk.mutable import MutableDiskShare |
---|
8102 | from allmydata.util import hashutil, log, fileutil, pollmixin |
---|
8103 | from allmydata.util.assertutil import precondition |
---|
8104 | from allmydata.util.consumer import download_to_data |
---|
8105 | hunk ./src/allmydata/test/common.py 481 |
---|
8106 | d.addBoth(flush_but_dont_ignore) |
---|
8107 | return d |
---|
8108 | |
---|
8109 | + def workdir(self, name): |
---|
8110 | + return os.path.join("system", self.__class__.__name__, name) |
---|
8111 | + |
---|
8112 | def getdir(self, subdir): |
---|
8113 | return os.path.join(self.basedir, subdir) |
---|
8114 | |
---|
8115 | hunk ./src/allmydata/test/common.py 596 |
---|
8116 | config += "web.port = tcp:0:interface=127.0.0.1\n" |
---|
8117 | config += "timeout.disconnect = 1800\n" |
---|
8118 | |
---|
8119 | - fileutil.write(os.path.join(basedir, 'tahoe.cfg'), config) |
---|
8120 | + # give subclasses a chance to append lines to the nodes' tahoe.cfg files. |
---|
8121 | + config += self._get_extra_config(i) |
---|
8122 | |
---|
8123 | hunk ./src/allmydata/test/common.py 599 |
---|
8124 | - # give subclasses a chance to append lines to the node's tahoe.cfg |
---|
8125 | - # files before they are launched. |
---|
8126 | - self._set_up_nodes_extra_config() |
---|
8127 | + fileutil.write(os.path.join(basedir, 'tahoe.cfg'), config) |
---|
8128 | |
---|
8129 | # start clients[0], wait for it's tub to be ready (at which point it |
---|
8130 | # will have registered the helper furl). |
---|
8131 | hunk ./src/allmydata/test/common.py 637 |
---|
8132 | d.addCallback(_connected) |
---|
8133 | return d |
---|
8134 | |
---|
8135 | - def _set_up_nodes_extra_config(self): |
---|
8136 | + def _get_extra_config(self, i): |
---|
8137 | # for overriding by subclasses |
---|
8138 | hunk ./src/allmydata/test/common.py 639 |
---|
8139 | - pass |
---|
8140 | + return "" |
---|
8141 | |
---|
8142 | def _grab_stats(self, res): |
---|
8143 | d = self.stats_gatherer.poll() |
---|
8144 | hunk ./src/allmydata/test/common.py 1299 |
---|
8145 | |
---|
8146 | def _corrupt_mutable_share_data(data, debug=False): |
---|
8147 | prefix = data[:32] |
---|
8148 | - assert prefix == MutableShareFile.MAGIC, "This function is designed to corrupt mutable shares of v1, and the magic number doesn't look right: %r vs %r" % (prefix, MutableShareFile.MAGIC) |
---|
8149 | - data_offset = MutableShareFile.DATA_OFFSET |
---|
8150 | + assert prefix == MutableDiskShare.MAGIC, "This function is designed to corrupt mutable shares of v1, and the magic number doesn't look right: %r vs %r" % (prefix, MutableDiskShare.MAGIC) |
---|
8151 | + data_offset = MutableDiskShare.DATA_OFFSET |
---|
8152 | sharetype = data[data_offset:data_offset+1] |
---|
8153 | assert sharetype == "\x00", "non-SDMF mutable shares not supported" |
---|
8154 | (version, ig_seqnum, ig_roothash, ig_IV, ig_k, ig_N, ig_segsize, |
---|
8155 | hunk ./src/allmydata/test/no_network.py 21 |
---|
8156 | from twisted.application import service |
---|
8157 | from twisted.internet import defer, reactor |
---|
8158 | from twisted.python.failure import Failure |
---|
8159 | +from twisted.python.filepath import FilePath |
---|
8160 | from foolscap.api import Referenceable, fireEventually, RemoteException |
---|
8161 | from base64 import b32encode |
---|
8162 | |
---|
8163 | hunk ./src/allmydata/test/no_network.py 27 |
---|
8164 | from allmydata import uri as tahoe_uri |
---|
8165 | from allmydata.client import Client |
---|
8166 | -from allmydata.storage.server import StorageServer, storage_index_to_dir |
---|
8167 | +from allmydata.storage.server import StorageServer |
---|
8168 | +from allmydata.storage.backends.disk.disk_backend import DiskBackend |
---|
8169 | from allmydata.util import fileutil, idlib, hashutil |
---|
8170 | from allmydata.util.hashutil import sha1 |
---|
8171 | from allmydata.test.common_web import HTTPClientGETFactory |
---|
8172 | hunk ./src/allmydata/test/no_network.py 36 |
---|
8173 | from allmydata.test.common import TEST_RSA_KEY_SIZE |
---|
8174 | |
---|
8175 | |
---|
8176 | +PRINT_TRACEBACKS = False |
---|
8177 | + |
---|
8178 | class IntentionalError(Exception): |
---|
8179 | pass |
---|
8180 | |
---|
8181 | hunk ./src/allmydata/test/no_network.py 87 |
---|
8182 | return d2 |
---|
8183 | return _really_call() |
---|
8184 | |
---|
8185 | + if PRINT_TRACEBACKS: |
---|
8186 | + import traceback |
---|
8187 | + tb = traceback.extract_stack() |
---|
8188 | d = fireEventually() |
---|
8189 | d.addCallback(lambda res: _call()) |
---|
8190 | def _wrap_exception(f): |
---|
8191 | hunk ./src/allmydata/test/no_network.py 93 |
---|
8192 | + if PRINT_TRACEBACKS and not f.check(NameError): |
---|
8193 | + print ">>>" + ">>>".join(traceback.format_list(tb)) |
---|
8194 | + print "+++ %s%r %r: %s" % (methname, args, kwargs, f) |
---|
8195 | + #f.printDetailedTraceback() |
---|
8196 | return Failure(RemoteException(f)) |
---|
8197 | d.addErrback(_wrap_exception) |
---|
8198 | def _return_membrane(res): |
---|
8199 | hunk ./src/allmydata/test/no_network.py 105 |
---|
8200 | # objects that cross the simulated wire and replace them with |
---|
8201 | # wrappers), we special-case certain methods that we happen to |
---|
8202 | # know will return Referenceables. |
---|
8203 | + # The outer return value of such a method may be Deferred, but |
---|
8204 | + # its components must not be. |
---|
8205 | if methname == "allocate_buckets": |
---|
8206 | (alreadygot, allocated) = res |
---|
8207 | for shnum in allocated: |
---|
8208 | hunk ./src/allmydata/test/no_network.py 110 |
---|
8209 | + assert not isinstance(allocated[shnum], defer.Deferred), (methname, allocated) |
---|
8210 | allocated[shnum] = LocalWrapper(allocated[shnum]) |
---|
8211 | if methname == "get_buckets": |
---|
8212 | for shnum in res: |
---|
8213 | hunk ./src/allmydata/test/no_network.py 114 |
---|
8214 | + assert not isinstance(res[shnum], defer.Deferred), (methname, res) |
---|
8215 | res[shnum] = LocalWrapper(res[shnum]) |
---|
8216 | return res |
---|
8217 | d.addCallback(_return_membrane) |
---|
8218 | hunk ./src/allmydata/test/no_network.py 178 |
---|
8219 | def get_nickname_for_serverid(self, serverid): |
---|
8220 | return None |
---|
8221 | |
---|
8222 | + def get_known_servers(self): |
---|
8223 | + return self.get_connected_servers() |
---|
8224 | + |
---|
8225 | + def get_all_serverids(self): |
---|
8226 | + return self.client.get_all_serverids() |
---|
8227 | + |
---|
8228 | + |
---|
8229 | class NoNetworkClient(Client): |
---|
8230 | def create_tub(self): |
---|
8231 | pass |
---|
8232 | hunk ./src/allmydata/test/no_network.py 278 |
---|
8233 | |
---|
8234 | def make_server(self, i, readonly=False): |
---|
8235 | serverid = hashutil.tagged_hash("serverid", str(i))[:20] |
---|
8236 | - serverdir = os.path.join(self.basedir, "servers", |
---|
8237 | - idlib.shortnodeid_b2a(serverid), "storage") |
---|
8238 | - fileutil.make_dirs(serverdir) |
---|
8239 | - ss = StorageServer(serverdir, serverid, stats_provider=SimpleStats(), |
---|
8240 | - readonly_storage=readonly) |
---|
8241 | + storagedir = FilePath(self.basedir).child("servers").child(idlib.shortnodeid_b2a(serverid)).child("storage") |
---|
8242 | + |
---|
8243 | + # The backend will make the storage directory and any necessary parents. |
---|
8244 | + backend = DiskBackend(storagedir, readonly=readonly) |
---|
8245 | + ss = StorageServer(serverid, backend, storagedir, stats_provider=SimpleStats()) |
---|
8246 | ss._no_network_server_number = i |
---|
8247 | return ss |
---|
8248 | |
---|
8249 | hunk ./src/allmydata/test/no_network.py 292 |
---|
8250 | middleman = service.MultiService() |
---|
8251 | middleman.setServiceParent(self) |
---|
8252 | ss.setServiceParent(middleman) |
---|
8253 | - serverid = ss.my_nodeid |
---|
8254 | + serverid = ss.get_serverid() |
---|
8255 | self.servers_by_number[i] = ss |
---|
8256 | wrapper = wrap_storage_server(ss) |
---|
8257 | self.wrappers_by_id[serverid] = wrapper |
---|
8258 | hunk ./src/allmydata/test/no_network.py 311 |
---|
8259 | # it's enough to remove the server from c._servers (we don't actually |
---|
8260 | # have to detach and stopService it) |
---|
8261 | for i,ss in self.servers_by_number.items(): |
---|
8262 | - if ss.my_nodeid == serverid: |
---|
8263 | + if ss.get_serverid() == serverid: |
---|
8264 | del self.servers_by_number[i] |
---|
8265 | break |
---|
8266 | del self.wrappers_by_id[serverid] |
---|
8267 | hunk ./src/allmydata/test/no_network.py 361 |
---|
8268 | def get_clientdir(self, i=0): |
---|
8269 | return self.g.clients[i].basedir |
---|
8270 | |
---|
8271 | + def get_server(self, i): |
---|
8272 | + return self.g.servers_by_number[i] |
---|
8273 | + |
---|
8274 | def get_serverdir(self, i): |
---|
8275 | hunk ./src/allmydata/test/no_network.py 365 |
---|
8276 | - return self.g.servers_by_number[i].storedir |
---|
8277 | + return self.g.servers_by_number[i].backend._storedir |
---|
8278 | + |
---|
8279 | + def remove_server(self, i): |
---|
8280 | + self.g.remove_server(self.g.servers_by_number[i].get_serverid()) |
---|
8281 | |
---|
8282 | def iterate_servers(self): |
---|
8283 | for i in sorted(self.g.servers_by_number.keys()): |
---|
8284 | hunk ./src/allmydata/test/no_network.py 373 |
---|
8285 | ss = self.g.servers_by_number[i] |
---|
8286 | - yield (i, ss, ss.storedir) |
---|
8287 | + yield (i, ss, ss.backend._storedir) |
---|
8288 | |
---|
8289 | def find_uri_shares(self, uri): |
---|
8290 | si = tahoe_uri.from_string(uri).get_storage_index() |
---|
8291 | hunk ./src/allmydata/test/no_network.py 377 |
---|
8292 | - prefixdir = storage_index_to_dir(si) |
---|
8293 | - shares = [] |
---|
8294 | - for i,ss in self.g.servers_by_number.items(): |
---|
8295 | - serverid = ss.my_nodeid |
---|
8296 | - basedir = os.path.join(ss.sharedir, prefixdir) |
---|
8297 | - if not os.path.exists(basedir): |
---|
8298 | - continue |
---|
8299 | - for f in os.listdir(basedir): |
---|
8300 | - try: |
---|
8301 | - shnum = int(f) |
---|
8302 | - shares.append((shnum, serverid, os.path.join(basedir, f))) |
---|
8303 | - except ValueError: |
---|
8304 | - pass |
---|
8305 | - return sorted(shares) |
---|
8306 | + sharelist = [] |
---|
8307 | + d = defer.succeed(None) |
---|
8308 | + for i, ss in self.g.servers_by_number.items(): |
---|
8309 | + d.addCallback(lambda ign, ss=ss: ss.backend.get_shareset(si).get_shares()) |
---|
8310 | + def _append_shares( (shares_for_server, corrupted), ss=ss): |
---|
8311 | + assert len(corrupted) == 0, (shares_for_server, corrupted) |
---|
8312 | + for share in shares_for_server: |
---|
8313 | + assert not isinstance(share, defer.Deferred), share |
---|
8314 | + sharelist.append( (share.get_shnum(), ss.get_serverid(), share._get_filepath()) ) |
---|
8315 | + d.addCallback(_append_shares) |
---|
8316 | + |
---|
8317 | + d.addCallback(lambda ign: sorted(sharelist)) |
---|
8318 | + return d |
---|
8319 | + |
---|
8320 | + def count_leases(self, uri): |
---|
8321 | + """Return (filename, leasecount) pairs in arbitrary order.""" |
---|
8322 | + si = tahoe_uri.from_string(uri).get_storage_index() |
---|
8323 | + lease_counts = [] |
---|
8324 | + d = defer.succeed(None) |
---|
8325 | + for i, ss in self.g.servers_by_number.items(): |
---|
8326 | + d.addCallback(lambda ign, ss=ss: ss.backend.get_shareset(si).get_shares()) |
---|
8327 | + def _append_counts( (shares_for_server, corrupted) ): |
---|
8328 | + assert len(corrupted) == 0, (shares_for_server, corrupted) |
---|
8329 | + for share in shares_for_server: |
---|
8330 | + num_leases = len(list(share.get_leases())) |
---|
8331 | + lease_counts.append( (share._get_filepath().path, num_leases) ) |
---|
8332 | + d.addCallback(_append_counts) |
---|
8333 | + |
---|
8334 | + d.addCallback(lambda ign: lease_counts) |
---|
8335 | + return d |
---|
8336 | |
---|
8337 | def copy_shares(self, uri): |
---|
8338 | shares = {} |
---|
8339 | hunk ./src/allmydata/test/no_network.py 410 |
---|
8340 | - for (shnum, serverid, sharefile) in self.find_uri_shares(uri): |
---|
8341 | - shares[sharefile] = open(sharefile, "rb").read() |
---|
8342 | - return shares |
---|
8343 | + d = self.find_uri_shares(uri) |
---|
8344 | + def _got_shares(sharelist): |
---|
8345 | + for (shnum, serverid, sharefp) in sharelist: |
---|
8346 | + shares[sharefp.path] = sharefp.getContent() |
---|
8347 | + |
---|
8348 | + return shares |
---|
8349 | + d.addCallback(_got_shares) |
---|
8350 | + return d |
---|
8351 | + |
---|
8352 | + def copy_share(self, from_share, uri, to_server): |
---|
8353 | + si = tahoe_uri.from_string(uri).get_storage_index() |
---|
8354 | + (i_shnum, i_serverid, i_sharefp) = from_share |
---|
8355 | + shares_dir = to_server.backend.get_shareset(si)._get_sharedir() |
---|
8356 | + fileutil.fp_make_dirs(shares_dir) |
---|
8357 | + i_sharefp.copyTo(shares_dir.child(str(i_shnum))) |
---|
8358 | |
---|
8359 | def restore_all_shares(self, shares): |
---|
8360 | hunk ./src/allmydata/test/no_network.py 427 |
---|
8361 | - for sharefile, data in shares.items(): |
---|
8362 | - open(sharefile, "wb").write(data) |
---|
8363 | + for sharepath, data in shares.items(): |
---|
8364 | + FilePath(sharepath).setContent(data) |
---|
8365 | |
---|
8366 | hunk ./src/allmydata/test/no_network.py 430 |
---|
8367 | - def delete_share(self, (shnum, serverid, sharefile)): |
---|
8368 | - os.unlink(sharefile) |
---|
8369 | + def delete_share(self, (shnum, serverid, sharefp)): |
---|
8370 | + sharefp.remove() |
---|
8371 | |
---|
8372 | def delete_shares_numbered(self, uri, shnums): |
---|
8373 | hunk ./src/allmydata/test/no_network.py 434 |
---|
8374 | - for (i_shnum, i_serverid, i_sharefile) in self.find_uri_shares(uri): |
---|
8375 | - if i_shnum in shnums: |
---|
8376 | - os.unlink(i_sharefile) |
---|
8377 | + d = self.find_uri_shares(uri) |
---|
8378 | + def _got_shares(sharelist): |
---|
8379 | + for (i_shnum, i_serverid, i_sharefp) in sharelist: |
---|
8380 | + if i_shnum in shnums: |
---|
8381 | + i_sharefp.remove() |
---|
8382 | + d.addCallback(_got_shares) |
---|
8383 | + return d |
---|
8384 | + |
---|
8385 | + def delete_all_shares(self, uri): |
---|
8386 | + d = self.find_uri_shares(uri) |
---|
8387 | + def _got_shares(shares): |
---|
8388 | + for sh in shares: |
---|
8389 | + self.delete_share(sh) |
---|
8390 | + d.addCallback(_got_shares) |
---|
8391 | + return d |
---|
8392 | |
---|
8393 | hunk ./src/allmydata/test/no_network.py 450 |
---|
8394 | - def corrupt_share(self, (shnum, serverid, sharefile), corruptor_function): |
---|
8395 | - sharedata = open(sharefile, "rb").read() |
---|
8396 | - corruptdata = corruptor_function(sharedata) |
---|
8397 | - open(sharefile, "wb").write(corruptdata) |
---|
8398 | + def corrupt_share(self, (shnum, serverid, sharefp), corruptor_function, debug=False): |
---|
8399 | + sharedata = sharefp.getContent() |
---|
8400 | + corruptdata = corruptor_function(sharedata, debug=debug) |
---|
8401 | + sharefp.setContent(corruptdata) |
---|
8402 | |
---|
8403 | def corrupt_shares_numbered(self, uri, shnums, corruptor, debug=False): |
---|
8404 | hunk ./src/allmydata/test/no_network.py 456 |
---|
8405 | - for (i_shnum, i_serverid, i_sharefile) in self.find_uri_shares(uri): |
---|
8406 | - if i_shnum in shnums: |
---|
8407 | - sharedata = open(i_sharefile, "rb").read() |
---|
8408 | - corruptdata = corruptor(sharedata, debug=debug) |
---|
8409 | - open(i_sharefile, "wb").write(corruptdata) |
---|
8410 | + d = self.find_uri_shares(uri) |
---|
8411 | + def _got_shares(sharelist): |
---|
8412 | + for (i_shnum, i_serverid, i_sharefp) in sharelist: |
---|
8413 | + if i_shnum in shnums: |
---|
8414 | + self.corrupt_share((i_shnum, i_serverid, i_sharefp), corruptor, debug=debug) |
---|
8415 | + d.addCallback(_got_shares) |
---|
8416 | + return d |
---|
8417 | |
---|
8418 | def corrupt_all_shares(self, uri, corruptor, debug=False): |
---|
8419 | hunk ./src/allmydata/test/no_network.py 465 |
---|
8420 | - for (i_shnum, i_serverid, i_sharefile) in self.find_uri_shares(uri): |
---|
8421 | - sharedata = open(i_sharefile, "rb").read() |
---|
8422 | - corruptdata = corruptor(sharedata, debug=debug) |
---|
8423 | - open(i_sharefile, "wb").write(corruptdata) |
---|
8424 | + d = self.find_uri_shares(uri) |
---|
8425 | + def _got_shares(sharelist): |
---|
8426 | + for (i_shnum, i_serverid, i_sharefp) in sharelist: |
---|
8427 | + self.corrupt_share((i_shnum, i_serverid, i_sharefp), corruptor, debug=debug) |
---|
8428 | + d.addCallback(_got_shares) |
---|
8429 | + return d |
---|
8430 | |
---|
8431 | def GET(self, urlpath, followRedirect=False, return_response=False, |
---|
8432 | method="GET", clientnum=0, **kwargs): |
---|
8433 | hunk ./src/allmydata/test/test_cli.py 2901 |
---|
8434 | self.failUnlessReallyEqual(to_str(data["summary"]), "Healthy") |
---|
8435 | d.addCallback(_check2) |
---|
8436 | |
---|
8437 | - def _clobber_shares(ignored): |
---|
8438 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
8439 | + def _clobber_shares(shares): |
---|
8440 | # delete one, corrupt a second |
---|
8441 | hunk ./src/allmydata/test/test_cli.py 2904 |
---|
8442 | - shares = self.find_uri_shares(self.uri) |
---|
8443 | self.failUnlessReallyEqual(len(shares), 10) |
---|
8444 | hunk ./src/allmydata/test/test_cli.py 2905 |
---|
8445 | - os.unlink(shares[0][2]) |
---|
8446 | - cso = debug.CorruptShareOptions() |
---|
8447 | - cso.stdout = StringIO() |
---|
8448 | - cso.parseOptions([shares[1][2]]) |
---|
8449 | + shares[0][2].remove() |
---|
8450 | + stdout = StringIO() |
---|
8451 | + sharefile = shares[1][2] |
---|
8452 | storage_index = uri.from_string(self.uri).get_storage_index() |
---|
8453 | self._corrupt_share_line = " server %s, SI %s, shnum %d" % \ |
---|
8454 | (base32.b2a(shares[1][1]), |
---|
8455 | hunk ./src/allmydata/test/test_cli.py 2913 |
---|
8456 | base32.b2a(storage_index), |
---|
8457 | shares[1][0]) |
---|
8458 | - debug.corrupt_share(cso) |
---|
8459 | + debug.do_corrupt_share(stdout, sharefile) |
---|
8460 | d.addCallback(_clobber_shares) |
---|
8461 | |
---|
8462 | d.addCallback(lambda ign: self.do_cli("check", "--verify", self.uri)) |
---|
8463 | hunk ./src/allmydata/test/test_cli.py 3027 |
---|
8464 | self.failUnlessIn(" 317-1000 : 1 (1000 B, 1000 B)", lines) |
---|
8465 | d.addCallback(_check_stats) |
---|
8466 | |
---|
8467 | - def _clobber_shares(ignored): |
---|
8468 | - shares = self.find_uri_shares(self.uris[u"g\u00F6\u00F6d"]) |
---|
8469 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris[u"g\u00F6\u00F6d"])) |
---|
8470 | + def _clobber_shares(shares): |
---|
8471 | self.failUnlessReallyEqual(len(shares), 10) |
---|
8472 | hunk ./src/allmydata/test/test_cli.py 3030 |
---|
8473 | - os.unlink(shares[0][2]) |
---|
8474 | + shares[0][2].remove() |
---|
8475 | + d.addCallback(_clobber_shares) |
---|
8476 | |
---|
8477 | hunk ./src/allmydata/test/test_cli.py 3033 |
---|
8478 | - shares = self.find_uri_shares(self.uris["mutable"]) |
---|
8479 | - cso = debug.CorruptShareOptions() |
---|
8480 | - cso.stdout = StringIO() |
---|
8481 | - cso.parseOptions([shares[1][2]]) |
---|
8482 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["mutable"])) |
---|
8483 | + def _clobber_mutable_shares(shares): |
---|
8484 | + stdout = StringIO() |
---|
8485 | + sharefile = shares[1][2] |
---|
8486 | storage_index = uri.from_string(self.uris["mutable"]).get_storage_index() |
---|
8487 | self._corrupt_share_line = " corrupt: server %s, SI %s, shnum %d" % \ |
---|
8488 | (base32.b2a(shares[1][1]), |
---|
8489 | hunk ./src/allmydata/test/test_cli.py 3042 |
---|
8490 | base32.b2a(storage_index), |
---|
8491 | shares[1][0]) |
---|
8492 | - debug.corrupt_share(cso) |
---|
8493 | - d.addCallback(_clobber_shares) |
---|
8494 | + debug.do_corrupt_share(stdout, sharefile) |
---|
8495 | + d.addCallback(_clobber_mutable_shares) |
---|
8496 | |
---|
8497 | # root |
---|
8498 | # root/g\u00F6\u00F6d [9 shares] |
---|
8499 | hunk ./src/allmydata/test/test_client.py 6 |
---|
8500 | from twisted.application import service |
---|
8501 | |
---|
8502 | import allmydata |
---|
8503 | -from allmydata.node import OldConfigError |
---|
8504 | +from allmydata.node import OldConfigError, InvalidValueError, MissingConfigEntry |
---|
8505 | from allmydata import client |
---|
8506 | from allmydata.storage_client import StorageFarmBroker |
---|
8507 | hunk ./src/allmydata/test/test_client.py 9 |
---|
8508 | +from allmydata.storage.backends.disk.disk_backend import DiskBackend |
---|
8509 | +from allmydata.storage.backends.s3.s3_backend import S3Backend |
---|
8510 | from allmydata.util import base32, fileutil |
---|
8511 | from allmydata.interfaces import IFilesystemNode, IFileNode, \ |
---|
8512 | IImmutableFileNode, IMutableFileNode, IDirectoryNode |
---|
8513 | hunk ./src/allmydata/test/test_client.py 31 |
---|
8514 | def test_loadable(self): |
---|
8515 | basedir = "test_client.Basic.test_loadable" |
---|
8516 | os.mkdir(basedir) |
---|
8517 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
8518 | - BASECONFIG) |
---|
8519 | - client.Client(basedir) |
---|
8520 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8521 | + BASECONFIG) |
---|
8522 | + c = client.Client(basedir) |
---|
8523 | + server = c.getServiceNamed("storage") |
---|
8524 | + self.failUnless(isinstance(server.backend, DiskBackend), server.backend) |
---|
8525 | |
---|
8526 | @mock.patch('twisted.python.log.msg') |
---|
8527 | def test_error_on_old_config_files(self, mock_log_msg): |
---|
8528 | hunk ./src/allmydata/test/test_client.py 94 |
---|
8529 | "enabled = true\n" + |
---|
8530 | "reserved_space = 1000\n") |
---|
8531 | c = client.Client(basedir) |
---|
8532 | - self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 1000) |
---|
8533 | + server = c.getServiceNamed("storage") |
---|
8534 | + self.failUnlessReallyEqual(server.backend._reserved_space, 1000) |
---|
8535 | |
---|
8536 | def test_reserved_2(self): |
---|
8537 | basedir = "client.Basic.test_reserved_2" |
---|
8538 | hunk ./src/allmydata/test/test_client.py 106 |
---|
8539 | "enabled = true\n" + |
---|
8540 | "reserved_space = 10K\n") |
---|
8541 | c = client.Client(basedir) |
---|
8542 | - self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000) |
---|
8543 | + server = c.getServiceNamed("storage") |
---|
8544 | + self.failUnlessReallyEqual(server.backend._reserved_space, 10*1000) |
---|
8545 | |
---|
8546 | def test_reserved_3(self): |
---|
8547 | basedir = "client.Basic.test_reserved_3" |
---|
8548 | hunk ./src/allmydata/test/test_client.py 118 |
---|
8549 | "enabled = true\n" + |
---|
8550 | "reserved_space = 5mB\n") |
---|
8551 | c = client.Client(basedir) |
---|
8552 | - self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, |
---|
8553 | - 5*1000*1000) |
---|
8554 | + server = c.getServiceNamed("storage") |
---|
8555 | + self.failUnlessReallyEqual(server.backend._reserved_space, 5*1000*1000) |
---|
8556 | |
---|
8557 | def test_reserved_4(self): |
---|
8558 | basedir = "client.Basic.test_reserved_4" |
---|
8559 | hunk ./src/allmydata/test/test_client.py 124 |
---|
8560 | os.mkdir(basedir) |
---|
8561 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
8562 | - BASECONFIG + \ |
---|
8563 | - "[storage]\n" + \ |
---|
8564 | - "enabled = true\n" + \ |
---|
8565 | - "reserved_space = 78Gb\n") |
---|
8566 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8567 | + BASECONFIG + |
---|
8568 | + "[storage]\n" + |
---|
8569 | + "enabled = true\n" + |
---|
8570 | + "reserved_space = 78Gb\n") |
---|
8571 | + c = client.Client(basedir) |
---|
8572 | + server = c.getServiceNamed("storage") |
---|
8573 | + self.failUnlessReallyEqual(server.backend._reserved_space, 78*1000*1000*1000) |
---|
8574 | + |
---|
8575 | + def test_reserved_default(self): |
---|
8576 | + # This is testing the default when 'reserved_space' is not present, not |
---|
8577 | + # the default for a newly created node. |
---|
8578 | + basedir = "client.Basic.test_reserved_default" |
---|
8579 | + os.mkdir(basedir) |
---|
8580 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8581 | + BASECONFIG + |
---|
8582 | + "[storage]\n" + |
---|
8583 | + "enabled = true\n") |
---|
8584 | c = client.Client(basedir) |
---|
8585 | hunk ./src/allmydata/test/test_client.py 143 |
---|
8586 | - self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, |
---|
8587 | - 78*1000*1000*1000) |
---|
8588 | + server = c.getServiceNamed("storage") |
---|
8589 | + self.failUnlessReallyEqual(server.backend._reserved_space, 0) |
---|
8590 | |
---|
8591 | def test_reserved_bad(self): |
---|
8592 | basedir = "client.Basic.test_reserved_bad" |
---|
8593 | hunk ./src/allmydata/test/test_client.py 149 |
---|
8594 | os.mkdir(basedir) |
---|
8595 | - fileutil.write(os.path.join(basedir, "tahoe.cfg"), \ |
---|
8596 | - BASECONFIG + \ |
---|
8597 | - "[storage]\n" + \ |
---|
8598 | - "enabled = true\n" + \ |
---|
8599 | - "reserved_space = bogus\n") |
---|
8600 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8601 | + BASECONFIG + |
---|
8602 | + "[storage]\n" + |
---|
8603 | + "enabled = true\n" + |
---|
8604 | + "reserved_space = bogus\n") |
---|
8605 | + self.failUnlessRaises(InvalidValueError, client.Client, basedir) |
---|
8606 | + |
---|
8607 | + def _write_s3secret(self, basedir, secret="dummy"): |
---|
8608 | + os.mkdir(os.path.join(basedir, "private")) |
---|
8609 | + fileutil.write(os.path.join(basedir, "private", "s3secret"), secret) |
---|
8610 | + |
---|
8611 | + @mock.patch('allmydata.storage.backends.s3.s3_bucket.S3Bucket') |
---|
8612 | + def test_s3_config_good_defaults(self, mock_S3Bucket): |
---|
8613 | + basedir = "client.Basic.test_s3_config_good_defaults" |
---|
8614 | + os.mkdir(basedir) |
---|
8615 | + self._write_s3secret(basedir) |
---|
8616 | + config = (BASECONFIG + |
---|
8617 | + "[storage]\n" + |
---|
8618 | + "enabled = true\n" + |
---|
8619 | + "backend = s3\n" + |
---|
8620 | + "s3.access_key_id = keyid\n" + |
---|
8621 | + "s3.bucket = test\n") |
---|
8622 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), config) |
---|
8623 | + |
---|
8624 | + c = client.Client(basedir) |
---|
8625 | + mock_S3Bucket.assert_called_with("keyid", "dummy", "http://s3.amazonaws.com", "test", None, None) |
---|
8626 | + server = c.getServiceNamed("storage") |
---|
8627 | + self.failUnless(isinstance(server.backend, S3Backend), server.backend) |
---|
8628 | + |
---|
8629 | + mock_S3Bucket.reset_mock() |
---|
8630 | + fileutil.write(os.path.join(basedir, "private", "s3producttoken"), "{ProductToken}") |
---|
8631 | + self.failUnlessRaises(InvalidValueError, client.Client, basedir) |
---|
8632 | + |
---|
8633 | + mock_S3Bucket.reset_mock() |
---|
8634 | + fileutil.write(os.path.join(basedir, "private", "s3usertoken"), "{UserToken}") |
---|
8635 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), config + "s3.url = http://s3.example.com\n") |
---|
8636 | + |
---|
8637 | c = client.Client(basedir) |
---|
8638 | hunk ./src/allmydata/test/test_client.py 187 |
---|
8639 | - self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 0) |
---|
8640 | + mock_S3Bucket.assert_called_with("keyid", "dummy", "http://s3.example.com", "test", |
---|
8641 | + "{UserToken}", "{ProductToken}") |
---|
8642 | + |
---|
8643 | + def test_s3_readonly_bad(self): |
---|
8644 | + basedir = "client.Basic.test_s3_readonly_bad" |
---|
8645 | + os.mkdir(basedir) |
---|
8646 | + self._write_s3secret(basedir) |
---|
8647 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8648 | + BASECONFIG + |
---|
8649 | + "[storage]\n" + |
---|
8650 | + "enabled = true\n" + |
---|
8651 | + "readonly = true\n" + |
---|
8652 | + "backend = s3\n" + |
---|
8653 | + "s3.access_key_id = keyid\n" + |
---|
8654 | + "s3.bucket = test\n") |
---|
8655 | + self.failUnlessRaises(InvalidValueError, client.Client, basedir) |
---|
8656 | + |
---|
8657 | + def test_s3_config_no_access_key_id(self): |
---|
8658 | + basedir = "client.Basic.test_s3_config_no_access_key_id" |
---|
8659 | + os.mkdir(basedir) |
---|
8660 | + self._write_s3secret(basedir) |
---|
8661 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8662 | + BASECONFIG + |
---|
8663 | + "[storage]\n" + |
---|
8664 | + "enabled = true\n" + |
---|
8665 | + "backend = s3\n" + |
---|
8666 | + "s3.bucket = test\n") |
---|
8667 | + self.failUnlessRaises(MissingConfigEntry, client.Client, basedir) |
---|
8668 | + |
---|
8669 | + def test_s3_config_no_bucket(self): |
---|
8670 | + basedir = "client.Basic.test_s3_config_no_bucket" |
---|
8671 | + os.mkdir(basedir) |
---|
8672 | + self._write_s3secret(basedir) |
---|
8673 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8674 | + BASECONFIG + |
---|
8675 | + "[storage]\n" + |
---|
8676 | + "enabled = true\n" + |
---|
8677 | + "backend = s3\n" + |
---|
8678 | + "s3.access_key_id = keyid\n") |
---|
8679 | + self.failUnlessRaises(MissingConfigEntry, client.Client, basedir) |
---|
8680 | + |
---|
8681 | + def test_s3_config_no_s3secret(self): |
---|
8682 | + basedir = "client.Basic.test_s3_config_no_s3secret" |
---|
8683 | + os.mkdir(basedir) |
---|
8684 | + fileutil.write(os.path.join(basedir, "tahoe.cfg"), |
---|
8685 | + BASECONFIG + |
---|
8686 | + "[storage]\n" + |
---|
8687 | + "enabled = true\n" + |
---|
8688 | + "backend = s3\n" + |
---|
8689 | + "s3.access_key_id = keyid\n" + |
---|
8690 | + "s3.bucket = test\n") |
---|
8691 | + self.failUnlessRaises(MissingConfigEntry, client.Client, basedir) |
---|
8692 | |
---|
8693 | def _permute(self, sb, key): |
---|
8694 | return [ s.get_longname() for s in sb.get_servers_for_psi(key) ] |
---|
8695 | hunk ./src/allmydata/test/test_crawler.py 3 |
---|
8696 | |
---|
8697 | import time |
---|
8698 | -import os.path |
---|
8699 | + |
---|
8700 | from twisted.trial import unittest |
---|
8701 | from twisted.application import service |
---|
8702 | from twisted.internet import defer |
---|
8703 | hunk ./src/allmydata/test/test_crawler.py 7 |
---|
8704 | +from twisted.python.filepath import FilePath |
---|
8705 | from foolscap.api import eventually, fireEventually |
---|
8706 | |
---|
8707 | hunk ./src/allmydata/test/test_crawler.py 10 |
---|
8708 | -from allmydata.util import fileutil, hashutil, pollmixin |
---|
8709 | +from allmydata.util import hashutil, pollmixin |
---|
8710 | from allmydata.storage.server import StorageServer, si_b2a |
---|
8711 | from allmydata.storage.crawler import ShareCrawler, TimeSliceExceeded |
---|
8712 | hunk ./src/allmydata/test/test_crawler.py 13 |
---|
8713 | +from allmydata.storage.backends.disk.disk_backend import DiskBackend |
---|
8714 | |
---|
8715 | from allmydata.test.test_storage import FakeCanary |
---|
8716 | from allmydata.test.common_util import StallMixin |
---|
8717 | hunk ./src/allmydata/test/test_crawler.py 26 |
---|
8718 | ShareCrawler.__init__(self, *args, **kwargs) |
---|
8719 | self.all_buckets = [] |
---|
8720 | self.finished_d = defer.Deferred() |
---|
8721 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
8722 | - self.all_buckets.append(storage_index_b32) |
---|
8723 | + |
---|
8724 | + def process_shareset(self, cycle, prefix, shareset, *args, **kwargs): |
---|
8725 | + self.all_buckets.append(shareset.get_storage_index_string()) |
---|
8726 | + |
---|
8727 | def finished_cycle(self, cycle): |
---|
8728 | eventually(self.finished_d.callback, None) |
---|
8729 | |
---|
8730 | hunk ./src/allmydata/test/test_crawler.py 44 |
---|
8731 | self.all_buckets = [] |
---|
8732 | self.finished_d = defer.Deferred() |
---|
8733 | self.yield_cb = None |
---|
8734 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
8735 | - self.all_buckets.append(storage_index_b32) |
---|
8736 | + |
---|
8737 | + def process_shareset(self, cycle, prefix, shareset, *args, **kwargs): |
---|
8738 | + self.all_buckets.append(shareset.get_storage_index_string()) |
---|
8739 | self.countdown -= 1 |
---|
8740 | if self.countdown == 0: |
---|
8741 | # force a timeout. We restore it in yielding() |
---|
8742 | hunk ./src/allmydata/test/test_crawler.py 72 |
---|
8743 | self.accumulated = 0.0 |
---|
8744 | self.cycles = 0 |
---|
8745 | self.last_yield = 0.0 |
---|
8746 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
8747 | + |
---|
8748 | + def process_shareset(self, *args, **kwargs): |
---|
8749 | start = time.time() |
---|
8750 | time.sleep(0.05) |
---|
8751 | elapsed = time.time() - start |
---|
8752 | hunk ./src/allmydata/test/test_crawler.py 95 |
---|
8753 | ShareCrawler.__init__(self, *args, **kwargs) |
---|
8754 | self.counter = 0 |
---|
8755 | self.finished_d = defer.Deferred() |
---|
8756 | - def process_bucket(self, cycle, prefix, prefixdir, storage_index_b32): |
---|
8757 | + |
---|
8758 | + def process_shareset(self, *args, **kwargs): |
---|
8759 | self.counter += 1 |
---|
8760 | |
---|
8761 | def finished_cycle(self, cycle): |
---|
8762 | hunk ./src/allmydata/test/test_crawler.py 124 |
---|
8763 | def write(self, i, ss, serverid, tail=0): |
---|
8764 | si = self.si(i) |
---|
8765 | si = si[:-1] + chr(tail) |
---|
8766 | - had,made = ss.remote_allocate_buckets(si, |
---|
8767 | - self.rs(i, serverid), |
---|
8768 | - self.cs(i, serverid), |
---|
8769 | - set([0]), 99, FakeCanary()) |
---|
8770 | - made[0].remote_write(0, "data") |
---|
8771 | - made[0].remote_close() |
---|
8772 | - return si_b2a(si) |
---|
8773 | + d = defer.succeed(None) |
---|
8774 | + d.addCallback(lambda ign: ss.remote_allocate_buckets(si, |
---|
8775 | + self.rs(i, serverid), |
---|
8776 | + self.cs(i, serverid), |
---|
8777 | + set([0]), 99, FakeCanary())) |
---|
8778 | + def _allocated( (had, made) ): |
---|
8779 | + d2 = defer.succeed(None) |
---|
8780 | + d2.addCallback(lambda ign: made[0].remote_write(0, "data")) |
---|
8781 | + d2.addCallback(lambda ign: made[0].remote_close()) |
---|
8782 | + d2.addCallback(lambda ign: si_b2a(si)) |
---|
8783 | + return d2 |
---|
8784 | + d.addCallback(_allocated) |
---|
8785 | + return d |
---|
8786 | |
---|
8787 | def test_immediate(self): |
---|
8788 | self.basedir = "crawler/Basic/immediate" |
---|
8789 | hunk ./src/allmydata/test/test_crawler.py 140 |
---|
8790 | - fileutil.make_dirs(self.basedir) |
---|
8791 | serverid = "\x00" * 20 |
---|
8792 | hunk ./src/allmydata/test/test_crawler.py 141 |
---|
8793 | - ss = StorageServer(self.basedir, serverid) |
---|
8794 | + fp = FilePath(self.basedir) |
---|
8795 | + backend = DiskBackend(fp) |
---|
8796 | + ss = StorageServer(serverid, backend, fp) |
---|
8797 | ss.setServiceParent(self.s) |
---|
8798 | |
---|
8799 | hunk ./src/allmydata/test/test_crawler.py 146 |
---|
8800 | - sis = [self.write(i, ss, serverid) for i in range(10)] |
---|
8801 | - statefile = os.path.join(self.basedir, "statefile") |
---|
8802 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(10)]) |
---|
8803 | + def _done_writes(sis): |
---|
8804 | + statefp = fp.child("statefile") |
---|
8805 | |
---|
8806 | hunk ./src/allmydata/test/test_crawler.py 150 |
---|
8807 | - c = BucketEnumeratingCrawler(ss, statefile, allowed_cpu_percentage=.1) |
---|
8808 | - c.load_state() |
---|
8809 | + c = BucketEnumeratingCrawler(backend, statefp, allowed_cpu_percentage=.1) |
---|
8810 | + c.load_state() |
---|
8811 | |
---|
8812 | hunk ./src/allmydata/test/test_crawler.py 153 |
---|
8813 | - c.start_current_prefix(time.time()) |
---|
8814 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8815 | + c.start_current_prefix(time.time()) |
---|
8816 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8817 | |
---|
8818 | hunk ./src/allmydata/test/test_crawler.py 156 |
---|
8819 | - # make sure the statefile has been returned to the starting point |
---|
8820 | - c.finished_d = defer.Deferred() |
---|
8821 | - c.all_buckets = [] |
---|
8822 | - c.start_current_prefix(time.time()) |
---|
8823 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8824 | + # make sure the statefile has been returned to the starting point |
---|
8825 | + c.finished_d = defer.Deferred() |
---|
8826 | + c.all_buckets = [] |
---|
8827 | + c.start_current_prefix(time.time()) |
---|
8828 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8829 | |
---|
8830 | hunk ./src/allmydata/test/test_crawler.py 162 |
---|
8831 | - # check that a new crawler picks up on the state file properly |
---|
8832 | - c2 = BucketEnumeratingCrawler(ss, statefile) |
---|
8833 | - c2.load_state() |
---|
8834 | + # check that a new crawler picks up on the state file properly |
---|
8835 | + c2 = BucketEnumeratingCrawler(backend, statefp) |
---|
8836 | + c2.load_state() |
---|
8837 | |
---|
8838 | hunk ./src/allmydata/test/test_crawler.py 166 |
---|
8839 | - c2.start_current_prefix(time.time()) |
---|
8840 | - self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
8841 | + c2.start_current_prefix(time.time()) |
---|
8842 | + self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
8843 | + d.addCallback(_done_writes) |
---|
8844 | + return d |
---|
8845 | |
---|
8846 | def test_service(self): |
---|
8847 | self.basedir = "crawler/Basic/service" |
---|
8848 | hunk ./src/allmydata/test/test_crawler.py 173 |
---|
8849 | - fileutil.make_dirs(self.basedir) |
---|
8850 | serverid = "\x00" * 20 |
---|
8851 | hunk ./src/allmydata/test/test_crawler.py 174 |
---|
8852 | - ss = StorageServer(self.basedir, serverid) |
---|
8853 | + fp = FilePath(self.basedir) |
---|
8854 | + backend = DiskBackend(fp) |
---|
8855 | + ss = StorageServer(serverid, backend, fp) |
---|
8856 | ss.setServiceParent(self.s) |
---|
8857 | |
---|
8858 | hunk ./src/allmydata/test/test_crawler.py 179 |
---|
8859 | - sis = [self.write(i, ss, serverid) for i in range(10)] |
---|
8860 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(10)]) |
---|
8861 | + def _done_writes(sis): |
---|
8862 | + statefp = fp.child("statefile") |
---|
8863 | + c = BucketEnumeratingCrawler(backend, statefp) |
---|
8864 | + c.setServiceParent(self.s) |
---|
8865 | |
---|
8866 | hunk ./src/allmydata/test/test_crawler.py 185 |
---|
8867 | - statefile = os.path.join(self.basedir, "statefile") |
---|
8868 | - c = BucketEnumeratingCrawler(ss, statefile) |
---|
8869 | - c.setServiceParent(self.s) |
---|
8870 | - |
---|
8871 | - # it should be legal to call get_state() and get_progress() right |
---|
8872 | - # away, even before the first tick is performed. No work should have |
---|
8873 | - # been done yet. |
---|
8874 | - s = c.get_state() |
---|
8875 | - p = c.get_progress() |
---|
8876 | - self.failUnlessEqual(s["last-complete-prefix"], None) |
---|
8877 | - self.failUnlessEqual(s["current-cycle"], None) |
---|
8878 | - self.failUnlessEqual(p["cycle-in-progress"], False) |
---|
8879 | + # it should be legal to call get_state() and get_progress() right |
---|
8880 | + # away, even before the first tick is performed. No work should have |
---|
8881 | + # been done yet. |
---|
8882 | + s = c.get_state() |
---|
8883 | + p = c.get_progress() |
---|
8884 | + self.failUnlessEqual(s["last-complete-prefix"], None) |
---|
8885 | + self.failUnlessEqual(s["current-cycle"], None) |
---|
8886 | + self.failUnlessEqual(p["cycle-in-progress"], False) |
---|
8887 | |
---|
8888 | hunk ./src/allmydata/test/test_crawler.py 194 |
---|
8889 | - d = c.finished_d |
---|
8890 | - def _check(ignored): |
---|
8891 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8892 | - d.addCallback(_check) |
---|
8893 | + d2 = c.finished_d |
---|
8894 | + def _check(ignored): |
---|
8895 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8896 | + d2.addCallback(_check) |
---|
8897 | + return d2 |
---|
8898 | + d.addCallback(_done_writes) |
---|
8899 | return d |
---|
8900 | |
---|
8901 | def test_paced(self): |
---|
8902 | hunk ./src/allmydata/test/test_crawler.py 204 |
---|
8903 | self.basedir = "crawler/Basic/paced" |
---|
8904 | - fileutil.make_dirs(self.basedir) |
---|
8905 | serverid = "\x00" * 20 |
---|
8906 | hunk ./src/allmydata/test/test_crawler.py 205 |
---|
8907 | - ss = StorageServer(self.basedir, serverid) |
---|
8908 | + fp = FilePath(self.basedir) |
---|
8909 | + backend = DiskBackend(fp) |
---|
8910 | + ss = StorageServer(serverid, backend, fp) |
---|
8911 | ss.setServiceParent(self.s) |
---|
8912 | |
---|
8913 | hunk ./src/allmydata/test/test_crawler.py 210 |
---|
8914 | - # put four buckets in each prefixdir |
---|
8915 | - sis = [] |
---|
8916 | + # put four sharesets in each prefixdir |
---|
8917 | + d_sis = [] |
---|
8918 | for i in range(10): |
---|
8919 | for tail in range(4): |
---|
8920 | hunk ./src/allmydata/test/test_crawler.py 214 |
---|
8921 | - sis.append(self.write(i, ss, serverid, tail)) |
---|
8922 | + d_sis.append(self.write(i, ss, serverid, tail)) |
---|
8923 | + d = defer.gatherResults(d_sis) |
---|
8924 | + def _done_writes(sis): |
---|
8925 | + statefp = fp.child("statefile") |
---|
8926 | |
---|
8927 | hunk ./src/allmydata/test/test_crawler.py 219 |
---|
8928 | - statefile = os.path.join(self.basedir, "statefile") |
---|
8929 | - |
---|
8930 | - c = PacedCrawler(ss, statefile) |
---|
8931 | - c.load_state() |
---|
8932 | - try: |
---|
8933 | - c.start_current_prefix(time.time()) |
---|
8934 | - except TimeSliceExceeded: |
---|
8935 | - pass |
---|
8936 | - # that should stop in the middle of one of the buckets. Since we |
---|
8937 | - # aren't using its normal scheduler, we have to save its state |
---|
8938 | - # manually. |
---|
8939 | - c.save_state() |
---|
8940 | - c.cpu_slice = PacedCrawler.cpu_slice |
---|
8941 | - self.failUnlessEqual(len(c.all_buckets), 6) |
---|
8942 | - |
---|
8943 | - c.start_current_prefix(time.time()) # finish it |
---|
8944 | - self.failUnlessEqual(len(sis), len(c.all_buckets)) |
---|
8945 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8946 | + c = PacedCrawler(backend, statefp) |
---|
8947 | + c.load_state() |
---|
8948 | + try: |
---|
8949 | + c.start_current_prefix(time.time()) |
---|
8950 | + except TimeSliceExceeded: |
---|
8951 | + pass |
---|
8952 | + # that should stop in the middle of one of the sharesets. Since we |
---|
8953 | + # aren't using its normal scheduler, we have to save its state |
---|
8954 | + # manually. |
---|
8955 | + c.save_state() |
---|
8956 | + c.cpu_slice = PacedCrawler.cpu_slice |
---|
8957 | + self.failUnlessEqual(len(c.all_buckets), 6) |
---|
8958 | |
---|
8959 | hunk ./src/allmydata/test/test_crawler.py 232 |
---|
8960 | - # make sure the statefile has been returned to the starting point |
---|
8961 | - c.finished_d = defer.Deferred() |
---|
8962 | - c.all_buckets = [] |
---|
8963 | - c.start_current_prefix(time.time()) |
---|
8964 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8965 | - del c |
---|
8966 | + c.start_current_prefix(time.time()) # finish it |
---|
8967 | + self.failUnlessEqual(len(sis), len(c.all_buckets)) |
---|
8968 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8969 | |
---|
8970 | hunk ./src/allmydata/test/test_crawler.py 236 |
---|
8971 | - # start a new crawler, it should start from the beginning |
---|
8972 | - c = PacedCrawler(ss, statefile) |
---|
8973 | - c.load_state() |
---|
8974 | - try: |
---|
8975 | + # make sure the statefile has been returned to the starting point |
---|
8976 | + c.finished_d = defer.Deferred() |
---|
8977 | + c.all_buckets = [] |
---|
8978 | c.start_current_prefix(time.time()) |
---|
8979 | hunk ./src/allmydata/test/test_crawler.py 240 |
---|
8980 | - except TimeSliceExceeded: |
---|
8981 | - pass |
---|
8982 | - # that should stop in the middle of one of the buckets. Since we |
---|
8983 | - # aren't using its normal scheduler, we have to save its state |
---|
8984 | - # manually. |
---|
8985 | - c.save_state() |
---|
8986 | - c.cpu_slice = PacedCrawler.cpu_slice |
---|
8987 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
8988 | |
---|
8989 | hunk ./src/allmydata/test/test_crawler.py 242 |
---|
8990 | - # a third crawler should pick up from where it left off |
---|
8991 | - c2 = PacedCrawler(ss, statefile) |
---|
8992 | - c2.all_buckets = c.all_buckets[:] |
---|
8993 | - c2.load_state() |
---|
8994 | - c2.countdown = -1 |
---|
8995 | - c2.start_current_prefix(time.time()) |
---|
8996 | - self.failUnlessEqual(len(sis), len(c2.all_buckets)) |
---|
8997 | - self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
8998 | - del c, c2 |
---|
8999 | + # start a new crawler, it should start from the beginning |
---|
9000 | + c = PacedCrawler(backend, statefp) |
---|
9001 | + c.load_state() |
---|
9002 | + try: |
---|
9003 | + c.start_current_prefix(time.time()) |
---|
9004 | + except TimeSliceExceeded: |
---|
9005 | + pass |
---|
9006 | + # that should stop in the middle of one of the sharesets. Since we |
---|
9007 | + # aren't using its normal scheduler, we have to save its state |
---|
9008 | + # manually. |
---|
9009 | + c.save_state() |
---|
9010 | + c.cpu_slice = PacedCrawler.cpu_slice |
---|
9011 | |
---|
9012 | hunk ./src/allmydata/test/test_crawler.py 255 |
---|
9013 | - # now stop it at the end of a bucket (countdown=4), to exercise a |
---|
9014 | - # different place that checks the time |
---|
9015 | - c = PacedCrawler(ss, statefile) |
---|
9016 | - c.load_state() |
---|
9017 | - c.countdown = 4 |
---|
9018 | - try: |
---|
9019 | - c.start_current_prefix(time.time()) |
---|
9020 | - except TimeSliceExceeded: |
---|
9021 | - pass |
---|
9022 | - # that should stop at the end of one of the buckets. Again we must |
---|
9023 | - # save state manually. |
---|
9024 | - c.save_state() |
---|
9025 | - c.cpu_slice = PacedCrawler.cpu_slice |
---|
9026 | - self.failUnlessEqual(len(c.all_buckets), 4) |
---|
9027 | - c.start_current_prefix(time.time()) # finish it |
---|
9028 | - self.failUnlessEqual(len(sis), len(c.all_buckets)) |
---|
9029 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
9030 | - del c |
---|
9031 | + # a third crawler should pick up from where it left off |
---|
9032 | + c2 = PacedCrawler(backend, statefp) |
---|
9033 | + c2.all_buckets = c.all_buckets[:] |
---|
9034 | + c2.load_state() |
---|
9035 | + c2.countdown = -1 |
---|
9036 | + c2.start_current_prefix(time.time()) |
---|
9037 | + self.failUnlessEqual(len(sis), len(c2.all_buckets)) |
---|
9038 | + self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
9039 | + del c2 |
---|
9040 | |
---|
9041 | hunk ./src/allmydata/test/test_crawler.py 265 |
---|
9042 | - # stop it again at the end of the bucket, check that a new checker |
---|
9043 | - # picks up correctly |
---|
9044 | - c = PacedCrawler(ss, statefile) |
---|
9045 | - c.load_state() |
---|
9046 | - c.countdown = 4 |
---|
9047 | - try: |
---|
9048 | - c.start_current_prefix(time.time()) |
---|
9049 | - except TimeSliceExceeded: |
---|
9050 | - pass |
---|
9051 | - # that should stop at the end of one of the buckets. |
---|
9052 | - c.save_state() |
---|
9053 | + # now stop it at the end of a shareset (countdown=4), to exercise a |
---|
9054 | + # different place that checks the time |
---|
9055 | + c = PacedCrawler(backend, statefp) |
---|
9056 | + c.load_state() |
---|
9057 | + c.countdown = 4 |
---|
9058 | + try: |
---|
9059 | + c.start_current_prefix(time.time()) |
---|
9060 | + except TimeSliceExceeded: |
---|
9061 | + pass |
---|
9062 | + # that should stop at the end of one of the sharesets. Again we must |
---|
9063 | + # save state manually. |
---|
9064 | + c.save_state() |
---|
9065 | + c.cpu_slice = PacedCrawler.cpu_slice |
---|
9066 | + self.failUnlessEqual(len(c.all_buckets), 4) |
---|
9067 | + c.start_current_prefix(time.time()) # finish it |
---|
9068 | + self.failUnlessEqual(len(sis), len(c.all_buckets)) |
---|
9069 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
9070 | + |
---|
9071 | + # stop it again at the end of the shareset, check that a new checker |
---|
9072 | + # picks up correctly |
---|
9073 | + c = PacedCrawler(backend, statefp) |
---|
9074 | + c.load_state() |
---|
9075 | + c.countdown = 4 |
---|
9076 | + try: |
---|
9077 | + c.start_current_prefix(time.time()) |
---|
9078 | + except TimeSliceExceeded: |
---|
9079 | + pass |
---|
9080 | + # that should stop at the end of one of the sharesets. |
---|
9081 | + c.save_state() |
---|
9082 | |
---|
9083 | hunk ./src/allmydata/test/test_crawler.py 295 |
---|
9084 | - c2 = PacedCrawler(ss, statefile) |
---|
9085 | - c2.all_buckets = c.all_buckets[:] |
---|
9086 | - c2.load_state() |
---|
9087 | - c2.countdown = -1 |
---|
9088 | - c2.start_current_prefix(time.time()) |
---|
9089 | - self.failUnlessEqual(len(sis), len(c2.all_buckets)) |
---|
9090 | - self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
9091 | - del c, c2 |
---|
9092 | + c2 = PacedCrawler(backend, statefp) |
---|
9093 | + c2.all_buckets = c.all_buckets[:] |
---|
9094 | + c2.load_state() |
---|
9095 | + c2.countdown = -1 |
---|
9096 | + c2.start_current_prefix(time.time()) |
---|
9097 | + self.failUnlessEqual(len(sis), len(c2.all_buckets)) |
---|
9098 | + self.failUnlessEqual(sorted(sis), sorted(c2.all_buckets)) |
---|
9099 | + d.addCallback(_done_writes) |
---|
9100 | + return d |
---|
9101 | |
---|
9102 | def test_paced_service(self): |
---|
9103 | self.basedir = "crawler/Basic/paced_service" |
---|
9104 | hunk ./src/allmydata/test/test_crawler.py 307 |
---|
9105 | - fileutil.make_dirs(self.basedir) |
---|
9106 | serverid = "\x00" * 20 |
---|
9107 | hunk ./src/allmydata/test/test_crawler.py 308 |
---|
9108 | - ss = StorageServer(self.basedir, serverid) |
---|
9109 | + fp = FilePath(self.basedir) |
---|
9110 | + backend = DiskBackend(fp) |
---|
9111 | + ss = StorageServer(serverid, backend, fp) |
---|
9112 | ss.setServiceParent(self.s) |
---|
9113 | |
---|
9114 | hunk ./src/allmydata/test/test_crawler.py 313 |
---|
9115 | - sis = [self.write(i, ss, serverid) for i in range(10)] |
---|
9116 | - |
---|
9117 | - statefile = os.path.join(self.basedir, "statefile") |
---|
9118 | - c = PacedCrawler(ss, statefile) |
---|
9119 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(10)]) |
---|
9120 | + def _done_writes(sis): |
---|
9121 | + statefp = fp.child("statefile") |
---|
9122 | + c = PacedCrawler(backend, statefp) |
---|
9123 | |
---|
9124 | hunk ./src/allmydata/test/test_crawler.py 318 |
---|
9125 | - did_check_progress = [False] |
---|
9126 | - def check_progress(): |
---|
9127 | - c.yield_cb = None |
---|
9128 | - try: |
---|
9129 | - p = c.get_progress() |
---|
9130 | - self.failUnlessEqual(p["cycle-in-progress"], True) |
---|
9131 | - pct = p["cycle-complete-percentage"] |
---|
9132 | - # after 6 buckets, we happen to be at 76.17% complete. As |
---|
9133 | - # long as we create shares in deterministic order, this will |
---|
9134 | - # continue to be true. |
---|
9135 | - self.failUnlessEqual(int(pct), 76) |
---|
9136 | - left = p["remaining-sleep-time"] |
---|
9137 | - self.failUnless(isinstance(left, float), left) |
---|
9138 | - self.failUnless(left > 0.0, left) |
---|
9139 | - except Exception, e: |
---|
9140 | - did_check_progress[0] = e |
---|
9141 | - else: |
---|
9142 | - did_check_progress[0] = True |
---|
9143 | - c.yield_cb = check_progress |
---|
9144 | + did_check_progress = [False] |
---|
9145 | + def check_progress(): |
---|
9146 | + c.yield_cb = None |
---|
9147 | + try: |
---|
9148 | + p = c.get_progress() |
---|
9149 | + self.failUnlessEqual(p["cycle-in-progress"], True) |
---|
9150 | + pct = p["cycle-complete-percentage"] |
---|
9151 | + # after 6 sharesets, we happen to be at 76.17% complete. As |
---|
9152 | + # long as we create shares in deterministic order, this will |
---|
9153 | + # continue to be true. |
---|
9154 | + self.failUnlessEqual(int(pct), 76) |
---|
9155 | + left = p["remaining-sleep-time"] |
---|
9156 | + self.failUnless(isinstance(left, float), left) |
---|
9157 | + self.failUnless(left > 0.0, left) |
---|
9158 | + except Exception, e: |
---|
9159 | + did_check_progress[0] = e |
---|
9160 | + else: |
---|
9161 | + did_check_progress[0] = True |
---|
9162 | + c.yield_cb = check_progress |
---|
9163 | |
---|
9164 | hunk ./src/allmydata/test/test_crawler.py 338 |
---|
9165 | - c.setServiceParent(self.s) |
---|
9166 | - # that should get through 6 buckets, pause for a little while (and |
---|
9167 | - # run check_progress()), then resume |
---|
9168 | + c.setServiceParent(self.s) |
---|
9169 | + # that should get through 6 sharesets, pause for a little while (and |
---|
9170 | + # run check_progress()), then resume |
---|
9171 | |
---|
9172 | hunk ./src/allmydata/test/test_crawler.py 342 |
---|
9173 | - d = c.finished_d |
---|
9174 | - def _check(ignored): |
---|
9175 | - if did_check_progress[0] is not True: |
---|
9176 | - raise did_check_progress[0] |
---|
9177 | - self.failUnless(did_check_progress[0]) |
---|
9178 | - self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
9179 | - # at this point, the crawler should be sitting in the inter-cycle |
---|
9180 | - # timer, which should be pegged at the minumum cycle time |
---|
9181 | - self.failUnless(c.timer) |
---|
9182 | - self.failUnless(c.sleeping_between_cycles) |
---|
9183 | - self.failUnlessEqual(c.current_sleep_time, c.minimum_cycle_time) |
---|
9184 | + d2 = c.finished_d |
---|
9185 | + def _check(ignored): |
---|
9186 | + if did_check_progress[0] is not True: |
---|
9187 | + raise did_check_progress[0] |
---|
9188 | + self.failUnless(did_check_progress[0]) |
---|
9189 | + self.failUnlessEqual(sorted(sis), sorted(c.all_buckets)) |
---|
9190 | + # at this point, the crawler should be sitting in the inter-cycle |
---|
9191 | + # timer, which should be pegged at the minumum cycle time |
---|
9192 | + self.failUnless(c.timer) |
---|
9193 | + self.failUnless(c.sleeping_between_cycles) |
---|
9194 | + self.failUnlessEqual(c.current_sleep_time, c.minimum_cycle_time) |
---|
9195 | |
---|
9196 | hunk ./src/allmydata/test/test_crawler.py 354 |
---|
9197 | - p = c.get_progress() |
---|
9198 | - self.failUnlessEqual(p["cycle-in-progress"], False) |
---|
9199 | - naptime = p["remaining-wait-time"] |
---|
9200 | - self.failUnless(isinstance(naptime, float), naptime) |
---|
9201 | - # min-cycle-time is 300, so this is basically testing that it took |
---|
9202 | - # less than 290s to crawl |
---|
9203 | - self.failUnless(naptime > 10.0, naptime) |
---|
9204 | - soon = p["next-crawl-time"] - time.time() |
---|
9205 | - self.failUnless(soon > 10.0, soon) |
---|
9206 | + p = c.get_progress() |
---|
9207 | + self.failUnlessEqual(p["cycle-in-progress"], False) |
---|
9208 | + naptime = p["remaining-wait-time"] |
---|
9209 | + self.failUnless(isinstance(naptime, float), naptime) |
---|
9210 | + # min-cycle-time is 300, so this is basically testing that it took |
---|
9211 | + # less than 290s to crawl |
---|
9212 | + self.failUnless(naptime > 10.0, naptime) |
---|
9213 | + soon = p["next-crawl-time"] - time.time() |
---|
9214 | + self.failUnless(soon > 10.0, soon) |
---|
9215 | |
---|
9216 | hunk ./src/allmydata/test/test_crawler.py 364 |
---|
9217 | - d.addCallback(_check) |
---|
9218 | + d2.addCallback(_check) |
---|
9219 | + return d2 |
---|
9220 | + d.addCallback(_done_writes) |
---|
9221 | return d |
---|
9222 | |
---|
9223 | def OFF_test_cpu_usage(self): |
---|
9224 | hunk ./src/allmydata/test/test_crawler.py 377 |
---|
9225 | # and read the stdout when it runs. |
---|
9226 | |
---|
9227 | self.basedir = "crawler/Basic/cpu_usage" |
---|
9228 | - fileutil.make_dirs(self.basedir) |
---|
9229 | serverid = "\x00" * 20 |
---|
9230 | hunk ./src/allmydata/test/test_crawler.py 378 |
---|
9231 | - ss = StorageServer(self.basedir, serverid) |
---|
9232 | + fp = FilePath(self.basedir) |
---|
9233 | + backend = DiskBackend(fp) |
---|
9234 | + ss = StorageServer(serverid, backend, fp) |
---|
9235 | ss.setServiceParent(self.s) |
---|
9236 | |
---|
9237 | hunk ./src/allmydata/test/test_crawler.py 383 |
---|
9238 | - for i in range(10): |
---|
9239 | - self.write(i, ss, serverid) |
---|
9240 | - |
---|
9241 | - statefile = os.path.join(self.basedir, "statefile") |
---|
9242 | - c = ConsumingCrawler(ss, statefile) |
---|
9243 | - c.setServiceParent(self.s) |
---|
9244 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(10)]) |
---|
9245 | + def _done_writes(sis): |
---|
9246 | + statefp = fp.child("statefile") |
---|
9247 | + c = ConsumingCrawler(backend, statefp) |
---|
9248 | + c.setServiceParent(self.s) |
---|
9249 | |
---|
9250 | hunk ./src/allmydata/test/test_crawler.py 389 |
---|
9251 | - # this will run as fast as it can, consuming about 50ms per call to |
---|
9252 | - # process_bucket(), limited by the Crawler to about 50% cpu. We let |
---|
9253 | - # it run for a few seconds, then compare how much time |
---|
9254 | - # process_bucket() got vs wallclock time. It should get between 10% |
---|
9255 | - # and 70% CPU. This is dicey, there's about 100ms of overhead per |
---|
9256 | - # 300ms slice (saving the state file takes about 150-200us, but we do |
---|
9257 | - # it 1024 times per cycle, one for each [empty] prefixdir), leaving |
---|
9258 | - # 200ms for actual processing, which is enough to get through 4 |
---|
9259 | - # buckets each slice, then the crawler sleeps for 300ms/0.5 = 600ms, |
---|
9260 | - # giving us 900ms wallclock per slice. In 4.0 seconds we can do 4.4 |
---|
9261 | - # slices, giving us about 17 shares, so we merely assert that we've |
---|
9262 | - # finished at least one cycle in that time. |
---|
9263 | + # this will run as fast as it can, consuming about 50ms per call to |
---|
9264 | + # process_shareset(), limited by the Crawler to about 50% cpu. We let |
---|
9265 | + # it run for a few seconds, then compare how much time |
---|
9266 | + # process_shareset() got vs wallclock time. It should get between 10% |
---|
9267 | + # and 70% CPU. This is dicey, there's about 100ms of overhead per |
---|
9268 | + # 300ms slice (saving the state file takes about 150-200us, but we do |
---|
9269 | + # it 1024 times per cycle, one for each [empty] prefixdir), leaving |
---|
9270 | + # 200ms for actual processing, which is enough to get through 4 |
---|
9271 | + # sharesets each slice, then the crawler sleeps for 300ms/0.5 = 600ms, |
---|
9272 | + # giving us 900ms wallclock per slice. In 4.0 seconds we can do 4.4 |
---|
9273 | + # slices, giving us about 17 shares, so we merely assert that we've |
---|
9274 | + # finished at least one cycle in that time. |
---|
9275 | |
---|
9276 | hunk ./src/allmydata/test/test_crawler.py 402 |
---|
9277 | - # with a short cpu_slice (so we can keep this test down to 4 |
---|
9278 | - # seconds), the overhead is enough to make a nominal 50% usage more |
---|
9279 | - # like 30%. Forcing sleep_time to 0 only gets us 67% usage. |
---|
9280 | + # with a short cpu_slice (so we can keep this test down to 4 |
---|
9281 | + # seconds), the overhead is enough to make a nominal 50% usage more |
---|
9282 | + # like 30%. Forcing sleep_time to 0 only gets us 67% usage. |
---|
9283 | |
---|
9284 | hunk ./src/allmydata/test/test_crawler.py 406 |
---|
9285 | - start = time.time() |
---|
9286 | - d = self.stall(delay=4.0) |
---|
9287 | - def _done(res): |
---|
9288 | - elapsed = time.time() - start |
---|
9289 | - percent = 100.0 * c.accumulated / elapsed |
---|
9290 | - # our buildslaves vary too much in their speeds and load levels, |
---|
9291 | - # and many of them only manage to hit 7% usage when our target is |
---|
9292 | - # 50%. So don't assert anything about the results, just log them. |
---|
9293 | - print |
---|
9294 | - print "crawler: got %d%% percent when trying for 50%%" % percent |
---|
9295 | - print "crawler: got %d full cycles" % c.cycles |
---|
9296 | - d.addCallback(_done) |
---|
9297 | + start = time.time() |
---|
9298 | + d2 = self.stall(delay=4.0) |
---|
9299 | + def _done(res): |
---|
9300 | + elapsed = time.time() - start |
---|
9301 | + percent = 100.0 * c.accumulated / elapsed |
---|
9302 | + # our buildslaves vary too much in their speeds and load levels, |
---|
9303 | + # and many of them only manage to hit 7% usage when our target is |
---|
9304 | + # 50%. So don't assert anything about the results, just log them. |
---|
9305 | + print |
---|
9306 | + print "crawler: got %d%% percent when trying for 50%%" % percent |
---|
9307 | + print "crawler: got %d full cycles" % c.cycles |
---|
9308 | + d2.addCallback(_done) |
---|
9309 | + return d2 |
---|
9310 | + d.addCallback(_done_writes) |
---|
9311 | return d |
---|
9312 | |
---|
9313 | def test_empty_subclass(self): |
---|
9314 | hunk ./src/allmydata/test/test_crawler.py 424 |
---|
9315 | self.basedir = "crawler/Basic/empty_subclass" |
---|
9316 | - fileutil.make_dirs(self.basedir) |
---|
9317 | serverid = "\x00" * 20 |
---|
9318 | hunk ./src/allmydata/test/test_crawler.py 425 |
---|
9319 | - ss = StorageServer(self.basedir, serverid) |
---|
9320 | + fp = FilePath(self.basedir) |
---|
9321 | + backend = DiskBackend(fp) |
---|
9322 | + ss = StorageServer(serverid, backend, fp) |
---|
9323 | ss.setServiceParent(self.s) |
---|
9324 | |
---|
9325 | hunk ./src/allmydata/test/test_crawler.py 430 |
---|
9326 | - for i in range(10): |
---|
9327 | - self.write(i, ss, serverid) |
---|
9328 | - |
---|
9329 | - statefile = os.path.join(self.basedir, "statefile") |
---|
9330 | - c = ShareCrawler(ss, statefile) |
---|
9331 | - c.slow_start = 0 |
---|
9332 | - c.setServiceParent(self.s) |
---|
9333 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(10)]) |
---|
9334 | + def _done_writes(sis): |
---|
9335 | + statefp = fp.child("statefile") |
---|
9336 | + c = ShareCrawler(backend, statefp) |
---|
9337 | + c.slow_start = 0 |
---|
9338 | + c.setServiceParent(self.s) |
---|
9339 | |
---|
9340 | hunk ./src/allmydata/test/test_crawler.py 437 |
---|
9341 | - # we just let it run for a while, to get figleaf coverage of the |
---|
9342 | - # empty methods in the base class |
---|
9343 | + # we just let it run for a while, to get figleaf coverage of the |
---|
9344 | + # empty methods in the base class |
---|
9345 | |
---|
9346 | hunk ./src/allmydata/test/test_crawler.py 440 |
---|
9347 | - def _check(): |
---|
9348 | - return bool(c.state["last-cycle-finished"] is not None) |
---|
9349 | - d = self.poll(_check) |
---|
9350 | - def _done(ignored): |
---|
9351 | - state = c.get_state() |
---|
9352 | - self.failUnless(state["last-cycle-finished"] is not None) |
---|
9353 | - d.addCallback(_done) |
---|
9354 | + def _check(): |
---|
9355 | + return bool(c.state["last-cycle-finished"] is not None) |
---|
9356 | + d2 = self.poll(_check) |
---|
9357 | + def _done(ignored): |
---|
9358 | + state = c.get_state() |
---|
9359 | + self.failUnless(state["last-cycle-finished"] is not None) |
---|
9360 | + d2.addCallback(_done) |
---|
9361 | + return d2 |
---|
9362 | + d.addCallback(_done_writes) |
---|
9363 | return d |
---|
9364 | |
---|
9365 | def test_oneshot(self): |
---|
9366 | hunk ./src/allmydata/test/test_crawler.py 453 |
---|
9367 | self.basedir = "crawler/Basic/oneshot" |
---|
9368 | - fileutil.make_dirs(self.basedir) |
---|
9369 | serverid = "\x00" * 20 |
---|
9370 | hunk ./src/allmydata/test/test_crawler.py 454 |
---|
9371 | - ss = StorageServer(self.basedir, serverid) |
---|
9372 | + fp = FilePath(self.basedir) |
---|
9373 | + backend = DiskBackend(fp) |
---|
9374 | + ss = StorageServer(serverid, backend, fp) |
---|
9375 | ss.setServiceParent(self.s) |
---|
9376 | |
---|
9377 | hunk ./src/allmydata/test/test_crawler.py 459 |
---|
9378 | - for i in range(30): |
---|
9379 | - self.write(i, ss, serverid) |
---|
9380 | - |
---|
9381 | - statefile = os.path.join(self.basedir, "statefile") |
---|
9382 | - c = OneShotCrawler(ss, statefile) |
---|
9383 | - c.setServiceParent(self.s) |
---|
9384 | + d = defer.gatherResults([self.write(i, ss, serverid) for i in range(30)]) |
---|
9385 | + def _done_writes(sis): |
---|
9386 | + statefp = fp.child("statefile") |
---|
9387 | + c = OneShotCrawler(backend, statefp) |
---|
9388 | + c.setServiceParent(self.s) |
---|
9389 | |
---|
9390 | hunk ./src/allmydata/test/test_crawler.py 465 |
---|
9391 | - d = c.finished_d |
---|
9392 | - def _finished_first_cycle(ignored): |
---|
9393 | - return fireEventually(c.counter) |
---|
9394 | - d.addCallback(_finished_first_cycle) |
---|
9395 | - def _check(old_counter): |
---|
9396 | - # the crawler should do any work after it's been stopped |
---|
9397 | - self.failUnlessEqual(old_counter, c.counter) |
---|
9398 | - self.failIf(c.running) |
---|
9399 | - self.failIf(c.timer) |
---|
9400 | - self.failIf(c.current_sleep_time) |
---|
9401 | - s = c.get_state() |
---|
9402 | - self.failUnlessEqual(s["last-cycle-finished"], 0) |
---|
9403 | - self.failUnlessEqual(s["current-cycle"], None) |
---|
9404 | - d.addCallback(_check) |
---|
9405 | + d2 = c.finished_d |
---|
9406 | + def _finished_first_cycle(ignored): |
---|
9407 | + return fireEventually(c.counter) |
---|
9408 | + d2.addCallback(_finished_first_cycle) |
---|
9409 | + def _check(old_counter): |
---|
9410 | + # the crawler should do any work after it's been stopped |
---|
9411 | + self.failUnlessEqual(old_counter, c.counter) |
---|
9412 | + self.failIf(c.running) |
---|
9413 | + self.failIf(c.timer) |
---|
9414 | + self.failIf(c.current_sleep_time) |
---|
9415 | + s = c.get_state() |
---|
9416 | + self.failUnlessEqual(s["last-cycle-finished"], 0) |
---|
9417 | + self.failUnlessEqual(s["current-cycle"], None) |
---|
9418 | + d2.addCallback(_check) |
---|
9419 | + return d2 |
---|
9420 | + d.addCallback(_done_writes) |
---|
9421 | return d |
---|
9422 | hunk ./src/allmydata/test/test_deepcheck.py 23 |
---|
9423 | ShouldFailMixin |
---|
9424 | from allmydata.test.common_util import StallMixin |
---|
9425 | from allmydata.test.no_network import GridTestMixin |
---|
9426 | +from allmydata.scripts import debug |
---|
9427 | + |
---|
9428 | |
---|
9429 | timeout = 2400 # One of these took 1046.091s on Zandr's ARM box. |
---|
9430 | |
---|
9431 | hunk ./src/allmydata/test/test_deepcheck.py 68 |
---|
9432 | def _stash_and_corrupt(node): |
---|
9433 | self.node = node |
---|
9434 | self.fileurl = "uri/" + urllib.quote(node.get_uri()) |
---|
9435 | - self.corrupt_shares_numbered(node.get_uri(), [0], |
---|
9436 | - _corrupt_mutable_share_data) |
---|
9437 | + return self.corrupt_shares_numbered(node.get_uri(), [0], |
---|
9438 | + _corrupt_mutable_share_data) |
---|
9439 | d.addCallback(_stash_and_corrupt) |
---|
9440 | # now make sure the webapi verifier notices it |
---|
9441 | d.addCallback(lambda ign: self.GET(self.fileurl+"?t=check&verify=true", |
---|
9442 | hunk ./src/allmydata/test/test_deepcheck.py 989 |
---|
9443 | |
---|
9444 | return d |
---|
9445 | |
---|
9446 | - def _run_cli(self, argv): |
---|
9447 | - stdout, stderr = StringIO(), StringIO() |
---|
9448 | - # this can only do synchronous operations |
---|
9449 | - assert argv[0] == "debug" |
---|
9450 | - runner.runner(argv, run_by_human=False, stdout=stdout, stderr=stderr) |
---|
9451 | - return stdout.getvalue() |
---|
9452 | - |
---|
9453 | def _delete_some_shares(self, node): |
---|
9454 | hunk ./src/allmydata/test/test_deepcheck.py 990 |
---|
9455 | - self.delete_shares_numbered(node.get_uri(), [0,1]) |
---|
9456 | + return self.delete_shares_numbered(node.get_uri(), [0,1]) |
---|
9457 | |
---|
9458 | def _corrupt_some_shares(self, node): |
---|
9459 | hunk ./src/allmydata/test/test_deepcheck.py 993 |
---|
9460 | - for (shnum, serverid, sharefile) in self.find_uri_shares(node.get_uri()): |
---|
9461 | - if shnum in (0,1): |
---|
9462 | - self._run_cli(["debug", "corrupt-share", sharefile]) |
---|
9463 | + d = self.find_uri_shares(node.get_uri()) |
---|
9464 | + def _got_shares(sharelist): |
---|
9465 | + for (shnum, serverid, sharefile) in sharelist: |
---|
9466 | + if shnum in (0,1): |
---|
9467 | + debug.do_corrupt_share(StringIO(), sharefile) |
---|
9468 | + d.addCallback(_got_shares) |
---|
9469 | + return d |
---|
9470 | |
---|
9471 | def _delete_most_shares(self, node): |
---|
9472 | hunk ./src/allmydata/test/test_deepcheck.py 1002 |
---|
9473 | - self.delete_shares_numbered(node.get_uri(), range(1,10)) |
---|
9474 | - |
---|
9475 | + return self.delete_shares_numbered(node.get_uri(), range(1,10)) |
---|
9476 | |
---|
9477 | def check_is_healthy(self, cr, where): |
---|
9478 | try: |
---|
9479 | hunk ./src/allmydata/test/test_download.py 6 |
---|
9480 | # a previous run. This asserts that the current code is capable of decoding |
---|
9481 | # shares from a previous version. |
---|
9482 | |
---|
9483 | -import os |
---|
9484 | from twisted.trial import unittest |
---|
9485 | from twisted.internet import defer, reactor |
---|
9486 | from allmydata import uri |
---|
9487 | hunk ./src/allmydata/test/test_download.py 9 |
---|
9488 | -from allmydata.storage.server import storage_index_to_dir |
---|
9489 | from allmydata.util import base32, fileutil, spans, log, hashutil |
---|
9490 | from allmydata.util.consumer import download_to_data, MemoryConsumer |
---|
9491 | from allmydata.immutable import upload, layout |
---|
9492 | hunk ./src/allmydata/test/test_download.py 85 |
---|
9493 | u = upload.Data(plaintext, None) |
---|
9494 | d = self.c0.upload(u) |
---|
9495 | f = open("stored_shares.py", "w") |
---|
9496 | - def _created_immutable(ur): |
---|
9497 | - # write the generated shares and URI to a file, which can then be |
---|
9498 | - # incorporated into this one next time. |
---|
9499 | - f.write('immutable_uri = "%s"\n' % ur.uri) |
---|
9500 | - f.write('immutable_shares = {\n') |
---|
9501 | - si = uri.from_string(ur.uri).get_storage_index() |
---|
9502 | - si_dir = storage_index_to_dir(si) |
---|
9503 | + |
---|
9504 | + def _write_py(uri): |
---|
9505 | + si = uri.from_string(uri).get_storage_index() |
---|
9506 | for (i,ss,ssdir) in self.iterate_servers(): |
---|
9507 | hunk ./src/allmydata/test/test_download.py 89 |
---|
9508 | - sharedir = os.path.join(ssdir, "shares", si_dir) |
---|
9509 | - shares = {} |
---|
9510 | - for fn in os.listdir(sharedir): |
---|
9511 | - shnum = int(fn) |
---|
9512 | - sharedata = open(os.path.join(sharedir, fn), "rb").read() |
---|
9513 | - shares[shnum] = sharedata |
---|
9514 | - fileutil.rm_dir(sharedir) |
---|
9515 | - if shares: |
---|
9516 | + sharemap = {} |
---|
9517 | + shareset = ss.backend.get_shareset(si) |
---|
9518 | + (shares, corrupted) = shareset.get_shares_synchronous() |
---|
9519 | + assert len(corrupted) == 0, (shares, corrupted) |
---|
9520 | + for share in shares: |
---|
9521 | + sharedata = share._get_filepath().getContent() |
---|
9522 | + sharemap[share.get_shnum()] = sharedata |
---|
9523 | + |
---|
9524 | + fileutil.fp_remove(shareset._get_sharedir()) |
---|
9525 | + if sharemap: |
---|
9526 | f.write(' %d: { # client[%d]\n' % (i, i)) |
---|
9527 | hunk ./src/allmydata/test/test_download.py 100 |
---|
9528 | - for shnum in sorted(shares.keys()): |
---|
9529 | + for shnum in sorted(sharemap.keys()): |
---|
9530 | f.write(' %d: base32.a2b("%s"),\n' % |
---|
9531 | hunk ./src/allmydata/test/test_download.py 102 |
---|
9532 | - (shnum, base32.b2a(shares[shnum]))) |
---|
9533 | + (shnum, base32.b2a(sharemap[shnum]))) |
---|
9534 | f.write(' },\n') |
---|
9535 | f.write('}\n') |
---|
9536 | hunk ./src/allmydata/test/test_download.py 105 |
---|
9537 | - f.write('\n') |
---|
9538 | |
---|
9539 | hunk ./src/allmydata/test/test_download.py 106 |
---|
9540 | + def _created_immutable(ur): |
---|
9541 | + # write the generated shares and URI to a file, which can then be |
---|
9542 | + # incorporated into this one next time. |
---|
9543 | + f.write('immutable_uri = "%s"\n' % ur.uri) |
---|
9544 | + f.write('immutable_shares = {\n') |
---|
9545 | + _write_py(ur.uri) |
---|
9546 | + f.write('\n') |
---|
9547 | d.addCallback(_created_immutable) |
---|
9548 | |
---|
9549 | d.addCallback(lambda ignored: |
---|
9550 | hunk ./src/allmydata/test/test_download.py 120 |
---|
9551 | def _created_mutable(n): |
---|
9552 | f.write('mutable_uri = "%s"\n' % n.get_uri()) |
---|
9553 | f.write('mutable_shares = {\n') |
---|
9554 | - si = uri.from_string(n.get_uri()).get_storage_index() |
---|
9555 | - si_dir = storage_index_to_dir(si) |
---|
9556 | - for (i,ss,ssdir) in self.iterate_servers(): |
---|
9557 | - sharedir = os.path.join(ssdir, "shares", si_dir) |
---|
9558 | - shares = {} |
---|
9559 | - for fn in os.listdir(sharedir): |
---|
9560 | - shnum = int(fn) |
---|
9561 | - sharedata = open(os.path.join(sharedir, fn), "rb").read() |
---|
9562 | - shares[shnum] = sharedata |
---|
9563 | - fileutil.rm_dir(sharedir) |
---|
9564 | - if shares: |
---|
9565 | - f.write(' %d: { # client[%d]\n' % (i, i)) |
---|
9566 | - for shnum in sorted(shares.keys()): |
---|
9567 | - f.write(' %d: base32.a2b("%s"),\n' % |
---|
9568 | - (shnum, base32.b2a(shares[shnum]))) |
---|
9569 | - f.write(' },\n') |
---|
9570 | - f.write('}\n') |
---|
9571 | - |
---|
9572 | - f.close() |
---|
9573 | + _write_py(n.get_uri()) |
---|
9574 | d.addCallback(_created_mutable) |
---|
9575 | |
---|
9576 | def _done(ignored): |
---|
9577 | hunk ./src/allmydata/test/test_download.py 125 |
---|
9578 | f.close() |
---|
9579 | - d.addCallback(_done) |
---|
9580 | + d.addBoth(_done) |
---|
9581 | |
---|
9582 | return d |
---|
9583 | |
---|
9584 | hunk ./src/allmydata/test/test_download.py 129 |
---|
9585 | + def _write_shares(self, fileuri, shares): |
---|
9586 | + si = uri.from_string(fileuri).get_storage_index() |
---|
9587 | + for i in shares: |
---|
9588 | + shares_for_server = shares[i] |
---|
9589 | + for shnum in shares_for_server: |
---|
9590 | + share_dir = self.get_server(i).backend.get_shareset(si)._get_sharedir() |
---|
9591 | + fileutil.fp_make_dirs(share_dir) |
---|
9592 | + share_dir.child(str(shnum)).setContent(shares_for_server[shnum]) |
---|
9593 | + |
---|
9594 | def load_shares(self, ignored=None): |
---|
9595 | # this uses the data generated by create_shares() to populate the |
---|
9596 | # storage servers with pre-generated shares |
---|
9597 | hunk ./src/allmydata/test/test_download.py 141 |
---|
9598 | - si = uri.from_string(immutable_uri).get_storage_index() |
---|
9599 | - si_dir = storage_index_to_dir(si) |
---|
9600 | - for i in immutable_shares: |
---|
9601 | - shares = immutable_shares[i] |
---|
9602 | - for shnum in shares: |
---|
9603 | - dn = os.path.join(self.get_serverdir(i), "shares", si_dir) |
---|
9604 | - fileutil.make_dirs(dn) |
---|
9605 | - fn = os.path.join(dn, str(shnum)) |
---|
9606 | - f = open(fn, "wb") |
---|
9607 | - f.write(shares[shnum]) |
---|
9608 | - f.close() |
---|
9609 | - |
---|
9610 | - si = uri.from_string(mutable_uri).get_storage_index() |
---|
9611 | - si_dir = storage_index_to_dir(si) |
---|
9612 | - for i in mutable_shares: |
---|
9613 | - shares = mutable_shares[i] |
---|
9614 | - for shnum in shares: |
---|
9615 | - dn = os.path.join(self.get_serverdir(i), "shares", si_dir) |
---|
9616 | - fileutil.make_dirs(dn) |
---|
9617 | - fn = os.path.join(dn, str(shnum)) |
---|
9618 | - f = open(fn, "wb") |
---|
9619 | - f.write(shares[shnum]) |
---|
9620 | - f.close() |
---|
9621 | + self._write_shares(immutable_uri, immutable_shares) |
---|
9622 | + self._write_shares(mutable_uri, mutable_shares) |
---|
9623 | |
---|
9624 | def download_immutable(self, ignored=None): |
---|
9625 | n = self.c0.create_node_from_uri(immutable_uri) |
---|
9626 | hunk ./src/allmydata/test/test_download.py 185 |
---|
9627 | |
---|
9628 | self.load_shares() |
---|
9629 | si = uri.from_string(immutable_uri).get_storage_index() |
---|
9630 | - si_dir = storage_index_to_dir(si) |
---|
9631 | |
---|
9632 | n = self.c0.create_node_from_uri(immutable_uri) |
---|
9633 | d = download_to_data(n) |
---|
9634 | hunk ./src/allmydata/test/test_download.py 196 |
---|
9635 | # find the three shares that were used, and delete them. Then |
---|
9636 | # download again, forcing the downloader to fail over to other |
---|
9637 | # shares |
---|
9638 | + d2 = defer.succeed(None) |
---|
9639 | for s in n._cnode._node._shares: |
---|
9640 | for clientnum in immutable_shares: |
---|
9641 | for shnum in immutable_shares[clientnum]: |
---|
9642 | hunk ./src/allmydata/test/test_download.py 201 |
---|
9643 | if s._shnum == shnum: |
---|
9644 | - fn = os.path.join(self.get_serverdir(clientnum), |
---|
9645 | - "shares", si_dir, str(shnum)) |
---|
9646 | - os.unlink(fn) |
---|
9647 | + d2.addCallback(lambda ign, clientnum=clientnum, shnum=shnum: |
---|
9648 | + self.get_server(clientnum).backend.get_shareset(si).get_share(shnum)) |
---|
9649 | + d2.addCallback(lambda share: share.unlink()) |
---|
9650 | + return d2 |
---|
9651 | d.addCallback(_clobber_some_shares) |
---|
9652 | d.addCallback(lambda ign: download_to_data(n)) |
---|
9653 | d.addCallback(_got_data) |
---|
9654 | hunk ./src/allmydata/test/test_download.py 213 |
---|
9655 | # delete all but one of the shares that are still alive |
---|
9656 | live_shares = [s for s in n._cnode._node._shares if s.is_alive()] |
---|
9657 | save_me = live_shares[0]._shnum |
---|
9658 | + d2 = defer.succeed(None) |
---|
9659 | for clientnum in immutable_shares: |
---|
9660 | for shnum in immutable_shares[clientnum]: |
---|
9661 | if shnum == save_me: |
---|
9662 | hunk ./src/allmydata/test/test_download.py 218 |
---|
9663 | continue |
---|
9664 | - fn = os.path.join(self.get_serverdir(clientnum), |
---|
9665 | - "shares", si_dir, str(shnum)) |
---|
9666 | - if os.path.exists(fn): |
---|
9667 | - os.unlink(fn) |
---|
9668 | + d2.addCallback(lambda ign, clientnum=clientnum, shnum=shnum: |
---|
9669 | + self.get_server(clientnum).backend.get_shareset(si).get_share(shnum)) |
---|
9670 | + def _eb(f): |
---|
9671 | + f.trap(EnvironmentError) |
---|
9672 | + d2.addCallbacks(lambda share: share.unlink(), _eb) |
---|
9673 | + |
---|
9674 | # now the download should fail with NotEnoughSharesError |
---|
9675 | hunk ./src/allmydata/test/test_download.py 225 |
---|
9676 | - return self.shouldFail(NotEnoughSharesError, "1shares", None, |
---|
9677 | - download_to_data, n) |
---|
9678 | + d2.addCallback(lambda ign: self.shouldFail(NotEnoughSharesError, "1shares", None, |
---|
9679 | + download_to_data, n)) |
---|
9680 | + return d2 |
---|
9681 | d.addCallback(_clobber_most_shares) |
---|
9682 | |
---|
9683 | def _clobber_all_shares(ign): |
---|
9684 | hunk ./src/allmydata/test/test_download.py 234 |
---|
9685 | # delete the last remaining share |
---|
9686 | for clientnum in immutable_shares: |
---|
9687 | for shnum in immutable_shares[clientnum]: |
---|
9688 | - fn = os.path.join(self.get_serverdir(clientnum), |
---|
9689 | - "shares", si_dir, str(shnum)) |
---|
9690 | - if os.path.exists(fn): |
---|
9691 | - os.unlink(fn) |
---|
9692 | + share_dir = self.get_server(clientnum).backend.get_shareset(si)._get_sharedir() |
---|
9693 | + fileutil.fp_remove(share_dir.child(str(shnum))) |
---|
9694 | # now a new download should fail with NoSharesError. We want a |
---|
9695 | # new ImmutableFileNode so it will forget about the old shares. |
---|
9696 | # If we merely called create_node_from_uri() without first |
---|
9697 | hunk ./src/allmydata/test/test_download.py 812 |
---|
9698 | # will report two shares, and the ShareFinder will handle the |
---|
9699 | # duplicate by attaching both to the same CommonShare instance. |
---|
9700 | si = uri.from_string(immutable_uri).get_storage_index() |
---|
9701 | - si_dir = storage_index_to_dir(si) |
---|
9702 | - sh0_file = [sharefile |
---|
9703 | - for (shnum, serverid, sharefile) |
---|
9704 | - in self.find_uri_shares(immutable_uri) |
---|
9705 | - if shnum == 0][0] |
---|
9706 | - sh0_data = open(sh0_file, "rb").read() |
---|
9707 | - for clientnum in immutable_shares: |
---|
9708 | - if 0 in immutable_shares[clientnum]: |
---|
9709 | - continue |
---|
9710 | - cdir = self.get_serverdir(clientnum) |
---|
9711 | - target = os.path.join(cdir, "shares", si_dir, "0") |
---|
9712 | - outf = open(target, "wb") |
---|
9713 | - outf.write(sh0_data) |
---|
9714 | - outf.close() |
---|
9715 | |
---|
9716 | hunk ./src/allmydata/test/test_download.py 813 |
---|
9717 | - d = self.download_immutable() |
---|
9718 | + d = defer.succeed(None) |
---|
9719 | + d.addCallback(lambda ign: self.find_uri_shares(immutable_uri)) |
---|
9720 | + def _duplicate(sharelist): |
---|
9721 | + sh0_fp = [sharefp for (shnum, serverid, sharefp) in sharelist |
---|
9722 | + if shnum == 0][0] |
---|
9723 | + sh0_data = sh0_fp.getContent() |
---|
9724 | + for clientnum in immutable_shares: |
---|
9725 | + if 0 in immutable_shares[clientnum]: |
---|
9726 | + continue |
---|
9727 | + cdir = self.get_server(clientnum).backend.get_shareset(si)._get_sharedir() |
---|
9728 | + fileutil.fp_make_dirs(cdir) |
---|
9729 | + cdir.child(str(shnum)).setContent(sh0_data) |
---|
9730 | + d.addCallback(_duplicate) |
---|
9731 | + |
---|
9732 | + d.addCallback(lambda ign: self.download_immutable()) |
---|
9733 | return d |
---|
9734 | |
---|
9735 | def test_verifycap(self): |
---|
9736 | hunk ./src/allmydata/test/test_download.py 912 |
---|
9737 | log.msg("corrupt %d" % which) |
---|
9738 | def _corruptor(s, debug=False): |
---|
9739 | return s[:which] + chr(ord(s[which])^0x01) + s[which+1:] |
---|
9740 | - self.corrupt_shares_numbered(imm_uri, [0], _corruptor) |
---|
9741 | + return self.corrupt_shares_numbered(imm_uri, [0], _corruptor) |
---|
9742 | |
---|
9743 | def _corrupt_set(self, ign, imm_uri, which, newvalue): |
---|
9744 | log.msg("corrupt %d" % which) |
---|
9745 | hunk ./src/allmydata/test/test_download.py 918 |
---|
9746 | def _corruptor(s, debug=False): |
---|
9747 | return s[:which] + chr(newvalue) + s[which+1:] |
---|
9748 | - self.corrupt_shares_numbered(imm_uri, [0], _corruptor) |
---|
9749 | + return self.corrupt_shares_numbered(imm_uri, [0], _corruptor) |
---|
9750 | |
---|
9751 | def test_each_byte(self): |
---|
9752 | # Setting catalog_detection=True performs an exhaustive test of the |
---|
9753 | hunk ./src/allmydata/test/test_download.py 929 |
---|
9754 | # (since we don't need every byte of the share). That takes 50s to |
---|
9755 | # run on my laptop and doesn't have any actual asserts, so we don't |
---|
9756 | # normally do that. |
---|
9757 | + # XXX this has bitrotted (before v1.8.2) and gives an AttributeError. |
---|
9758 | self.catalog_detection = False |
---|
9759 | |
---|
9760 | self.basedir = "download/Corruption/each_byte" |
---|
9761 | hunk ./src/allmydata/test/test_download.py 981 |
---|
9762 | d = self.c0.upload(u) |
---|
9763 | def _uploaded(ur): |
---|
9764 | imm_uri = ur.uri |
---|
9765 | - self.shares = self.copy_shares(imm_uri) |
---|
9766 | - d = defer.succeed(None) |
---|
9767 | + |
---|
9768 | # 'victims' is a list of corruption tests to run. Each one flips |
---|
9769 | # the low-order bit of the specified offset in the share file (so |
---|
9770 | # offset=0 is the MSB of the container version, offset=15 is the |
---|
9771 | hunk ./src/allmydata/test/test_download.py 1025 |
---|
9772 | [(i, "need-4th") for i in need_4th_victims]) |
---|
9773 | if self.catalog_detection: |
---|
9774 | corrupt_me = [(i, "") for i in range(len(self.sh0_orig))] |
---|
9775 | - for i,expected in corrupt_me: |
---|
9776 | - # All these tests result in a successful download. What we're |
---|
9777 | - # measuring is how many shares the downloader had to use. |
---|
9778 | - d.addCallback(self._corrupt_flip, imm_uri, i) |
---|
9779 | - d.addCallback(_download, imm_uri, i, expected) |
---|
9780 | - d.addCallback(lambda ign: self.restore_all_shares(self.shares)) |
---|
9781 | - d.addCallback(fireEventually) |
---|
9782 | - corrupt_values = [(3, 2, "no-sh0"), |
---|
9783 | - (15, 2, "need-4th"), # share looks v2 |
---|
9784 | - ] |
---|
9785 | - for i,newvalue,expected in corrupt_values: |
---|
9786 | - d.addCallback(self._corrupt_set, imm_uri, i, newvalue) |
---|
9787 | - d.addCallback(_download, imm_uri, i, expected) |
---|
9788 | - d.addCallback(lambda ign: self.restore_all_shares(self.shares)) |
---|
9789 | - d.addCallback(fireEventually) |
---|
9790 | - return d |
---|
9791 | + |
---|
9792 | + d2 = defer.succeed(None) |
---|
9793 | + d2.addCallback(lambda ign: self.copy_shares(imm_uri)) |
---|
9794 | + def _copied(copied_shares): |
---|
9795 | + d3 = defer.succeed(None) |
---|
9796 | + |
---|
9797 | + for i, expected in corrupt_me: |
---|
9798 | + # All these tests result in a successful download. What we're |
---|
9799 | + # measuring is how many shares the downloader had to use. |
---|
9800 | + d3.addCallback(self._corrupt_flip, imm_uri, i) |
---|
9801 | + d3.addCallback(_download, imm_uri, i, expected) |
---|
9802 | + d3.addCallback(lambda ign: self.restore_all_shares(copied_shares)) |
---|
9803 | + d3.addCallback(fireEventually) |
---|
9804 | + corrupt_values = [(3, 2, "no-sh0"), |
---|
9805 | + (15, 2, "need-4th"), # share looks v2 |
---|
9806 | + ] |
---|
9807 | + for i, newvalue, expected in corrupt_values: |
---|
9808 | + d3.addCallback(self._corrupt_set, imm_uri, i, newvalue) |
---|
9809 | + d3.addCallback(_download, imm_uri, i, expected) |
---|
9810 | + d3.addCallback(lambda ign: self.restore_all_shares(copied_shares)) |
---|
9811 | + d3.addCallback(fireEventually) |
---|
9812 | + return d3 |
---|
9813 | + d2.addCallback(_copied) |
---|
9814 | + return d2 |
---|
9815 | d.addCallback(_uploaded) |
---|
9816 | |
---|
9817 | def _show_results(ign): |
---|
9818 | hunk ./src/allmydata/test/test_download.py 1086 |
---|
9819 | d = self.c0.upload(u) |
---|
9820 | def _uploaded(ur): |
---|
9821 | imm_uri = ur.uri |
---|
9822 | - self.shares = self.copy_shares(imm_uri) |
---|
9823 | - |
---|
9824 | corrupt_me = [(48, "block data", "Last failure: None"), |
---|
9825 | (600+2*32, "block_hashes[2]", "BadHashError"), |
---|
9826 | (376+2*32, "crypttext_hash_tree[2]", "BadHashError"), |
---|
9827 | hunk ./src/allmydata/test/test_download.py 1099 |
---|
9828 | assert not n._cnode._node._shares |
---|
9829 | return download_to_data(n) |
---|
9830 | |
---|
9831 | - d = defer.succeed(None) |
---|
9832 | - for i,which,substring in corrupt_me: |
---|
9833 | - # All these tests result in a failed download. |
---|
9834 | - d.addCallback(self._corrupt_flip_all, imm_uri, i) |
---|
9835 | - d.addCallback(lambda ign, which=which, substring=substring: |
---|
9836 | - self.shouldFail(NoSharesError, which, |
---|
9837 | - substring, |
---|
9838 | - _download, imm_uri)) |
---|
9839 | - d.addCallback(lambda ign: self.restore_all_shares(self.shares)) |
---|
9840 | - d.addCallback(fireEventually) |
---|
9841 | - return d |
---|
9842 | - d.addCallback(_uploaded) |
---|
9843 | + d2 = defer.succeed(None) |
---|
9844 | + d2.addCallback(lambda ign: self.copy_shares(imm_uri)) |
---|
9845 | + def _copied(copied_shares): |
---|
9846 | + d3 = defer.succeed(None) |
---|
9847 | |
---|
9848 | hunk ./src/allmydata/test/test_download.py 1104 |
---|
9849 | + for i, which, substring in corrupt_me: |
---|
9850 | + # All these tests result in a failed download. |
---|
9851 | + d3.addCallback(self._corrupt_flip_all, imm_uri, i) |
---|
9852 | + d3.addCallback(lambda ign, which=which, substring=substring: |
---|
9853 | + self.shouldFail(NoSharesError, which, |
---|
9854 | + substring, |
---|
9855 | + _download, imm_uri)) |
---|
9856 | + d3.addCallback(lambda ign: self.restore_all_shares(copied_shares)) |
---|
9857 | + d3.addCallback(fireEventually) |
---|
9858 | + return d3 |
---|
9859 | + d2.addCallback(_copied) |
---|
9860 | + return d2 |
---|
9861 | + d.addCallback(_uploaded) |
---|
9862 | return d |
---|
9863 | |
---|
9864 | def _corrupt_flip_all(self, ign, imm_uri, which): |
---|
9865 | hunk ./src/allmydata/test/test_download.py 1122 |
---|
9866 | def _corruptor(s, debug=False): |
---|
9867 | return s[:which] + chr(ord(s[which])^0x01) + s[which+1:] |
---|
9868 | - self.corrupt_all_shares(imm_uri, _corruptor) |
---|
9869 | + return self.corrupt_all_shares(imm_uri, _corruptor) |
---|
9870 | + |
---|
9871 | |
---|
9872 | class DownloadV2(_Base, unittest.TestCase): |
---|
9873 | # tests which exercise v2-share code. They first upload a file with |
---|
9874 | hunk ./src/allmydata/test/test_download.py 1193 |
---|
9875 | d = self.c0.upload(u) |
---|
9876 | def _uploaded(ur): |
---|
9877 | imm_uri = ur.uri |
---|
9878 | - def _do_corrupt(which, newvalue): |
---|
9879 | - def _corruptor(s, debug=False): |
---|
9880 | - return s[:which] + chr(newvalue) + s[which+1:] |
---|
9881 | - self.corrupt_shares_numbered(imm_uri, [0], _corruptor) |
---|
9882 | - _do_corrupt(12+3, 0x00) |
---|
9883 | - n = self.c0.create_node_from_uri(imm_uri) |
---|
9884 | - d = download_to_data(n) |
---|
9885 | - def _got_data(data): |
---|
9886 | - self.failUnlessEqual(data, plaintext) |
---|
9887 | - d.addCallback(_got_data) |
---|
9888 | - return d |
---|
9889 | + which = 12+3 |
---|
9890 | + newvalue = 0x00 |
---|
9891 | + def _corruptor(s, debug=False): |
---|
9892 | + return s[:which] + chr(newvalue) + s[which+1:] |
---|
9893 | + |
---|
9894 | + d2 = defer.succeed(None) |
---|
9895 | + d2.addCallback(lambda ign: self.corrupt_shares_numbered(imm_uri, [0], _corruptor)) |
---|
9896 | + d2.addCallback(lambda ign: self.c0.create_node_from_uri(imm_uri)) |
---|
9897 | + d2.addCallback(lambda n: download_to_data(n)) |
---|
9898 | + d2.addCallback(lambda data: self.failUnlessEqual(data, plaintext)) |
---|
9899 | + return d2 |
---|
9900 | d.addCallback(_uploaded) |
---|
9901 | return d |
---|
9902 | |
---|
9903 | hunk ./src/allmydata/test/test_encode.py 134 |
---|
9904 | d.addCallback(_try) |
---|
9905 | return d |
---|
9906 | |
---|
9907 | - def get_share_hashes(self, at_least_these=()): |
---|
9908 | + def get_share_hashes(self): |
---|
9909 | d = self._start() |
---|
9910 | def _try(unused=None): |
---|
9911 | if self.mode == "bad sharehash": |
---|
9912 | hunk ./src/allmydata/test/test_hung_server.py 3 |
---|
9913 | # -*- coding: utf-8 -*- |
---|
9914 | |
---|
9915 | -import os, shutil |
---|
9916 | from twisted.trial import unittest |
---|
9917 | from twisted.internet import defer |
---|
9918 | hunk ./src/allmydata/test/test_hung_server.py 5 |
---|
9919 | -from allmydata import uri |
---|
9920 | + |
---|
9921 | from allmydata.util.consumer import download_to_data |
---|
9922 | from allmydata.immutable import upload |
---|
9923 | from allmydata.mutable.common import UnrecoverableFileError |
---|
9924 | hunk ./src/allmydata/test/test_hung_server.py 10 |
---|
9925 | from allmydata.mutable.publish import MutableData |
---|
9926 | -from allmydata.storage.common import storage_index_to_dir |
---|
9927 | from allmydata.test.no_network import GridTestMixin |
---|
9928 | from allmydata.test.common import ShouldFailMixin |
---|
9929 | from allmydata.util.pollmixin import PollMixin |
---|
9930 | hunk ./src/allmydata/test/test_hung_server.py 31 |
---|
9931 | timeout = 240 |
---|
9932 | |
---|
9933 | def _break(self, servers): |
---|
9934 | - for (id, ss) in servers: |
---|
9935 | - self.g.break_server(id) |
---|
9936 | + for ss in servers: |
---|
9937 | + self.g.break_server(ss.original.get_serverid()) |
---|
9938 | |
---|
9939 | def _hang(self, servers, **kwargs): |
---|
9940 | hunk ./src/allmydata/test/test_hung_server.py 35 |
---|
9941 | - for (id, ss) in servers: |
---|
9942 | - self.g.hang_server(id, **kwargs) |
---|
9943 | + for ss in servers: |
---|
9944 | + self.g.hang_server(ss.original.get_serverid(), **kwargs) |
---|
9945 | |
---|
9946 | def _unhang(self, servers, **kwargs): |
---|
9947 | hunk ./src/allmydata/test/test_hung_server.py 39 |
---|
9948 | - for (id, ss) in servers: |
---|
9949 | - self.g.unhang_server(id, **kwargs) |
---|
9950 | + for ss in servers: |
---|
9951 | + self.g.unhang_server(ss.original.get_serverid(), **kwargs) |
---|
9952 | |
---|
9953 | def _hang_shares(self, shnums, **kwargs): |
---|
9954 | # hang all servers who are holding the given shares |
---|
9955 | hunk ./src/allmydata/test/test_hung_server.py 52 |
---|
9956 | hung_serverids.add(i_serverid) |
---|
9957 | |
---|
9958 | def _delete_all_shares_from(self, servers): |
---|
9959 | - serverids = [id for (id, ss) in servers] |
---|
9960 | - for (i_shnum, i_serverid, i_sharefile) in self.shares: |
---|
9961 | + serverids = [ss.original.get_serverid() for ss in servers] |
---|
9962 | + for (i_shnum, i_serverid, i_sharefp) in self.shares: |
---|
9963 | if i_serverid in serverids: |
---|
9964 | hunk ./src/allmydata/test/test_hung_server.py 55 |
---|
9965 | - os.unlink(i_sharefile) |
---|
9966 | + i_sharefp.remove() |
---|
9967 | |
---|
9968 | def _corrupt_all_shares_in(self, servers, corruptor_func): |
---|
9969 | hunk ./src/allmydata/test/test_hung_server.py 58 |
---|
9970 | - serverids = [id for (id, ss) in servers] |
---|
9971 | - for (i_shnum, i_serverid, i_sharefile) in self.shares: |
---|
9972 | + serverids = [ss.original.get_serverid() for ss in servers] |
---|
9973 | + for (i_shnum, i_serverid, i_sharefp) in self.shares: |
---|
9974 | if i_serverid in serverids: |
---|
9975 | hunk ./src/allmydata/test/test_hung_server.py 61 |
---|
9976 | - self._corrupt_share((i_shnum, i_sharefile), corruptor_func) |
---|
9977 | + self.corrupt_share((i_shnum, i_serverid, i_sharefp), corruptor_func) |
---|
9978 | |
---|
9979 | def _copy_all_shares_from(self, from_servers, to_server): |
---|
9980 | hunk ./src/allmydata/test/test_hung_server.py 64 |
---|
9981 | - serverids = [id for (id, ss) in from_servers] |
---|
9982 | - for (i_shnum, i_serverid, i_sharefile) in self.shares: |
---|
9983 | + serverids = [ss.original.get_serverid() for ss in from_servers] |
---|
9984 | + for (i_shnum, i_serverid, i_sharefp) in self.shares: |
---|
9985 | if i_serverid in serverids: |
---|
9986 | hunk ./src/allmydata/test/test_hung_server.py 67 |
---|
9987 | - self._copy_share((i_shnum, i_sharefile), to_server) |
---|
9988 | - |
---|
9989 | - def _copy_share(self, share, to_server): |
---|
9990 | - (sharenum, sharefile) = share |
---|
9991 | - (id, ss) = to_server |
---|
9992 | - shares_dir = os.path.join(ss.original.storedir, "shares") |
---|
9993 | - si = uri.from_string(self.uri).get_storage_index() |
---|
9994 | - si_dir = os.path.join(shares_dir, storage_index_to_dir(si)) |
---|
9995 | - if not os.path.exists(si_dir): |
---|
9996 | - os.makedirs(si_dir) |
---|
9997 | - new_sharefile = os.path.join(si_dir, str(sharenum)) |
---|
9998 | - shutil.copy(sharefile, new_sharefile) |
---|
9999 | - self.shares = self.find_uri_shares(self.uri) |
---|
10000 | - # Make sure that the storage server has the share. |
---|
10001 | - self.failUnless((sharenum, ss.original.my_nodeid, new_sharefile) |
---|
10002 | - in self.shares) |
---|
10003 | + self.copy_share((i_shnum, i_serverid, i_sharefp), self.uri, to_server.original) |
---|
10004 | |
---|
10005 | hunk ./src/allmydata/test/test_hung_server.py 69 |
---|
10006 | - def _corrupt_share(self, share, corruptor_func): |
---|
10007 | - (sharenum, sharefile) = share |
---|
10008 | - data = open(sharefile, "rb").read() |
---|
10009 | - newdata = corruptor_func(data) |
---|
10010 | - os.unlink(sharefile) |
---|
10011 | - wf = open(sharefile, "wb") |
---|
10012 | - wf.write(newdata) |
---|
10013 | - wf.close() |
---|
10014 | + d = self.find_uri_shares(self.uri) |
---|
10015 | + def _got_shares(shares): |
---|
10016 | + self.shares = shares |
---|
10017 | + d.addCallback(_got_shares) |
---|
10018 | + return d |
---|
10019 | |
---|
10020 | def _set_up(self, mutable, testdir, num_clients=1, num_servers=10): |
---|
10021 | self.mutable = mutable |
---|
10022 | hunk ./src/allmydata/test/test_hung_server.py 86 |
---|
10023 | |
---|
10024 | self.c0 = self.g.clients[0] |
---|
10025 | nm = self.c0.nodemaker |
---|
10026 | - self.servers = sorted([(s.get_serverid(), s.get_rref()) |
---|
10027 | - for s in nm.storage_broker.get_connected_servers()]) |
---|
10028 | + unsorted = [(s.get_serverid(), s.get_rref()) for s in nm.storage_broker.get_connected_servers()] |
---|
10029 | + self.servers = [ss for (id, ss) in sorted(unsorted)] |
---|
10030 | self.servers = self.servers[5:] + self.servers[:5] |
---|
10031 | |
---|
10032 | if mutable: |
---|
10033 | hunk ./src/allmydata/test/test_hung_server.py 95 |
---|
10034 | d = nm.create_mutable_file(uploadable) |
---|
10035 | def _uploaded_mutable(node): |
---|
10036 | self.uri = node.get_uri() |
---|
10037 | - self.shares = self.find_uri_shares(self.uri) |
---|
10038 | d.addCallback(_uploaded_mutable) |
---|
10039 | else: |
---|
10040 | data = upload.Data(immutable_plaintext, convergence="") |
---|
10041 | hunk ./src/allmydata/test/test_hung_server.py 101 |
---|
10042 | d = self.c0.upload(data) |
---|
10043 | def _uploaded_immutable(upload_res): |
---|
10044 | self.uri = upload_res.uri |
---|
10045 | - self.shares = self.find_uri_shares(self.uri) |
---|
10046 | d.addCallback(_uploaded_immutable) |
---|
10047 | hunk ./src/allmydata/test/test_hung_server.py 102 |
---|
10048 | + |
---|
10049 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
10050 | + def _got_shares(shares): |
---|
10051 | + self.shares = shares |
---|
10052 | + d.addCallback(_got_shares) |
---|
10053 | return d |
---|
10054 | |
---|
10055 | def _start_download(self): |
---|
10056 | hunk ./src/allmydata/test/test_immutable.py 240 |
---|
10057 | d = self.startup("download_from_only_3_shares_with_good_crypttext_hash") |
---|
10058 | def _corrupt_7(ign): |
---|
10059 | c = common._corrupt_offset_of_block_hashes_to_truncate_crypttext_hashes |
---|
10060 | - self.corrupt_shares_numbered(self.uri, self._shuffled(7), c) |
---|
10061 | + return self.corrupt_shares_numbered(self.uri, self._shuffled(7), c) |
---|
10062 | d.addCallback(_corrupt_7) |
---|
10063 | d.addCallback(self._download_and_check_plaintext) |
---|
10064 | return d |
---|
10065 | hunk ./src/allmydata/test/test_immutable.py 267 |
---|
10066 | d = self.startup("download_abort_if_too_many_corrupted_shares") |
---|
10067 | def _corrupt_8(ign): |
---|
10068 | c = common._corrupt_sharedata_version_number |
---|
10069 | - self.corrupt_shares_numbered(self.uri, self._shuffled(8), c) |
---|
10070 | + return self.corrupt_shares_numbered(self.uri, self._shuffled(8), c) |
---|
10071 | d.addCallback(_corrupt_8) |
---|
10072 | def _try_download(ign): |
---|
10073 | start_reads = self._count_reads() |
---|
10074 | hunk ./src/allmydata/test/test_mutable.py 21 |
---|
10075 | from foolscap.api import eventually, fireEventually |
---|
10076 | from foolscap.logging import log |
---|
10077 | from allmydata.storage_client import StorageFarmBroker |
---|
10078 | -from allmydata.storage.common import storage_index_to_dir |
---|
10079 | from allmydata.scripts import debug |
---|
10080 | |
---|
10081 | from allmydata.mutable.filenode import MutableFileNode, BackoffAgent |
---|
10082 | hunk ./src/allmydata/test/test_mutable.py 1865 |
---|
10083 | |
---|
10084 | class Repair(unittest.TestCase, PublishMixin, ShouldFailMixin): |
---|
10085 | |
---|
10086 | - def get_shares(self, s): |
---|
10087 | + def get_all_shares(self, s): |
---|
10088 | all_shares = {} # maps (peerid, shnum) to share data |
---|
10089 | for peerid in s._peers: |
---|
10090 | shares = s._peers[peerid] |
---|
10091 | hunk ./src/allmydata/test/test_mutable.py 1875 |
---|
10092 | return all_shares |
---|
10093 | |
---|
10094 | def copy_shares(self, ignored=None): |
---|
10095 | - self.old_shares.append(self.get_shares(self._storage)) |
---|
10096 | + self.old_shares.append(self.get_all_shares(self._storage)) |
---|
10097 | |
---|
10098 | def test_repair_nop(self): |
---|
10099 | self.old_shares = [] |
---|
10100 | hunk ./src/allmydata/test/test_mutable.py 2922 |
---|
10101 | fso = debug.FindSharesOptions() |
---|
10102 | storage_index = base32.b2a(n.get_storage_index()) |
---|
10103 | fso.si_s = storage_index |
---|
10104 | - fso.nodedirs = [unicode(os.path.dirname(os.path.abspath(storedir))) |
---|
10105 | + fso.nodedirs = [unicode(storedir.parent().path) |
---|
10106 | for (i,ss,storedir) |
---|
10107 | in self.iterate_servers()] |
---|
10108 | fso.stdout = StringIO() |
---|
10109 | hunk ./src/allmydata/test/test_mutable.py 2956 |
---|
10110 | cso.stderr = StringIO() |
---|
10111 | debug.catalog_shares(cso) |
---|
10112 | shares = cso.stdout.getvalue().splitlines() |
---|
10113 | + self.failIf(len(shares) < 1, shares) |
---|
10114 | oneshare = shares[0] # all shares should be MDMF |
---|
10115 | self.failIf(oneshare.startswith("UNKNOWN"), oneshare) |
---|
10116 | self.failUnless(oneshare.startswith("MDMF"), oneshare) |
---|
10117 | hunk ./src/allmydata/test/test_mutable.py 3556 |
---|
10118 | # Now execute each assignment by writing the storage. |
---|
10119 | for (share, servernum) in assignments: |
---|
10120 | sharedata = base64.b64decode(self.sdmf_old_shares[share]) |
---|
10121 | - storedir = self.get_serverdir(servernum) |
---|
10122 | - storage_path = os.path.join(storedir, "shares", |
---|
10123 | - storage_index_to_dir(si)) |
---|
10124 | - fileutil.make_dirs(storage_path) |
---|
10125 | - fileutil.write(os.path.join(storage_path, "%d" % share), |
---|
10126 | - sharedata) |
---|
10127 | + # This must be a disk backend. |
---|
10128 | + storage_dir = self.get_server(servernum).backend.get_shareset(si)._get_sharedir() |
---|
10129 | + fileutil.fp_make_dirs(storage_dir) |
---|
10130 | + storage_dir.child("%d" % share).setContent(sharedata) |
---|
10131 | # ...and verify that the shares are there. |
---|
10132 | hunk ./src/allmydata/test/test_mutable.py 3561 |
---|
10133 | - shares = self.find_uri_shares(self.sdmf_old_cap) |
---|
10134 | - assert len(shares) == 10 |
---|
10135 | + d = self.find_uri_shares(self.sdmf_old_cap) |
---|
10136 | + def _got_shares(shares): |
---|
10137 | + assert len(shares) == 10 |
---|
10138 | + d.addCallback(_got_shares) |
---|
10139 | + return d |
---|
10140 | |
---|
10141 | def test_new_downloader_can_read_old_shares(self): |
---|
10142 | self.basedir = "mutable/Interoperability/new_downloader_can_read_old_shares" |
---|
10143 | hunk ./src/allmydata/test/test_mutable.py 3570 |
---|
10144 | self.set_up_grid() |
---|
10145 | - self.copy_sdmf_shares() |
---|
10146 | - nm = self.g.clients[0].nodemaker |
---|
10147 | - n = nm.create_from_cap(self.sdmf_old_cap) |
---|
10148 | - d = n.download_best_version() |
---|
10149 | - d.addCallback(self.failUnlessEqual, self.sdmf_old_contents) |
---|
10150 | + d = self.copy_sdmf_shares() |
---|
10151 | + def _create_node(ign): |
---|
10152 | + nm = self.g.clients[0].nodemaker |
---|
10153 | + return nm.create_from_cap(self.sdmf_old_cap) |
---|
10154 | + d.addCallback(_create_node) |
---|
10155 | + d.addCallback(lambda n: n.download_best_version()) |
---|
10156 | + d.addCallback(lambda res: self.failUnlessEqual(res, self.sdmf_old_contents)) |
---|
10157 | return d |
---|
10158 | |
---|
10159 | |
---|
10160 | hunk ./src/allmydata/test/test_provisioning.py 13 |
---|
10161 | from nevow import inevow |
---|
10162 | from zope.interface import implements |
---|
10163 | |
---|
10164 | -class MyRequest: |
---|
10165 | +class MockRequest: |
---|
10166 | implements(inevow.IRequest) |
---|
10167 | pass |
---|
10168 | |
---|
10169 | hunk ./src/allmydata/test/test_provisioning.py 26 |
---|
10170 | def test_load(self): |
---|
10171 | pt = provisioning.ProvisioningTool() |
---|
10172 | self.fields = {} |
---|
10173 | - #r = MyRequest() |
---|
10174 | + #r = MockRequest() |
---|
10175 | #r.fields = self.fields |
---|
10176 | #ctx = RequestContext() |
---|
10177 | #unfilled = pt.renderSynchronously(ctx) |
---|
10178 | hunk ./src/allmydata/test/test_repairer.py 89 |
---|
10179 | self.failIfBigger(delta_reads, 0) |
---|
10180 | d.addCallback(_check) |
---|
10181 | |
---|
10182 | - def _remove_all(ignored): |
---|
10183 | - for sh in self.find_uri_shares(self.uri): |
---|
10184 | - self.delete_share(sh) |
---|
10185 | - d.addCallback(_remove_all) |
---|
10186 | + d.addCallback(lambda ign: self.delete_all_shares(self.uri)) |
---|
10187 | |
---|
10188 | d.addCallback(lambda ignored: self._stash_counts()) |
---|
10189 | d.addCallback(lambda ignored: |
---|
10190 | hunk ./src/allmydata/test/test_repairer.py 409 |
---|
10191 | Monitor(), verify=False)) |
---|
10192 | |
---|
10193 | # test share corruption |
---|
10194 | - def _test_corrupt(ignored): |
---|
10195 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
10196 | + def _test_corrupt(shares): |
---|
10197 | olddata = {} |
---|
10198 | hunk ./src/allmydata/test/test_repairer.py 412 |
---|
10199 | - shares = self.find_uri_shares(self.uri) |
---|
10200 | - for (shnum, serverid, sharefile) in shares: |
---|
10201 | - olddata[ (shnum, serverid) ] = open(sharefile, "rb").read() |
---|
10202 | + for (shnum, serverid, sharefp) in shares: |
---|
10203 | + olddata[ (shnum, serverid) ] = sharefp.getContent() |
---|
10204 | for sh in shares: |
---|
10205 | self.corrupt_share(sh, common._corrupt_uri_extension) |
---|
10206 | hunk ./src/allmydata/test/test_repairer.py 416 |
---|
10207 | - for (shnum, serverid, sharefile) in shares: |
---|
10208 | - newdata = open(sharefile, "rb").read() |
---|
10209 | + for (shnum, serverid, sharefp) in shares: |
---|
10210 | + newdata = sharefp.getContent() |
---|
10211 | self.failIfEqual(olddata[ (shnum, serverid) ], newdata) |
---|
10212 | d.addCallback(_test_corrupt) |
---|
10213 | |
---|
10214 | hunk ./src/allmydata/test/test_repairer.py 421 |
---|
10215 | - def _remove_all(ignored): |
---|
10216 | - for sh in self.find_uri_shares(self.uri): |
---|
10217 | - self.delete_share(sh) |
---|
10218 | - d.addCallback(_remove_all) |
---|
10219 | - d.addCallback(lambda ignored: self.find_uri_shares(self.uri)) |
---|
10220 | - d.addCallback(lambda shares: self.failUnlessEqual(shares, [])) |
---|
10221 | + d.addCallback(lambda ign: self.delete_all_shares(self.uri)) |
---|
10222 | |
---|
10223 | hunk ./src/allmydata/test/test_repairer.py 423 |
---|
10224 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
10225 | + d.addCallback(lambda shares: self.failUnlessEqual(shares, [])) |
---|
10226 | return d |
---|
10227 | |
---|
10228 | def test_repair_from_deletion_of_1(self): |
---|
10229 | hunk ./src/allmydata/test/test_repairer.py 450 |
---|
10230 | self.failIfBigger(delta_allocates, DELTA_WRITES_PER_SHARE) |
---|
10231 | self.failIf(pre.is_healthy()) |
---|
10232 | self.failUnless(post.is_healthy()) |
---|
10233 | - |
---|
10234 | - # Now we inspect the filesystem to make sure that it has 10 |
---|
10235 | - # shares. |
---|
10236 | - shares = self.find_uri_shares(self.uri) |
---|
10237 | - self.failIf(len(shares) < 10) |
---|
10238 | d.addCallback(_check_results) |
---|
10239 | |
---|
10240 | hunk ./src/allmydata/test/test_repairer.py 452 |
---|
10241 | + # Now we inspect the filesystem to make sure that it has 10 shares. |
---|
10242 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
10243 | + d.addCallback(lambda shares: self.failIf(len(shares) < 10)) |
---|
10244 | + |
---|
10245 | d.addCallback(lambda ignored: |
---|
10246 | self.c0_filenode.check(Monitor(), verify=True)) |
---|
10247 | d.addCallback(lambda vr: self.failUnless(vr.is_healthy())) |
---|
10248 | hunk ./src/allmydata/test/test_repairer.py 495 |
---|
10249 | self.failIfBigger(delta_allocates, (DELTA_WRITES_PER_SHARE * 7)) |
---|
10250 | self.failIf(pre.is_healthy()) |
---|
10251 | self.failUnless(post.is_healthy(), post.data) |
---|
10252 | - |
---|
10253 | - # Make sure we really have 10 shares. |
---|
10254 | - shares = self.find_uri_shares(self.uri) |
---|
10255 | - self.failIf(len(shares) < 10) |
---|
10256 | d.addCallback(_check_results) |
---|
10257 | |
---|
10258 | hunk ./src/allmydata/test/test_repairer.py 497 |
---|
10259 | + # Now we inspect the filesystem to make sure that it has 10 shares. |
---|
10260 | + d.addCallback(lambda ign: self.find_uri_shares(self.uri)) |
---|
10261 | + d.addCallback(lambda shares: self.failIf(len(shares) < 10)) |
---|
10262 | + |
---|
10263 | d.addCallback(lambda ignored: |
---|
10264 | self.c0_filenode.check(Monitor(), verify=True)) |
---|
10265 | d.addCallback(lambda vr: self.failUnless(vr.is_healthy())) |
---|
10266 | hunk ./src/allmydata/test/test_repairer.py 530 |
---|
10267 | # happiness setting. |
---|
10268 | def _delete_some_servers(ignored): |
---|
10269 | for i in xrange(7): |
---|
10270 | - self.g.remove_server(self.g.servers_by_number[i].my_nodeid) |
---|
10271 | + self.remove_server(i) |
---|
10272 | |
---|
10273 | assert len(self.g.servers_by_number) == 3 |
---|
10274 | |
---|
10275 | hunk ./src/allmydata/test/test_storage.py 1 |
---|
10276 | -import time, os.path, platform, stat, re, simplejson, struct, shutil |
---|
10277 | +import time, os.path, stat, platform, re, simplejson, struct, itertools |
---|
10278 | |
---|
10279 | import mock |
---|
10280 | |
---|
10281 | hunk ./src/allmydata/test/test_storage.py 8 |
---|
10282 | from twisted.trial import unittest |
---|
10283 | from twisted.internet import defer |
---|
10284 | from twisted.application import service |
---|
10285 | +from twisted.python.filepath import FilePath |
---|
10286 | from foolscap.api import fireEventually |
---|
10287 | hunk ./src/allmydata/test/test_storage.py 10 |
---|
10288 | -import itertools |
---|
10289 | + |
---|
10290 | from allmydata import interfaces |
---|
10291 | from allmydata.util import fileutil, hashutil, base32, pollmixin, time_format |
---|
10292 | hunk ./src/allmydata/test/test_storage.py 13 |
---|
10293 | +from allmydata.util.deferredutil import for_items |
---|
10294 | from allmydata.storage.server import StorageServer |
---|
10295 | hunk ./src/allmydata/test/test_storage.py 15 |
---|
10296 | -from allmydata.storage.mutable import MutableShareFile |
---|
10297 | -from allmydata.storage.immutable import BucketWriter, BucketReader |
---|
10298 | -from allmydata.storage.common import DataTooLargeError, storage_index_to_dir, \ |
---|
10299 | +from allmydata.storage.backends.null.null_backend import NullBackend |
---|
10300 | +from allmydata.storage.backends.disk.disk_backend import DiskBackend |
---|
10301 | +from allmydata.storage.backends.disk.immutable import load_immutable_disk_share, create_immutable_disk_share |
---|
10302 | +from allmydata.storage.backends.disk.mutable import MutableDiskShare |
---|
10303 | +from allmydata.storage.backends.s3.s3_backend import S3Backend |
---|
10304 | +from allmydata.storage.backends.s3.mock_s3 import MockS3Bucket |
---|
10305 | +from allmydata.storage.bucket import BucketWriter, BucketReader |
---|
10306 | +from allmydata.storage.common import DataTooLargeError, UnknownContainerVersionError, \ |
---|
10307 | UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError |
---|
10308 | from allmydata.storage.lease import LeaseInfo |
---|
10309 | from allmydata.storage.crawler import BucketCountingCrawler |
---|
10310 | hunk ./src/allmydata/test/test_storage.py 73 |
---|
10311 | |
---|
10312 | class Bucket(unittest.TestCase): |
---|
10313 | def make_workdir(self, name): |
---|
10314 | - basedir = os.path.join("storage", "Bucket", name) |
---|
10315 | - incoming = os.path.join(basedir, "tmp", "bucket") |
---|
10316 | - final = os.path.join(basedir, "bucket") |
---|
10317 | - fileutil.make_dirs(basedir) |
---|
10318 | - fileutil.make_dirs(os.path.join(basedir, "tmp")) |
---|
10319 | + basedir = FilePath("storage").child("Bucket").child(name) |
---|
10320 | + tmpdir = basedir.child("tmp") |
---|
10321 | + tmpdir.makedirs() |
---|
10322 | + incoming = tmpdir.child("bucket") |
---|
10323 | + final = basedir.child("bucket") |
---|
10324 | return incoming, final |
---|
10325 | |
---|
10326 | def bucket_writer_closed(self, bw, consumed): |
---|
10327 | hunk ./src/allmydata/test/test_storage.py 97 |
---|
10328 | |
---|
10329 | def test_create(self): |
---|
10330 | incoming, final = self.make_workdir("test_create") |
---|
10331 | - bw = BucketWriter(self, incoming, final, 200, self.make_lease(), |
---|
10332 | - FakeCanary()) |
---|
10333 | - bw.remote_write(0, "a"*25) |
---|
10334 | - bw.remote_write(25, "b"*25) |
---|
10335 | - bw.remote_write(50, "c"*25) |
---|
10336 | - bw.remote_write(75, "d"*7) |
---|
10337 | - bw.remote_close() |
---|
10338 | + d = defer.succeed(None) |
---|
10339 | + d.addCallback(lambda ign: create_immutable_disk_share(incoming, final, max_size=200)) |
---|
10340 | + def _got_share(share): |
---|
10341 | + bw = BucketWriter(self, share, self.make_lease(), FakeCanary()) |
---|
10342 | + d2 = defer.succeed(None) |
---|
10343 | + d2.addCallback(lambda ign: bw.remote_write(0, "a"*25)) |
---|
10344 | + d2.addCallback(lambda ign: bw.remote_write(25, "b"*25)) |
---|
10345 | + d2.addCallback(lambda ign: bw.remote_write(50, "c"*25)) |
---|
10346 | + d2.addCallback(lambda ign: bw.remote_write(75, "d"*7)) |
---|
10347 | + d2.addCallback(lambda ign: bw.remote_close()) |
---|
10348 | + return d2 |
---|
10349 | + d.addCallback(_got_share) |
---|
10350 | + return d |
---|
10351 | |
---|
10352 | def test_readwrite(self): |
---|
10353 | incoming, final = self.make_workdir("test_readwrite") |
---|
10354 | hunk ./src/allmydata/test/test_storage.py 113 |
---|
10355 | - bw = BucketWriter(self, incoming, final, 200, self.make_lease(), |
---|
10356 | - FakeCanary()) |
---|
10357 | - bw.remote_write(0, "a"*25) |
---|
10358 | - bw.remote_write(25, "b"*25) |
---|
10359 | - bw.remote_write(50, "c"*7) # last block may be short |
---|
10360 | - bw.remote_close() |
---|
10361 | + d = defer.succeed(None) |
---|
10362 | + d.addCallback(lambda ign: create_immutable_disk_share(incoming, final, max_size=200)) |
---|
10363 | + def _got_share(share): |
---|
10364 | + bw = BucketWriter(self, share, self.make_lease(), FakeCanary()) |
---|
10365 | + d2 = defer.succeed(None) |
---|
10366 | + d2.addCallback(lambda ign: bw.remote_write(0, "a"*25)) |
---|
10367 | + d2.addCallback(lambda ign: bw.remote_write(25, "b"*25)) |
---|
10368 | + d2.addCallback(lambda ign: bw.remote_write(50, "c"*7)) # last block may be short |
---|
10369 | + d2.addCallback(lambda ign: bw.remote_close()) |
---|
10370 | |
---|
10371 | hunk ./src/allmydata/test/test_storage.py 123 |
---|
10372 | - # now read from it |
---|
10373 | - br = BucketReader(self, bw.finalhome) |
---|
10374 | - self.failUnlessEqual(br.remote_read(0, 25), "a"*25) |
---|
10375 | - self.failUnlessEqual(br.remote_read(25, 25), "b"*25) |
---|
10376 | - self.failUnlessEqual(br.remote_read(50, 7), "c"*7) |
---|
10377 | + # now read from it |
---|
10378 | + def _read(ign): |
---|
10379 | + br = BucketReader(self, share) |
---|
10380 | + d3 = defer.succeed(None) |
---|
10381 | + d3.addCallback(lambda ign: br.remote_read(0, 25)) |
---|
10382 | + d3.addCallback(lambda res: self.failUnlessEqual(res, "a"*25)) |
---|
10383 | + d3.addCallback(lambda ign: br.remote_read(25, 25)) |
---|
10384 | + d3.addCallback(lambda res: self.failUnlessEqual(res, "b"*25)) |
---|
10385 | + d3.addCallback(lambda ign: br.remote_read(50, 7)) |
---|
10386 | + d3.addCallback(lambda res: self.failUnlessEqual(res, "c"*7)) |
---|
10387 | + return d3 |
---|
10388 | + d2.addCallback(_read) |
---|
10389 | + return d2 |
---|
10390 | + d.addCallback(_got_share) |
---|
10391 | + return d |
---|
10392 | |
---|
10393 | def test_read_past_end_of_share_data(self): |
---|
10394 | # test vector for immutable files (hard-coded contents of an immutable share |
---|
10395 | hunk ./src/allmydata/test/test_storage.py 159 |
---|
10396 | ownernumber = struct.pack('>L', 0) |
---|
10397 | renewsecret = 'THIS LETS ME RENEW YOUR FILE....' |
---|
10398 | assert len(renewsecret) == 32 |
---|
10399 | - cancelsecret = 'THIS LETS ME KILL YOUR FILE HAHA' |
---|
10400 | + cancelsecret = 'THIS USED TO LET ME KILL YR FILE' |
---|
10401 | assert len(cancelsecret) == 32 |
---|
10402 | expirationtime = struct.pack('>L', 60*60*24*31) # 31 days in seconds |
---|
10403 | |
---|
10404 | hunk ./src/allmydata/test/test_storage.py 169 |
---|
10405 | |
---|
10406 | incoming, final = self.make_workdir("test_read_past_end_of_share_data") |
---|
10407 | |
---|
10408 | - fileutil.write(final, share_file_data) |
---|
10409 | + final.setContent(share_file_data) |
---|
10410 | + d = defer.succeed(None) |
---|
10411 | + d.addCallback(lambda ign: load_immutable_disk_share(final)) |
---|
10412 | + def _got_share(share): |
---|
10413 | + mockstorageserver = mock.Mock() |
---|
10414 | |
---|
10415 | hunk ./src/allmydata/test/test_storage.py 175 |
---|
10416 | - mockstorageserver = mock.Mock() |
---|
10417 | + # Now read from it. |
---|
10418 | + br = BucketReader(mockstorageserver, share) |
---|
10419 | |
---|
10420 | hunk ./src/allmydata/test/test_storage.py 178 |
---|
10421 | - # Now read from it. |
---|
10422 | - br = BucketReader(mockstorageserver, final) |
---|
10423 | + d2 = br.remote_read(0, len(share_data)) |
---|
10424 | + d2.addCallback(lambda res: self.failUnlessEqual(res, share_data)) |
---|
10425 | |
---|
10426 | hunk ./src/allmydata/test/test_storage.py 181 |
---|
10427 | - self.failUnlessEqual(br.remote_read(0, len(share_data)), share_data) |
---|
10428 | + # Read past the end of share data to get the cancel secret. |
---|
10429 | + read_length = len(share_data) + len(ownernumber) + len(renewsecret) + len(cancelsecret) |
---|
10430 | |
---|
10431 | hunk ./src/allmydata/test/test_storage.py 184 |
---|
10432 | - # Read past the end of share data to get the cancel secret. |
---|
10433 | - read_length = len(share_data) + len(ownernumber) + len(renewsecret) + len(cancelsecret) |
---|
10434 | + d2.addCallback(lambda ign: br.remote_read(0, read_length)) |
---|
10435 | + d2.addCallback(lambda res: self.failUnlessEqual(res, share_data)) |
---|
10436 | |
---|
10437 | hunk ./src/allmydata/test/test_storage.py 187 |
---|
10438 | - result_of_read = br.remote_read(0, read_length) |
---|
10439 | - self.failUnlessEqual(result_of_read, share_data) |
---|
10440 | + d2.addCallback(lambda ign: br.remote_read(0, len(share_data)+1)) |
---|
10441 | + d2.addCallback(lambda res: self.failUnlessEqual(res, share_data)) |
---|
10442 | + return d2 |
---|
10443 | + d.addCallback(_got_share) |
---|
10444 | + return d |
---|
10445 | |
---|
10446 | hunk ./src/allmydata/test/test_storage.py 193 |
---|
10447 | - result_of_read = br.remote_read(0, len(share_data)+1) |
---|
10448 | - self.failUnlessEqual(result_of_read, share_data) |
---|
10449 | |
---|
10450 | class RemoteBucket: |
---|
10451 | |
---|
10452 | hunk ./src/allmydata/test/test_storage.py 215 |
---|
10453 | |
---|
10454 | class BucketProxy(unittest.TestCase): |
---|
10455 | def make_bucket(self, name, size): |
---|
10456 | - basedir = os.path.join("storage", "BucketProxy", name) |
---|
10457 | - incoming = os.path.join(basedir, "tmp", "bucket") |
---|
10458 | - final = os.path.join(basedir, "bucket") |
---|
10459 | - fileutil.make_dirs(basedir) |
---|
10460 | - fileutil.make_dirs(os.path.join(basedir, "tmp")) |
---|
10461 | - bw = BucketWriter(self, incoming, final, size, self.make_lease(), |
---|
10462 | - FakeCanary()) |
---|
10463 | - rb = RemoteBucket() |
---|
10464 | - rb.target = bw |
---|
10465 | - return bw, rb, final |
---|
10466 | + basedir = FilePath("storage").child("BucketProxy").child(name) |
---|
10467 | + tmpdir = basedir.child("tmp") |
---|
10468 | + tmpdir.makedirs() |
---|
10469 | + incoming = tmpdir.child("bucket") |
---|
10470 | + final = basedir.child("bucket") |
---|
10471 | + |
---|
10472 | + d = defer.succeed(None) |
---|
10473 | + d.addCallback(lambda ign: create_immutable_disk_share(incoming, final, size)) |
---|
10474 | + def _got_share(share): |
---|
10475 | + bw = BucketWriter(self, share, self.make_lease(), FakeCanary()) |
---|
10476 | + rb = RemoteBucket() |
---|
10477 | + rb.target = bw |
---|
10478 | + return bw, rb, final |
---|
10479 | + d.addCallback(_got_share) |
---|
10480 | + return d |
---|
10481 | |
---|
10482 | def make_lease(self): |
---|
10483 | owner_num = 0 |
---|
10484 | hunk ./src/allmydata/test/test_storage.py 247 |
---|
10485 | pass |
---|
10486 | |
---|
10487 | def test_create(self): |
---|
10488 | - bw, rb, sharefname = self.make_bucket("test_create", 500) |
---|
10489 | - bp = WriteBucketProxy(rb, None, |
---|
10490 | - data_size=300, |
---|
10491 | - block_size=10, |
---|
10492 | - num_segments=5, |
---|
10493 | - num_share_hashes=3, |
---|
10494 | - uri_extension_size_max=500) |
---|
10495 | - self.failUnless(interfaces.IStorageBucketWriter.providedBy(bp), bp) |
---|
10496 | + d = self.make_bucket("test_create", 500) |
---|
10497 | + def _made_bucket( (bw, rb, sharefp) ): |
---|
10498 | + bp = WriteBucketProxy(rb, None, |
---|
10499 | + data_size=300, |
---|
10500 | + block_size=10, |
---|
10501 | + num_segments=5, |
---|
10502 | + num_share_hashes=3, |
---|
10503 | + uri_extension_size_max=500) |
---|
10504 | + self.failUnless(interfaces.IStorageBucketWriter.providedBy(bp), bp) |
---|
10505 | + d.addCallback(_made_bucket) |
---|
10506 | + return d |
---|
10507 | |
---|
10508 | def _do_test_readwrite(self, name, header_size, wbp_class, rbp_class): |
---|
10509 | # Let's pretend each share has 100 bytes of data, and that there are |
---|
10510 | hunk ./src/allmydata/test/test_storage.py 281 |
---|
10511 | for i in (1,9,13)] |
---|
10512 | uri_extension = "s" + "E"*498 + "e" |
---|
10513 | |
---|
10514 | - bw, rb, sharefname = self.make_bucket(name, sharesize) |
---|
10515 | - bp = wbp_class(rb, None, |
---|
10516 | - data_size=95, |
---|
10517 | - block_size=25, |
---|
10518 | - num_segments=4, |
---|
10519 | - num_share_hashes=3, |
---|
10520 | - uri_extension_size_max=len(uri_extension)) |
---|
10521 | + d = self.make_bucket(name, sharesize) |
---|
10522 | + def _made_bucket( (bw, rb, sharefp) ): |
---|
10523 | + bp = wbp_class(rb, None, |
---|
10524 | + data_size=95, |
---|
10525 | + block_size=25, |
---|
10526 | + num_segments=4, |
---|
10527 | + num_share_hashes=3, |
---|
10528 | + uri_extension_size_max=len(uri_extension)) |
---|
10529 | + |
---|
10530 | + d2 = bp.put_header() |
---|
10531 | + d2.addCallback(lambda ign: bp.put_block(0, "a"*25)) |
---|
10532 | + d2.addCallback(lambda ign: bp.put_block(1, "b"*25)) |
---|
10533 | + d2.addCallback(lambda ign: bp.put_block(2, "c"*25)) |
---|
10534 | + d2.addCallback(lambda ign: bp.put_block(3, "d"*20)) |
---|
10535 | + d2.addCallback(lambda ign: bp.put_crypttext_hashes(crypttext_hashes)) |
---|
10536 | + d2.addCallback(lambda ign: bp.put_block_hashes(block_hashes)) |
---|
10537 | + d2.addCallback(lambda ign: bp.put_share_hashes(share_hashes)) |
---|
10538 | + d2.addCallback(lambda ign: bp.put_uri_extension(uri_extension)) |
---|
10539 | + d2.addCallback(lambda ign: bp.close()) |
---|
10540 | |
---|
10541 | hunk ./src/allmydata/test/test_storage.py 301 |
---|
10542 | - d = bp.put_header() |
---|
10543 | - d.addCallback(lambda res: bp.put_block(0, "a"*25)) |
---|
10544 | - d.addCallback(lambda res: bp.put_block(1, "b"*25)) |
---|
10545 | - d.addCallback(lambda res: bp.put_block(2, "c"*25)) |
---|
10546 | - d.addCallback(lambda res: bp.put_block(3, "d"*20)) |
---|
10547 | - d.addCallback(lambda res: bp.put_crypttext_hashes(crypttext_hashes)) |
---|
10548 | - d.addCallback(lambda res: bp.put_block_hashes(block_hashes)) |
---|
10549 | - d.addCallback(lambda res: bp.put_share_hashes(share_hashes)) |
---|
10550 | - d.addCallback(lambda res: bp.put_uri_extension(uri_extension)) |
---|
10551 | - d.addCallback(lambda res: bp.close()) |
---|
10552 | + d2.addCallback(lambda ign: load_immutable_disk_share(sharefp)) |
---|
10553 | + return d2 |
---|
10554 | + d.addCallback(_made_bucket) |
---|
10555 | |
---|
10556 | # now read everything back |
---|
10557 | hunk ./src/allmydata/test/test_storage.py 306 |
---|
10558 | - def _start_reading(res): |
---|
10559 | - br = BucketReader(self, sharefname) |
---|
10560 | + def _start_reading(share): |
---|
10561 | + br = BucketReader(self, share) |
---|
10562 | rb = RemoteBucket() |
---|
10563 | rb.target = br |
---|
10564 | server = NoNetworkServer("abc", None) |
---|
10565 | hunk ./src/allmydata/test/test_storage.py 315 |
---|
10566 | self.failUnlessIn("to peer", repr(rbp)) |
---|
10567 | self.failUnless(interfaces.IStorageBucketReader.providedBy(rbp), rbp) |
---|
10568 | |
---|
10569 | - d1 = rbp.get_block_data(0, 25, 25) |
---|
10570 | - d1.addCallback(lambda res: self.failUnlessEqual(res, "a"*25)) |
---|
10571 | - d1.addCallback(lambda res: rbp.get_block_data(1, 25, 25)) |
---|
10572 | - d1.addCallback(lambda res: self.failUnlessEqual(res, "b"*25)) |
---|
10573 | - d1.addCallback(lambda res: rbp.get_block_data(2, 25, 25)) |
---|
10574 | - d1.addCallback(lambda res: self.failUnlessEqual(res, "c"*25)) |
---|
10575 | - d1.addCallback(lambda res: rbp.get_block_data(3, 25, 20)) |
---|
10576 | - d1.addCallback(lambda res: self.failUnlessEqual(res, "d"*20)) |
---|
10577 | - |
---|
10578 | - d1.addCallback(lambda res: rbp.get_crypttext_hashes()) |
---|
10579 | - d1.addCallback(lambda res: |
---|
10580 | - self.failUnlessEqual(res, crypttext_hashes)) |
---|
10581 | - d1.addCallback(lambda res: rbp.get_block_hashes(set(range(4)))) |
---|
10582 | - d1.addCallback(lambda res: self.failUnlessEqual(res, block_hashes)) |
---|
10583 | - d1.addCallback(lambda res: rbp.get_share_hashes()) |
---|
10584 | - d1.addCallback(lambda res: self.failUnlessEqual(res, share_hashes)) |
---|
10585 | - d1.addCallback(lambda res: rbp.get_uri_extension()) |
---|
10586 | - d1.addCallback(lambda res: |
---|
10587 | - self.failUnlessEqual(res, uri_extension)) |
---|
10588 | - |
---|
10589 | - return d1 |
---|
10590 | + d2 = defer.succeed(None) |
---|
10591 | + d2.addCallback(lambda ign: rbp.get_block_data(0, 25, 25)) |
---|
10592 | + d2.addCallback(lambda res: self.failUnlessEqual(res, "a"*25)) |
---|
10593 | + d2.addCallback(lambda ign: rbp.get_block_data(1, 25, 25)) |
---|
10594 | + d2.addCallback(lambda res: self.failUnlessEqual(res, "b"*25)) |
---|
10595 | + d2.addCallback(lambda ign: rbp.get_block_data(2, 25, 25)) |
---|
10596 | + d2.addCallback(lambda res: self.failUnlessEqual(res, "c"*25)) |
---|
10597 | + d2.addCallback(lambda ign: rbp.get_block_data(3, 25, 20)) |
---|
10598 | + d2.addCallback(lambda res: self.failUnlessEqual(res, "d"*20)) |
---|
10599 | |
---|
10600 | hunk ./src/allmydata/test/test_storage.py 325 |
---|
10601 | + d2.addCallback(lambda ign: rbp.get_crypttext_hashes()) |
---|
10602 | + d2.addCallback(lambda res: self.failUnlessEqual(res, crypttext_hashes)) |
---|
10603 | + d2.addCallback(lambda ign: rbp.get_block_hashes(set(range(4)))) |
---|
10604 | + d2.addCallback(lambda res: self.failUnlessEqual(res, block_hashes)) |
---|
10605 | + d2.addCallback(lambda ign: rbp.get_share_hashes()) |
---|
10606 | + d2.addCallback(lambda res: self.failUnlessEqual(res, share_hashes)) |
---|
10607 | + d2.addCallback(lambda ign: rbp.get_uri_extension()) |
---|
10608 | + d2.addCallback(lambda res: self.failUnlessEqual(res, uri_extension)) |
---|
10609 | + return d2 |
---|
10610 | d.addCallback(_start_reading) |
---|
10611 | return d |
---|
10612 | |
---|
10613 | hunk ./src/allmydata/test/test_storage.py 345 |
---|
10614 | return self._do_test_readwrite("test_readwrite_v2", |
---|
10615 | 0x44, WriteBucketProxy_v2, ReadBucketProxy) |
---|
10616 | |
---|
10617 | -class Server(unittest.TestCase): |
---|
10618 | |
---|
10619 | hunk ./src/allmydata/test/test_storage.py 346 |
---|
10620 | +class Seek(unittest.TestCase): |
---|
10621 | + def workdir(self, name): |
---|
10622 | + return FilePath("storage").child(self.__class__.__name__).child(name) |
---|
10623 | + |
---|
10624 | + def test_seek(self): |
---|
10625 | + basedir = self.workdir("test_seek") |
---|
10626 | + basedir.makedirs() |
---|
10627 | + fp = basedir.child("testfile") |
---|
10628 | + fp.setContent("start") |
---|
10629 | + |
---|
10630 | + # mode="w" allows seeking-to-create-holes, but truncates pre-existing |
---|
10631 | + # files. mode="a" preserves previous contents but does not allow |
---|
10632 | + # seeking-to-create-holes. mode="r+" allows both. |
---|
10633 | + f = fp.open("rb+") |
---|
10634 | + try: |
---|
10635 | + f.seek(100) |
---|
10636 | + f.write("100") |
---|
10637 | + finally: |
---|
10638 | + f.close() |
---|
10639 | + fp.restat() |
---|
10640 | + filelen = fp.getsize() |
---|
10641 | + self.failUnlessEqual(filelen, 100+3) |
---|
10642 | + f2 = fp.open("rb") |
---|
10643 | + try: |
---|
10644 | + self.failUnlessEqual(f2.read(5), "start") |
---|
10645 | + finally: |
---|
10646 | + f2.close() |
---|
10647 | + |
---|
10648 | + |
---|
10649 | +class ServerMixin: |
---|
10650 | def setUp(self): |
---|
10651 | self.sparent = LoggingServiceParent() |
---|
10652 | self.sparent.startService() |
---|
10653 | hunk ./src/allmydata/test/test_storage.py 384 |
---|
10654 | return self.sparent.stopService() |
---|
10655 | |
---|
10656 | def workdir(self, name): |
---|
10657 | - basedir = os.path.join("storage", "Server", name) |
---|
10658 | - return basedir |
---|
10659 | + return FilePath("storage").child(self.__class__.__name__).child(name) |
---|
10660 | |
---|
10661 | hunk ./src/allmydata/test/test_storage.py 386 |
---|
10662 | - def create(self, name, reserved_space=0, klass=StorageServer): |
---|
10663 | - workdir = self.workdir(name) |
---|
10664 | - ss = klass(workdir, "\x00" * 20, reserved_space=reserved_space, |
---|
10665 | - stats_provider=FakeStatsProvider()) |
---|
10666 | - ss.setServiceParent(self.sparent) |
---|
10667 | - return ss |
---|
10668 | + def allocate(self, ss, storage_index, sharenums, size, canary=None): |
---|
10669 | + renew_secret = hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()) |
---|
10670 | + cancel_secret = hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()) |
---|
10671 | + if not canary: |
---|
10672 | + canary = FakeCanary() |
---|
10673 | + return defer.maybeDeferred(ss.remote_allocate_buckets, |
---|
10674 | + storage_index, renew_secret, cancel_secret, |
---|
10675 | + sharenums, size, canary) |
---|
10676 | + |
---|
10677 | + def _write_and_close(self, ign, i, bw): |
---|
10678 | + d = defer.succeed(None) |
---|
10679 | + d.addCallback(lambda ign: bw.remote_write(0, "%25d" % i)) |
---|
10680 | + d.addCallback(lambda ign: bw.remote_close()) |
---|
10681 | + return d |
---|
10682 | |
---|
10683 | hunk ./src/allmydata/test/test_storage.py 401 |
---|
10684 | + def _close_writer(self, ign, i, bw): |
---|
10685 | + return bw.remote_close() |
---|
10686 | + |
---|
10687 | + def _abort_writer(self, ign, i, bw): |
---|
10688 | + return bw.remote_abort() |
---|
10689 | + |
---|
10690 | + |
---|
10691 | +class ServerTest(ServerMixin, ShouldFailMixin): |
---|
10692 | def test_create(self): |
---|
10693 | self.create("test_create") |
---|
10694 | |
---|
10695 | hunk ./src/allmydata/test/test_storage.py 418 |
---|
10696 | sv1 = ver['http://allmydata.org/tahoe/protocols/storage/v1'] |
---|
10697 | self.failUnless(sv1.get('prevents-read-past-end-of-share-data'), sv1) |
---|
10698 | |
---|
10699 | - def allocate(self, ss, storage_index, sharenums, size, canary=None): |
---|
10700 | - renew_secret = hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()) |
---|
10701 | - cancel_secret = hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()) |
---|
10702 | - if not canary: |
---|
10703 | - canary = FakeCanary() |
---|
10704 | - return ss.remote_allocate_buckets(storage_index, |
---|
10705 | - renew_secret, cancel_secret, |
---|
10706 | - sharenums, size, canary) |
---|
10707 | + def test_has_immutable_readv(self): |
---|
10708 | + ss = self.create("test_has_immutable_readv") |
---|
10709 | + ver = ss.remote_get_version() |
---|
10710 | + sv1 = ver['http://allmydata.org/tahoe/protocols/storage/v1'] |
---|
10711 | + self.failUnless(sv1.get('has-immutable-readv'), sv1) |
---|
10712 | |
---|
10713 | hunk ./src/allmydata/test/test_storage.py 424 |
---|
10714 | - def test_large_share(self): |
---|
10715 | - syslow = platform.system().lower() |
---|
10716 | - if 'cygwin' in syslow or 'windows' in syslow or 'darwin' in syslow: |
---|
10717 | - raise unittest.SkipTest("If your filesystem doesn't support efficient sparse files then it is very expensive (Mac OS X and Windows don't support efficient sparse files).") |
---|
10718 | + # TODO: test that we actually support it |
---|
10719 | |
---|
10720 | hunk ./src/allmydata/test/test_storage.py 426 |
---|
10721 | - avail = fileutil.get_available_space('.', 512*2**20) |
---|
10722 | - if avail <= 4*2**30: |
---|
10723 | - raise unittest.SkipTest("This test will spuriously fail if you have less than 4 GiB free on your filesystem.") |
---|
10724 | + def test_create_share(self): |
---|
10725 | + ss = self.create("test_create_share") |
---|
10726 | |
---|
10727 | hunk ./src/allmydata/test/test_storage.py 429 |
---|
10728 | - ss = self.create("test_large_share") |
---|
10729 | + d = self.allocate(ss, "si1", [0], 75) |
---|
10730 | + def _allocated( (already, writers) ): |
---|
10731 | + self.failUnlessEqual(already, set()) |
---|
10732 | + self.failUnlessEqual(set(writers.keys()), set([0])) |
---|
10733 | |
---|
10734 | hunk ./src/allmydata/test/test_storage.py 434 |
---|
10735 | - already,writers = self.allocate(ss, "allocate", [0], 2**32+2) |
---|
10736 | - self.failUnlessEqual(already, set()) |
---|
10737 | - self.failUnlessEqual(set(writers.keys()), set([0])) |
---|
10738 | + d2 = defer.succeed(None) |
---|
10739 | + d2.addCallback(lambda ign: writers[0].remote_write(0, "data")) |
---|
10740 | + d2.addCallback(lambda ign: writers[0].remote_close()) |
---|
10741 | |
---|
10742 | hunk ./src/allmydata/test/test_storage.py 438 |
---|
10743 | - shnum, bucket = writers.items()[0] |
---|
10744 | - # This test is going to hammer your filesystem if it doesn't make a sparse file for this. :-( |
---|
10745 | - bucket.remote_write(2**32, "ab") |
---|
10746 | - bucket.remote_close() |
---|
10747 | + d2.addCallback(lambda ign: ss.backend.get_shareset("si1").get_share(0)) |
---|
10748 | + d2.addCallback(lambda share: self.failUnless(interfaces.IShareForReading.providedBy(share))) |
---|
10749 | |
---|
10750 | hunk ./src/allmydata/test/test_storage.py 441 |
---|
10751 | - readers = ss.remote_get_buckets("allocate") |
---|
10752 | - reader = readers[shnum] |
---|
10753 | - self.failUnlessEqual(reader.remote_read(2**32, 2), "ab") |
---|
10754 | + d2.addCallback(lambda ign: ss.backend.get_shareset("si1").get_shares()) |
---|
10755 | + def _check( (shares, corrupted) ): |
---|
10756 | + self.failUnlessEqual(len(shares), 1, str(shares)) |
---|
10757 | + self.failUnlessEqual(len(corrupted), 0, str(corrupted)) |
---|
10758 | + d2.addCallback(_check) |
---|
10759 | + return d2 |
---|
10760 | + d.addCallback(_allocated) |
---|
10761 | + return d |
---|
10762 | |
---|
10763 | def test_dont_overfill_dirs(self): |
---|
10764 | """ |
---|
10765 | hunk ./src/allmydata/test/test_storage.py 457 |
---|
10766 | same storage index), this won't add an entry to the share directory. |
---|
10767 | """ |
---|
10768 | ss = self.create("test_dont_overfill_dirs") |
---|
10769 | - already, writers = self.allocate(ss, "storageindex", [0], 10) |
---|
10770 | - for i, wb in writers.items(): |
---|
10771 | - wb.remote_write(0, "%10d" % i) |
---|
10772 | - wb.remote_close() |
---|
10773 | - storedir = os.path.join(self.workdir("test_dont_overfill_dirs"), |
---|
10774 | - "shares") |
---|
10775 | - children_of_storedir = set(os.listdir(storedir)) |
---|
10776 | + storedir = self.workdir("test_dont_overfill_dirs").child("shares") |
---|
10777 | |
---|
10778 | hunk ./src/allmydata/test/test_storage.py 459 |
---|
10779 | - # Now store another one under another storageindex that has leading |
---|
10780 | - # chars the same as the first storageindex. |
---|
10781 | - already, writers = self.allocate(ss, "storageindey", [0], 10) |
---|
10782 | - for i, wb in writers.items(): |
---|
10783 | - wb.remote_write(0, "%10d" % i) |
---|
10784 | - wb.remote_close() |
---|
10785 | - storedir = os.path.join(self.workdir("test_dont_overfill_dirs"), |
---|
10786 | - "shares") |
---|
10787 | - new_children_of_storedir = set(os.listdir(storedir)) |
---|
10788 | - self.failUnlessEqual(children_of_storedir, new_children_of_storedir) |
---|
10789 | + def _write_and_get_children( (already, writers) ): |
---|
10790 | + d = for_items(self._write_and_close, writers) |
---|
10791 | + d.addCallback(lambda ign: sorted([str(child.basename()) for child in storedir.children()])) |
---|
10792 | + return d |
---|
10793 | |
---|
10794 | hunk ./src/allmydata/test/test_storage.py 464 |
---|
10795 | - def test_remove_incoming(self): |
---|
10796 | - ss = self.create("test_remove_incoming") |
---|
10797 | - already, writers = self.allocate(ss, "vid", range(3), 10) |
---|
10798 | - for i,wb in writers.items(): |
---|
10799 | - wb.remote_write(0, "%10d" % i) |
---|
10800 | - wb.remote_close() |
---|
10801 | - incoming_share_dir = wb.incominghome |
---|
10802 | - incoming_bucket_dir = os.path.dirname(incoming_share_dir) |
---|
10803 | - incoming_prefix_dir = os.path.dirname(incoming_bucket_dir) |
---|
10804 | - incoming_dir = os.path.dirname(incoming_prefix_dir) |
---|
10805 | - self.failIf(os.path.exists(incoming_bucket_dir), incoming_bucket_dir) |
---|
10806 | - self.failIf(os.path.exists(incoming_prefix_dir), incoming_prefix_dir) |
---|
10807 | - self.failUnless(os.path.exists(incoming_dir), incoming_dir) |
---|
10808 | + d = self.allocate(ss, "storageindex", [0], 25) |
---|
10809 | + d.addCallback(_write_and_get_children) |
---|
10810 | + |
---|
10811 | + def _got_children(children_of_storedir): |
---|
10812 | + # Now store another one under another storageindex that has leading |
---|
10813 | + # chars the same as the first storageindex. |
---|
10814 | + d2 = self.allocate(ss, "storageindey", [0], 25) |
---|
10815 | + d2.addCallback(_write_and_get_children) |
---|
10816 | + d2.addCallback(lambda res: self.failUnlessEqual(res, children_of_storedir)) |
---|
10817 | + return d2 |
---|
10818 | + d.addCallback(_got_children) |
---|
10819 | + return d |
---|
10820 | |
---|
10821 | def test_abort(self): |
---|
10822 | # remote_abort, when called on a writer, should make sure that |
---|
10823 | hunk ./src/allmydata/test/test_storage.py 482 |
---|
10824 | # the allocated size of the bucket is not counted by the storage |
---|
10825 | # server when accounting for space. |
---|
10826 | ss = self.create("test_abort") |
---|
10827 | - already, writers = self.allocate(ss, "allocate", [0, 1, 2], 150) |
---|
10828 | - self.failIfEqual(ss.allocated_size(), 0) |
---|
10829 | |
---|
10830 | hunk ./src/allmydata/test/test_storage.py 483 |
---|
10831 | - # Now abort the writers. |
---|
10832 | - for writer in writers.itervalues(): |
---|
10833 | - writer.remote_abort() |
---|
10834 | - self.failUnlessEqual(ss.allocated_size(), 0) |
---|
10835 | + d = self.allocate(ss, "allocate", [0, 1, 2], 150) |
---|
10836 | + def _allocated( (already, writers) ): |
---|
10837 | + self.failIfEqual(ss.allocated_size(), 0) |
---|
10838 | |
---|
10839 | hunk ./src/allmydata/test/test_storage.py 487 |
---|
10840 | + # Now abort the writers. |
---|
10841 | + d2 = for_items(self._abort_writer, writers) |
---|
10842 | + d2.addCallback(lambda ign: self.failUnlessEqual(ss.allocated_size(), 0)) |
---|
10843 | + return d2 |
---|
10844 | + d.addCallback(_allocated) |
---|
10845 | + return d |
---|
10846 | |
---|
10847 | def test_allocate(self): |
---|
10848 | ss = self.create("test_allocate") |
---|
10849 | hunk ./src/allmydata/test/test_storage.py 497 |
---|
10850 | |
---|
10851 | - self.failUnlessEqual(ss.remote_get_buckets("allocate"), {}) |
---|
10852 | + d = defer.succeed(None) |
---|
10853 | + d.addCallback(lambda ign: ss.remote_get_buckets("allocate")) |
---|
10854 | + d.addCallback(lambda res: self.failUnlessEqual(res, {})) |
---|
10855 | |
---|
10856 | hunk ./src/allmydata/test/test_storage.py 501 |
---|
10857 | - already,writers = self.allocate(ss, "allocate", [0,1,2], 75) |
---|
10858 | - self.failUnlessEqual(already, set()) |
---|
10859 | - self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
10860 | + d.addCallback(lambda ign: self.allocate(ss, "allocate", [0,1,2], 75)) |
---|
10861 | + def _allocated( (already, writers) ): |
---|
10862 | + self.failUnlessEqual(already, set()) |
---|
10863 | + self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
10864 | |
---|
10865 | hunk ./src/allmydata/test/test_storage.py 506 |
---|
10866 | - # while the buckets are open, they should not count as readable |
---|
10867 | - self.failUnlessEqual(ss.remote_get_buckets("allocate"), {}) |
---|
10868 | + # while the buckets are open, they should not count as readable |
---|
10869 | + d2 = defer.succeed(None) |
---|
10870 | + d2.addCallback(lambda ign: ss.remote_get_buckets("allocate")) |
---|
10871 | + d2.addCallback(lambda res: self.failUnlessEqual(res, {})) |
---|
10872 | |
---|
10873 | hunk ./src/allmydata/test/test_storage.py 511 |
---|
10874 | - # close the buckets |
---|
10875 | - for i,wb in writers.items(): |
---|
10876 | - wb.remote_write(0, "%25d" % i) |
---|
10877 | - wb.remote_close() |
---|
10878 | - # aborting a bucket that was already closed is a no-op |
---|
10879 | - wb.remote_abort() |
---|
10880 | + # close the buckets |
---|
10881 | + for i, bw in writers.items(): |
---|
10882 | + d2.addCallback(self._write_and_close, i, bw) |
---|
10883 | + # aborting a bucket that was already closed is a no-op |
---|
10884 | + d2.addCallback(self._abort_writer, i, bw) |
---|
10885 | |
---|
10886 | hunk ./src/allmydata/test/test_storage.py 517 |
---|
10887 | - # now they should be readable |
---|
10888 | - b = ss.remote_get_buckets("allocate") |
---|
10889 | - self.failUnlessEqual(set(b.keys()), set([0,1,2])) |
---|
10890 | - self.failUnlessEqual(b[0].remote_read(0, 25), "%25d" % 0) |
---|
10891 | - b_str = str(b[0]) |
---|
10892 | - self.failUnlessIn("BucketReader", b_str) |
---|
10893 | - self.failUnlessIn("mfwgy33dmf2g 0", b_str) |
---|
10894 | + # now they should be readable |
---|
10895 | + d2.addCallback(lambda ign: ss.remote_get_buckets("allocate")) |
---|
10896 | + def _got_buckets(b): |
---|
10897 | + self.failUnlessEqual(set(b.keys()), set([0,1,2])) |
---|
10898 | + b_str = str(b[0]) |
---|
10899 | + self.failUnlessIn("BucketReader", b_str) |
---|
10900 | + self.failUnlessIn("mfwgy33dmf2g 0", b_str) |
---|
10901 | + |
---|
10902 | + d3 = defer.succeed(None) |
---|
10903 | + d3.addCallback(lambda ign: b[0].remote_read(0, 25)) |
---|
10904 | + d3.addCallback(lambda res: self.failUnlessEqual(res, "%25d" % 0)) |
---|
10905 | + return d3 |
---|
10906 | + d2.addCallback(_got_buckets) |
---|
10907 | + d.addCallback(_allocated) |
---|
10908 | |
---|
10909 | # now if we ask about writing again, the server should offer those |
---|
10910 | # three buckets as already present. It should offer them even if we |
---|
10911 | hunk ./src/allmydata/test/test_storage.py 535 |
---|
10912 | # don't ask about those specific ones. |
---|
10913 | - already,writers = self.allocate(ss, "allocate", [2,3,4], 75) |
---|
10914 | - self.failUnlessEqual(already, set([0,1,2])) |
---|
10915 | - self.failUnlessEqual(set(writers.keys()), set([3,4])) |
---|
10916 | |
---|
10917 | hunk ./src/allmydata/test/test_storage.py 536 |
---|
10918 | - # while those two buckets are open for writing, the server should |
---|
10919 | - # refuse to offer them to uploaders |
---|
10920 | + d.addCallback(lambda ign: self.allocate(ss, "allocate", [2,3,4], 75)) |
---|
10921 | + def _allocated_again( (already, writers) ): |
---|
10922 | + self.failUnlessEqual(already, set([0,1,2])) |
---|
10923 | + self.failUnlessEqual(set(writers.keys()), set([3,4])) |
---|
10924 | |
---|
10925 | hunk ./src/allmydata/test/test_storage.py 541 |
---|
10926 | - already2,writers2 = self.allocate(ss, "allocate", [2,3,4,5], 75) |
---|
10927 | - self.failUnlessEqual(already2, set([0,1,2])) |
---|
10928 | - self.failUnlessEqual(set(writers2.keys()), set([5])) |
---|
10929 | + # while those two buckets are open for writing, the server should |
---|
10930 | + # refuse to offer them to uploaders |
---|
10931 | |
---|
10932 | hunk ./src/allmydata/test/test_storage.py 544 |
---|
10933 | - # aborting the writes should remove the tempfiles |
---|
10934 | - for i,wb in writers2.items(): |
---|
10935 | - wb.remote_abort() |
---|
10936 | - already2,writers2 = self.allocate(ss, "allocate", [2,3,4,5], 75) |
---|
10937 | - self.failUnlessEqual(already2, set([0,1,2])) |
---|
10938 | - self.failUnlessEqual(set(writers2.keys()), set([5])) |
---|
10939 | + d2 = self.allocate(ss, "allocate", [2,3,4,5], 75) |
---|
10940 | + def _allocated_again2( (already2, writers2) ): |
---|
10941 | + self.failUnlessEqual(already2, set([0,1,2])) |
---|
10942 | + self.failUnlessEqual(set(writers2.keys()), set([5])) |
---|
10943 | |
---|
10944 | hunk ./src/allmydata/test/test_storage.py 549 |
---|
10945 | - for i,wb in writers2.items(): |
---|
10946 | - wb.remote_abort() |
---|
10947 | - for i,wb in writers.items(): |
---|
10948 | - wb.remote_abort() |
---|
10949 | + # aborting the writes should remove the tempfiles |
---|
10950 | + return for_items(self._abort_writer, writers2) |
---|
10951 | + d2.addCallback(_allocated_again2) |
---|
10952 | |
---|
10953 | hunk ./src/allmydata/test/test_storage.py 553 |
---|
10954 | - def test_bad_container_version(self): |
---|
10955 | - ss = self.create("test_bad_container_version") |
---|
10956 | - a,w = self.allocate(ss, "si1", [0], 10) |
---|
10957 | - w[0].remote_write(0, "\xff"*10) |
---|
10958 | - w[0].remote_close() |
---|
10959 | - |
---|
10960 | - fn = os.path.join(ss.sharedir, storage_index_to_dir("si1"), "0") |
---|
10961 | - f = open(fn, "rb+") |
---|
10962 | - f.seek(0) |
---|
10963 | - f.write(struct.pack(">L", 0)) # this is invalid: minimum used is v1 |
---|
10964 | - f.close() |
---|
10965 | + d2.addCallback(lambda ign: self.allocate(ss, "allocate", [2,3,4,5], 75)) |
---|
10966 | + d2.addCallback(_allocated_again2) |
---|
10967 | |
---|
10968 | hunk ./src/allmydata/test/test_storage.py 556 |
---|
10969 | - ss.remote_get_buckets("allocate") |
---|
10970 | + d2.addCallback(lambda ign: for_items(self._abort_writer, writers)) |
---|
10971 | + return d2 |
---|
10972 | + d.addCallback(_allocated_again) |
---|
10973 | + return d |
---|
10974 | |
---|
10975 | hunk ./src/allmydata/test/test_storage.py 561 |
---|
10976 | - e = self.failUnlessRaises(UnknownImmutableContainerVersionError, |
---|
10977 | - ss.remote_get_buckets, "si1") |
---|
10978 | - self.failUnlessIn(" had version 0 but we wanted 1", str(e)) |
---|
10979 | + # The following share file content was generated with |
---|
10980 | + # storage.immutable.ShareFile from Tahoe-LAFS v1.8.2 |
---|
10981 | + # with share data == 'a'. The total size of this input |
---|
10982 | + # is 85 bytes. |
---|
10983 | + shareversionnumber = '\x00\x00\x00\x01' |
---|
10984 | + sharedatalength = '\x00\x00\x00\x01' |
---|
10985 | + numberofleases = '\x00\x00\x00\x01' |
---|
10986 | + shareinputdata = 'a' |
---|
10987 | + ownernumber = '\x00\x00\x00\x00' |
---|
10988 | + renewsecret = 'x'*32 |
---|
10989 | + cancelsecret = 'y'*32 |
---|
10990 | + expirationtime = '\x00(\xde\x80' |
---|
10991 | + nextlease = '' |
---|
10992 | + containerdata = shareversionnumber + sharedatalength + numberofleases |
---|
10993 | + client_data = (shareinputdata + ownernumber + renewsecret + |
---|
10994 | + cancelsecret + expirationtime + nextlease) |
---|
10995 | + share_data = containerdata + client_data |
---|
10996 | + testnodeid = 'testnodeidxxxxxxxxxx' |
---|
10997 | |
---|
10998 | hunk ./src/allmydata/test/test_storage.py 580 |
---|
10999 | - def test_disconnect(self): |
---|
11000 | - # simulate a disconnection |
---|
11001 | - ss = self.create("test_disconnect") |
---|
11002 | + def test_write_and_read_share(self): |
---|
11003 | + """ |
---|
11004 | + Write a new share, read it, and test the server's (and disk backend's) |
---|
11005 | + handling of simultaneous and successive attempts to write the same |
---|
11006 | + share. |
---|
11007 | + """ |
---|
11008 | + ss = self.create("test_write_and_read_share") |
---|
11009 | canary = FakeCanary() |
---|
11010 | hunk ./src/allmydata/test/test_storage.py 588 |
---|
11011 | - already,writers = self.allocate(ss, "disconnect", [0,1,2], 75, canary) |
---|
11012 | - self.failUnlessEqual(already, set()) |
---|
11013 | - self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
11014 | - for (f,args,kwargs) in canary.disconnectors.values(): |
---|
11015 | - f(*args, **kwargs) |
---|
11016 | - del already |
---|
11017 | - del writers |
---|
11018 | |
---|
11019 | hunk ./src/allmydata/test/test_storage.py 589 |
---|
11020 | - # that ought to delete the incoming shares |
---|
11021 | - already,writers = self.allocate(ss, "disconnect", [0,1,2], 75) |
---|
11022 | - self.failUnlessEqual(already, set()) |
---|
11023 | - self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
11024 | + shareset = ss.backend.get_shareset('teststorage_index') |
---|
11025 | + self.failIf(shareset.has_incoming(0)) |
---|
11026 | |
---|
11027 | hunk ./src/allmydata/test/test_storage.py 592 |
---|
11028 | - @mock.patch('allmydata.util.fileutil.get_disk_stats') |
---|
11029 | - def test_reserved_space(self, mock_get_disk_stats): |
---|
11030 | - reserved_space=10000 |
---|
11031 | - mock_get_disk_stats.return_value = { |
---|
11032 | - 'free_for_nonroot': 15000, |
---|
11033 | - 'avail': max(15000 - reserved_space, 0), |
---|
11034 | - } |
---|
11035 | + # Populate incoming with the sharenum: 0. |
---|
11036 | + d = ss.remote_allocate_buckets('teststorage_index', 'x'*32, 'y'*32, frozenset((0,)), 1, canary) |
---|
11037 | + def _allocated( (already, writers) ): |
---|
11038 | + # This is a white-box test: Inspect incoming and fail unless the sharenum: 0 is listed there. |
---|
11039 | + self.failUnless(shareset.has_incoming(0)) |
---|
11040 | |
---|
11041 | hunk ./src/allmydata/test/test_storage.py 598 |
---|
11042 | - ss = self.create("test_reserved_space", reserved_space=reserved_space) |
---|
11043 | - # 15k available, 10k reserved, leaves 5k for shares |
---|
11044 | + # Attempt to create a second share writer with the same sharenum. |
---|
11045 | + d2 = ss.remote_allocate_buckets('teststorage_index', 'x'*32, 'y'*32, frozenset((0,)), 1, canary) |
---|
11046 | |
---|
11047 | hunk ./src/allmydata/test/test_storage.py 601 |
---|
11048 | - # a newly created and filled share incurs this much overhead, beyond |
---|
11049 | - # the size we request. |
---|
11050 | - OVERHEAD = 3*4 |
---|
11051 | - LEASE_SIZE = 4+32+32+4 |
---|
11052 | - canary = FakeCanary(True) |
---|
11053 | - already,writers = self.allocate(ss, "vid1", [0,1,2], 1000, canary) |
---|
11054 | - self.failUnlessEqual(len(writers), 3) |
---|
11055 | - # now the StorageServer should have 3000 bytes provisionally |
---|
11056 | - # allocated, allowing only 2000 more to be claimed |
---|
11057 | - self.failUnlessEqual(len(ss._active_writers), 3) |
---|
11058 | - |
---|
11059 | - # allocating 1001-byte shares only leaves room for one |
---|
11060 | - already2,writers2 = self.allocate(ss, "vid2", [0,1,2], 1001, canary) |
---|
11061 | - self.failUnlessEqual(len(writers2), 1) |
---|
11062 | - self.failUnlessEqual(len(ss._active_writers), 4) |
---|
11063 | - |
---|
11064 | - # we abandon the first set, so their provisional allocation should be |
---|
11065 | - # returned |
---|
11066 | - del already |
---|
11067 | - del writers |
---|
11068 | - self.failUnlessEqual(len(ss._active_writers), 1) |
---|
11069 | - # now we have a provisional allocation of 1001 bytes |
---|
11070 | - |
---|
11071 | - # and we close the second set, so their provisional allocation should |
---|
11072 | - # become real, long-term allocation, and grows to include the |
---|
11073 | - # overhead. |
---|
11074 | - for bw in writers2.values(): |
---|
11075 | - bw.remote_write(0, "a"*25) |
---|
11076 | - bw.remote_close() |
---|
11077 | - del already2 |
---|
11078 | - del writers2 |
---|
11079 | - del bw |
---|
11080 | - self.failUnlessEqual(len(ss._active_writers), 0) |
---|
11081 | - |
---|
11082 | - allocated = 1001 + OVERHEAD + LEASE_SIZE |
---|
11083 | - |
---|
11084 | - # we have to manually increase available, since we're not doing real |
---|
11085 | - # disk measurements |
---|
11086 | - mock_get_disk_stats.return_value = { |
---|
11087 | - 'free_for_nonroot': 15000 - allocated, |
---|
11088 | - 'avail': max(15000 - allocated - reserved_space, 0), |
---|
11089 | - } |
---|
11090 | - |
---|
11091 | - # now there should be ALLOCATED=1001+12+72=1085 bytes allocated, and |
---|
11092 | - # 5000-1085=3915 free, therefore we can fit 39 100byte shares |
---|
11093 | - already3,writers3 = self.allocate(ss,"vid3", range(100), 100, canary) |
---|
11094 | - self.failUnlessEqual(len(writers3), 39) |
---|
11095 | - self.failUnlessEqual(len(ss._active_writers), 39) |
---|
11096 | - |
---|
11097 | - del already3 |
---|
11098 | - del writers3 |
---|
11099 | - self.failUnlessEqual(len(ss._active_writers), 0) |
---|
11100 | - ss.disownServiceParent() |
---|
11101 | - del ss |
---|
11102 | + # Show that no sharewriter results from a remote_allocate_buckets |
---|
11103 | + # with the same si and sharenum, until BucketWriter.remote_close() |
---|
11104 | + # has been called. |
---|
11105 | + d2.addCallback(lambda (already2, writers2): self.failIf(writers2)) |
---|
11106 | |
---|
11107 | hunk ./src/allmydata/test/test_storage.py 606 |
---|
11108 | - def test_seek(self): |
---|
11109 | - basedir = self.workdir("test_seek_behavior") |
---|
11110 | - fileutil.make_dirs(basedir) |
---|
11111 | - filename = os.path.join(basedir, "testfile") |
---|
11112 | - f = open(filename, "wb") |
---|
11113 | - f.write("start") |
---|
11114 | - f.close() |
---|
11115 | - # mode="w" allows seeking-to-create-holes, but truncates pre-existing |
---|
11116 | - # files. mode="a" preserves previous contents but does not allow |
---|
11117 | - # seeking-to-create-holes. mode="r+" allows both. |
---|
11118 | - f = open(filename, "rb+") |
---|
11119 | - f.seek(100) |
---|
11120 | - f.write("100") |
---|
11121 | - f.close() |
---|
11122 | - filelen = os.stat(filename)[stat.ST_SIZE] |
---|
11123 | - self.failUnlessEqual(filelen, 100+3) |
---|
11124 | - f2 = open(filename, "rb") |
---|
11125 | - self.failUnlessEqual(f2.read(5), "start") |
---|
11126 | - |
---|
11127 | - |
---|
11128 | - def test_leases(self): |
---|
11129 | - ss = self.create("test_leases") |
---|
11130 | - canary = FakeCanary() |
---|
11131 | - sharenums = range(5) |
---|
11132 | - size = 100 |
---|
11133 | + # Test allocated size. |
---|
11134 | + d2.addCallback(lambda ign: ss.allocated_size()) |
---|
11135 | + d2.addCallback(lambda space: self.failUnlessEqual(space, 1)) |
---|
11136 | |
---|
11137 | hunk ./src/allmydata/test/test_storage.py 610 |
---|
11138 | - rs0,cs0 = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11139 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11140 | - already,writers = ss.remote_allocate_buckets("si0", rs0, cs0, |
---|
11141 | - sharenums, size, canary) |
---|
11142 | - self.failUnlessEqual(len(already), 0) |
---|
11143 | - self.failUnlessEqual(len(writers), 5) |
---|
11144 | - for wb in writers.values(): |
---|
11145 | - wb.remote_close() |
---|
11146 | + # Write 'a' to shnum 0. Only tested together with close and read. |
---|
11147 | + d2.addCallback(lambda ign: writers[0].remote_write(0, 'a')) |
---|
11148 | |
---|
11149 | hunk ./src/allmydata/test/test_storage.py 613 |
---|
11150 | - leases = list(ss.get_leases("si0")) |
---|
11151 | - self.failUnlessEqual(len(leases), 1) |
---|
11152 | - self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs0])) |
---|
11153 | + # Preclose: Inspect final, failUnless nothing there. |
---|
11154 | + d2.addCallback(lambda ign: ss.backend.get_shareset('teststorage_index').get_shares()) |
---|
11155 | + def _check( (shares, corrupted) ): |
---|
11156 | + self.failUnlessEqual(len(shares), 0, str(shares)) |
---|
11157 | + self.failUnlessEqual(len(corrupted), 0, str(corrupted)) |
---|
11158 | + d2.addCallback(_check) |
---|
11159 | |
---|
11160 | hunk ./src/allmydata/test/test_storage.py 620 |
---|
11161 | - rs1,cs1 = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11162 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11163 | - already,writers = ss.remote_allocate_buckets("si1", rs1, cs1, |
---|
11164 | - sharenums, size, canary) |
---|
11165 | - for wb in writers.values(): |
---|
11166 | - wb.remote_close() |
---|
11167 | + d2.addCallback(lambda ign: writers[0].remote_close()) |
---|
11168 | |
---|
11169 | hunk ./src/allmydata/test/test_storage.py 622 |
---|
11170 | - # take out a second lease on si1 |
---|
11171 | - rs2,cs2 = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11172 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11173 | - already,writers = ss.remote_allocate_buckets("si1", rs2, cs2, |
---|
11174 | - sharenums, size, canary) |
---|
11175 | - self.failUnlessEqual(len(already), 5) |
---|
11176 | - self.failUnlessEqual(len(writers), 0) |
---|
11177 | + # Postclose: fail unless written data is in final. |
---|
11178 | + d2.addCallback(lambda ign: ss.backend.get_shareset('teststorage_index').get_shares()) |
---|
11179 | + def _got_shares( (sharesinfinal, corrupted) ): |
---|
11180 | + self.failUnlessEqual(len(sharesinfinal), 1, str(sharesinfinal)) |
---|
11181 | + self.failUnlessEqual(len(corrupted), 0, str(corrupted)) |
---|
11182 | |
---|
11183 | hunk ./src/allmydata/test/test_storage.py 628 |
---|
11184 | - leases = list(ss.get_leases("si1")) |
---|
11185 | - self.failUnlessEqual(len(leases), 2) |
---|
11186 | - self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs1, rs2])) |
---|
11187 | + d3 = defer.succeed(None) |
---|
11188 | + d3.addCallback(lambda ign: sharesinfinal[0].read_share_data(0, 73)) |
---|
11189 | + d3.addCallback(lambda contents: self.failUnlessEqual(contents, self.shareinputdata)) |
---|
11190 | + return d3 |
---|
11191 | + d2.addCallback(_got_shares) |
---|
11192 | |
---|
11193 | hunk ./src/allmydata/test/test_storage.py 634 |
---|
11194 | - # and a third lease, using add-lease |
---|
11195 | - rs2a,cs2a = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11196 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11197 | - ss.remote_add_lease("si1", rs2a, cs2a) |
---|
11198 | - leases = list(ss.get_leases("si1")) |
---|
11199 | - self.failUnlessEqual(len(leases), 3) |
---|
11200 | - self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs1, rs2, rs2a])) |
---|
11201 | + # Exercise the case that the share we're asking to allocate is |
---|
11202 | + # already (completely) uploaded. |
---|
11203 | + d2.addCallback(lambda ign: ss.remote_allocate_buckets('teststorage_index', |
---|
11204 | + 'x'*32, 'y'*32, set((0,)), 1, canary)) |
---|
11205 | + return d2 |
---|
11206 | + d.addCallback(_allocated) |
---|
11207 | + return d |
---|
11208 | |
---|
11209 | hunk ./src/allmydata/test/test_storage.py 642 |
---|
11210 | - # add-lease on a missing storage index is silently ignored |
---|
11211 | - self.failUnlessEqual(ss.remote_add_lease("si18", "", ""), None) |
---|
11212 | + def test_read_old_share(self): |
---|
11213 | + """ |
---|
11214 | + This tests whether the code correctly finds and reads shares written out by |
---|
11215 | + pre-pluggable-backends (Tahoe-LAFS <= v1.8.2) servers. There is a similar test |
---|
11216 | + in test_download, but that one is from the perspective of the client and exercises |
---|
11217 | + a deeper stack of code. This one is for exercising just the StorageServer and backend. |
---|
11218 | + """ |
---|
11219 | + ss = self.create("test_read_old_share") |
---|
11220 | |
---|
11221 | hunk ./src/allmydata/test/test_storage.py 651 |
---|
11222 | - # check that si0 is readable |
---|
11223 | - readers = ss.remote_get_buckets("si0") |
---|
11224 | - self.failUnlessEqual(len(readers), 5) |
---|
11225 | + # Contruct a file with the appropriate contents. |
---|
11226 | + datalen = len(self.share_data) |
---|
11227 | + sharedir = ss.backend.get_shareset('teststorage_index')._get_sharedir() |
---|
11228 | + fileutil.fp_make_dirs(sharedir) |
---|
11229 | + sharedir.child("0").setContent(self.share_data) |
---|
11230 | |
---|
11231 | hunk ./src/allmydata/test/test_storage.py 657 |
---|
11232 | - # renew the first lease. Only the proper renew_secret should work |
---|
11233 | - ss.remote_renew_lease("si0", rs0) |
---|
11234 | - self.failUnlessRaises(IndexError, ss.remote_renew_lease, "si0", cs0) |
---|
11235 | - self.failUnlessRaises(IndexError, ss.remote_renew_lease, "si0", rs1) |
---|
11236 | + # Now begin the test. |
---|
11237 | + d = ss.remote_get_buckets('teststorage_index') |
---|
11238 | + def _got_buckets(bs): |
---|
11239 | + self.failUnlessEqual(len(bs), 1) |
---|
11240 | + self.failUnlessIn(0, bs) |
---|
11241 | + b = bs[0] |
---|
11242 | |
---|
11243 | hunk ./src/allmydata/test/test_storage.py 664 |
---|
11244 | - # check that si0 is still readable |
---|
11245 | - readers = ss.remote_get_buckets("si0") |
---|
11246 | - self.failUnlessEqual(len(readers), 5) |
---|
11247 | + d2 = defer.succeed(None) |
---|
11248 | + d2.addCallback(lambda ign: b.remote_read(0, datalen)) |
---|
11249 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.shareinputdata)) |
---|
11250 | |
---|
11251 | hunk ./src/allmydata/test/test_storage.py 668 |
---|
11252 | - # There is no such method as remote_cancel_lease for now -- see |
---|
11253 | - # ticket #1528. |
---|
11254 | - self.failIf(hasattr(ss, 'remote_cancel_lease'), \ |
---|
11255 | - "ss should not have a 'remote_cancel_lease' method/attribute") |
---|
11256 | + # If you try to read past the end you get as much input data as is there. |
---|
11257 | + d2.addCallback(lambda ign: b.remote_read(0, datalen+20)) |
---|
11258 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.shareinputdata)) |
---|
11259 | |
---|
11260 | hunk ./src/allmydata/test/test_storage.py 672 |
---|
11261 | - # test overlapping uploads |
---|
11262 | - rs3,cs3 = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11263 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11264 | - rs4,cs4 = (hashutil.tagged_hash("blah", "%d" % self._lease_secret.next()), |
---|
11265 | - hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
11266 | - already,writers = ss.remote_allocate_buckets("si3", rs3, cs3, |
---|
11267 | - sharenums, size, canary) |
---|
11268 | - self.failUnlessEqual(len(already), 0) |
---|
11269 | - self.failUnlessEqual(len(writers), 5) |
---|
11270 | - already2,writers2 = ss.remote_allocate_buckets("si3", rs4, cs4, |
---|
11271 | - sharenums, size, canary) |
---|
11272 | - self.failUnlessEqual(len(already2), 0) |
---|
11273 | - self.failUnlessEqual(len(writers2), 0) |
---|
11274 | - for wb in writers.values(): |
---|
11275 | - wb.remote_close() |
---|
11276 | + # If you start reading past the end of the file you get the empty string. |
---|
11277 | + d2.addCallback(lambda ign: b.remote_read(datalen+1, 3)) |
---|
11278 | + d2.addCallback(lambda res: self.failUnlessEqual(res, '')) |
---|
11279 | + return d2 |
---|
11280 | + d.addCallback(_got_buckets) |
---|
11281 | + return d |
---|
11282 | |
---|
11283 | hunk ./src/allmydata/test/test_storage.py 679 |
---|
11284 | - leases = list(ss.get_leases("si3")) |
---|
11285 | - self.failUnlessEqual(len(leases), 1) |
---|
11286 | + def test_bad_container_version(self): |
---|
11287 | + ss = self.create("test_bad_container_version") |
---|
11288 | |
---|
11289 | hunk ./src/allmydata/test/test_storage.py 682 |
---|
11290 | - already3,writers3 = ss.remote_allocate_buckets("si3", rs4, cs4, |
---|
11291 | - sharenums, size, canary) |
---|
11292 | - self.failUnlessEqual(len(already3), 5) |
---|
11293 | - self.failUnlessEqual(len(writers3), 0) |
---|
11294 | + d = self.allocate(ss, "si1", [0,1], 25) |
---|
11295 | + d.addCallback(lambda (already, writers): for_items(self._write_and_close, writers)) |
---|
11296 | |
---|
11297 | hunk ./src/allmydata/test/test_storage.py 685 |
---|
11298 | - leases = list(ss.get_leases("si3")) |
---|
11299 | - self.failUnlessEqual(len(leases), 2) |
---|
11300 | + d.addCallback(lambda ign: ss.backend.get_shareset("si1").get_share(0)) |
---|
11301 | + def _write_invalid_version(share0): |
---|
11302 | + f = share0._get_filepath().open("rb+") |
---|
11303 | + try: |
---|
11304 | + f.seek(0) |
---|
11305 | + f.write(struct.pack(">L", 0)) # this is invalid: minimum used is v1 |
---|
11306 | + finally: |
---|
11307 | + f.close() |
---|
11308 | + d.addCallback(_write_invalid_version) |
---|
11309 | |
---|
11310 | hunk ./src/allmydata/test/test_storage.py 695 |
---|
11311 | - def test_readonly(self): |
---|
11312 | - workdir = self.workdir("test_readonly") |
---|
11313 | - ss = StorageServer(workdir, "\x00" * 20, readonly_storage=True) |
---|
11314 | - ss.setServiceParent(self.sparent) |
---|
11315 | + # The corrupt shnum 0 should be ignored... |
---|
11316 | + d.addCallback(lambda ign: ss.remote_get_buckets("si1")) |
---|
11317 | + d.addCallback(lambda b: self.failUnlessEqual(set(b.keys()), set([1]))) |
---|
11318 | |
---|
11319 | hunk ./src/allmydata/test/test_storage.py 699 |
---|
11320 | - already,writers = self.allocate(ss, "vid", [0,1,2], 75) |
---|
11321 | - self.failUnlessEqual(already, set()) |
---|
11322 | - self.failUnlessEqual(writers, {}) |
---|
11323 | + # but the error should still be reported if we specifically ask for shnum 0. |
---|
11324 | + d.addCallback(lambda ign: self.shouldFail(UnknownImmutableContainerVersionError, |
---|
11325 | + 'bad_container_version', " had version 0 but we wanted 1", |
---|
11326 | + lambda: ss.backend.get_shareset("si1").get_share(0) )) |
---|
11327 | + return d |
---|
11328 | |
---|
11329 | hunk ./src/allmydata/test/test_storage.py 705 |
---|
11330 | - stats = ss.get_stats() |
---|
11331 | - self.failUnlessEqual(stats["storage_server.accepting_immutable_shares"], 0) |
---|
11332 | - if "storage_server.disk_avail" in stats: |
---|
11333 | - # Some platforms may not have an API to get disk stats. |
---|
11334 | - # But if there are stats, readonly_storage means disk_avail=0 |
---|
11335 | - self.failUnlessEqual(stats["storage_server.disk_avail"], 0) |
---|
11336 | + def test_disconnect(self): |
---|
11337 | + # simulate a disconnection |
---|
11338 | + ss = self.create("test_disconnect") |
---|
11339 | + canary = FakeCanary() |
---|
11340 | |
---|
11341 | hunk ./src/allmydata/test/test_storage.py 710 |
---|
11342 | - def test_discard(self): |
---|
11343 | - # discard is really only used for other tests, but we test it anyways |
---|
11344 | - workdir = self.workdir("test_discard") |
---|
11345 | - ss = StorageServer(workdir, "\x00" * 20, discard_storage=True) |
---|
11346 | - ss.setServiceParent(self.sparent) |
---|
11347 | + d = self.allocate(ss, "disconnect", [0,1,2], 75, canary) |
---|
11348 | + def _allocated( (already, writers) ): |
---|
11349 | + self.failUnlessEqual(already, set()) |
---|
11350 | + self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
11351 | + for (f,args,kwargs) in canary.disconnectors.values(): |
---|
11352 | + f(*args, **kwargs) |
---|
11353 | + d.addCallback(_allocated) |
---|
11354 | |
---|
11355 | hunk ./src/allmydata/test/test_storage.py 718 |
---|
11356 | - already,writers = self.allocate(ss, "vid", [0,1,2], 75) |
---|
11357 | - self.failUnlessEqual(already, set()) |
---|
11358 | - self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
11359 | - for i,wb in writers.items(): |
---|
11360 | - wb.remote_write(0, "%25d" % i) |
---|
11361 | - wb.remote_close() |
---|
11362 | - # since we discard the data, the shares should be present but sparse. |
---|
11363 | - # Since we write with some seeks, the data we read back will be all |
---|
11364 | - # zeros. |
---|
11365 | - b = ss.remote_get_buckets("vid") |
---|
11366 | - self.failUnlessEqual(set(b.keys()), set([0,1,2])) |
---|
11367 | - self.failUnlessEqual(b[0].remote_read(0, 25), "\x00" * 25) |
---|
11368 | + # returning from _allocated ought to delete the incoming shares |
---|
11369 | + d.addCallback(lambda ign: self.allocate(ss, "disconnect", [0,1,2], 75)) |
---|
11370 | + def _allocated2( (already, writers) ): |
---|
11371 | + self.failUnlessEqual(already, set()) |
---|
11372 | + self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
11373 | + d.addCallback(_allocated2) |
---|
11374 | + return d |
---|
11375 | |
---|
11376 | def test_advise_corruption(self): |
---|
11377 | hunk ./src/allmydata/test/test_storage.py 727 |
---|
11378 | - workdir = self.workdir("test_advise_corruption") |
---|
11379 | - ss = StorageServer(workdir, "\x00" * 20, discard_storage=True) |
---|
11380 | - ss.setServiceParent(self.sparent) |
---|
11381 | + ss = self.create("test_advise_corruption") |
---|
11382 | |
---|
11383 | si0_s = base32.b2a("si0") |
---|
11384 | ss.remote_advise_corrupt_share("immutable", "si0", 0, |
---|
11385 | hunk ./src/allmydata/test/test_storage.py 732 |
---|
11386 | "This share smells funny.\n") |
---|
11387 | - reportdir = os.path.join(workdir, "corruption-advisories") |
---|
11388 | - reports = os.listdir(reportdir) |
---|
11389 | + reportdir = ss._statedir.child("corruption-advisories") |
---|
11390 | + self.failUnless(reportdir.exists(), reportdir) |
---|
11391 | + reports = [child.basename() for child in reportdir.children()] |
---|
11392 | self.failUnlessEqual(len(reports), 1) |
---|
11393 | report_si0 = reports[0] |
---|
11394 | hunk ./src/allmydata/test/test_storage.py 737 |
---|
11395 | - self.failUnlessIn(si0_s, report_si0) |
---|
11396 | - f = open(os.path.join(reportdir, report_si0), "r") |
---|
11397 | - report = f.read() |
---|
11398 | - f.close() |
---|
11399 | + self.failUnlessIn(si0_s, str(report_si0)) |
---|
11400 | + report = reportdir.child(report_si0).getContent() |
---|
11401 | + |
---|
11402 | self.failUnlessIn("type: immutable", report) |
---|
11403 | self.failUnlessIn("storage_index: %s" % si0_s, report) |
---|
11404 | self.failUnlessIn("share_number: 0", report) |
---|
11405 | hunk ./src/allmydata/test/test_storage.py 747 |
---|
11406 | |
---|
11407 | # test the RIBucketWriter version too |
---|
11408 | si1_s = base32.b2a("si1") |
---|
11409 | - already,writers = self.allocate(ss, "si1", [1], 75) |
---|
11410 | - self.failUnlessEqual(already, set()) |
---|
11411 | - self.failUnlessEqual(set(writers.keys()), set([1])) |
---|
11412 | - writers[1].remote_write(0, "data") |
---|
11413 | - writers[1].remote_close() |
---|
11414 | + d = self.allocate(ss, "si1", [1], 75) |
---|
11415 | + def _allocated( (already, writers) ): |
---|
11416 | + self.failUnlessEqual(already, set()) |
---|
11417 | + self.failUnlessEqual(set(writers.keys()), set([1])) |
---|
11418 | |
---|
11419 | hunk ./src/allmydata/test/test_storage.py 752 |
---|
11420 | - b = ss.remote_get_buckets("si1") |
---|
11421 | - self.failUnlessEqual(set(b.keys()), set([1])) |
---|
11422 | - b[1].remote_advise_corrupt_share("This share tastes like dust.\n") |
---|
11423 | + d2 = defer.succeed(None) |
---|
11424 | + d2.addCallback(lambda ign: writers[1].remote_write(0, "data")) |
---|
11425 | + d2.addCallback(lambda ign: writers[1].remote_close()) |
---|
11426 | |
---|
11427 | hunk ./src/allmydata/test/test_storage.py 756 |
---|
11428 | - reports = os.listdir(reportdir) |
---|
11429 | - self.failUnlessEqual(len(reports), 2) |
---|
11430 | - report_si1 = [r for r in reports if si1_s in r][0] |
---|
11431 | - f = open(os.path.join(reportdir, report_si1), "r") |
---|
11432 | - report = f.read() |
---|
11433 | - f.close() |
---|
11434 | - self.failUnlessIn("type: immutable", report) |
---|
11435 | - self.failUnlessIn("storage_index: %s" % si1_s, report) |
---|
11436 | - self.failUnlessIn("share_number: 1", report) |
---|
11437 | - self.failUnlessIn("This share tastes like dust.", report) |
---|
11438 | + d2.addCallback(lambda ign: ss.remote_get_buckets("si1")) |
---|
11439 | + def _got_buckets(b): |
---|
11440 | + self.failUnlessEqual(set(b.keys()), set([1])) |
---|
11441 | + b[1].remote_advise_corrupt_share("This share tastes like dust.\n") |
---|
11442 | |
---|
11443 | hunk ./src/allmydata/test/test_storage.py 761 |
---|
11444 | + reports = [child.basename() for child in reportdir.children()] |
---|
11445 | + self.failUnlessEqual(len(reports), 2) |
---|
11446 | + report_si1 = [r for r in reports if si1_s in str(r)][0] |
---|
11447 | + report = reportdir.child(report_si1).getContent() |
---|
11448 | |
---|
11449 | hunk ./src/allmydata/test/test_storage.py 766 |
---|
11450 | + self.failUnlessIn("type: immutable", report) |
---|
11451 | + self.failUnlessIn("storage_index: %s" % si1_s, report) |
---|
11452 | + self.failUnlessIn("share_number: 1", report) |
---|
11453 | + self.failUnlessIn("This share tastes like dust.", report) |
---|
11454 | + d2.addCallback(_got_buckets) |
---|
11455 | + return d2 |
---|
11456 | + d.addCallback(_allocated) |
---|
11457 | + return d |
---|
11458 | |
---|
11459 | hunk ./src/allmydata/test/test_storage.py 775 |
---|
11460 | -class MutableServer(unittest.TestCase): |
---|
11461 | |
---|
11462 | hunk ./src/allmydata/test/test_storage.py 776 |
---|
11463 | +class MutableServerMixin: |
---|
11464 | def setUp(self): |
---|
11465 | self.sparent = LoggingServiceParent() |
---|
11466 | hunk ./src/allmydata/test/test_storage.py 779 |
---|
11467 | + self.sparent.startService() |
---|
11468 | self._lease_secret = itertools.count() |
---|
11469 | def tearDown(self): |
---|
11470 | return self.sparent.stopService() |
---|
11471 | hunk ./src/allmydata/test/test_storage.py 785 |
---|
11472 | |
---|
11473 | def workdir(self, name): |
---|
11474 | - basedir = os.path.join("storage", "MutableServer", name) |
---|
11475 | - return basedir |
---|
11476 | - |
---|
11477 | - def create(self, name): |
---|
11478 | - workdir = self.workdir(name) |
---|
11479 | - ss = StorageServer(workdir, "\x00" * 20) |
---|
11480 | - ss.setServiceParent(self.sparent) |
---|
11481 | - return ss |
---|
11482 | - |
---|
11483 | - def test_create(self): |
---|
11484 | - self.create("test_create") |
---|
11485 | + return FilePath("storage").child(self.__class__.__name__).child(name) |
---|
11486 | |
---|
11487 | def write_enabler(self, we_tag): |
---|
11488 | return hashutil.tagged_hash("we_blah", we_tag) |
---|
11489 | hunk ./src/allmydata/test/test_storage.py 802 |
---|
11490 | cancel_secret = self.cancel_secret(lease_tag) |
---|
11491 | rstaraw = ss.remote_slot_testv_and_readv_and_writev |
---|
11492 | testandwritev = dict( [ (shnum, ([], [], None) ) |
---|
11493 | - for shnum in sharenums ] ) |
---|
11494 | + for shnum in sharenums ] ) |
---|
11495 | readv = [] |
---|
11496 | hunk ./src/allmydata/test/test_storage.py 804 |
---|
11497 | - rc = rstaraw(storage_index, |
---|
11498 | - (write_enabler, renew_secret, cancel_secret), |
---|
11499 | - testandwritev, |
---|
11500 | - readv) |
---|
11501 | - (did_write, readv_data) = rc |
---|
11502 | - self.failUnless(did_write) |
---|
11503 | - self.failUnless(isinstance(readv_data, dict)) |
---|
11504 | - self.failUnlessEqual(len(readv_data), 0) |
---|
11505 | |
---|
11506 | hunk ./src/allmydata/test/test_storage.py 805 |
---|
11507 | + d = defer.succeed(None) |
---|
11508 | + d.addCallback(lambda ign: rstaraw(storage_index, |
---|
11509 | + (write_enabler, renew_secret, cancel_secret), |
---|
11510 | + testandwritev, |
---|
11511 | + readv)) |
---|
11512 | + def _check( (did_write, readv_data) ): |
---|
11513 | + self.failUnless(did_write) |
---|
11514 | + self.failUnless(isinstance(readv_data, dict)) |
---|
11515 | + self.failUnlessEqual(len(readv_data), 0) |
---|
11516 | + d.addCallback(_check) |
---|
11517 | + return d |
---|
11518 | + |
---|
11519 | + |
---|
11520 | +class MutableServerTest(MutableServerMixin, ShouldFailMixin): |
---|
11521 | def test_bad_magic(self): |
---|
11522 | ss = self.create("test_bad_magic") |
---|
11523 | hunk ./src/allmydata/test/test_storage.py 821 |
---|
11524 | - self.allocate(ss, "si1", "we1", self._lease_secret.next(), set([0]), 10) |
---|
11525 | - fn = os.path.join(ss.sharedir, storage_index_to_dir("si1"), "0") |
---|
11526 | - f = open(fn, "rb+") |
---|
11527 | - f.seek(0) |
---|
11528 | - f.write("BAD MAGIC") |
---|
11529 | - f.close() |
---|
11530 | read = ss.remote_slot_readv |
---|
11531 | hunk ./src/allmydata/test/test_storage.py 822 |
---|
11532 | - e = self.failUnlessRaises(UnknownMutableContainerVersionError, |
---|
11533 | - read, "si1", [0], [(0,10)]) |
---|
11534 | - self.failUnlessIn(" had magic ", str(e)) |
---|
11535 | - self.failUnlessIn(" but we wanted ", str(e)) |
---|
11536 | + |
---|
11537 | + d = self.allocate(ss, "si1", "we1", self._lease_secret.next(), set([0,1]), 25) |
---|
11538 | + d.addCallback(lambda ign: ss.backend.get_shareset("si1").get_share(0)) |
---|
11539 | + def _write_bad_magic(share0): |
---|
11540 | + f = share0._get_filepath().open("rb+") |
---|
11541 | + try: |
---|
11542 | + f.seek(0) |
---|
11543 | + f.write("BAD MAGIC") |
---|
11544 | + finally: |
---|
11545 | + f.close() |
---|
11546 | + d.addCallback(_write_bad_magic) |
---|
11547 | + |
---|
11548 | + # The corrupt shnum 0 should be ignored when we read shnum 1... |
---|
11549 | + d.addCallback(lambda ign: read("si1", [1], [(0,25)])) |
---|
11550 | + d.addCallback(lambda res: self.failUnlessEqual(res, {1: [""]})) |
---|
11551 | + |
---|
11552 | + # but the error should still be reported if we specifically ask for shnum 0. |
---|
11553 | + # This used to test for UnknownMutableContainerVersionError, |
---|
11554 | + # but the current code raises UnknownImmutableContainerVersionError. |
---|
11555 | + # (It changed because remote_slot_readv now works with either |
---|
11556 | + # mutable or immutable shares.) Since the share file doesn't have |
---|
11557 | + # the mutable magic, it's not clear that this is wrong. |
---|
11558 | + # For now, accept either exception. |
---|
11559 | + d.addCallback(lambda ign: |
---|
11560 | + self.shouldFail(UnknownContainerVersionError, "bad_magic", |
---|
11561 | + " but we wanted ", |
---|
11562 | + lambda: read("si1", [0], [(0,25)]) )) |
---|
11563 | + return d |
---|
11564 | + test_bad_magic.todo = "Error reporting for corrupt shares doesn't currently work." |
---|
11565 | |
---|
11566 | def test_container_size(self): |
---|
11567 | ss = self.create("test_container_size") |
---|
11568 | hunk ./src/allmydata/test/test_storage.py 854 |
---|
11569 | - self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
11570 | - set([0,1,2]), 100) |
---|
11571 | read = ss.remote_slot_readv |
---|
11572 | rstaraw = ss.remote_slot_testv_and_readv_and_writev |
---|
11573 | secrets = ( self.write_enabler("we1"), |
---|
11574 | hunk ./src/allmydata/test/test_storage.py 860 |
---|
11575 | self.renew_secret("we1"), |
---|
11576 | self.cancel_secret("we1") ) |
---|
11577 | data = "".join([ ("%d" % i) * 10 for i in range(10) ]) |
---|
11578 | - answer = rstaraw("si1", secrets, |
---|
11579 | - {0: ([], [(0,data)], len(data)+12)}, |
---|
11580 | - []) |
---|
11581 | - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) |
---|
11582 | + |
---|
11583 | + d = self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
11584 | + set([0,1,2]), 100) |
---|
11585 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11586 | + {0: ([], [(0,data)], len(data)+12)}, |
---|
11587 | + [])) |
---|
11588 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11589 | |
---|
11590 | # Trying to make the container too large (by sending a write vector |
---|
11591 | # whose offset is too high) will raise an exception. |
---|
11592 | hunk ./src/allmydata/test/test_storage.py 870 |
---|
11593 | - TOOBIG = MutableShareFile.MAX_SIZE + 10 |
---|
11594 | - self.failUnlessRaises(DataTooLargeError, |
---|
11595 | - rstaraw, "si1", secrets, |
---|
11596 | - {0: ([], [(TOOBIG,data)], None)}, |
---|
11597 | - []) |
---|
11598 | + TOOBIG = MutableDiskShare.MAX_SIZE + 10 |
---|
11599 | + d.addCallback(lambda ign: self.shouldFail(DataTooLargeError, |
---|
11600 | + 'make container too large', None, |
---|
11601 | + lambda: rstaraw("si1", secrets, |
---|
11602 | + {0: ([], [(TOOBIG,data)], None)}, |
---|
11603 | + []) )) |
---|
11604 | |
---|
11605 | hunk ./src/allmydata/test/test_storage.py 877 |
---|
11606 | - answer = rstaraw("si1", secrets, |
---|
11607 | - {0: ([], [(0,data)], None)}, |
---|
11608 | - []) |
---|
11609 | - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) |
---|
11610 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11611 | + {0: ([], [(0,data)], None)}, |
---|
11612 | + [])) |
---|
11613 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11614 | |
---|
11615 | hunk ./src/allmydata/test/test_storage.py 882 |
---|
11616 | - read_answer = read("si1", [0], [(0,10)]) |
---|
11617 | - self.failUnlessEqual(read_answer, {0: [data[:10]]}) |
---|
11618 | + d.addCallback(lambda ign: read("si1", [0], [(0,10)])) |
---|
11619 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data[:10]]})) |
---|
11620 | |
---|
11621 | # Sending a new_length shorter than the current length truncates the |
---|
11622 | # data. |
---|
11623 | hunk ./src/allmydata/test/test_storage.py 887 |
---|
11624 | - answer = rstaraw("si1", secrets, |
---|
11625 | - {0: ([], [], 9)}, |
---|
11626 | - []) |
---|
11627 | - read_answer = read("si1", [0], [(0,10)]) |
---|
11628 | - self.failUnlessEqual(read_answer, {0: [data[:9]]}) |
---|
11629 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11630 | + {0: ([], [], 9)}, |
---|
11631 | + [])) |
---|
11632 | + d.addCallback(lambda ign: read("si1", [0], [(0,10)])) |
---|
11633 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data[:9]]})) |
---|
11634 | |
---|
11635 | # Sending a new_length longer than the current length doesn't change |
---|
11636 | # the data. |
---|
11637 | hunk ./src/allmydata/test/test_storage.py 895 |
---|
11638 | - answer = rstaraw("si1", secrets, |
---|
11639 | - {0: ([], [], 20)}, |
---|
11640 | - []) |
---|
11641 | - assert answer == (True, {0:[],1:[],2:[]}) |
---|
11642 | - read_answer = read("si1", [0], [(0, 20)]) |
---|
11643 | - self.failUnlessEqual(read_answer, {0: [data[:9]]}) |
---|
11644 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11645 | + {0: ([], [], 20)}, |
---|
11646 | + [])) |
---|
11647 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11648 | + d.addCallback(lambda ign: read("si1", [0], [(0, 20)])) |
---|
11649 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data[:9]]})) |
---|
11650 | |
---|
11651 | # Sending a write vector whose start is after the end of the current |
---|
11652 | # data doesn't reveal "whatever was there last time" (palimpsest), |
---|
11653 | hunk ./src/allmydata/test/test_storage.py 908 |
---|
11654 | |
---|
11655 | # To test this, we fill the data area with a recognizable pattern. |
---|
11656 | pattern = ''.join([chr(i) for i in range(100)]) |
---|
11657 | - answer = rstaraw("si1", secrets, |
---|
11658 | - {0: ([], [(0, pattern)], None)}, |
---|
11659 | - []) |
---|
11660 | - assert answer == (True, {0:[],1:[],2:[]}) |
---|
11661 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11662 | + {0: ([], [(0, pattern)], None)}, |
---|
11663 | + [])) |
---|
11664 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11665 | # Then truncate the data... |
---|
11666 | hunk ./src/allmydata/test/test_storage.py 913 |
---|
11667 | - answer = rstaraw("si1", secrets, |
---|
11668 | - {0: ([], [], 20)}, |
---|
11669 | - []) |
---|
11670 | - assert answer == (True, {0:[],1:[],2:[]}) |
---|
11671 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11672 | + {0: ([], [], 20)}, |
---|
11673 | + [])) |
---|
11674 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11675 | # Just confirm that you get an empty string if you try to read from |
---|
11676 | # past the (new) endpoint now. |
---|
11677 | hunk ./src/allmydata/test/test_storage.py 919 |
---|
11678 | - answer = rstaraw("si1", secrets, |
---|
11679 | - {0: ([], [], None)}, |
---|
11680 | - [(20, 1980)]) |
---|
11681 | - self.failUnlessEqual(answer, (True, {0:[''],1:[''],2:['']})) |
---|
11682 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11683 | + {0: ([], [], None)}, |
---|
11684 | + [(20, 1980)])) |
---|
11685 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[''],1:[''],2:['']}) )) |
---|
11686 | |
---|
11687 | # Then the extend the file by writing a vector which starts out past |
---|
11688 | # the end... |
---|
11689 | hunk ./src/allmydata/test/test_storage.py 926 |
---|
11690 | - answer = rstaraw("si1", secrets, |
---|
11691 | - {0: ([], [(50, 'hellothere')], None)}, |
---|
11692 | - []) |
---|
11693 | - assert answer == (True, {0:[],1:[],2:[]}) |
---|
11694 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11695 | + {0: ([], [(50, 'hellothere')], None)}, |
---|
11696 | + [])) |
---|
11697 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11698 | # Now if you read the stuff between 20 (where we earlier truncated) |
---|
11699 | # and 50, it had better be all zeroes. |
---|
11700 | hunk ./src/allmydata/test/test_storage.py 932 |
---|
11701 | - answer = rstaraw("si1", secrets, |
---|
11702 | - {0: ([], [], None)}, |
---|
11703 | - [(20, 30)]) |
---|
11704 | - self.failUnlessEqual(answer, (True, {0:['\x00'*30],1:[''],2:['']})) |
---|
11705 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11706 | + {0: ([], [], None)}, |
---|
11707 | + [(20, 30)])) |
---|
11708 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:['\x00'*30],1:[''],2:['']}) )) |
---|
11709 | |
---|
11710 | # Also see if the server explicitly declares that it supports this |
---|
11711 | # feature. |
---|
11712 | hunk ./src/allmydata/test/test_storage.py 939 |
---|
11713 | - ver = ss.remote_get_version() |
---|
11714 | - storage_v1_ver = ver["http://allmydata.org/tahoe/protocols/storage/v1"] |
---|
11715 | - self.failUnless(storage_v1_ver.get("fills-holes-with-zero-bytes")) |
---|
11716 | + d.addCallback(lambda ign: ss.remote_get_version()) |
---|
11717 | + def _check_declaration(ver): |
---|
11718 | + storage_v1_ver = ver["http://allmydata.org/tahoe/protocols/storage/v1"] |
---|
11719 | + self.failUnless(storage_v1_ver.get("fills-holes-with-zero-bytes")) |
---|
11720 | + d.addCallback(_check_declaration) |
---|
11721 | |
---|
11722 | # If the size is dropped to zero the share is deleted. |
---|
11723 | hunk ./src/allmydata/test/test_storage.py 946 |
---|
11724 | - answer = rstaraw("si1", secrets, |
---|
11725 | - {0: ([], [(0,data)], 0)}, |
---|
11726 | - []) |
---|
11727 | - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) |
---|
11728 | + d.addCallback(lambda ign: rstaraw("si1", secrets, |
---|
11729 | + {0: ([], [(0,data)], 0)}, |
---|
11730 | + [])) |
---|
11731 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11732 | |
---|
11733 | hunk ./src/allmydata/test/test_storage.py 951 |
---|
11734 | - read_answer = read("si1", [0], [(0,10)]) |
---|
11735 | - self.failUnlessEqual(read_answer, {}) |
---|
11736 | + d.addCallback(lambda ign: read("si1", [0], [(0,10)])) |
---|
11737 | + d.addCallback(lambda res: self.failUnlessEqual(res, {})) |
---|
11738 | + return d |
---|
11739 | |
---|
11740 | def test_allocate(self): |
---|
11741 | ss = self.create("test_allocate") |
---|
11742 | hunk ./src/allmydata/test/test_storage.py 957 |
---|
11743 | - self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
11744 | - set([0,1,2]), 100) |
---|
11745 | - |
---|
11746 | read = ss.remote_slot_readv |
---|
11747 | hunk ./src/allmydata/test/test_storage.py 958 |
---|
11748 | - self.failUnlessEqual(read("si1", [0], [(0, 10)]), |
---|
11749 | - {0: [""]}) |
---|
11750 | - self.failUnlessEqual(read("si1", [], [(0, 10)]), |
---|
11751 | - {0: [""], 1: [""], 2: [""]}) |
---|
11752 | - self.failUnlessEqual(read("si1", [0], [(100, 10)]), |
---|
11753 | - {0: [""]}) |
---|
11754 | + write = ss.remote_slot_testv_and_readv_and_writev |
---|
11755 | + |
---|
11756 | + d = self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
11757 | + set([0,1,2]), 100) |
---|
11758 | + |
---|
11759 | + d.addCallback(lambda ign: read("si1", [0], [(0, 10)])) |
---|
11760 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [""]})) |
---|
11761 | + d.addCallback(lambda ign: read("si1", [], [(0, 10)])) |
---|
11762 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [""], 1: [""], 2: [""]})) |
---|
11763 | + d.addCallback(lambda ign: read("si1", [0], [(100, 10)])) |
---|
11764 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [""]})) |
---|
11765 | |
---|
11766 | # try writing to one |
---|
11767 | secrets = ( self.write_enabler("we1"), |
---|
11768 | hunk ./src/allmydata/test/test_storage.py 975 |
---|
11769 | self.renew_secret("we1"), |
---|
11770 | self.cancel_secret("we1") ) |
---|
11771 | data = "".join([ ("%d" % i) * 10 for i in range(10) ]) |
---|
11772 | - write = ss.remote_slot_testv_and_readv_and_writev |
---|
11773 | - answer = write("si1", secrets, |
---|
11774 | - {0: ([], [(0,data)], None)}, |
---|
11775 | - []) |
---|
11776 | - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) |
---|
11777 | |
---|
11778 | hunk ./src/allmydata/test/test_storage.py 976 |
---|
11779 | - self.failUnlessEqual(read("si1", [0], [(0,20)]), |
---|
11780 | - {0: ["00000000001111111111"]}) |
---|
11781 | - self.failUnlessEqual(read("si1", [0], [(95,10)]), |
---|
11782 | - {0: ["99999"]}) |
---|
11783 | - #self.failUnlessEqual(s0.remote_get_length(), 100) |
---|
11784 | + d.addCallback(lambda ign: write("si1", secrets, |
---|
11785 | + {0: ([], [(0,data)], None)}, |
---|
11786 | + [])) |
---|
11787 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
11788 | + |
---|
11789 | + d.addCallback(lambda ign: read("si1", [0], [(0,20)])) |
---|
11790 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["00000000001111111111"]})) |
---|
11791 | + d.addCallback(lambda ign: read("si1", [0], [(95,10)])) |
---|
11792 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["99999"]})) |
---|
11793 | + #d.addCallback(lambda ign: s0.remote_get_length()) |
---|
11794 | + #d.addCallback(lambda res: self.failUnlessEqual(res, 100)) |
---|
11795 | |
---|
11796 | bad_secrets = ("bad write enabler", secrets[1], secrets[2]) |
---|
11797 | hunk ./src/allmydata/test/test_storage.py 989 |
---|
11798 | - f = self.failUnlessRaises(BadWriteEnablerError, |
---|
11799 | - write, "si1", bad_secrets, |
---|
11800 | - {}, []) |
---|
11801 | - self.failUnlessIn("The write enabler was recorded by nodeid 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.", f) |
---|
11802 | + d.addCallback(lambda ign: self.shouldFail(BadWriteEnablerError, 'bad write enabler', |
---|
11803 | + "The write enabler was recorded by nodeid " |
---|
11804 | + "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.", |
---|
11805 | + lambda: write("si1", bad_secrets, {}, []) )) |
---|
11806 | |
---|
11807 | # this testv should fail |
---|
11808 | hunk ./src/allmydata/test/test_storage.py 995 |
---|
11809 | - answer = write("si1", secrets, |
---|
11810 | - {0: ([(0, 12, "eq", "444444444444"), |
---|
11811 | - (20, 5, "eq", "22222"), |
---|
11812 | - ], |
---|
11813 | - [(0, "x"*100)], |
---|
11814 | - None), |
---|
11815 | - }, |
---|
11816 | - [(0,12), (20,5)], |
---|
11817 | - ) |
---|
11818 | - self.failUnlessEqual(answer, (False, |
---|
11819 | - {0: ["000000000011", "22222"], |
---|
11820 | - 1: ["", ""], |
---|
11821 | - 2: ["", ""], |
---|
11822 | - })) |
---|
11823 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
11824 | + d.addCallback(lambda ign: write("si1", secrets, |
---|
11825 | + {0: ([(0, 12, "eq", "444444444444"), |
---|
11826 | + (20, 5, "eq", "22222"),], |
---|
11827 | + [(0, "x"*100)], |
---|
11828 | + None)}, |
---|
11829 | + [(0,12), (20,5)])) |
---|
11830 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, |
---|
11831 | + {0: ["000000000011", "22222"], |
---|
11832 | + 1: ["", ""], |
---|
11833 | + 2: ["", ""]}) )) |
---|
11834 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11835 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11836 | |
---|
11837 | # as should this one |
---|
11838 | hunk ./src/allmydata/test/test_storage.py 1009 |
---|
11839 | - answer = write("si1", secrets, |
---|
11840 | - {0: ([(10, 5, "lt", "11111"), |
---|
11841 | - ], |
---|
11842 | - [(0, "x"*100)], |
---|
11843 | - None), |
---|
11844 | - }, |
---|
11845 | - [(10,5)], |
---|
11846 | - ) |
---|
11847 | - self.failUnlessEqual(answer, (False, |
---|
11848 | - {0: ["11111"], |
---|
11849 | - 1: [""], |
---|
11850 | - 2: [""]}, |
---|
11851 | - )) |
---|
11852 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
11853 | - |
---|
11854 | + d.addCallback(lambda ign: write("si1", secrets, |
---|
11855 | + {0: ([(10, 5, "lt", "11111"),], |
---|
11856 | + [(0, "x"*100)], |
---|
11857 | + None)}, |
---|
11858 | + [(10,5)])) |
---|
11859 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, |
---|
11860 | + {0: ["11111"], |
---|
11861 | + 1: [""], |
---|
11862 | + 2: [""]}) )) |
---|
11863 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11864 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11865 | + return d |
---|
11866 | |
---|
11867 | def test_operators(self): |
---|
11868 | # test operators, the data we're comparing is '11111' in all cases. |
---|
11869 | hunk ./src/allmydata/test/test_storage.py 1034 |
---|
11870 | write = ss.remote_slot_testv_and_readv_and_writev |
---|
11871 | read = ss.remote_slot_readv |
---|
11872 | |
---|
11873 | - def reset(): |
---|
11874 | - write("si1", secrets, |
---|
11875 | - {0: ([], [(0,data)], None)}, |
---|
11876 | - []) |
---|
11877 | + def _reset(ign): |
---|
11878 | + return write("si1", secrets, |
---|
11879 | + {0: ([], [(0,data)], None)}, |
---|
11880 | + []) |
---|
11881 | |
---|
11882 | hunk ./src/allmydata/test/test_storage.py 1039 |
---|
11883 | - reset() |
---|
11884 | + d = defer.succeed(None) |
---|
11885 | + d.addCallback(_reset) |
---|
11886 | |
---|
11887 | # lt |
---|
11888 | hunk ./src/allmydata/test/test_storage.py 1043 |
---|
11889 | - answer = write("si1", secrets, {0: ([(10, 5, "lt", "11110"), |
---|
11890 | - ], |
---|
11891 | - [(0, "x"*100)], |
---|
11892 | - None, |
---|
11893 | - )}, [(10,5)]) |
---|
11894 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
11895 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
11896 | - self.failUnlessEqual(read("si1", [], [(0,100)]), {0: [data]}) |
---|
11897 | - reset() |
---|
11898 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "lt", "11110"),], |
---|
11899 | + [(0, "x"*100)], |
---|
11900 | + None, |
---|
11901 | + )}, [(10,5)])) |
---|
11902 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
11903 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11904 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11905 | + d.addCallback(lambda ign: read("si1", [], [(0,100)])) |
---|
11906 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11907 | + d.addCallback(_reset) |
---|
11908 | |
---|
11909 | hunk ./src/allmydata/test/test_storage.py 1054 |
---|
11910 | - answer = write("si1", secrets, {0: ([(10, 5, "lt", "11111"), |
---|
11911 | - ], |
---|
11912 | - [(0, "x"*100)], |
---|
11913 | - None, |
---|
11914 | - )}, [(10,5)]) |
---|
11915 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
11916 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
11917 | - reset() |
---|
11918 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "lt", "11111"),], |
---|
11919 | + [(0, "x"*100)], |
---|
11920 | + None, |
---|
11921 | + )}, [(10,5)])) |
---|
11922 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
11923 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11924 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11925 | + d.addCallback(_reset) |
---|
11926 | |
---|
11927 | hunk ./src/allmydata/test/test_storage.py 1063 |
---|
11928 | - answer = write("si1", secrets, {0: ([(10, 5, "lt", "11112"), |
---|
11929 | - ], |
---|
11930 | - [(0, "y"*100)], |
---|
11931 | - None, |
---|
11932 | - )}, [(10,5)]) |
---|
11933 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
11934 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
11935 | - reset() |
---|
11936 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "lt", "11112"),], |
---|
11937 | + [(0, "y"*100)], |
---|
11938 | + None, |
---|
11939 | + )}, [(10,5)])) |
---|
11940 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
11941 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11942 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
11943 | + d.addCallback(_reset) |
---|
11944 | |
---|
11945 | # le |
---|
11946 | hunk ./src/allmydata/test/test_storage.py 1073 |
---|
11947 | - answer = write("si1", secrets, {0: ([(10, 5, "le", "11110"), |
---|
11948 | - ], |
---|
11949 | - [(0, "x"*100)], |
---|
11950 | - None, |
---|
11951 | - )}, [(10,5)]) |
---|
11952 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
11953 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
11954 | - reset() |
---|
11955 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "le", "11110"),], |
---|
11956 | + [(0, "x"*100)], |
---|
11957 | + None, |
---|
11958 | + )}, [(10,5)])) |
---|
11959 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
11960 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11961 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
11962 | + d.addCallback(_reset) |
---|
11963 | |
---|
11964 | hunk ./src/allmydata/test/test_storage.py 1082 |
---|
11965 | - answer = write("si1", secrets, {0: ([(10, 5, "le", "11111"), |
---|
11966 | - ], |
---|
11967 | - [(0, "y"*100)], |
---|
11968 | - None, |
---|
11969 | - )}, [(10,5)]) |
---|
11970 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
11971 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
11972 | - reset() |
---|
11973 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "le", "11111"),], |
---|
11974 | + [(0, "y"*100)], |
---|
11975 | + None, |
---|
11976 | + )}, [(10,5)])) |
---|
11977 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
11978 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11979 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
11980 | + d.addCallback(_reset) |
---|
11981 | |
---|
11982 | hunk ./src/allmydata/test/test_storage.py 1091 |
---|
11983 | - answer = write("si1", secrets, {0: ([(10, 5, "le", "11112"), |
---|
11984 | - ], |
---|
11985 | - [(0, "y"*100)], |
---|
11986 | - None, |
---|
11987 | - )}, [(10,5)]) |
---|
11988 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
11989 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
11990 | - reset() |
---|
11991 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "le", "11112"),], |
---|
11992 | + [(0, "y"*100)], |
---|
11993 | + None, |
---|
11994 | + )}, [(10,5)])) |
---|
11995 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
11996 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
11997 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
11998 | + d.addCallback(_reset) |
---|
11999 | |
---|
12000 | # eq |
---|
12001 | hunk ./src/allmydata/test/test_storage.py 1101 |
---|
12002 | - answer = write("si1", secrets, {0: ([(10, 5, "eq", "11112"), |
---|
12003 | - ], |
---|
12004 | - [(0, "x"*100)], |
---|
12005 | - None, |
---|
12006 | - )}, [(10,5)]) |
---|
12007 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12008 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12009 | - reset() |
---|
12010 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "eq", "11112"),], |
---|
12011 | + [(0, "x"*100)], |
---|
12012 | + None, |
---|
12013 | + )}, [(10,5)])) |
---|
12014 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12015 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12016 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12017 | + d.addCallback(_reset) |
---|
12018 | |
---|
12019 | hunk ./src/allmydata/test/test_storage.py 1110 |
---|
12020 | - answer = write("si1", secrets, {0: ([(10, 5, "eq", "11111"), |
---|
12021 | - ], |
---|
12022 | - [(0, "y"*100)], |
---|
12023 | - None, |
---|
12024 | - )}, [(10,5)]) |
---|
12025 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
12026 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
12027 | - reset() |
---|
12028 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "eq", "11111"),], |
---|
12029 | + [(0, "y"*100)], |
---|
12030 | + None, |
---|
12031 | + )}, [(10,5)])) |
---|
12032 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
12033 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12034 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
12035 | + d.addCallback(_reset) |
---|
12036 | |
---|
12037 | # ne |
---|
12038 | hunk ./src/allmydata/test/test_storage.py 1120 |
---|
12039 | - answer = write("si1", secrets, {0: ([(10, 5, "ne", "11111"), |
---|
12040 | - ], |
---|
12041 | - [(0, "x"*100)], |
---|
12042 | - None, |
---|
12043 | - )}, [(10,5)]) |
---|
12044 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12045 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12046 | - reset() |
---|
12047 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "ne", "11111"),], |
---|
12048 | + [(0, "x"*100)], |
---|
12049 | + None, |
---|
12050 | + )}, [(10,5)])) |
---|
12051 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12052 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12053 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12054 | + d.addCallback(_reset) |
---|
12055 | |
---|
12056 | hunk ./src/allmydata/test/test_storage.py 1129 |
---|
12057 | - answer = write("si1", secrets, {0: ([(10, 5, "ne", "11112"), |
---|
12058 | - ], |
---|
12059 | - [(0, "y"*100)], |
---|
12060 | - None, |
---|
12061 | - )}, [(10,5)]) |
---|
12062 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
12063 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
12064 | - reset() |
---|
12065 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "ne", "11112"),], |
---|
12066 | + [(0, "y"*100)], |
---|
12067 | + None, |
---|
12068 | + )}, [(10,5)])) |
---|
12069 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
12070 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12071 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
12072 | + d.addCallback(_reset) |
---|
12073 | |
---|
12074 | # ge |
---|
12075 | hunk ./src/allmydata/test/test_storage.py 1139 |
---|
12076 | - answer = write("si1", secrets, {0: ([(10, 5, "ge", "11110"), |
---|
12077 | - ], |
---|
12078 | - [(0, "y"*100)], |
---|
12079 | - None, |
---|
12080 | - )}, [(10,5)]) |
---|
12081 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
12082 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
12083 | - reset() |
---|
12084 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "ge", "11110"),], |
---|
12085 | + [(0, "y"*100)], |
---|
12086 | + None, |
---|
12087 | + )}, [(10,5)])) |
---|
12088 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
12089 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12090 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
12091 | + d.addCallback(_reset) |
---|
12092 | |
---|
12093 | hunk ./src/allmydata/test/test_storage.py 1148 |
---|
12094 | - answer = write("si1", secrets, {0: ([(10, 5, "ge", "11111"), |
---|
12095 | - ], |
---|
12096 | - [(0, "y"*100)], |
---|
12097 | - None, |
---|
12098 | - )}, [(10,5)]) |
---|
12099 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
12100 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
12101 | - reset() |
---|
12102 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "ge", "11111"),], |
---|
12103 | + [(0, "y"*100)], |
---|
12104 | + None, |
---|
12105 | + )}, [(10,5)])) |
---|
12106 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
12107 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12108 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
12109 | + d.addCallback(_reset) |
---|
12110 | |
---|
12111 | hunk ./src/allmydata/test/test_storage.py 1157 |
---|
12112 | - answer = write("si1", secrets, {0: ([(10, 5, "ge", "11112"), |
---|
12113 | - ], |
---|
12114 | - [(0, "y"*100)], |
---|
12115 | - None, |
---|
12116 | - )}, [(10,5)]) |
---|
12117 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12118 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12119 | - reset() |
---|
12120 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "ge", "11112"),], |
---|
12121 | + [(0, "y"*100)], |
---|
12122 | + None, |
---|
12123 | + )}, [(10,5)])) |
---|
12124 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12125 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12126 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12127 | + d.addCallback(_reset) |
---|
12128 | |
---|
12129 | # gt |
---|
12130 | hunk ./src/allmydata/test/test_storage.py 1167 |
---|
12131 | - answer = write("si1", secrets, {0: ([(10, 5, "gt", "11110"), |
---|
12132 | - ], |
---|
12133 | - [(0, "y"*100)], |
---|
12134 | - None, |
---|
12135 | - )}, [(10,5)]) |
---|
12136 | - self.failUnlessEqual(answer, (True, {0: ["11111"]})) |
---|
12137 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: ["y"*100]}) |
---|
12138 | - reset() |
---|
12139 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "gt", "11110"),], |
---|
12140 | + [(0, "y"*100)], |
---|
12141 | + None, |
---|
12142 | + )}, [(10,5)])) |
---|
12143 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0: ["11111"]}) )) |
---|
12144 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12145 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["y"*100]})) |
---|
12146 | + d.addCallback(_reset) |
---|
12147 | |
---|
12148 | hunk ./src/allmydata/test/test_storage.py 1176 |
---|
12149 | - answer = write("si1", secrets, {0: ([(10, 5, "gt", "11111"), |
---|
12150 | - ], |
---|
12151 | - [(0, "x"*100)], |
---|
12152 | - None, |
---|
12153 | - )}, [(10,5)]) |
---|
12154 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12155 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12156 | - reset() |
---|
12157 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "gt", "11111"),], |
---|
12158 | + [(0, "x"*100)], |
---|
12159 | + None, |
---|
12160 | + )}, [(10,5)])) |
---|
12161 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12162 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12163 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12164 | + d.addCallback(_reset) |
---|
12165 | |
---|
12166 | hunk ./src/allmydata/test/test_storage.py 1185 |
---|
12167 | - answer = write("si1", secrets, {0: ([(10, 5, "gt", "11112"), |
---|
12168 | - ], |
---|
12169 | - [(0, "x"*100)], |
---|
12170 | - None, |
---|
12171 | - )}, [(10,5)]) |
---|
12172 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12173 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12174 | - reset() |
---|
12175 | + d.addCallback(lambda ign: write("si1", secrets, {0: ([(10, 5, "gt", "11112"),], |
---|
12176 | + [(0, "x"*100)], |
---|
12177 | + None, |
---|
12178 | + )}, [(10,5)])) |
---|
12179 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12180 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12181 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12182 | + d.addCallback(_reset) |
---|
12183 | |
---|
12184 | # finally, test some operators against empty shares |
---|
12185 | hunk ./src/allmydata/test/test_storage.py 1195 |
---|
12186 | - answer = write("si1", secrets, {1: ([(10, 5, "eq", "11112"), |
---|
12187 | - ], |
---|
12188 | - [(0, "x"*100)], |
---|
12189 | - None, |
---|
12190 | - )}, [(10,5)]) |
---|
12191 | - self.failUnlessEqual(answer, (False, {0: ["11111"]})) |
---|
12192 | - self.failUnlessEqual(read("si1", [0], [(0,100)]), {0: [data]}) |
---|
12193 | - reset() |
---|
12194 | + d.addCallback(lambda ign: write("si1", secrets, {1: ([(10, 5, "eq", "11112"),], |
---|
12195 | + [(0, "x"*100)], |
---|
12196 | + None, |
---|
12197 | + )}, [(10,5)])) |
---|
12198 | + d.addCallback(lambda res: self.failUnlessEqual(res, (False, {0: ["11111"]}) )) |
---|
12199 | + d.addCallback(lambda ign: read("si1", [0], [(0,100)])) |
---|
12200 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
12201 | + d.addCallback(_reset) |
---|
12202 | + return d |
---|
12203 | |
---|
12204 | def test_readv(self): |
---|
12205 | ss = self.create("test_readv") |
---|
12206 | hunk ./src/allmydata/test/test_storage.py 1214 |
---|
12207 | write = ss.remote_slot_testv_and_readv_and_writev |
---|
12208 | read = ss.remote_slot_readv |
---|
12209 | data = [("%d" % i) * 100 for i in range(3)] |
---|
12210 | - rc = write("si1", secrets, |
---|
12211 | - {0: ([], [(0,data[0])], None), |
---|
12212 | - 1: ([], [(0,data[1])], None), |
---|
12213 | - 2: ([], [(0,data[2])], None), |
---|
12214 | - }, []) |
---|
12215 | - self.failUnlessEqual(rc, (True, {})) |
---|
12216 | |
---|
12217 | hunk ./src/allmydata/test/test_storage.py 1215 |
---|
12218 | - answer = read("si1", [], [(0, 10)]) |
---|
12219 | - self.failUnlessEqual(answer, {0: ["0"*10], |
---|
12220 | - 1: ["1"*10], |
---|
12221 | - 2: ["2"*10]}) |
---|
12222 | + d = defer.succeed(None) |
---|
12223 | + d.addCallback(lambda ign: write("si1", secrets, |
---|
12224 | + {0: ([], [(0,data[0])], None), |
---|
12225 | + 1: ([], [(0,data[1])], None), |
---|
12226 | + 2: ([], [(0,data[2])], None), |
---|
12227 | + }, [])) |
---|
12228 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {}) )) |
---|
12229 | + |
---|
12230 | + d.addCallback(lambda ign: read("si1", [], [(0, 10)])) |
---|
12231 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: ["0"*10], |
---|
12232 | + 1: ["1"*10], |
---|
12233 | + 2: ["2"*10]})) |
---|
12234 | + return d |
---|
12235 | + |
---|
12236 | + def test_remove(self): |
---|
12237 | + ss = self.create("test_remove") |
---|
12238 | + readv = ss.remote_slot_readv |
---|
12239 | + writev = ss.remote_slot_testv_and_readv_and_writev |
---|
12240 | + secrets = ( self.write_enabler("we1"), |
---|
12241 | + self.renew_secret("we1"), |
---|
12242 | + self.cancel_secret("we1") ) |
---|
12243 | + |
---|
12244 | + d = defer.succeed(None) |
---|
12245 | + d.addCallback(lambda ign: self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
12246 | + set([0,1,2]), 100)) |
---|
12247 | + # delete sh0 by setting its size to zero |
---|
12248 | + d.addCallback(lambda ign: writev("si1", secrets, |
---|
12249 | + {0: ([], [], 0)}, |
---|
12250 | + [])) |
---|
12251 | + # the answer should mention all the shares that existed before the |
---|
12252 | + # write |
---|
12253 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {0:[],1:[],2:[]}) )) |
---|
12254 | + # but a new read should show only sh1 and sh2 |
---|
12255 | + d.addCallback(lambda ign: readv("si1", [], [(0,10)])) |
---|
12256 | + d.addCallback(lambda res: self.failUnlessEqual(res, {1: [""], 2: [""]})) |
---|
12257 | + |
---|
12258 | + # delete sh1 by setting its size to zero |
---|
12259 | + d.addCallback(lambda ign: writev("si1", secrets, |
---|
12260 | + {1: ([], [], 0)}, |
---|
12261 | + [])) |
---|
12262 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {1:[],2:[]}) )) |
---|
12263 | + d.addCallback(lambda ign: readv("si1", [], [(0,10)])) |
---|
12264 | + d.addCallback(lambda res: self.failUnlessEqual(res, {2: [""]})) |
---|
12265 | + |
---|
12266 | + # delete sh2 by setting its size to zero |
---|
12267 | + d.addCallback(lambda ign: writev("si1", secrets, |
---|
12268 | + {2: ([], [], 0)}, |
---|
12269 | + [])) |
---|
12270 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {2:[]}) )) |
---|
12271 | + d.addCallback(lambda ign: readv("si1", [], [(0,10)])) |
---|
12272 | + d.addCallback(lambda res: self.failUnlessEqual(res, {})) |
---|
12273 | + |
---|
12274 | + d.addCallback(lambda ign: ss.backend.get_shareset("si1").get_overhead()) |
---|
12275 | + d.addCallback(lambda overhead: self.failUnlessEqual(overhead, 0)) |
---|
12276 | + |
---|
12277 | + # and the shareset directory should now be gone. This check is only |
---|
12278 | + # applicable to the disk backend. |
---|
12279 | + def _check_gone(ign): |
---|
12280 | + si = base32.b2a("si1") |
---|
12281 | + # note: this is a detail of the disk backend, and may change in the future |
---|
12282 | + prefix = si[:2] |
---|
12283 | + prefixdir = self.workdir("test_remove").child("shares").child(prefix) |
---|
12284 | + sidir = prefixdir.child(si) |
---|
12285 | + self.failUnless(prefixdir.exists(), prefixdir) |
---|
12286 | + self.failIf(sidir.exists(), sidir) |
---|
12287 | + |
---|
12288 | + if isinstance(ss.backend, DiskBackend): |
---|
12289 | + d.addCallback(_check_gone) |
---|
12290 | + return d |
---|
12291 | + |
---|
12292 | + |
---|
12293 | +class ServerWithNullBackend(ServerMixin, unittest.TestCase): |
---|
12294 | + def test_null_backend(self): |
---|
12295 | + workdir = self.workdir("test_null_backend") |
---|
12296 | + backend = NullBackend() |
---|
12297 | + ss = StorageServer("\x00" * 20, backend, workdir) |
---|
12298 | + ss.setServiceParent(self.sparent) |
---|
12299 | + |
---|
12300 | + d = self.allocate(ss, "vid", [0,1,2], 75) |
---|
12301 | + def _allocated( (already, writers) ): |
---|
12302 | + self.failUnlessEqual(already, set()) |
---|
12303 | + self.failUnlessEqual(set(writers.keys()), set([0,1,2])) |
---|
12304 | + |
---|
12305 | + d2 = for_items(self._write_and_close, writers) |
---|
12306 | + |
---|
12307 | + # The shares should be present but have no data. |
---|
12308 | + d2.addCallback(lambda ign: ss.remote_get_buckets("vid")) |
---|
12309 | + def _check(buckets): |
---|
12310 | + self.failUnlessEqual(set(buckets.keys()), set([0,1,2])) |
---|
12311 | + d3 = defer.succeed(None) |
---|
12312 | + d3.addCallback(lambda ign: buckets[0].remote_read(0, 25)) |
---|
12313 | + d3.addCallback(lambda res: self.failUnlessEqual(res, "")) |
---|
12314 | + return d3 |
---|
12315 | + d2.addCallback(_check) |
---|
12316 | + return d2 |
---|
12317 | + d.addCallback(_allocated) |
---|
12318 | + return d |
---|
12319 | + |
---|
12320 | + |
---|
12321 | +class CreateS3Backend: |
---|
12322 | + def create(self, name, readonly=False, reserved_space=0, klass=StorageServer): |
---|
12323 | + assert not readonly |
---|
12324 | + workdir = self.workdir(name) |
---|
12325 | + s3bucket = MockS3Bucket(workdir) |
---|
12326 | + corruption_advisory_dir = workdir.child("corruption-advisories") |
---|
12327 | + backend = S3Backend(s3bucket, corruption_advisory_dir=corruption_advisory_dir) |
---|
12328 | + ss = klass("\x00" * 20, backend, workdir, |
---|
12329 | + stats_provider=FakeStatsProvider()) |
---|
12330 | + ss.setServiceParent(self.sparent) |
---|
12331 | + return ss |
---|
12332 | + |
---|
12333 | + |
---|
12334 | +class CreateDiskBackend: |
---|
12335 | + def create(self, name, readonly=False, reserved_space=0, klass=StorageServer): |
---|
12336 | + workdir = self.workdir(name) |
---|
12337 | + backend = DiskBackend(workdir, readonly=readonly, reserved_space=reserved_space) |
---|
12338 | + ss = klass("\x00" * 20, backend, workdir, |
---|
12339 | + stats_provider=FakeStatsProvider()) |
---|
12340 | + ss.setServiceParent(self.sparent) |
---|
12341 | + return ss |
---|
12342 | + |
---|
12343 | + |
---|
12344 | +class ServerWithS3Backend(ServerTest, CreateS3Backend, unittest.TestCase): |
---|
12345 | + def test_bad_container_version(self): |
---|
12346 | + return ServerTest.test_bad_container_version(self) |
---|
12347 | + test_bad_container_version.todo = "The S3 backend doesn't pass this test." |
---|
12348 | + |
---|
12349 | + |
---|
12350 | + |
---|
12351 | +class ServerWithDiskBackend(ServerTest, CreateDiskBackend, unittest.TestCase): |
---|
12352 | + |
---|
12353 | + # The following tests are for behaviour that is only supported by a disk backend. |
---|
12354 | + |
---|
12355 | + def test_readonly(self): |
---|
12356 | + ss = self.create("test_readonly", readonly=True) |
---|
12357 | + |
---|
12358 | + d = self.allocate(ss, "vid", [0,1,2], 75) |
---|
12359 | + def _allocated( (already, writers) ): |
---|
12360 | + self.failUnlessEqual(already, set()) |
---|
12361 | + self.failUnlessEqual(writers, {}) |
---|
12362 | + |
---|
12363 | + stats = ss.get_stats() |
---|
12364 | + self.failUnlessEqual(stats["storage_server.accepting_immutable_shares"], 0) |
---|
12365 | + if "storage_server.disk_avail" in stats: |
---|
12366 | + # Some platforms may not have an API to get disk stats. |
---|
12367 | + # But if there are stats, readonly_storage means disk_avail=0 |
---|
12368 | + self.failUnlessEqual(stats["storage_server.disk_avail"], 0) |
---|
12369 | + d.addCallback(_allocated) |
---|
12370 | + return d |
---|
12371 | + |
---|
12372 | + def test_large_share(self): |
---|
12373 | + syslow = platform.system().lower() |
---|
12374 | + if 'cygwin' in syslow or 'windows' in syslow or 'darwin' in syslow: |
---|
12375 | + raise unittest.SkipTest("If your filesystem doesn't support efficient sparse files then it is very expensive (Mac OS X and Windows don't support efficient sparse files).") |
---|
12376 | + |
---|
12377 | + avail = fileutil.get_available_space(FilePath('.'), 512*2**20) |
---|
12378 | + if avail <= 4*2**30: |
---|
12379 | + raise unittest.SkipTest("This test will spuriously fail if you have less than 4 GiB free on your filesystem.") |
---|
12380 | + |
---|
12381 | + ss = self.create("test_large_share") |
---|
12382 | + |
---|
12383 | + d = self.allocate(ss, "allocate", [0], 2**32+2) |
---|
12384 | + def _allocated( (already, writers) ): |
---|
12385 | + self.failUnlessEqual(already, set()) |
---|
12386 | + self.failUnlessEqual(set(writers.keys()), set([0])) |
---|
12387 | + |
---|
12388 | + shnum, bucket = writers.items()[0] |
---|
12389 | + |
---|
12390 | + # This test is going to hammer your filesystem if it doesn't make a sparse file for this. :-( |
---|
12391 | + d2 = defer.succeed(None) |
---|
12392 | + d2.addCallback(lambda ign: bucket.remote_write(2**32, "ab")) |
---|
12393 | + d2.addCallback(lambda ign: bucket.remote_close()) |
---|
12394 | + |
---|
12395 | + d2.addCallback(lambda ign: ss.remote_get_buckets("allocate")) |
---|
12396 | + d2.addCallback(lambda readers: readers[shnum].remote_read(2**32, 2)) |
---|
12397 | + d2.addCallback(lambda res: self.failUnlessEqual(res, "ab")) |
---|
12398 | + return d2 |
---|
12399 | + d.addCallback(_allocated) |
---|
12400 | + return d |
---|
12401 | + |
---|
12402 | + def test_immutable_leases(self): |
---|
12403 | + ss = self.create("test_immutable_leases") |
---|
12404 | + canary = FakeCanary() |
---|
12405 | + sharenums = range(5) |
---|
12406 | + size = 100 |
---|
12407 | + |
---|
12408 | + rs = [] |
---|
12409 | + cs = [] |
---|
12410 | + for i in range(6): |
---|
12411 | + rs.append(hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
12412 | + cs.append(hashutil.tagged_hash("blah", "%d" % self._lease_secret.next())) |
---|
12413 | + |
---|
12414 | + d = ss.remote_allocate_buckets("si0", rs[0], cs[0], |
---|
12415 | + sharenums, size, canary) |
---|
12416 | + def _allocated( (already, writers) ): |
---|
12417 | + self.failUnlessEqual(len(already), 0) |
---|
12418 | + self.failUnlessEqual(len(writers), 5) |
---|
12419 | + |
---|
12420 | + d2 = for_items(self._close_writer, writers) |
---|
12421 | + |
---|
12422 | + d2.addCallback(lambda ign: list(ss.get_leases("si0"))) |
---|
12423 | + def _check_leases(leases): |
---|
12424 | + self.failUnlessEqual(len(leases), 1) |
---|
12425 | + self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs[0]])) |
---|
12426 | + d2.addCallback(_check_leases) |
---|
12427 | + |
---|
12428 | + d2.addCallback(lambda ign: ss.remote_allocate_buckets("si1", rs[1], cs[1], |
---|
12429 | + sharenums, size, canary)) |
---|
12430 | + return d2 |
---|
12431 | + d.addCallback(_allocated) |
---|
12432 | + |
---|
12433 | + def _allocated2( (already, writers) ): |
---|
12434 | + d2 = for_items(self._close_writer, writers) |
---|
12435 | + |
---|
12436 | + # take out a second lease on si1 |
---|
12437 | + d2.addCallback(lambda ign: ss.remote_allocate_buckets("si1", rs[2], cs[2], |
---|
12438 | + sharenums, size, canary)) |
---|
12439 | + return d2 |
---|
12440 | + d.addCallback(_allocated2) |
---|
12441 | + |
---|
12442 | + def _allocated2a( (already, writers) ): |
---|
12443 | + self.failUnlessEqual(len(already), 5) |
---|
12444 | + self.failUnlessEqual(len(writers), 0) |
---|
12445 | + |
---|
12446 | + d2 = defer.succeed(None) |
---|
12447 | + d2.addCallback(lambda ign: list(ss.get_leases("si1"))) |
---|
12448 | + def _check_leases2(leases): |
---|
12449 | + self.failUnlessEqual(len(leases), 2) |
---|
12450 | + self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs[1], rs[2]])) |
---|
12451 | + d2.addCallback(_check_leases2) |
---|
12452 | + |
---|
12453 | + # and a third lease, using add-lease |
---|
12454 | + d2.addCallback(lambda ign: ss.remote_add_lease("si1", rs[3], cs[3])) |
---|
12455 | + |
---|
12456 | + d2.addCallback(lambda ign: list(ss.get_leases("si1"))) |
---|
12457 | + def _check_leases3(leases): |
---|
12458 | + self.failUnlessEqual(len(leases), 3) |
---|
12459 | + self.failUnlessEqual(set([l.renew_secret for l in leases]), set([rs[1], rs[2], rs[3]])) |
---|
12460 | + d2.addCallback(_check_leases3) |
---|
12461 | + |
---|
12462 | + # add-lease on a missing storage index is silently ignored |
---|
12463 | + d2.addCallback(lambda ign: ss.remote_add_lease("si18", "", "")) |
---|
12464 | + d2.addCallback(lambda res: self.failUnlessEqual(res, None)) |
---|
12465 | + |
---|
12466 | + # check that si0 is readable |
---|
12467 | + d2.addCallback(lambda ign: ss.remote_get_buckets("si0")) |
---|
12468 | + d2.addCallback(lambda readers: self.failUnlessEqual(len(readers), 5)) |
---|
12469 | + |
---|
12470 | + # renew the first lease. Only the proper renew_secret should work |
---|
12471 | + d2.addCallback(lambda ign: ss.remote_renew_lease("si0", rs[0])) |
---|
12472 | + d2.addCallback(lambda ign: self.shouldFail(IndexError, 'wrong secret 1', None, |
---|
12473 | + lambda: ss.remote_renew_lease("si0", cs[0]) )) |
---|
12474 | + d2.addCallback(lambda ign: self.shouldFail(IndexError, 'wrong secret 2', None, |
---|
12475 | + lambda: ss.remote_renew_lease("si0", rs[1]) )) |
---|
12476 | + |
---|
12477 | + # check that si0 is still readable |
---|
12478 | + d2.addCallback(lambda ign: ss.remote_get_buckets("si0")) |
---|
12479 | + d2.addCallback(lambda readers: self.failUnlessEqual(len(readers), 5)) |
---|
12480 | + |
---|
12481 | + # There is no such method as remote_cancel_lease for now -- see |
---|
12482 | + # ticket #1528. |
---|
12483 | + d2.addCallback(lambda ign: self.failIf(hasattr(ss, 'remote_cancel_lease'), |
---|
12484 | + "ss should not have a 'remote_cancel_lease' method/attribute")) |
---|
12485 | + |
---|
12486 | + # test overlapping uploads |
---|
12487 | + d2.addCallback(lambda ign: ss.remote_allocate_buckets("si3", rs[4], cs[4], |
---|
12488 | + sharenums, size, canary)) |
---|
12489 | + return d2 |
---|
12490 | + d.addCallback(_allocated2a) |
---|
12491 | + |
---|
12492 | + def _allocated4( (already, writers) ): |
---|
12493 | + self.failUnlessEqual(len(already), 0) |
---|
12494 | + self.failUnlessEqual(len(writers), 5) |
---|
12495 | + |
---|
12496 | + d2 = defer.succeed(None) |
---|
12497 | + d2.addCallback(lambda ign: ss.remote_allocate_buckets("si3", rs[5], cs[5], |
---|
12498 | + sharenums, size, canary)) |
---|
12499 | + def _allocated5( (already2, writers2) ): |
---|
12500 | + self.failUnlessEqual(len(already2), 0) |
---|
12501 | + self.failUnlessEqual(len(writers2), 0) |
---|
12502 | + |
---|
12503 | + d3 = for_items(self._close_writer, writers) |
---|
12504 | + |
---|
12505 | + d3.addCallback(lambda ign: list(ss.get_leases("si3"))) |
---|
12506 | + d3.addCallback(lambda leases: self.failUnlessEqual(len(leases), 1)) |
---|
12507 | + |
---|
12508 | + d3.addCallback(lambda ign: ss.remote_allocate_buckets("si3", rs[5], cs[5], |
---|
12509 | + sharenums, size, canary)) |
---|
12510 | + return d3 |
---|
12511 | + d2.addCallback(_allocated5) |
---|
12512 | + |
---|
12513 | + def _allocated6( (already3, writers3) ): |
---|
12514 | + self.failUnlessEqual(len(already3), 5) |
---|
12515 | + self.failUnlessEqual(len(writers3), 0) |
---|
12516 | + |
---|
12517 | + d3 = defer.succeed(None) |
---|
12518 | + d3.addCallback(lambda ign: list(ss.get_leases("si3"))) |
---|
12519 | + d3.addCallback(lambda leases: self.failUnlessEqual(len(leases), 2)) |
---|
12520 | + return d3 |
---|
12521 | + d2.addCallback(_allocated6) |
---|
12522 | + return d2 |
---|
12523 | + d.addCallback(_allocated4) |
---|
12524 | + return d |
---|
12525 | + |
---|
12526 | + def test_remove_incoming(self): |
---|
12527 | + ss = self.create("test_remove_incoming") |
---|
12528 | + d = self.allocate(ss, "vid", range(3), 25) |
---|
12529 | + def _allocated( (already, writers) ): |
---|
12530 | + d2 = defer.succeed(None) |
---|
12531 | + for i, bw in writers.items(): |
---|
12532 | + incoming_share_home = bw._share._get_filepath() |
---|
12533 | + d2.addCallback(self._write_and_close, i, bw) |
---|
12534 | + |
---|
12535 | + incoming_si_dir = incoming_share_home.parent() |
---|
12536 | + incoming_prefix_dir = incoming_si_dir.parent() |
---|
12537 | + incoming_dir = incoming_prefix_dir.parent() |
---|
12538 | + |
---|
12539 | + def _check_existence(ign): |
---|
12540 | + self.failIf(incoming_si_dir.exists(), incoming_si_dir) |
---|
12541 | + self.failIf(incoming_prefix_dir.exists(), incoming_prefix_dir) |
---|
12542 | + self.failUnless(incoming_dir.exists(), incoming_dir) |
---|
12543 | + d2.addCallback(_check_existence) |
---|
12544 | + return d2 |
---|
12545 | + d.addCallback(_allocated) |
---|
12546 | + return d |
---|
12547 | + |
---|
12548 | + @mock.patch('allmydata.util.fileutil.get_disk_stats') |
---|
12549 | + def test_reserved_space(self, mock_get_disk_stats): |
---|
12550 | + reserved_space=10000 |
---|
12551 | + mock_get_disk_stats.return_value = { |
---|
12552 | + 'free_for_nonroot': 15000, |
---|
12553 | + 'avail': max(15000 - reserved_space, 0), |
---|
12554 | + } |
---|
12555 | + |
---|
12556 | + ss = self.create("test_reserved_space", reserved_space=reserved_space) |
---|
12557 | + # 15k available, 10k reserved, leaves 5k for shares |
---|
12558 | + |
---|
12559 | + # a newly created and filled share incurs this much overhead, beyond |
---|
12560 | + # the size we request. |
---|
12561 | + OVERHEAD = 3*4 |
---|
12562 | + LEASE_SIZE = 4+32+32+4 |
---|
12563 | + canary = FakeCanary(True) |
---|
12564 | + |
---|
12565 | + d = self.allocate(ss, "vid1", [0,1,2], 1000, canary) |
---|
12566 | + def _allocated( (already, writers) ): |
---|
12567 | + self.failUnlessEqual(len(writers), 3) |
---|
12568 | + # now the StorageServer should have 3000 bytes provisionally |
---|
12569 | + # allocated, allowing only 2000 more to be claimed |
---|
12570 | + self.failUnlessEqual(len(ss._active_writers), 3) |
---|
12571 | + self.writers = writers |
---|
12572 | + del already |
---|
12573 | + |
---|
12574 | + # allocating 1001-byte shares only leaves room for one |
---|
12575 | + d2 = self.allocate(ss, "vid2", [0,1,2], 1001, canary) |
---|
12576 | + def _allocated2( (already2, writers2) ): |
---|
12577 | + self.failUnlessEqual(len(writers2), 1) |
---|
12578 | + self.failUnlessEqual(len(ss._active_writers), 4) |
---|
12579 | + |
---|
12580 | + # we abandon the first set, so their provisional allocation should be |
---|
12581 | + # returned |
---|
12582 | + d3 = for_items(self._abort_writer, self.writers) |
---|
12583 | + #def _del_writers(ign): |
---|
12584 | + # del self.writers |
---|
12585 | + #d3.addCallback(_del_writers) |
---|
12586 | + d3.addCallback(lambda ign: self.failUnlessEqual(len(ss._active_writers), 1)) |
---|
12587 | + |
---|
12588 | + # and we close the second set, so their provisional allocation should |
---|
12589 | + # become real, long-term allocation, and grows to include the |
---|
12590 | + # overhead. |
---|
12591 | + d3.addCallback(lambda ign: for_items(self._write_and_close, writers2)) |
---|
12592 | + d3.addCallback(lambda ign: self.failUnlessEqual(len(ss._active_writers), 0)) |
---|
12593 | + return d3 |
---|
12594 | + d2.addCallback(_allocated2) |
---|
12595 | + |
---|
12596 | + allocated = 1001 + OVERHEAD + LEASE_SIZE |
---|
12597 | + |
---|
12598 | + # we have to manually increase available, since we're not doing real |
---|
12599 | + # disk measurements |
---|
12600 | + def _mock(ign): |
---|
12601 | + mock_get_disk_stats.return_value = { |
---|
12602 | + 'free_for_nonroot': 15000 - allocated, |
---|
12603 | + 'avail': max(15000 - allocated - reserved_space, 0), |
---|
12604 | + } |
---|
12605 | + d2.addCallback(_mock) |
---|
12606 | + |
---|
12607 | + # now there should be ALLOCATED=1001+12+72=1085 bytes allocated, and |
---|
12608 | + # 5000-1085=3915 free, therefore we can fit 39 100byte shares |
---|
12609 | + d2.addCallback(lambda ign: self.allocate(ss,"vid3", range(100), 100, canary)) |
---|
12610 | + def _allocated3( (already3, writers3) ): |
---|
12611 | + self.failUnlessEqual(len(writers3), 39) |
---|
12612 | + self.failUnlessEqual(len(ss._active_writers), 39) |
---|
12613 | + |
---|
12614 | + d3 = for_items(self._abort_writer, writers3) |
---|
12615 | + d3.addCallback(lambda ign: self.failUnlessEqual(len(ss._active_writers), 0)) |
---|
12616 | + d3.addCallback(lambda ign: ss.disownServiceParent()) |
---|
12617 | + return d3 |
---|
12618 | + d2.addCallback(_allocated3) |
---|
12619 | + d.addCallback(_allocated) |
---|
12620 | + return d |
---|
12621 | + |
---|
12622 | + |
---|
12623 | +class MutableServerWithS3Backend(MutableServerTest, CreateS3Backend, unittest.TestCase): |
---|
12624 | + def test_bad_magic(self): |
---|
12625 | + return MutableServerTest.test_bad_magic(self) |
---|
12626 | + test_bad_magic.todo = "The S3 backend doesn't pass this test." |
---|
12627 | + |
---|
12628 | + |
---|
12629 | +class MutableServerWithDiskBackend(MutableServerTest, CreateDiskBackend, unittest.TestCase): |
---|
12630 | + |
---|
12631 | + # The following tests are for behaviour that is only supported by a disk backend. |
---|
12632 | |
---|
12633 | def compare_leases_without_timestamps(self, leases_a, leases_b): |
---|
12634 | self.failUnlessEqual(len(leases_a), len(leases_b)) |
---|
12635 | hunk ./src/allmydata/test/test_storage.py 1647 |
---|
12636 | self.failUnlessEqual(a.nodeid, b.nodeid) |
---|
12637 | self.failUnlessEqual(a.expiration_time, b.expiration_time) |
---|
12638 | |
---|
12639 | - def test_leases(self): |
---|
12640 | - ss = self.create("test_leases") |
---|
12641 | + def test_mutable_leases(self): |
---|
12642 | + ss = self.create("test_mutable_leases") |
---|
12643 | def secrets(n): |
---|
12644 | return ( self.write_enabler("we1"), |
---|
12645 | self.renew_secret("we1-%d" % n), |
---|
12646 | hunk ./src/allmydata/test/test_storage.py 1656 |
---|
12647 | data = "".join([ ("%d" % i) * 10 for i in range(10) ]) |
---|
12648 | write = ss.remote_slot_testv_and_readv_and_writev |
---|
12649 | read = ss.remote_slot_readv |
---|
12650 | - rc = write("si1", secrets(0), {0: ([], [(0,data)], None)}, []) |
---|
12651 | - self.failUnlessEqual(rc, (True, {})) |
---|
12652 | |
---|
12653 | hunk ./src/allmydata/test/test_storage.py 1657 |
---|
12654 | - # create a random non-numeric file in the bucket directory, to |
---|
12655 | - # exercise the code that's supposed to ignore those. |
---|
12656 | - bucket_dir = os.path.join(self.workdir("test_leases"), |
---|
12657 | - "shares", storage_index_to_dir("si1")) |
---|
12658 | - f = open(os.path.join(bucket_dir, "ignore_me.txt"), "w") |
---|
12659 | - f.write("you ought to be ignoring me\n") |
---|
12660 | - f.close() |
---|
12661 | + d = write("si1", secrets(0), {0: ([], [(0,data)], None)}, []) |
---|
12662 | + d.addCallback(lambda res: self.failUnlessEqual(res, (True, {}) )) |
---|
12663 | |
---|
12664 | hunk ./src/allmydata/test/test_storage.py 1660 |
---|
12665 | - s0 = MutableShareFile(os.path.join(bucket_dir, "0")) |
---|
12666 | - self.failUnlessEqual(len(list(s0.get_leases())), 1) |
---|
12667 | + def _create_nonsharefile(ign): |
---|
12668 | + # create a random non-numeric file in the shareset directory, to |
---|
12669 | + # exercise the code that's supposed to ignore those. |
---|
12670 | |
---|
12671 | hunk ./src/allmydata/test/test_storage.py 1664 |
---|
12672 | - # add-lease on a missing storage index is silently ignored |
---|
12673 | - self.failUnlessEqual(ss.remote_add_lease("si18", "", ""), None) |
---|
12674 | + shareset = ss.backend.get_shareset("si1") |
---|
12675 | + shareset._get_sharedir().child("ignore_me.txt").setContent("you ought to be ignoring me\n") |
---|
12676 | + return shareset.get_share(0) |
---|
12677 | + d.addCallback(_create_nonsharefile) |
---|
12678 | + def _got_s0(s0): |
---|
12679 | + self.failUnlessEqual(len(list(s0.get_leases())), 1) |
---|
12680 | |
---|
12681 | hunk ./src/allmydata/test/test_storage.py 1671 |
---|
12682 | - # re-allocate the slots and use the same secrets, that should update |
---|
12683 | - # the lease |
---|
12684 | - write("si1", secrets(0), {0: ([], [(0,data)], None)}, []) |
---|
12685 | - self.failUnlessEqual(len(list(s0.get_leases())), 1) |
---|
12686 | + d2 = defer.succeed(None) |
---|
12687 | + d2.addCallback(lambda ign: ss.remote_add_lease("si18", "", "")) |
---|
12688 | + # add-lease on a missing storage index is silently ignored |
---|
12689 | + d2.addCallback(lambda res: self.failUnlessEqual(res, None)) |
---|
12690 | |
---|
12691 | hunk ./src/allmydata/test/test_storage.py 1676 |
---|
12692 | - # renew it directly |
---|
12693 | - ss.remote_renew_lease("si1", secrets(0)[1]) |
---|
12694 | - self.failUnlessEqual(len(list(s0.get_leases())), 1) |
---|
12695 | + # re-allocate the slots and use the same secrets, that should update |
---|
12696 | + # the lease |
---|
12697 | + d2.addCallback(lambda ign: write("si1", secrets(0), {0: ([], [(0,data)], None)}, [])) |
---|
12698 | + d2.addCallback(lambda ign: self.failUnlessEqual(len(list(s0.get_leases())), 1)) |
---|
12699 | |
---|
12700 | hunk ./src/allmydata/test/test_storage.py 1681 |
---|
12701 | - # now allocate them with a bunch of different secrets, to trigger the |
---|
12702 | - # extended lease code. Use add_lease for one of them. |
---|
12703 | - write("si1", secrets(1), {0: ([], [(0,data)], None)}, []) |
---|
12704 | - self.failUnlessEqual(len(list(s0.get_leases())), 2) |
---|
12705 | - secrets2 = secrets(2) |
---|
12706 | - ss.remote_add_lease("si1", secrets2[1], secrets2[2]) |
---|
12707 | - self.failUnlessEqual(len(list(s0.get_leases())), 3) |
---|
12708 | - write("si1", secrets(3), {0: ([], [(0,data)], None)}, []) |
---|
12709 | - write("si1", secrets(4), {0: ([], [(0,data)], None)}, []) |
---|
12710 | - write("si1", secrets(5), {0: ([], [(0,data)], None)}, []) |
---|
12711 | + # renew it directly |
---|
12712 | + d2.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(0)[1])) |
---|
12713 | + d2.addCallback(lambda ign: self.failUnlessEqual(len(list(s0.get_leases())), 1)) |
---|
12714 | |
---|
12715 | hunk ./src/allmydata/test/test_storage.py 1685 |
---|
12716 | - self.failUnlessEqual(len(list(s0.get_leases())), 6) |
---|
12717 | + # now allocate them with a bunch of different secrets, to trigger the |
---|
12718 | + # extended lease code. Use add_lease for one of them. |
---|
12719 | + d2.addCallback(lambda ign: write("si1", secrets(1), {0: ([], [(0,data)], None)}, [])) |
---|
12720 | + d2.addCallback(lambda ign: self.failUnlessEqual(len(list(s0.get_leases())), 2)) |
---|
12721 | + secrets2 = secrets(2) |
---|
12722 | + d2.addCallback(lambda ign: ss.remote_add_lease("si1", secrets2[1], secrets2[2])) |
---|
12723 | + d2.addCallback(lambda ign: self.failUnlessEqual(len(list(s0.get_leases())), 3)) |
---|
12724 | + d2.addCallback(lambda ign: write("si1", secrets(3), {0: ([], [(0,data)], None)}, [])) |
---|
12725 | + d2.addCallback(lambda ign: write("si1", secrets(4), {0: ([], [(0,data)], None)}, [])) |
---|
12726 | + d2.addCallback(lambda ign: write("si1", secrets(5), {0: ([], [(0,data)], None)}, [])) |
---|
12727 | |
---|
12728 | hunk ./src/allmydata/test/test_storage.py 1696 |
---|
12729 | - all_leases = list(s0.get_leases()) |
---|
12730 | - # and write enough data to expand the container, forcing the server |
---|
12731 | - # to move the leases |
---|
12732 | - write("si1", secrets(0), |
---|
12733 | - {0: ([], [(0,data)], 200), }, |
---|
12734 | - []) |
---|
12735 | + d2.addCallback(lambda ign: self.failUnlessEqual(len(list(s0.get_leases())), 6)) |
---|
12736 | |
---|
12737 | hunk ./src/allmydata/test/test_storage.py 1698 |
---|
12738 | - # read back the leases, make sure they're still intact. |
---|
12739 | - self.compare_leases_without_timestamps(all_leases, list(s0.get_leases())) |
---|
12740 | + def _check_all_leases(ign): |
---|
12741 | + all_leases = list(s0.get_leases()) |
---|
12742 | |
---|
12743 | hunk ./src/allmydata/test/test_storage.py 1701 |
---|
12744 | - ss.remote_renew_lease("si1", secrets(0)[1]) |
---|
12745 | - ss.remote_renew_lease("si1", secrets(1)[1]) |
---|
12746 | - ss.remote_renew_lease("si1", secrets(2)[1]) |
---|
12747 | - ss.remote_renew_lease("si1", secrets(3)[1]) |
---|
12748 | - ss.remote_renew_lease("si1", secrets(4)[1]) |
---|
12749 | - self.compare_leases_without_timestamps(all_leases, list(s0.get_leases())) |
---|
12750 | - # get a new copy of the leases, with the current timestamps. Reading |
---|
12751 | - # data and failing to renew/cancel leases should leave the timestamps |
---|
12752 | - # alone. |
---|
12753 | - all_leases = list(s0.get_leases()) |
---|
12754 | - # renewing with a bogus token should prompt an error message |
---|
12755 | + # and write enough data to expand the container, forcing the server |
---|
12756 | + # to move the leases |
---|
12757 | + d3 = defer.succeed(None) |
---|
12758 | + d3.addCallback(lambda ign: write("si1", secrets(0), |
---|
12759 | + {0: ([], [(0,data)], 200), }, |
---|
12760 | + [])) |
---|
12761 | |
---|
12762 | hunk ./src/allmydata/test/test_storage.py 1708 |
---|
12763 | - # examine the exception thus raised, make sure the old nodeid is |
---|
12764 | - # present, to provide for share migration |
---|
12765 | - e = self.failUnlessRaises(IndexError, |
---|
12766 | - ss.remote_renew_lease, "si1", |
---|
12767 | - secrets(20)[1]) |
---|
12768 | - e_s = str(e) |
---|
12769 | - self.failUnlessIn("Unable to renew non-existent lease", e_s) |
---|
12770 | - self.failUnlessIn("I have leases accepted by nodeids:", e_s) |
---|
12771 | - self.failUnlessIn("nodeids: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' .", e_s) |
---|
12772 | + # read back the leases, make sure they're still intact. |
---|
12773 | + d3.addCallback(lambda ign: self.compare_leases_without_timestamps(all_leases, |
---|
12774 | + list(s0.get_leases()))) |
---|
12775 | |
---|
12776 | hunk ./src/allmydata/test/test_storage.py 1712 |
---|
12777 | - self.compare_leases(all_leases, list(s0.get_leases())) |
---|
12778 | + d3.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(0)[1])) |
---|
12779 | + d3.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(1)[1])) |
---|
12780 | + d3.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(2)[1])) |
---|
12781 | + d3.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(3)[1])) |
---|
12782 | + d3.addCallback(lambda ign: ss.remote_renew_lease("si1", secrets(4)[1])) |
---|
12783 | + d3.addCallback(lambda ign: self.compare_leases_without_timestamps(all_leases, |
---|
12784 | + list(s0.get_leases()))) |
---|
12785 | + d2.addCallback(_check_all_leases) |
---|
12786 | |
---|
12787 | hunk ./src/allmydata/test/test_storage.py 1721 |
---|
12788 | - # reading shares should not modify the timestamp |
---|
12789 | - read("si1", [], [(0,200)]) |
---|
12790 | - self.compare_leases(all_leases, list(s0.get_leases())) |
---|
12791 | + def _check_all_leases_again(ign): |
---|
12792 | + # get a new copy of the leases, with the current timestamps. Reading |
---|
12793 | + # data and failing to renew/cancel leases should leave the timestamps |
---|
12794 | + # alone. |
---|
12795 | + all_leases = list(s0.get_leases()) |
---|
12796 | + # renewing with a bogus token should prompt an error message |
---|
12797 | |
---|
12798 | hunk ./src/allmydata/test/test_storage.py 1728 |
---|
12799 | - write("si1", secrets(0), |
---|
12800 | - {0: ([], [(200, "make me bigger")], None)}, []) |
---|
12801 | - self.compare_leases_without_timestamps(all_leases, list(s0.get_leases())) |
---|
12802 | + # examine the exception thus raised, make sure the old nodeid is |
---|
12803 | + # present, to provide for share migration |
---|
12804 | + d3 = self.shouldFail(IndexError, 'old nodeid present', |
---|
12805 | + "Unable to renew non-existent lease. " |
---|
12806 | + "I have leases accepted by nodeids: " |
---|
12807 | + "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' .", |
---|
12808 | + lambda: ss.remote_renew_lease("si1", secrets(20)[1]) ) |
---|
12809 | |
---|
12810 | hunk ./src/allmydata/test/test_storage.py 1736 |
---|
12811 | - write("si1", secrets(0), |
---|
12812 | - {0: ([], [(500, "make me really bigger")], None)}, []) |
---|
12813 | - self.compare_leases_without_timestamps(all_leases, list(s0.get_leases())) |
---|
12814 | + d3.addCallback(lambda ign: self.compare_leases(all_leases, list(s0.get_leases()))) |
---|
12815 | |
---|
12816 | hunk ./src/allmydata/test/test_storage.py 1738 |
---|
12817 | - def test_remove(self): |
---|
12818 | - ss = self.create("test_remove") |
---|
12819 | - self.allocate(ss, "si1", "we1", self._lease_secret.next(), |
---|
12820 | - set([0,1,2]), 100) |
---|
12821 | - readv = ss.remote_slot_readv |
---|
12822 | - writev = ss.remote_slot_testv_and_readv_and_writev |
---|
12823 | - secrets = ( self.write_enabler("we1"), |
---|
12824 | - self.renew_secret("we1"), |
---|
12825 | - self.cancel_secret("we1") ) |
---|
12826 | - # delete sh0 by setting its size to zero |
---|
12827 | - answer = writev("si1", secrets, |
---|
12828 | - {0: ([], [], 0)}, |
---|
12829 | - []) |
---|
12830 | - # the answer should mention all the shares that existed before the |
---|
12831 | - # write |
---|
12832 | - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) |
---|
12833 | - # but a new read should show only sh1 and sh2 |
---|
12834 | - self.failUnlessEqual(readv("si1", [], [(0,10)]), |
---|
12835 | - {1: [""], 2: [""]}) |
---|
12836 | + # reading shares should not modify the timestamp |
---|
12837 | + d3.addCallback(lambda ign: read("si1", [], [(0,200)])) |
---|
12838 | + d3.addCallback(lambda ign: self.compare_leases(all_leases, list(s0.get_leases()))) |
---|
12839 | |
---|
12840 | hunk ./src/allmydata/test/test_storage.py 1742 |
---|
12841 | - # delete sh1 by setting its size to zero |
---|
12842 | - answer = writev("si1", secrets, |
---|
12843 | - {1: ([], [], 0)}, |
---|
12844 | - []) |
---|
12845 | - self.failUnlessEqual(answer, (True, {1:[],2:[]}) ) |
---|
12846 | - self.failUnlessEqual(readv("si1", [], [(0,10)]), |
---|
12847 | - {2: [""]}) |
---|
12848 | + d3.addCallback(lambda ign: write("si1", secrets(0), |
---|
12849 | + {0: ([], [(200, "make me bigger")], None)}, [])) |
---|
12850 | + d3.addCallback(lambda ign: self.compare_leases_without_timestamps(all_leases, list(s0.get_leases()))) |
---|
12851 | |
---|
12852 | hunk ./src/allmydata/test/test_storage.py 1746 |
---|
12853 | - # delete sh2 by setting its size to zero |
---|
12854 | - answer = writev("si1", secrets, |
---|
12855 | - {2: ([], [], 0)}, |
---|
12856 | - []) |
---|
12857 | - self.failUnlessEqual(answer, (True, {2:[]}) ) |
---|
12858 | - self.failUnlessEqual(readv("si1", [], [(0,10)]), |
---|
12859 | - {}) |
---|
12860 | - # and the bucket directory should now be gone |
---|
12861 | - si = base32.b2a("si1") |
---|
12862 | - # note: this is a detail of the storage server implementation, and |
---|
12863 | - # may change in the future |
---|
12864 | - prefix = si[:2] |
---|
12865 | - prefixdir = os.path.join(self.workdir("test_remove"), "shares", prefix) |
---|
12866 | - bucketdir = os.path.join(prefixdir, si) |
---|
12867 | - self.failUnless(os.path.exists(prefixdir), prefixdir) |
---|
12868 | - self.failIf(os.path.exists(bucketdir), bucketdir) |
---|
12869 | + d3.addCallback(lambda ign: write("si1", secrets(0), |
---|
12870 | + {0: ([], [(500, "make me really bigger")], None)}, [])) |
---|
12871 | + d3.addCallback(lambda ign: self.compare_leases_without_timestamps(all_leases, list(s0.get_leases()))) |
---|
12872 | + d2.addCallback(_check_all_leases_again) |
---|
12873 | + return d2 |
---|
12874 | + d.addCallback(_got_s0) |
---|
12875 | + return d |
---|
12876 | |
---|
12877 | |
---|
12878 | class MDMFProxies(unittest.TestCase, ShouldFailMixin): |
---|
12879 | hunk ./src/allmydata/test/test_storage.py 1787 |
---|
12880 | |
---|
12881 | def tearDown(self): |
---|
12882 | self.sparent.stopService() |
---|
12883 | - shutil.rmtree(self.workdir("MDMFProxies storage test server")) |
---|
12884 | - |
---|
12885 | + fileutil.fp_remove(self.workdir("MDMFProxies storage test server")) |
---|
12886 | |
---|
12887 | def write_enabler(self, we_tag): |
---|
12888 | return hashutil.tagged_hash("we_blah", we_tag) |
---|
12889 | hunk ./src/allmydata/test/test_storage.py 1799 |
---|
12890 | return hashutil.tagged_hash("cancel_blah", str(tag)) |
---|
12891 | |
---|
12892 | def workdir(self, name): |
---|
12893 | - basedir = os.path.join("storage", "MutableServer", name) |
---|
12894 | - return basedir |
---|
12895 | - |
---|
12896 | + return FilePath("storage").child(self.__class__.__name__).child(name) |
---|
12897 | |
---|
12898 | def create(self, name): |
---|
12899 | workdir = self.workdir(name) |
---|
12900 | hunk ./src/allmydata/test/test_storage.py 1803 |
---|
12901 | - ss = StorageServer(workdir, "\x00" * 20) |
---|
12902 | + backend = DiskBackend(workdir) |
---|
12903 | + ss = StorageServer("\x00" * 20, backend, workdir) |
---|
12904 | ss.setServiceParent(self.sparent) |
---|
12905 | return ss |
---|
12906 | |
---|
12907 | hunk ./src/allmydata/test/test_storage.py 1923 |
---|
12908 | tws = {} |
---|
12909 | tws[0] = (testvs, [(0, data)], None) |
---|
12910 | readv = [(0, 1)] |
---|
12911 | - results = write(storage_index, self.secrets, tws, readv) |
---|
12912 | - self.failUnless(results[0]) |
---|
12913 | |
---|
12914 | hunk ./src/allmydata/test/test_storage.py 1924 |
---|
12915 | + d = defer.succeed(None) |
---|
12916 | + d.addCallback(lambda ign: write(storage_index, self.secrets, tws, readv)) |
---|
12917 | + d.addCallback(lambda results: self.failUnless(results[0])) |
---|
12918 | + return d |
---|
12919 | |
---|
12920 | def build_test_sdmf_share(self, empty=False): |
---|
12921 | if empty: |
---|
12922 | hunk ./src/allmydata/test/test_storage.py 1991 |
---|
12923 | tws = {} |
---|
12924 | tws[0] = (testvs, [(0, share)], None) |
---|
12925 | readv = [] |
---|
12926 | - results = write(storage_index, self.secrets, tws, readv) |
---|
12927 | - self.failUnless(results[0]) |
---|
12928 | - |
---|
12929 | |
---|
12930 | hunk ./src/allmydata/test/test_storage.py 1992 |
---|
12931 | - def test_read(self): |
---|
12932 | - self.write_test_share_to_server("si1") |
---|
12933 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
12934 | - # Check that every method equals what we expect it to. |
---|
12935 | d = defer.succeed(None) |
---|
12936 | hunk ./src/allmydata/test/test_storage.py 1993 |
---|
12937 | - def _check_block_and_salt((block, salt)): |
---|
12938 | - self.failUnlessEqual(block, self.block) |
---|
12939 | - self.failUnlessEqual(salt, self.salt) |
---|
12940 | + d.addCallback(lambda ign: write(storage_index, self.secrets, tws, readv)) |
---|
12941 | + d.addCallback(lambda results: self.failUnless(results[0], results)) |
---|
12942 | + return d |
---|
12943 | |
---|
12944 | hunk ./src/allmydata/test/test_storage.py 1997 |
---|
12945 | - for i in xrange(6): |
---|
12946 | - d.addCallback(lambda ignored, i=i: |
---|
12947 | - mr.get_block_and_salt(i)) |
---|
12948 | - d.addCallback(_check_block_and_salt) |
---|
12949 | + def test_read(self): |
---|
12950 | + d = self.write_test_share_to_server("si1") |
---|
12951 | + def _written(ign): |
---|
12952 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
12953 | + # Check that every method returns what we expect it to. |
---|
12954 | + def _check_block_and_salt((block, salt)): |
---|
12955 | + self.failUnlessEqual(block, self.block) |
---|
12956 | + self.failUnlessEqual(salt, self.salt) |
---|
12957 | |
---|
12958 | hunk ./src/allmydata/test/test_storage.py 2006 |
---|
12959 | - d.addCallback(lambda ignored: |
---|
12960 | - mr.get_encprivkey()) |
---|
12961 | - d.addCallback(lambda encprivkey: |
---|
12962 | - self.failUnlessEqual(self.encprivkey, encprivkey)) |
---|
12963 | + d2 = defer.succeed(None) |
---|
12964 | + for i in xrange(6): |
---|
12965 | + d2.addCallback(lambda ign, i=i: mr.get_block_and_salt(i)) |
---|
12966 | + d2.addCallback(_check_block_and_salt) |
---|
12967 | |
---|
12968 | hunk ./src/allmydata/test/test_storage.py 2011 |
---|
12969 | - d.addCallback(lambda ignored: |
---|
12970 | - mr.get_blockhashes()) |
---|
12971 | - d.addCallback(lambda blockhashes: |
---|
12972 | - self.failUnlessEqual(self.block_hash_tree, blockhashes)) |
---|
12973 | + d2.addCallback(lambda ign: mr.get_encprivkey()) |
---|
12974 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.encprivkey)) |
---|
12975 | |
---|
12976 | hunk ./src/allmydata/test/test_storage.py 2014 |
---|
12977 | - d.addCallback(lambda ignored: |
---|
12978 | - mr.get_sharehashes()) |
---|
12979 | - d.addCallback(lambda sharehashes: |
---|
12980 | - self.failUnlessEqual(self.share_hash_chain, sharehashes)) |
---|
12981 | + d2.addCallback(lambda ign: mr.get_blockhashes()) |
---|
12982 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.block_hash_tree)) |
---|
12983 | |
---|
12984 | hunk ./src/allmydata/test/test_storage.py 2017 |
---|
12985 | - d.addCallback(lambda ignored: |
---|
12986 | - mr.get_signature()) |
---|
12987 | - d.addCallback(lambda signature: |
---|
12988 | - self.failUnlessEqual(signature, self.signature)) |
---|
12989 | + d2.addCallback(lambda ign: mr.get_sharehashes()) |
---|
12990 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.share_hash_chain)) |
---|
12991 | |
---|
12992 | hunk ./src/allmydata/test/test_storage.py 2020 |
---|
12993 | - d.addCallback(lambda ignored: |
---|
12994 | - mr.get_verification_key()) |
---|
12995 | - d.addCallback(lambda verification_key: |
---|
12996 | - self.failUnlessEqual(verification_key, self.verification_key)) |
---|
12997 | + d2.addCallback(lambda ign: mr.get_signature()) |
---|
12998 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.signature)) |
---|
12999 | |
---|
13000 | hunk ./src/allmydata/test/test_storage.py 2023 |
---|
13001 | - d.addCallback(lambda ignored: |
---|
13002 | - mr.get_seqnum()) |
---|
13003 | - d.addCallback(lambda seqnum: |
---|
13004 | - self.failUnlessEqual(seqnum, 0)) |
---|
13005 | + d2.addCallback(lambda ign: mr.get_verification_key()) |
---|
13006 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.verification_key)) |
---|
13007 | |
---|
13008 | hunk ./src/allmydata/test/test_storage.py 2026 |
---|
13009 | - d.addCallback(lambda ignored: |
---|
13010 | - mr.get_root_hash()) |
---|
13011 | - d.addCallback(lambda root_hash: |
---|
13012 | - self.failUnlessEqual(self.root_hash, root_hash)) |
---|
13013 | + d2.addCallback(lambda ign: mr.get_seqnum()) |
---|
13014 | + d2.addCallback(lambda seqnum: self.failUnlessEqual(seqnum, 0)) |
---|
13015 | |
---|
13016 | hunk ./src/allmydata/test/test_storage.py 2029 |
---|
13017 | - d.addCallback(lambda ignored: |
---|
13018 | - mr.get_seqnum()) |
---|
13019 | - d.addCallback(lambda seqnum: |
---|
13020 | - self.failUnlessEqual(0, seqnum)) |
---|
13021 | + d2.addCallback(lambda ign: mr.get_root_hash()) |
---|
13022 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.root_hash)) |
---|
13023 | |
---|
13024 | hunk ./src/allmydata/test/test_storage.py 2032 |
---|
13025 | - d.addCallback(lambda ignored: |
---|
13026 | - mr.get_encoding_parameters()) |
---|
13027 | - def _check_encoding_parameters((k, n, segsize, datalen)): |
---|
13028 | - self.failUnlessEqual(k, 3) |
---|
13029 | - self.failUnlessEqual(n, 10) |
---|
13030 | - self.failUnlessEqual(segsize, 6) |
---|
13031 | - self.failUnlessEqual(datalen, 36) |
---|
13032 | - d.addCallback(_check_encoding_parameters) |
---|
13033 | + d2.addCallback(lambda ign: mr.get_encoding_parameters()) |
---|
13034 | + def _check_encoding_parameters((k, n, segsize, datalen)): |
---|
13035 | + self.failUnlessEqual(k, 3) |
---|
13036 | + self.failUnlessEqual(n, 10) |
---|
13037 | + self.failUnlessEqual(segsize, 6) |
---|
13038 | + self.failUnlessEqual(datalen, 36) |
---|
13039 | + d2.addCallback(_check_encoding_parameters) |
---|
13040 | |
---|
13041 | hunk ./src/allmydata/test/test_storage.py 2040 |
---|
13042 | - d.addCallback(lambda ignored: |
---|
13043 | - mr.get_checkstring()) |
---|
13044 | - d.addCallback(lambda checkstring: |
---|
13045 | - self.failUnlessEqual(checkstring, checkstring)) |
---|
13046 | + d2.addCallback(lambda ign: mr.get_checkstring()) |
---|
13047 | + # XXX check against expected value |
---|
13048 | + return d2 |
---|
13049 | + d.addCallback(_written) |
---|
13050 | return d |
---|
13051 | |
---|
13052 | def test_read_with_different_tail_segment_size(self): |
---|
13053 | hunk ./src/allmydata/test/test_storage.py 2047 |
---|
13054 | - self.write_test_share_to_server("si1", tail_segment=True) |
---|
13055 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13056 | - d = mr.get_block_and_salt(5) |
---|
13057 | + d = self.write_test_share_to_server("si1", tail_segment=True) |
---|
13058 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13059 | + d.addCallback(lambda mr: mr.get_block_and_salt(5)) |
---|
13060 | def _check_tail_segment(results): |
---|
13061 | block, salt = results |
---|
13062 | self.failUnlessEqual(len(block), 1) |
---|
13063 | hunk ./src/allmydata/test/test_storage.py 2058 |
---|
13064 | return d |
---|
13065 | |
---|
13066 | def test_get_block_with_invalid_segnum(self): |
---|
13067 | - self.write_test_share_to_server("si1") |
---|
13068 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13069 | - d = defer.succeed(None) |
---|
13070 | - d.addCallback(lambda ignored: |
---|
13071 | + d = self.write_test_share_to_server("si1") |
---|
13072 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13073 | + d.addCallback(lambda mr: |
---|
13074 | self.shouldFail(LayoutInvalid, "test invalid segnum", |
---|
13075 | None, |
---|
13076 | hunk ./src/allmydata/test/test_storage.py 2063 |
---|
13077 | - mr.get_block_and_salt, 7)) |
---|
13078 | + lambda: mr.get_block_and_salt(7) )) |
---|
13079 | return d |
---|
13080 | |
---|
13081 | def test_get_encoding_parameters_first(self): |
---|
13082 | hunk ./src/allmydata/test/test_storage.py 2067 |
---|
13083 | - self.write_test_share_to_server("si1") |
---|
13084 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13085 | - d = mr.get_encoding_parameters() |
---|
13086 | + d = self.write_test_share_to_server("si1") |
---|
13087 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13088 | + d.addCallback(lambda mr: mr.get_encoding_parameters()) |
---|
13089 | def _check_encoding_parameters((k, n, segment_size, datalen)): |
---|
13090 | self.failUnlessEqual(k, 3) |
---|
13091 | self.failUnlessEqual(n, 10) |
---|
13092 | hunk ./src/allmydata/test/test_storage.py 2079 |
---|
13093 | return d |
---|
13094 | |
---|
13095 | def test_get_seqnum_first(self): |
---|
13096 | - self.write_test_share_to_server("si1") |
---|
13097 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13098 | - d = mr.get_seqnum() |
---|
13099 | + d = self.write_test_share_to_server("si1") |
---|
13100 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13101 | + d.addCallback(lambda mr: mr.get_seqnum()) |
---|
13102 | d.addCallback(lambda seqnum: |
---|
13103 | self.failUnlessEqual(seqnum, 0)) |
---|
13104 | return d |
---|
13105 | hunk ./src/allmydata/test/test_storage.py 2087 |
---|
13106 | |
---|
13107 | def test_get_root_hash_first(self): |
---|
13108 | - self.write_test_share_to_server("si1") |
---|
13109 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13110 | - d = mr.get_root_hash() |
---|
13111 | + d = self.write_test_share_to_server("si1") |
---|
13112 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13113 | + d.addCallback(lambda mr: mr.get_root_hash()) |
---|
13114 | d.addCallback(lambda root_hash: |
---|
13115 | self.failUnlessEqual(root_hash, self.root_hash)) |
---|
13116 | return d |
---|
13117 | hunk ./src/allmydata/test/test_storage.py 2095 |
---|
13118 | |
---|
13119 | def test_get_checkstring_first(self): |
---|
13120 | - self.write_test_share_to_server("si1") |
---|
13121 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13122 | - d = mr.get_checkstring() |
---|
13123 | + d = self.write_test_share_to_server("si1") |
---|
13124 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13125 | + d.addCallback(lambda mr: mr.get_checkstring()) |
---|
13126 | d.addCallback(lambda checkstring: |
---|
13127 | self.failUnlessEqual(checkstring, self.checkstring)) |
---|
13128 | return d |
---|
13129 | hunk ./src/allmydata/test/test_storage.py 2145 |
---|
13130 | mw = self._make_new_mw("si1", 0) |
---|
13131 | d = defer.succeed(None) |
---|
13132 | for i in xrange(6): |
---|
13133 | - d.addCallback(lambda ignored, i=i: |
---|
13134 | - mw.put_block(self.block, i, self.salt)) |
---|
13135 | - d.addCallback(lambda ignored: |
---|
13136 | - mw.put_encprivkey(self.encprivkey)) |
---|
13137 | - d.addCallback(lambda ignored: |
---|
13138 | - mw.put_sharehashes(self.share_hash_chain)) |
---|
13139 | + d.addCallback(lambda ign, i=i: |
---|
13140 | + mw.put_block(self.block, i, self.salt)) |
---|
13141 | + d.addCallback(lambda ign: mw.put_encprivkey(self.encprivkey)) |
---|
13142 | + d.addCallback(lambda ign: mw.put_sharehashes(self.share_hash_chain)) |
---|
13143 | |
---|
13144 | # Now try to put the private key again. |
---|
13145 | d.addCallback(lambda ignored: |
---|
13146 | hunk ./src/allmydata/test/test_storage.py 2154 |
---|
13147 | self.shouldFail(LayoutInvalid, "test repeat private key", |
---|
13148 | None, |
---|
13149 | - mw.put_encprivkey, self.encprivkey)) |
---|
13150 | + lambda: mw.put_encprivkey(self.encprivkey) )) |
---|
13151 | return d |
---|
13152 | |
---|
13153 | def test_signature_after_verification_key(self): |
---|
13154 | hunk ./src/allmydata/test/test_storage.py 2162 |
---|
13155 | d = defer.succeed(None) |
---|
13156 | # Put everything up to and including the verification key. |
---|
13157 | for i in xrange(6): |
---|
13158 | - d.addCallback(lambda ignored, i=i: |
---|
13159 | - mw.put_block(self.block, i, self.salt)) |
---|
13160 | - d.addCallback(lambda ignored: |
---|
13161 | - mw.put_encprivkey(self.encprivkey)) |
---|
13162 | - d.addCallback(lambda ignored: |
---|
13163 | - mw.put_blockhashes(self.block_hash_tree)) |
---|
13164 | - d.addCallback(lambda ignored: |
---|
13165 | - mw.put_sharehashes(self.share_hash_chain)) |
---|
13166 | - d.addCallback(lambda ignored: |
---|
13167 | - mw.put_root_hash(self.root_hash)) |
---|
13168 | - d.addCallback(lambda ignored: |
---|
13169 | - mw.put_signature(self.signature)) |
---|
13170 | - d.addCallback(lambda ignored: |
---|
13171 | - mw.put_verification_key(self.verification_key)) |
---|
13172 | + d.addCallback(lambda ign, i=i: |
---|
13173 | + mw.put_block(self.block, i, self.salt)) |
---|
13174 | + d.addCallback(lambda ign: mw.put_encprivkey(self.encprivkey)) |
---|
13175 | + d.addCallback(lambda ign: mw.put_blockhashes(self.block_hash_tree)) |
---|
13176 | + d.addCallback(lambda ign: mw.put_sharehashes(self.share_hash_chain)) |
---|
13177 | + d.addCallback(lambda ign: mw.put_root_hash(self.root_hash)) |
---|
13178 | + d.addCallback(lambda ign: mw.put_signature(self.signature)) |
---|
13179 | + d.addCallback(lambda ign: mw.put_verification_key(self.verification_key)) |
---|
13180 | # Now try to put the signature again. This should fail |
---|
13181 | d.addCallback(lambda ignored: |
---|
13182 | self.shouldFail(LayoutInvalid, "signature after verification", |
---|
13183 | hunk ./src/allmydata/test/test_storage.py 2174 |
---|
13184 | None, |
---|
13185 | - mw.put_signature, self.signature)) |
---|
13186 | + lambda: mw.put_signature(self.signature) )) |
---|
13187 | return d |
---|
13188 | |
---|
13189 | def test_uncoordinated_write(self): |
---|
13190 | hunk ./src/allmydata/test/test_storage.py 2219 |
---|
13191 | d.addCallback(lambda ignored: |
---|
13192 | self.shouldFail(LayoutInvalid, "salt too big", |
---|
13193 | None, |
---|
13194 | - mw.put_block, self.block, 0, invalid_salt)) |
---|
13195 | + lambda: mw.put_block(self.block, 0, invalid_salt) )) |
---|
13196 | d.addCallback(lambda ignored: |
---|
13197 | self.shouldFail(LayoutInvalid, "salt too small", |
---|
13198 | None, |
---|
13199 | hunk ./src/allmydata/test/test_storage.py 2223 |
---|
13200 | - mw.put_block, self.block, 0, |
---|
13201 | - another_invalid_salt)) |
---|
13202 | + lambda: mw.put_block(self.block, 0, another_invalid_salt) )) |
---|
13203 | return d |
---|
13204 | |
---|
13205 | def test_write_test_vectors(self): |
---|
13206 | hunk ./src/allmydata/test/test_storage.py 2253 |
---|
13207 | |
---|
13208 | d = mw.finish_publishing() |
---|
13209 | d.addCallback(_check_failure) |
---|
13210 | - d.addCallback(lambda ignored: |
---|
13211 | - mw.set_checkstring("")) |
---|
13212 | - d.addCallback(lambda ignored: |
---|
13213 | - mw.finish_publishing()) |
---|
13214 | + d.addCallback(lambda ign: mw.set_checkstring("")) |
---|
13215 | + d.addCallback(lambda ign: mw.finish_publishing()) |
---|
13216 | d.addCallback(_check_success) |
---|
13217 | return d |
---|
13218 | |
---|
13219 | hunk ./src/allmydata/test/test_storage.py 2291 |
---|
13220 | mw.put_verification_key(self.verification_key) |
---|
13221 | |
---|
13222 | d = mw.finish_publishing() |
---|
13223 | - def _check_publish(results): |
---|
13224 | - self.failUnlessEqual(len(results), 2) |
---|
13225 | - result, ign = results |
---|
13226 | - self.failUnless(result, "publish failed") |
---|
13227 | - for i in xrange(6): |
---|
13228 | - self.failUnlessEqual(read("si1", [0], [(expected_sharedata_offset + (i * written_block_size), written_block_size)]), |
---|
13229 | - {0: [written_block]}) |
---|
13230 | + d.addCallback(lambda (result, ign): self.failUnless(result, "publish failed")) |
---|
13231 | + |
---|
13232 | + for i in xrange(6): |
---|
13233 | + d.addCallback(lambda ign, i=i: read("si1", [0], |
---|
13234 | + [(expected_sharedata_offset + (i * written_block_size), |
---|
13235 | + written_block_size)])) |
---|
13236 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [written_block]})) |
---|
13237 | |
---|
13238 | hunk ./src/allmydata/test/test_storage.py 2299 |
---|
13239 | - self.failUnlessEqual(len(self.encprivkey), 7) |
---|
13240 | - self.failUnlessEqual(read("si1", [0], [(expected_private_key_offset, 7)]), |
---|
13241 | - {0: [self.encprivkey]}) |
---|
13242 | + d.addCallback(lambda ign: self.failUnlessEqual(len(self.encprivkey), 7)) |
---|
13243 | + d.addCallback(lambda ign: read("si1", [0], [(expected_private_key_offset, 7)])) |
---|
13244 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.encprivkey]})) |
---|
13245 | |
---|
13246 | hunk ./src/allmydata/test/test_storage.py 2303 |
---|
13247 | - expected_block_hash_offset = expected_sharedata_offset + \ |
---|
13248 | - (6 * written_block_size) |
---|
13249 | - self.failUnlessEqual(len(self.block_hash_tree_s), 32 * 6) |
---|
13250 | - self.failUnlessEqual(read("si1", [0], [(expected_block_hash_offset, 32 * 6)]), |
---|
13251 | - {0: [self.block_hash_tree_s]}) |
---|
13252 | + expected_block_hash_offset = expected_sharedata_offset + (6 * written_block_size) |
---|
13253 | + d.addCallback(lambda ign: self.failUnlessEqual(len(self.block_hash_tree_s), 32 * 6)) |
---|
13254 | + d.addCallback(lambda ign, ebho=expected_block_hash_offset: |
---|
13255 | + read("si1", [0], [(ebho, 32 * 6)])) |
---|
13256 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.block_hash_tree_s]})) |
---|
13257 | |
---|
13258 | expected_share_hash_offset = expected_private_key_offset + len(self.encprivkey) |
---|
13259 | hunk ./src/allmydata/test/test_storage.py 2310 |
---|
13260 | - self.failUnlessEqual(read("si1", [0],[(expected_share_hash_offset, (32 + 2) * 6)]), |
---|
13261 | - {0: [self.share_hash_chain_s]}) |
---|
13262 | + d.addCallback(lambda ign, esho=expected_share_hash_offset: |
---|
13263 | + read("si1", [0], [(esho, (32 + 2) * 6)])) |
---|
13264 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.share_hash_chain_s]})) |
---|
13265 | |
---|
13266 | hunk ./src/allmydata/test/test_storage.py 2314 |
---|
13267 | - self.failUnlessEqual(read("si1", [0], [(9, 32)]), |
---|
13268 | - {0: [self.root_hash]}) |
---|
13269 | - expected_signature_offset = expected_share_hash_offset + \ |
---|
13270 | - len(self.share_hash_chain_s) |
---|
13271 | - self.failUnlessEqual(len(self.signature), 9) |
---|
13272 | - self.failUnlessEqual(read("si1", [0], [(expected_signature_offset, 9)]), |
---|
13273 | - {0: [self.signature]}) |
---|
13274 | + d.addCallback(lambda ign: read("si1", [0], [(9, 32)])) |
---|
13275 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.root_hash]})) |
---|
13276 | + |
---|
13277 | + expected_signature_offset = expected_share_hash_offset + len(self.share_hash_chain_s) |
---|
13278 | + d.addCallback(lambda ign: self.failUnlessEqual(len(self.signature), 9)) |
---|
13279 | + d.addCallback(lambda ign, esigo=expected_signature_offset: |
---|
13280 | + read("si1", [0], [(esigo, 9)])) |
---|
13281 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.signature]})) |
---|
13282 | |
---|
13283 | expected_verification_key_offset = expected_signature_offset + len(self.signature) |
---|
13284 | hunk ./src/allmydata/test/test_storage.py 2324 |
---|
13285 | - self.failUnlessEqual(len(self.verification_key), 6) |
---|
13286 | - self.failUnlessEqual(read("si1", [0], [(expected_verification_key_offset, 6)]), |
---|
13287 | - {0: [self.verification_key]}) |
---|
13288 | + d.addCallback(lambda ign: self.failUnlessEqual(len(self.verification_key), 6)) |
---|
13289 | + d.addCallback(lambda ign, evko=expected_verification_key_offset: |
---|
13290 | + read("si1", [0], [(evko, 6)])) |
---|
13291 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [self.verification_key]})) |
---|
13292 | |
---|
13293 | hunk ./src/allmydata/test/test_storage.py 2329 |
---|
13294 | - signable = mw.get_signable() |
---|
13295 | - verno, seq, roothash, k, n, segsize, datalen = \ |
---|
13296 | - struct.unpack(">BQ32sBBQQ", |
---|
13297 | - signable) |
---|
13298 | - self.failUnlessEqual(verno, 1) |
---|
13299 | - self.failUnlessEqual(seq, 0) |
---|
13300 | - self.failUnlessEqual(roothash, self.root_hash) |
---|
13301 | - self.failUnlessEqual(k, 3) |
---|
13302 | - self.failUnlessEqual(n, 10) |
---|
13303 | - self.failUnlessEqual(segsize, 6) |
---|
13304 | - self.failUnlessEqual(datalen, 36) |
---|
13305 | - expected_eof_offset = expected_block_hash_offset + \ |
---|
13306 | - len(self.block_hash_tree_s) |
---|
13307 | + def _check_other_fields(ign, ebho=expected_block_hash_offset, |
---|
13308 | + esho=expected_share_hash_offset, |
---|
13309 | + esigo=expected_signature_offset, |
---|
13310 | + evko=expected_verification_key_offset): |
---|
13311 | + signable = mw.get_signable() |
---|
13312 | + verno, seq, roothash, k, N, segsize, datalen = struct.unpack(">BQ32sBBQQ", |
---|
13313 | + signable) |
---|
13314 | + self.failUnlessEqual(verno, 1) |
---|
13315 | + self.failUnlessEqual(seq, 0) |
---|
13316 | + self.failUnlessEqual(roothash, self.root_hash) |
---|
13317 | + self.failUnlessEqual(k, 3) |
---|
13318 | + self.failUnlessEqual(N, 10) |
---|
13319 | + self.failUnlessEqual(segsize, 6) |
---|
13320 | + self.failUnlessEqual(datalen, 36) |
---|
13321 | + |
---|
13322 | + def _check_field(res, offset, fmt, which, value): |
---|
13323 | + encoded = struct.pack(fmt, value) |
---|
13324 | + d3 = defer.succeed(None) |
---|
13325 | + d3.addCallback(lambda ign: read("si1", [0], [(offset, len(encoded))])) |
---|
13326 | + d3.addCallback(lambda res: self.failUnlessEqual(res, {0: [encoded]}, which)) |
---|
13327 | + return d3 |
---|
13328 | + |
---|
13329 | + d2 = defer.succeed(None) |
---|
13330 | + d2.addCallback(_check_field, 0, ">B", "version number", verno) |
---|
13331 | + d2.addCallback(_check_field, 1, ">Q", "sequence number", seq) |
---|
13332 | + d2.addCallback(_check_field, 41, ">B", "k", k) |
---|
13333 | + d2.addCallback(_check_field, 42, ">B", "N", N) |
---|
13334 | + d2.addCallback(_check_field, 43, ">Q", "segment size", segsize) |
---|
13335 | + d2.addCallback(_check_field, 51, ">Q", "data length", datalen) |
---|
13336 | + d2.addCallback(_check_field, 59, ">Q", "private key offset", |
---|
13337 | + expected_private_key_offset) |
---|
13338 | + d2.addCallback(_check_field, 67, ">Q", "share hash offset", esho) |
---|
13339 | + d2.addCallback(_check_field, 75, ">Q", "signature offset", esigo) |
---|
13340 | + d2.addCallback(_check_field, 83, ">Q", "verification key offset", evko) |
---|
13341 | + d2.addCallback(_check_field, 91, ">Q", "end of verification key", |
---|
13342 | + evko + len(self.verification_key)) |
---|
13343 | + d2.addCallback(_check_field, 99, ">Q", "sharedata offset", |
---|
13344 | + expected_sharedata_offset) |
---|
13345 | + d2.addCallback(_check_field, 107, ">Q", "block hash offset", ebho) |
---|
13346 | + d2.addCallback(_check_field, 115, ">Q", "eof offset", |
---|
13347 | + ebho + len(self.block_hash_tree_s)) |
---|
13348 | + return d2 |
---|
13349 | + d.addCallback(_check_other_fields) |
---|
13350 | |
---|
13351 | hunk ./src/allmydata/test/test_storage.py 2373 |
---|
13352 | - # Check the version number to make sure that it is correct. |
---|
13353 | - expected_version_number = struct.pack(">B", 1) |
---|
13354 | - self.failUnlessEqual(read("si1", [0], [(0, 1)]), |
---|
13355 | - {0: [expected_version_number]}) |
---|
13356 | - # Check the sequence number to make sure that it is correct |
---|
13357 | - expected_sequence_number = struct.pack(">Q", 0) |
---|
13358 | - self.failUnlessEqual(read("si1", [0], [(1, 8)]), |
---|
13359 | - {0: [expected_sequence_number]}) |
---|
13360 | - # Check that the encoding parameters (k, N, segement size, data |
---|
13361 | - # length) are what they should be. These are 3, 10, 6, 36 |
---|
13362 | - expected_k = struct.pack(">B", 3) |
---|
13363 | - self.failUnlessEqual(read("si1", [0], [(41, 1)]), |
---|
13364 | - {0: [expected_k]}) |
---|
13365 | - expected_n = struct.pack(">B", 10) |
---|
13366 | - self.failUnlessEqual(read("si1", [0], [(42, 1)]), |
---|
13367 | - {0: [expected_n]}) |
---|
13368 | - expected_segment_size = struct.pack(">Q", 6) |
---|
13369 | - self.failUnlessEqual(read("si1", [0], [(43, 8)]), |
---|
13370 | - {0: [expected_segment_size]}) |
---|
13371 | - expected_data_length = struct.pack(">Q", 36) |
---|
13372 | - self.failUnlessEqual(read("si1", [0], [(51, 8)]), |
---|
13373 | - {0: [expected_data_length]}) |
---|
13374 | - expected_offset = struct.pack(">Q", expected_private_key_offset) |
---|
13375 | - self.failUnlessEqual(read("si1", [0], [(59, 8)]), |
---|
13376 | - {0: [expected_offset]}) |
---|
13377 | - expected_offset = struct.pack(">Q", expected_share_hash_offset) |
---|
13378 | - self.failUnlessEqual(read("si1", [0], [(67, 8)]), |
---|
13379 | - {0: [expected_offset]}) |
---|
13380 | - expected_offset = struct.pack(">Q", expected_signature_offset) |
---|
13381 | - self.failUnlessEqual(read("si1", [0], [(75, 8)]), |
---|
13382 | - {0: [expected_offset]}) |
---|
13383 | - expected_offset = struct.pack(">Q", expected_verification_key_offset) |
---|
13384 | - self.failUnlessEqual(read("si1", [0], [(83, 8)]), |
---|
13385 | - {0: [expected_offset]}) |
---|
13386 | - expected_offset = struct.pack(">Q", expected_verification_key_offset + len(self.verification_key)) |
---|
13387 | - self.failUnlessEqual(read("si1", [0], [(91, 8)]), |
---|
13388 | - {0: [expected_offset]}) |
---|
13389 | - expected_offset = struct.pack(">Q", expected_sharedata_offset) |
---|
13390 | - self.failUnlessEqual(read("si1", [0], [(99, 8)]), |
---|
13391 | - {0: [expected_offset]}) |
---|
13392 | - expected_offset = struct.pack(">Q", expected_block_hash_offset) |
---|
13393 | - self.failUnlessEqual(read("si1", [0], [(107, 8)]), |
---|
13394 | - {0: [expected_offset]}) |
---|
13395 | - expected_offset = struct.pack(">Q", expected_eof_offset) |
---|
13396 | - self.failUnlessEqual(read("si1", [0], [(115, 8)]), |
---|
13397 | - {0: [expected_offset]}) |
---|
13398 | - d.addCallback(_check_publish) |
---|
13399 | return d |
---|
13400 | |
---|
13401 | def _make_new_mw(self, si, share, datalength=36): |
---|
13402 | hunk ./src/allmydata/test/test_storage.py 2391 |
---|
13403 | # more than 6 blocks into each share. |
---|
13404 | d = defer.succeed(None) |
---|
13405 | for i in xrange(6): |
---|
13406 | - d.addCallback(lambda ignored, i=i: |
---|
13407 | - mw.put_block(self.block, i, self.salt)) |
---|
13408 | + d.addCallback(lambda ign, i=i: |
---|
13409 | + mw.put_block(self.block, i, self.salt)) |
---|
13410 | d.addCallback(lambda ignored: |
---|
13411 | self.shouldFail(LayoutInvalid, "too many blocks", |
---|
13412 | None, |
---|
13413 | hunk ./src/allmydata/test/test_storage.py 2396 |
---|
13414 | - mw.put_block, self.block, 7, self.salt)) |
---|
13415 | + lambda: mw.put_block(self.block, 7, self.salt) )) |
---|
13416 | return d |
---|
13417 | |
---|
13418 | def test_write_rejected_with_invalid_salt(self): |
---|
13419 | hunk ./src/allmydata/test/test_storage.py 2407 |
---|
13420 | d = defer.succeed(None) |
---|
13421 | d.addCallback(lambda ignored: |
---|
13422 | self.shouldFail(LayoutInvalid, "test_invalid_salt", |
---|
13423 | - None, mw.put_block, self.block, 7, bad_salt)) |
---|
13424 | + None, |
---|
13425 | + lambda: mw.put_block(self.block, 7, bad_salt) )) |
---|
13426 | return d |
---|
13427 | |
---|
13428 | def test_write_rejected_with_invalid_root_hash(self): |
---|
13429 | hunk ./src/allmydata/test/test_storage.py 2423 |
---|
13430 | # failures that match what we are looking for, but are caused by |
---|
13431 | # the constraints imposed on operation ordering. |
---|
13432 | for i in xrange(6): |
---|
13433 | - d.addCallback(lambda ignored, i=i: |
---|
13434 | - mw.put_block(self.block, i, self.salt)) |
---|
13435 | - d.addCallback(lambda ignored: |
---|
13436 | - mw.put_encprivkey(self.encprivkey)) |
---|
13437 | - d.addCallback(lambda ignored: |
---|
13438 | - mw.put_blockhashes(self.block_hash_tree)) |
---|
13439 | - d.addCallback(lambda ignored: |
---|
13440 | - mw.put_sharehashes(self.share_hash_chain)) |
---|
13441 | + d.addCallback(lambda ign, i=i: |
---|
13442 | + mw.put_block(self.block, i, self.salt)) |
---|
13443 | + d.addCallback(lambda ign: mw.put_encprivkey(self.encprivkey)) |
---|
13444 | + d.addCallback(lambda ign: mw.put_blockhashes(self.block_hash_tree)) |
---|
13445 | + d.addCallback(lambda ign: mw.put_sharehashes(self.share_hash_chain)) |
---|
13446 | d.addCallback(lambda ignored: |
---|
13447 | self.shouldFail(LayoutInvalid, "invalid root hash", |
---|
13448 | hunk ./src/allmydata/test/test_storage.py 2430 |
---|
13449 | - None, mw.put_root_hash, invalid_root_hash)) |
---|
13450 | + None, |
---|
13451 | + lambda: mw.put_root_hash(invalid_root_hash) )) |
---|
13452 | return d |
---|
13453 | |
---|
13454 | def test_write_rejected_with_invalid_blocksize(self): |
---|
13455 | hunk ./src/allmydata/test/test_storage.py 2446 |
---|
13456 | d = defer.succeed(None) |
---|
13457 | d.addCallback(lambda ignored, invalid_block=invalid_block: |
---|
13458 | self.shouldFail(LayoutInvalid, "test blocksize too small", |
---|
13459 | - None, mw.put_block, invalid_block, 0, |
---|
13460 | - self.salt)) |
---|
13461 | + None, |
---|
13462 | + lambda: mw.put_block(invalid_block, 0, self.salt) )) |
---|
13463 | invalid_block = invalid_block * 3 |
---|
13464 | # 3 bytes != 2 bytes |
---|
13465 | d.addCallback(lambda ignored: |
---|
13466 | hunk ./src/allmydata/test/test_storage.py 2453 |
---|
13467 | self.shouldFail(LayoutInvalid, "test blocksize too large", |
---|
13468 | None, |
---|
13469 | - mw.put_block, invalid_block, 0, self.salt)) |
---|
13470 | + lambda: mw.put_block(invalid_block, 0, self.salt) )) |
---|
13471 | for i in xrange(5): |
---|
13472 | hunk ./src/allmydata/test/test_storage.py 2455 |
---|
13473 | - d.addCallback(lambda ignored, i=i: |
---|
13474 | - mw.put_block(self.block, i, self.salt)) |
---|
13475 | + d.addCallback(lambda ign, i=i: |
---|
13476 | + mw.put_block(self.block, i, self.salt)) |
---|
13477 | # Try to put an invalid tail segment |
---|
13478 | d.addCallback(lambda ignored: |
---|
13479 | self.shouldFail(LayoutInvalid, "test invalid tail segment", |
---|
13480 | hunk ./src/allmydata/test/test_storage.py 2461 |
---|
13481 | None, |
---|
13482 | - mw.put_block, self.block, 5, self.salt)) |
---|
13483 | + lambda: mw.put_block(self.block, 5, self.salt) )) |
---|
13484 | valid_block = "a" |
---|
13485 | hunk ./src/allmydata/test/test_storage.py 2463 |
---|
13486 | - d.addCallback(lambda ignored: |
---|
13487 | - mw.put_block(valid_block, 5, self.salt)) |
---|
13488 | + d.addCallback(lambda ign: mw.put_block(valid_block, 5, self.salt)) |
---|
13489 | return d |
---|
13490 | |
---|
13491 | def test_write_enforces_order_constraints(self): |
---|
13492 | hunk ./src/allmydata/test/test_storage.py 2489 |
---|
13493 | # Write some shares |
---|
13494 | d = defer.succeed(None) |
---|
13495 | for i in xrange(6): |
---|
13496 | - d.addCallback(lambda ignored, i=i: |
---|
13497 | - mw0.put_block(self.block, i, self.salt)) |
---|
13498 | + d.addCallback(lambda ign, i=i: |
---|
13499 | + mw0.put_block(self.block, i, self.salt)) |
---|
13500 | |
---|
13501 | # Try to write the share hash chain without writing the |
---|
13502 | # encrypted private key |
---|
13503 | hunk ./src/allmydata/test/test_storage.py 2498 |
---|
13504 | self.shouldFail(LayoutInvalid, "share hash chain before " |
---|
13505 | "private key", |
---|
13506 | None, |
---|
13507 | - mw0.put_sharehashes, self.share_hash_chain)) |
---|
13508 | + lambda: mw0.put_sharehashes(self.share_hash_chain) )) |
---|
13509 | + |
---|
13510 | # Write the private key. |
---|
13511 | hunk ./src/allmydata/test/test_storage.py 2501 |
---|
13512 | - d.addCallback(lambda ignored: |
---|
13513 | - mw0.put_encprivkey(self.encprivkey)) |
---|
13514 | + d.addCallback(lambda ign: mw0.put_encprivkey(self.encprivkey)) |
---|
13515 | |
---|
13516 | # Now write the block hashes and try again |
---|
13517 | d.addCallback(lambda ignored: |
---|
13518 | hunk ./src/allmydata/test/test_storage.py 2511 |
---|
13519 | # be able to sign it. |
---|
13520 | d.addCallback(lambda ignored: |
---|
13521 | self.shouldFail(LayoutInvalid, "signature before root hash", |
---|
13522 | - None, mw0.put_signature, self.signature)) |
---|
13523 | + None, |
---|
13524 | + lambda: mw0.put_signature(self.signature) )) |
---|
13525 | |
---|
13526 | d.addCallback(lambda ignored: |
---|
13527 | self.failUnlessRaises(LayoutInvalid, mw0.get_signable)) |
---|
13528 | hunk ./src/allmydata/test/test_storage.py 2521 |
---|
13529 | # verification key. |
---|
13530 | d.addCallback(lambda ignored: |
---|
13531 | self.shouldFail(LayoutInvalid, "key before signature", |
---|
13532 | - None, mw0.put_verification_key, |
---|
13533 | - self.verification_key)) |
---|
13534 | + None, |
---|
13535 | + lambda: mw0.put_verification_key(self.verification_key) )) |
---|
13536 | |
---|
13537 | # Now write the share hashes. |
---|
13538 | hunk ./src/allmydata/test/test_storage.py 2525 |
---|
13539 | - d.addCallback(lambda ignored: |
---|
13540 | - mw0.put_sharehashes(self.share_hash_chain)) |
---|
13541 | + d.addCallback(lambda ign: mw0.put_sharehashes(self.share_hash_chain)) |
---|
13542 | + |
---|
13543 | # We should be able to write the root hash now too |
---|
13544 | hunk ./src/allmydata/test/test_storage.py 2528 |
---|
13545 | - d.addCallback(lambda ignored: |
---|
13546 | - mw0.put_root_hash(self.root_hash)) |
---|
13547 | + d.addCallback(lambda ign: mw0.put_root_hash(self.root_hash)) |
---|
13548 | |
---|
13549 | # We should still be unable to put the verification key |
---|
13550 | d.addCallback(lambda ignored: |
---|
13551 | hunk ./src/allmydata/test/test_storage.py 2533 |
---|
13552 | self.shouldFail(LayoutInvalid, "key before signature", |
---|
13553 | - None, mw0.put_verification_key, |
---|
13554 | - self.verification_key)) |
---|
13555 | + None, |
---|
13556 | + lambda: mw0.put_verification_key(self.verification_key) )) |
---|
13557 | |
---|
13558 | hunk ./src/allmydata/test/test_storage.py 2536 |
---|
13559 | - d.addCallback(lambda ignored: |
---|
13560 | - mw0.put_signature(self.signature)) |
---|
13561 | + d.addCallback(lambda ign: mw0.put_signature(self.signature)) |
---|
13562 | |
---|
13563 | # We shouldn't be able to write the offsets to the remote server |
---|
13564 | # until the offset table is finished; IOW, until we have written |
---|
13565 | hunk ./src/allmydata/test/test_storage.py 2556 |
---|
13566 | # reader knows how to read everything back to us. |
---|
13567 | d = defer.succeed(None) |
---|
13568 | for i in xrange(6): |
---|
13569 | - d.addCallback(lambda ignored, i=i: |
---|
13570 | - mw.put_block(self.block, i, self.salt)) |
---|
13571 | - d.addCallback(lambda ignored: |
---|
13572 | - mw.put_encprivkey(self.encprivkey)) |
---|
13573 | - d.addCallback(lambda ignored: |
---|
13574 | - mw.put_blockhashes(self.block_hash_tree)) |
---|
13575 | - d.addCallback(lambda ignored: |
---|
13576 | - mw.put_sharehashes(self.share_hash_chain)) |
---|
13577 | - d.addCallback(lambda ignored: |
---|
13578 | - mw.put_root_hash(self.root_hash)) |
---|
13579 | - d.addCallback(lambda ignored: |
---|
13580 | - mw.put_signature(self.signature)) |
---|
13581 | - d.addCallback(lambda ignored: |
---|
13582 | - mw.put_verification_key(self.verification_key)) |
---|
13583 | - d.addCallback(lambda ignored: |
---|
13584 | - mw.finish_publishing()) |
---|
13585 | + d.addCallback(lambda ign, i=i: |
---|
13586 | + mw.put_block(self.block, i, self.salt)) |
---|
13587 | + d.addCallback(lambda ign: mw.put_encprivkey(self.encprivkey)) |
---|
13588 | + d.addCallback(lambda ign: mw.put_blockhashes(self.block_hash_tree)) |
---|
13589 | + d.addCallback(lambda ign: mw.put_sharehashes(self.share_hash_chain)) |
---|
13590 | + d.addCallback(lambda ign: mw.put_root_hash(self.root_hash)) |
---|
13591 | + d.addCallback(lambda ign: mw.put_signature(self.signature)) |
---|
13592 | + d.addCallback(lambda ign: mw.put_verification_key(self.verification_key)) |
---|
13593 | + d.addCallback(lambda ign: mw.finish_publishing()) |
---|
13594 | |
---|
13595 | hunk ./src/allmydata/test/test_storage.py 2566 |
---|
13596 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13597 | - def _check_block_and_salt((block, salt)): |
---|
13598 | - self.failUnlessEqual(block, self.block) |
---|
13599 | - self.failUnlessEqual(salt, self.salt) |
---|
13600 | + def _published(ign): |
---|
13601 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13602 | + def _check_block_and_salt((block, salt)): |
---|
13603 | + self.failUnlessEqual(block, self.block) |
---|
13604 | + self.failUnlessEqual(salt, self.salt) |
---|
13605 | |
---|
13606 | hunk ./src/allmydata/test/test_storage.py 2572 |
---|
13607 | - for i in xrange(6): |
---|
13608 | - d.addCallback(lambda ignored, i=i: |
---|
13609 | - mr.get_block_and_salt(i)) |
---|
13610 | - d.addCallback(_check_block_and_salt) |
---|
13611 | + d2 = defer.succeed(None) |
---|
13612 | + for i in xrange(6): |
---|
13613 | + d2.addCallback(lambda ign, i=i: |
---|
13614 | + mr.get_block_and_salt(i)) |
---|
13615 | + d2.addCallback(_check_block_and_salt) |
---|
13616 | |
---|
13617 | hunk ./src/allmydata/test/test_storage.py 2578 |
---|
13618 | - d.addCallback(lambda ignored: |
---|
13619 | - mr.get_encprivkey()) |
---|
13620 | - d.addCallback(lambda encprivkey: |
---|
13621 | - self.failUnlessEqual(self.encprivkey, encprivkey)) |
---|
13622 | + d2.addCallback(lambda ign: mr.get_encprivkey()) |
---|
13623 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.encprivkey)) |
---|
13624 | |
---|
13625 | hunk ./src/allmydata/test/test_storage.py 2581 |
---|
13626 | - d.addCallback(lambda ignored: |
---|
13627 | - mr.get_blockhashes()) |
---|
13628 | - d.addCallback(lambda blockhashes: |
---|
13629 | - self.failUnlessEqual(self.block_hash_tree, blockhashes)) |
---|
13630 | + d2.addCallback(lambda ign: mr.get_blockhashes()) |
---|
13631 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.block_hash_tree)) |
---|
13632 | |
---|
13633 | hunk ./src/allmydata/test/test_storage.py 2584 |
---|
13634 | - d.addCallback(lambda ignored: |
---|
13635 | - mr.get_sharehashes()) |
---|
13636 | - d.addCallback(lambda sharehashes: |
---|
13637 | - self.failUnlessEqual(self.share_hash_chain, sharehashes)) |
---|
13638 | + d2.addCallback(lambda ign: mr.get_sharehashes()) |
---|
13639 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.share_hash_chain)) |
---|
13640 | |
---|
13641 | hunk ./src/allmydata/test/test_storage.py 2587 |
---|
13642 | - d.addCallback(lambda ignored: |
---|
13643 | - mr.get_signature()) |
---|
13644 | - d.addCallback(lambda signature: |
---|
13645 | - self.failUnlessEqual(signature, self.signature)) |
---|
13646 | + d2.addCallback(lambda ign: mr.get_signature()) |
---|
13647 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.signature)) |
---|
13648 | |
---|
13649 | hunk ./src/allmydata/test/test_storage.py 2590 |
---|
13650 | - d.addCallback(lambda ignored: |
---|
13651 | - mr.get_verification_key()) |
---|
13652 | - d.addCallback(lambda verification_key: |
---|
13653 | - self.failUnlessEqual(verification_key, self.verification_key)) |
---|
13654 | + d2.addCallback(lambda ign: mr.get_verification_key()) |
---|
13655 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.verification_key)) |
---|
13656 | |
---|
13657 | hunk ./src/allmydata/test/test_storage.py 2593 |
---|
13658 | - d.addCallback(lambda ignored: |
---|
13659 | - mr.get_seqnum()) |
---|
13660 | - d.addCallback(lambda seqnum: |
---|
13661 | - self.failUnlessEqual(seqnum, 0)) |
---|
13662 | + d2.addCallback(lambda ign: mr.get_seqnum()) |
---|
13663 | + d2.addCallback(lambda seqnum: self.failUnlessEqual(seqnum, 0)) |
---|
13664 | |
---|
13665 | hunk ./src/allmydata/test/test_storage.py 2596 |
---|
13666 | - d.addCallback(lambda ignored: |
---|
13667 | - mr.get_root_hash()) |
---|
13668 | - d.addCallback(lambda root_hash: |
---|
13669 | - self.failUnlessEqual(self.root_hash, root_hash)) |
---|
13670 | + d2.addCallback(lambda ign: mr.get_root_hash()) |
---|
13671 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.root_hash)) |
---|
13672 | |
---|
13673 | hunk ./src/allmydata/test/test_storage.py 2599 |
---|
13674 | - d.addCallback(lambda ignored: |
---|
13675 | - mr.get_encoding_parameters()) |
---|
13676 | - def _check_encoding_parameters((k, n, segsize, datalen)): |
---|
13677 | - self.failUnlessEqual(k, 3) |
---|
13678 | - self.failUnlessEqual(n, 10) |
---|
13679 | - self.failUnlessEqual(segsize, 6) |
---|
13680 | - self.failUnlessEqual(datalen, 36) |
---|
13681 | - d.addCallback(_check_encoding_parameters) |
---|
13682 | + d2.addCallback(lambda ign: mr.get_encoding_parameters()) |
---|
13683 | + def _check_encoding_parameters((k, n, segsize, datalen)): |
---|
13684 | + self.failUnlessEqual(k, 3) |
---|
13685 | + self.failUnlessEqual(n, 10) |
---|
13686 | + self.failUnlessEqual(segsize, 6) |
---|
13687 | + self.failUnlessEqual(datalen, 36) |
---|
13688 | + d2.addCallback(_check_encoding_parameters) |
---|
13689 | |
---|
13690 | hunk ./src/allmydata/test/test_storage.py 2607 |
---|
13691 | - d.addCallback(lambda ignored: |
---|
13692 | - mr.get_checkstring()) |
---|
13693 | - d.addCallback(lambda checkstring: |
---|
13694 | - self.failUnlessEqual(checkstring, mw.get_checkstring())) |
---|
13695 | + d2.addCallback(lambda ign: mr.get_checkstring()) |
---|
13696 | + d2.addCallback(lambda res: self.failUnlessEqual(res, mw.get_checkstring())) |
---|
13697 | + return d2 |
---|
13698 | + d.addCallback(_published) |
---|
13699 | return d |
---|
13700 | |
---|
13701 | def test_is_sdmf(self): |
---|
13702 | hunk ./src/allmydata/test/test_storage.py 2617 |
---|
13703 | # The MDMFSlotReadProxy should also know how to read SDMF files, |
---|
13704 | # since it will encounter them on the grid. Callers use the |
---|
13705 | # is_sdmf method to test this. |
---|
13706 | - self.write_sdmf_share_to_server("si1") |
---|
13707 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13708 | - d = mr.is_sdmf() |
---|
13709 | - d.addCallback(lambda issdmf: |
---|
13710 | - self.failUnless(issdmf)) |
---|
13711 | + d = self.write_sdmf_share_to_server("si1") |
---|
13712 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
13713 | + d.addCallback(lambda mr: mr.is_sdmf()) |
---|
13714 | + d.addCallback(lambda issdmf: self.failUnless(issdmf)) |
---|
13715 | return d |
---|
13716 | |
---|
13717 | def test_reads_sdmf(self): |
---|
13718 | hunk ./src/allmydata/test/test_storage.py 2626 |
---|
13719 | # The slot read proxy should, naturally, know how to tell us |
---|
13720 | # about data in the SDMF format |
---|
13721 | - self.write_sdmf_share_to_server("si1") |
---|
13722 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13723 | - d = defer.succeed(None) |
---|
13724 | - d.addCallback(lambda ignored: |
---|
13725 | - mr.is_sdmf()) |
---|
13726 | - d.addCallback(lambda issdmf: |
---|
13727 | - self.failUnless(issdmf)) |
---|
13728 | + d = self.write_sdmf_share_to_server("si1") |
---|
13729 | + def _written(ign): |
---|
13730 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13731 | + d2 = defer.succeed(None) |
---|
13732 | + d2.addCallback(lambda ign: mr.is_sdmf()) |
---|
13733 | + d2.addCallback(lambda issdmf: self.failUnless(issdmf)) |
---|
13734 | |
---|
13735 | hunk ./src/allmydata/test/test_storage.py 2633 |
---|
13736 | - # What do we need to read? |
---|
13737 | - # - The sharedata |
---|
13738 | - # - The salt |
---|
13739 | - d.addCallback(lambda ignored: |
---|
13740 | - mr.get_block_and_salt(0)) |
---|
13741 | - def _check_block_and_salt(results): |
---|
13742 | - block, salt = results |
---|
13743 | - # Our original file is 36 bytes long. Then each share is 12 |
---|
13744 | - # bytes in size. The share is composed entirely of the |
---|
13745 | - # letter a. self.block contains 2 as, so 6 * self.block is |
---|
13746 | - # what we are looking for. |
---|
13747 | - self.failUnlessEqual(block, self.block * 6) |
---|
13748 | - self.failUnlessEqual(salt, self.salt) |
---|
13749 | - d.addCallback(_check_block_and_salt) |
---|
13750 | + # What do we need to read? |
---|
13751 | + # - The sharedata |
---|
13752 | + # - The salt |
---|
13753 | + d2.addCallback(lambda ign: mr.get_block_and_salt(0)) |
---|
13754 | + def _check_block_and_salt(results): |
---|
13755 | + block, salt = results |
---|
13756 | + # Our original file is 36 bytes long. Then each share is 12 |
---|
13757 | + # bytes in size. The share is composed entirely of the |
---|
13758 | + # letter a. self.block contains 2 as, so 6 * self.block is |
---|
13759 | + # what we are looking for. |
---|
13760 | + self.failUnlessEqual(block, self.block * 6) |
---|
13761 | + self.failUnlessEqual(salt, self.salt) |
---|
13762 | + d2.addCallback(_check_block_and_salt) |
---|
13763 | |
---|
13764 | hunk ./src/allmydata/test/test_storage.py 2647 |
---|
13765 | - # - The blockhashes |
---|
13766 | - d.addCallback(lambda ignored: |
---|
13767 | - mr.get_blockhashes()) |
---|
13768 | - d.addCallback(lambda blockhashes: |
---|
13769 | - self.failUnlessEqual(self.block_hash_tree, |
---|
13770 | - blockhashes, |
---|
13771 | - blockhashes)) |
---|
13772 | - # - The sharehashes |
---|
13773 | - d.addCallback(lambda ignored: |
---|
13774 | - mr.get_sharehashes()) |
---|
13775 | - d.addCallback(lambda sharehashes: |
---|
13776 | - self.failUnlessEqual(self.share_hash_chain, |
---|
13777 | - sharehashes)) |
---|
13778 | - # - The keys |
---|
13779 | - d.addCallback(lambda ignored: |
---|
13780 | - mr.get_encprivkey()) |
---|
13781 | - d.addCallback(lambda encprivkey: |
---|
13782 | - self.failUnlessEqual(encprivkey, self.encprivkey, encprivkey)) |
---|
13783 | - d.addCallback(lambda ignored: |
---|
13784 | - mr.get_verification_key()) |
---|
13785 | - d.addCallback(lambda verification_key: |
---|
13786 | - self.failUnlessEqual(verification_key, |
---|
13787 | - self.verification_key, |
---|
13788 | - verification_key)) |
---|
13789 | - # - The signature |
---|
13790 | - d.addCallback(lambda ignored: |
---|
13791 | - mr.get_signature()) |
---|
13792 | - d.addCallback(lambda signature: |
---|
13793 | - self.failUnlessEqual(signature, self.signature, signature)) |
---|
13794 | + # - The blockhashes |
---|
13795 | + d2.addCallback(lambda ign: mr.get_blockhashes()) |
---|
13796 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.block_hash_tree)) |
---|
13797 | |
---|
13798 | hunk ./src/allmydata/test/test_storage.py 2651 |
---|
13799 | - # - The sequence number |
---|
13800 | - d.addCallback(lambda ignored: |
---|
13801 | - mr.get_seqnum()) |
---|
13802 | - d.addCallback(lambda seqnum: |
---|
13803 | - self.failUnlessEqual(seqnum, 0, seqnum)) |
---|
13804 | + # - The sharehashes |
---|
13805 | + d2.addCallback(lambda ign: mr.get_sharehashes()) |
---|
13806 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.share_hash_chain)) |
---|
13807 | |
---|
13808 | hunk ./src/allmydata/test/test_storage.py 2655 |
---|
13809 | - # - The root hash |
---|
13810 | - d.addCallback(lambda ignored: |
---|
13811 | - mr.get_root_hash()) |
---|
13812 | - d.addCallback(lambda root_hash: |
---|
13813 | - self.failUnlessEqual(root_hash, self.root_hash, root_hash)) |
---|
13814 | - return d |
---|
13815 | + # - The keys |
---|
13816 | + d2.addCallback(lambda ign: mr.get_encprivkey()) |
---|
13817 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.encprivkey)) |
---|
13818 | + d2.addCallback(lambda ign: mr.get_verification_key()) |
---|
13819 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.verification_key)) |
---|
13820 | + |
---|
13821 | + # - The signature |
---|
13822 | + d2.addCallback(lambda ign: mr.get_signature()) |
---|
13823 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.signature)) |
---|
13824 | |
---|
13825 | hunk ./src/allmydata/test/test_storage.py 2665 |
---|
13826 | + # - The sequence number |
---|
13827 | + d2.addCallback(lambda ign: mr.get_seqnum()) |
---|
13828 | + d2.addCallback(lambda seqnum: self.failUnlessEqual(seqnum, 0)) |
---|
13829 | + |
---|
13830 | + # - The root hash |
---|
13831 | + d2.addCallback(lambda ign: mr.get_root_hash()) |
---|
13832 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self.root_hash)) |
---|
13833 | + return d2 |
---|
13834 | + d.addCallback(_written) |
---|
13835 | + return d |
---|
13836 | |
---|
13837 | def test_only_reads_one_segment_sdmf(self): |
---|
13838 | # SDMF shares have only one segment, so it doesn't make sense to |
---|
13839 | hunk ./src/allmydata/test/test_storage.py 2680 |
---|
13840 | # read more segments than that. The reader should know this and |
---|
13841 | # complain if we try to do that. |
---|
13842 | - self.write_sdmf_share_to_server("si1") |
---|
13843 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13844 | - d = defer.succeed(None) |
---|
13845 | - d.addCallback(lambda ignored: |
---|
13846 | - mr.is_sdmf()) |
---|
13847 | - d.addCallback(lambda issdmf: |
---|
13848 | - self.failUnless(issdmf)) |
---|
13849 | - d.addCallback(lambda ignored: |
---|
13850 | - self.shouldFail(LayoutInvalid, "test bad segment", |
---|
13851 | - None, |
---|
13852 | - mr.get_block_and_salt, 1)) |
---|
13853 | + d = self.write_sdmf_share_to_server("si1") |
---|
13854 | + def _written(ign): |
---|
13855 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13856 | + d2 = defer.succeed(None) |
---|
13857 | + d2.addCallback(lambda ign: mr.is_sdmf()) |
---|
13858 | + d2.addCallback(lambda issdmf: self.failUnless(issdmf)) |
---|
13859 | + d2.addCallback(lambda ign: self.shouldFail(LayoutInvalid, "test bad segment", |
---|
13860 | + None, |
---|
13861 | + lambda: mr.get_block_and_salt(1) )) |
---|
13862 | + return d2 |
---|
13863 | + d.addCallback(_written) |
---|
13864 | return d |
---|
13865 | |
---|
13866 | def test_read_with_prefetched_mdmf_data(self): |
---|
13867 | hunk ./src/allmydata/test/test_storage.py 2700 |
---|
13868 | # finding out which shares are on the remote peer so that it |
---|
13869 | # doesn't waste round trips. |
---|
13870 | mdmf_data = self.build_test_mdmf_share() |
---|
13871 | - self.write_test_share_to_server("si1") |
---|
13872 | def _make_mr(ignored, length): |
---|
13873 | mr = MDMFSlotReadProxy(self.rref, "si1", 0, mdmf_data[:length]) |
---|
13874 | return mr |
---|
13875 | hunk ./src/allmydata/test/test_storage.py 2704 |
---|
13876 | |
---|
13877 | - d = defer.succeed(None) |
---|
13878 | + d = self.write_test_share_to_server("si1") |
---|
13879 | + |
---|
13880 | # This should be enough to fill in both the encoding parameters |
---|
13881 | # and the table of offsets, which will complete the version |
---|
13882 | # information tuple. |
---|
13883 | hunk ./src/allmydata/test/test_storage.py 2761 |
---|
13884 | |
---|
13885 | def test_read_with_prefetched_sdmf_data(self): |
---|
13886 | sdmf_data = self.build_test_sdmf_share() |
---|
13887 | - self.write_sdmf_share_to_server("si1") |
---|
13888 | def _make_mr(ignored, length): |
---|
13889 | mr = MDMFSlotReadProxy(self.rref, "si1", 0, sdmf_data[:length]) |
---|
13890 | return mr |
---|
13891 | hunk ./src/allmydata/test/test_storage.py 2765 |
---|
13892 | |
---|
13893 | - d = defer.succeed(None) |
---|
13894 | + d = self.write_sdmf_share_to_server("si1") |
---|
13895 | + |
---|
13896 | # This should be enough to get us the encoding parameters, |
---|
13897 | # offset table, and everything else we need to build a verinfo |
---|
13898 | # string. |
---|
13899 | hunk ./src/allmydata/test/test_storage.py 2826 |
---|
13900 | # Some tests upload a file with no contents to test things |
---|
13901 | # unrelated to the actual handling of the content of the file. |
---|
13902 | # The reader should behave intelligently in these cases. |
---|
13903 | - self.write_test_share_to_server("si1", empty=True) |
---|
13904 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13905 | - # We should be able to get the encoding parameters, and they |
---|
13906 | - # should be correct. |
---|
13907 | - d = defer.succeed(None) |
---|
13908 | - d.addCallback(lambda ignored: |
---|
13909 | - mr.get_encoding_parameters()) |
---|
13910 | - def _check_encoding_parameters(params): |
---|
13911 | - self.failUnlessEqual(len(params), 4) |
---|
13912 | - k, n, segsize, datalen = params |
---|
13913 | - self.failUnlessEqual(k, 3) |
---|
13914 | - self.failUnlessEqual(n, 10) |
---|
13915 | - self.failUnlessEqual(segsize, 0) |
---|
13916 | - self.failUnlessEqual(datalen, 0) |
---|
13917 | - d.addCallback(_check_encoding_parameters) |
---|
13918 | + d = self.write_test_share_to_server("si1", empty=True) |
---|
13919 | + def _written(ign): |
---|
13920 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13921 | |
---|
13922 | hunk ./src/allmydata/test/test_storage.py 2830 |
---|
13923 | - # We should not be able to fetch a block, since there are no |
---|
13924 | - # blocks to fetch |
---|
13925 | - d.addCallback(lambda ignored: |
---|
13926 | - self.shouldFail(LayoutInvalid, "get block on empty file", |
---|
13927 | - None, |
---|
13928 | - mr.get_block_and_salt, 0)) |
---|
13929 | - return d |
---|
13930 | + # We should be able to get the encoding parameters, and they |
---|
13931 | + # should be correct. |
---|
13932 | + d2 = defer.succeed(None) |
---|
13933 | + d2.addCallback(lambda ignored: |
---|
13934 | + mr.get_encoding_parameters()) |
---|
13935 | + def _check_encoding_parameters(params): |
---|
13936 | + self.failUnlessEqual(len(params), 4) |
---|
13937 | + k, n, segsize, datalen = params |
---|
13938 | + self.failUnlessEqual(k, 3) |
---|
13939 | + self.failUnlessEqual(n, 10) |
---|
13940 | + self.failUnlessEqual(segsize, 0) |
---|
13941 | + self.failUnlessEqual(datalen, 0) |
---|
13942 | + d2.addCallback(_check_encoding_parameters) |
---|
13943 | |
---|
13944 | hunk ./src/allmydata/test/test_storage.py 2844 |
---|
13945 | + # We should not be able to fetch a block, since there are no |
---|
13946 | + # blocks to fetch |
---|
13947 | + d2.addCallback(lambda ignored: |
---|
13948 | + self.shouldFail(LayoutInvalid, "get block on empty file", |
---|
13949 | + None, |
---|
13950 | + lambda: mr.get_block_and_salt(0) )) |
---|
13951 | + return d2 |
---|
13952 | + d.addCallback(_written) |
---|
13953 | + return d |
---|
13954 | |
---|
13955 | def test_read_with_empty_sdmf_file(self): |
---|
13956 | hunk ./src/allmydata/test/test_storage.py 2855 |
---|
13957 | - self.write_sdmf_share_to_server("si1", empty=True) |
---|
13958 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13959 | - # We should be able to get the encoding parameters, and they |
---|
13960 | - # should be correct |
---|
13961 | - d = defer.succeed(None) |
---|
13962 | - d.addCallback(lambda ignored: |
---|
13963 | - mr.get_encoding_parameters()) |
---|
13964 | - def _check_encoding_parameters(params): |
---|
13965 | - self.failUnlessEqual(len(params), 4) |
---|
13966 | - k, n, segsize, datalen = params |
---|
13967 | - self.failUnlessEqual(k, 3) |
---|
13968 | - self.failUnlessEqual(n, 10) |
---|
13969 | - self.failUnlessEqual(segsize, 0) |
---|
13970 | - self.failUnlessEqual(datalen, 0) |
---|
13971 | - d.addCallback(_check_encoding_parameters) |
---|
13972 | + d = self.write_sdmf_share_to_server("si1", empty=True) |
---|
13973 | + def _written(ign): |
---|
13974 | + mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
13975 | + # We should be able to get the encoding parameters, and they |
---|
13976 | + # should be correct |
---|
13977 | + d2 = defer.succeed(None) |
---|
13978 | + d2.addCallback(lambda ignored: |
---|
13979 | + mr.get_encoding_parameters()) |
---|
13980 | + def _check_encoding_parameters(params): |
---|
13981 | + self.failUnlessEqual(len(params), 4) |
---|
13982 | + k, n, segsize, datalen = params |
---|
13983 | + self.failUnlessEqual(k, 3) |
---|
13984 | + self.failUnlessEqual(n, 10) |
---|
13985 | + self.failUnlessEqual(segsize, 0) |
---|
13986 | + self.failUnlessEqual(datalen, 0) |
---|
13987 | + d2.addCallback(_check_encoding_parameters) |
---|
13988 | |
---|
13989 | hunk ./src/allmydata/test/test_storage.py 2872 |
---|
13990 | - # It does not make sense to get a block in this format, so we |
---|
13991 | - # should not be able to. |
---|
13992 | - d.addCallback(lambda ignored: |
---|
13993 | - self.shouldFail(LayoutInvalid, "get block on an empty file", |
---|
13994 | - None, |
---|
13995 | - mr.get_block_and_salt, 0)) |
---|
13996 | + # It does not make sense to get a block in this format, so we |
---|
13997 | + # should not be able to. |
---|
13998 | + d2.addCallback(lambda ignored: |
---|
13999 | + self.shouldFail(LayoutInvalid, "get block on an empty file", |
---|
14000 | + None, |
---|
14001 | + lambda: mr.get_block_and_salt(0) )) |
---|
14002 | + return d2 |
---|
14003 | + d.addCallback(_written) |
---|
14004 | return d |
---|
14005 | |
---|
14006 | def test_verinfo_with_sdmf_file(self): |
---|
14007 | hunk ./src/allmydata/test/test_storage.py 2883 |
---|
14008 | - self.write_sdmf_share_to_server("si1") |
---|
14009 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
14010 | - # We should be able to get the version information. |
---|
14011 | - d = defer.succeed(None) |
---|
14012 | - d.addCallback(lambda ignored: |
---|
14013 | - mr.get_verinfo()) |
---|
14014 | + d = self.write_sdmf_share_to_server("si1") |
---|
14015 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
14016 | + d.addCallback(lambda mr: mr.get_verinfo()) |
---|
14017 | def _check_verinfo(verinfo): |
---|
14018 | self.failUnless(verinfo) |
---|
14019 | self.failUnlessEqual(len(verinfo), 9) |
---|
14020 | hunk ./src/allmydata/test/test_storage.py 2920 |
---|
14021 | return d |
---|
14022 | |
---|
14023 | def test_verinfo_with_mdmf_file(self): |
---|
14024 | - self.write_test_share_to_server("si1") |
---|
14025 | - mr = MDMFSlotReadProxy(self.rref, "si1", 0) |
---|
14026 | - d = defer.succeed(None) |
---|
14027 | - d.addCallback(lambda ignored: |
---|
14028 | - mr.get_verinfo()) |
---|
14029 | + d = self.write_test_share_to_server("si1") |
---|
14030 | + d.addCallback(lambda ign: MDMFSlotReadProxy(self.rref, "si1", 0)) |
---|
14031 | + d.addCallback(lambda mr: mr.get_verinfo()) |
---|
14032 | def _check_verinfo(verinfo): |
---|
14033 | self.failUnless(verinfo) |
---|
14034 | self.failUnlessEqual(len(verinfo), 9) |
---|
14035 | hunk ./src/allmydata/test/test_storage.py 2990 |
---|
14036 | |
---|
14037 | # Now finish publishing |
---|
14038 | d = sdmfr.finish_publishing() |
---|
14039 | - def _then(ignored): |
---|
14040 | - self.failUnlessEqual(self.rref.write_count, 1) |
---|
14041 | - read = self.ss.remote_slot_readv |
---|
14042 | - self.failUnlessEqual(read("si1", [0], [(0, len(data))]), |
---|
14043 | - {0: [data]}) |
---|
14044 | - d.addCallback(_then) |
---|
14045 | + d.addCallback(lambda ign: self.failUnlessEqual(self.rref.write_count, 1)) |
---|
14046 | + d.addCallback(lambda ign: self.ss.remote_slot_readv("si1", [0], [(0, len(data))])) |
---|
14047 | + d.addCallback(lambda res: self.failUnlessEqual(res, {0: [data]})) |
---|
14048 | return d |
---|
14049 | |
---|
14050 | def test_sdmf_writer_preexisting_share(self): |
---|
14051 | hunk ./src/allmydata/test/test_storage.py 2997 |
---|
14052 | data = self.build_test_sdmf_share() |
---|
14053 | - self.write_sdmf_share_to_server("si1") |
---|
14054 | + d = self.write_sdmf_share_to_server("si1") |
---|
14055 | + def _written(ign): |
---|
14056 | + # Now there is a share on the storage server. To successfully |
---|
14057 | + # write, we need to set the checkstring correctly. When we |
---|
14058 | + # don't, no write should occur. |
---|
14059 | + sdmfw = SDMFSlotWriteProxy(0, |
---|
14060 | + self.rref, |
---|
14061 | + "si1", |
---|
14062 | + self.secrets, |
---|
14063 | + 1, 3, 10, 36, 36) |
---|
14064 | + sdmfw.put_block(self.blockdata, 0, self.salt) |
---|
14065 | |
---|
14066 | hunk ./src/allmydata/test/test_storage.py 3009 |
---|
14067 | - # Now there is a share on the storage server. To successfully |
---|
14068 | - # write, we need to set the checkstring correctly. When we |
---|
14069 | - # don't, no write should occur. |
---|
14070 | - sdmfw = SDMFSlotWriteProxy(0, |
---|
14071 | - self.rref, |
---|
14072 | - "si1", |
---|
14073 | - self.secrets, |
---|
14074 | - 1, 3, 10, 36, 36) |
---|
14075 | - sdmfw.put_block(self.blockdata, 0, self.salt) |
---|
14076 | + # Put the encprivkey |
---|
14077 | + sdmfw.put_encprivkey(self.encprivkey) |
---|
14078 | |
---|
14079 | hunk ./src/allmydata/test/test_storage.py 3012 |
---|
14080 | - # Put the encprivkey |
---|
14081 | - sdmfw.put_encprivkey(self.encprivkey) |
---|
14082 | + # Put the block and share hash chains |
---|
14083 | + sdmfw.put_blockhashes(self.block_hash_tree) |
---|
14084 | + sdmfw.put_sharehashes(self.share_hash_chain) |
---|
14085 | |
---|
14086 | hunk ./src/allmydata/test/test_storage.py 3016 |
---|
14087 | - # Put the block and share hash chains |
---|
14088 | - sdmfw.put_blockhashes(self.block_hash_tree) |
---|
14089 | - sdmfw.put_sharehashes(self.share_hash_chain) |
---|
14090 | + # Put the root hash |
---|
14091 | + sdmfw.put_root_hash(self.root_hash) |
---|
14092 | |
---|
14093 | hunk ./src/allmydata/test/test_storage.py 3019 |
---|
14094 | - # Put the root hash |
---|
14095 | - sdmfw.put_root_hash(self.root_hash) |
---|
14096 | + # Put the signature |
---|
14097 | + sdmfw.put_signature(self.signature) |
---|
14098 | |
---|
14099 | hunk ./src/allmydata/test/test_storage.py 3022 |
---|
14100 | - # Put the signature |
---|
14101 | - sdmfw.put_signature(self.signature) |
---|
14102 | + # Put the verification key |
---|
14103 | + sdmfw.put_verification_key(self.verification_key) |
---|
14104 | |
---|
14105 | hunk ./src/allmydata/test/test_storage.py 3025 |
---|
14106 | - # Put the verification key |
---|
14107 | - sdmfw.put_verification_key(self.verification_key) |
---|
14108 | + # We shouldn't have a checkstring yet |
---|
14109 | + self.failUnlessEqual(sdmfw.get_checkstring(), "") |
---|
14110 | |
---|
14111 | hunk ./src/allmydata/test/test_storage.py 3028 |
---|
14112 | - # We shouldn't have a checkstring yet |
---|
14113 | - self.failUnlessEqual(sdmfw.get_checkstring(), "") |
---|
14114 | + d2 = sdmfw.finish_publishing() |
---|
14115 | + def _then(results): |
---|
14116 | + self.failIf(results[0]) |
---|
14117 | + # this is the correct checkstring |
---|
14118 | + self._expected_checkstring = results[1][0][0] |
---|
14119 | + return self._expected_checkstring |
---|
14120 | |
---|
14121 | hunk ./src/allmydata/test/test_storage.py 3035 |
---|
14122 | - d = sdmfw.finish_publishing() |
---|
14123 | - def _then(results): |
---|
14124 | - self.failIf(results[0]) |
---|
14125 | - # this is the correct checkstring |
---|
14126 | - self._expected_checkstring = results[1][0][0] |
---|
14127 | - return self._expected_checkstring |
---|
14128 | + d2.addCallback(_then) |
---|
14129 | + d2.addCallback(sdmfw.set_checkstring) |
---|
14130 | + d2.addCallback(lambda ign: sdmfw.get_checkstring()) |
---|
14131 | + d2.addCallback(lambda res: self.failUnlessEqual(res, self._expected_checkstring)) |
---|
14132 | |
---|
14133 | hunk ./src/allmydata/test/test_storage.py 3040 |
---|
14134 | - d.addCallback(_then) |
---|
14135 | - d.addCallback(sdmfw.set_checkstring) |
---|
14136 | - d.addCallback(lambda ignored: |
---|
14137 | - sdmfw.get_checkstring()) |
---|
14138 | - d.addCallback(lambda checkstring: |
---|
14139 | - self.failUnlessEqual(checkstring, self._expected_checkstring)) |
---|
14140 | - d.addCallback(lambda ignored: |
---|
14141 | - sdmfw.finish_publishing()) |
---|
14142 | - def _then_again(results): |
---|
14143 | - self.failUnless(results[0]) |
---|
14144 | - read = self.ss.remote_slot_readv |
---|
14145 | - self.failUnlessEqual(read("si1", [0], [(1, 8)]), |
---|
14146 | - {0: [struct.pack(">Q", 1)]}) |
---|
14147 | - self.failUnlessEqual(read("si1", [0], [(9, len(data) - 9)]), |
---|
14148 | - {0: [data[9:]]}) |
---|
14149 | - d.addCallback(_then_again) |
---|
14150 | + d2.addCallback(lambda ign: sdmfw.finish_publishing()) |
---|
14151 | + d2.addCallback(lambda results: self.failUnless(results[0])) |
---|
14152 | + d2.addCallback(lambda ign: self.ss.remote_slot_readv("si1", [0], [(1, 8)])) |
---|
14153 | + d2.addCallback(lambda res: self.failUnlessEqual(res, {0: [struct.pack(">Q", 1)]})) |
---|
14154 | + d2.addCallback(lambda ign: self.ss.remote_slot_readv("si1", [0], [(9, len(data) - 9)])) |
---|
14155 | + d2.addCallback(lambda res: self.failUnlessEqual(res, {0: [data[9:]]})) |
---|
14156 | + return d2 |
---|
14157 | + d.addCallback(_written) |
---|
14158 | return d |
---|
14159 | |
---|
14160 | |
---|
14161 | hunk ./src/allmydata/test/test_storage.py 3060 |
---|
14162 | return self.sparent.stopService() |
---|
14163 | |
---|
14164 | def workdir(self, name): |
---|
14165 | - basedir = os.path.join("storage", "Server", name) |
---|
14166 | - return basedir |
---|
14167 | + return FilePath("storage").child(self.__class__.__name__).child(name) |
---|
14168 | |
---|
14169 | def create(self, name): |
---|
14170 | workdir = self.workdir(name) |
---|
14171 | hunk ./src/allmydata/test/test_storage.py 3064 |
---|
14172 | - ss = StorageServer(workdir, "\x00" * 20) |
---|
14173 | + backend = DiskBackend(workdir) |
---|
14174 | + ss = StorageServer("\x00" * 20, backend, workdir) |
---|
14175 | ss.setServiceParent(self.sparent) |
---|
14176 | return ss |
---|
14177 | |
---|
14178 | hunk ./src/allmydata/test/test_storage.py 3150 |
---|
14179 | d.callback(None) |
---|
14180 | |
---|
14181 | class MyStorageServer(StorageServer): |
---|
14182 | - def add_bucket_counter(self): |
---|
14183 | - statefile = os.path.join(self.storedir, "bucket_counter.state") |
---|
14184 | - self.bucket_counter = MyBucketCountingCrawler(self, statefile) |
---|
14185 | - self.bucket_counter.setServiceParent(self) |
---|
14186 | + BucketCounterClass = MyBucketCountingCrawler |
---|
14187 | + |
---|
14188 | |
---|
14189 | class BucketCounter(unittest.TestCase, pollmixin.PollMixin): |
---|
14190 | |
---|
14191 | hunk ./src/allmydata/test/test_storage.py 3163 |
---|
14192 | |
---|
14193 | def test_bucket_counter(self): |
---|
14194 | basedir = "storage/BucketCounter/bucket_counter" |
---|
14195 | - fileutil.make_dirs(basedir) |
---|
14196 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
14197 | + fp = FilePath(basedir) |
---|
14198 | + backend = DiskBackend(fp) |
---|
14199 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
14200 | + |
---|
14201 | # to make sure we capture the bucket-counting-crawler in the middle |
---|
14202 | # of a cycle, we reach in and reduce its maximum slice time to 0. We |
---|
14203 | # also make it start sooner than usual. |
---|
14204 | hunk ./src/allmydata/test/test_storage.py 3222 |
---|
14205 | |
---|
14206 | def test_bucket_counter_cleanup(self): |
---|
14207 | basedir = "storage/BucketCounter/bucket_counter_cleanup" |
---|
14208 | - fileutil.make_dirs(basedir) |
---|
14209 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
14210 | + fp = FilePath(basedir) |
---|
14211 | + backend = DiskBackend(fp) |
---|
14212 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
14213 | + |
---|
14214 | # to make sure we capture the bucket-counting-crawler in the middle |
---|
14215 | # of a cycle, we reach in and reduce its maximum slice time to 0. |
---|
14216 | ss.bucket_counter.slow_start = 0 |
---|
14217 | hunk ./src/allmydata/test/test_storage.py 3266 |
---|
14218 | |
---|
14219 | def test_bucket_counter_eta(self): |
---|
14220 | basedir = "storage/BucketCounter/bucket_counter_eta" |
---|
14221 | - fileutil.make_dirs(basedir) |
---|
14222 | - ss = MyStorageServer(basedir, "\x00" * 20) |
---|
14223 | + fp = FilePath(basedir) |
---|
14224 | + backend = DiskBackend(fp) |
---|
14225 | + ss = MyStorageServer("\x00" * 20, backend, fp) |
---|
14226 | ss.bucket_counter.slow_start = 0 |
---|
14227 | |
---|
14228 | # these will be fired inside finished_prefix() |
---|
14229 | hunk ./src/allmydata/test/test_storage.py 3306 |
---|
14230 | |
---|
14231 | |
---|
14232 | class InstrumentedLeaseCheckingCrawler(LeaseCheckingCrawler): |
---|
14233 | - stop_after_first_bucket = False |
---|
14234 | - def process_bucket(self, *args, **kwargs): |
---|
14235 | - LeaseCheckingCrawler.process_bucket(self, *args, **kwargs) |
---|
14236 | - if self.stop_after_first_bucket: |
---|
14237 | - self.stop_after_first_bucket = False |
---|
14238 | - self.cpu_slice = -1.0 |
---|
14239 | + hook_ds = None |
---|
14240 | + |
---|
14241 | + def process_shareset(self, *args, **kwargs): |
---|
14242 | + try: |
---|
14243 | + LeaseCheckingCrawler.process_shareset(self, *args, **kwargs) |
---|
14244 | + if self.hook_ds: |
---|
14245 | + self.cpu_slice = -1.0 |
---|
14246 | + d = self.hook_ds.pop(0) |
---|
14247 | + d.callback(None) |
---|
14248 | + except Exception, e: |
---|
14249 | + if self.hook_ds: |
---|
14250 | + self.cpu_slice = -1.0 |
---|
14251 | + d = self.hook_ds.pop(0) |
---|
14252 | + d.errback(e) |
---|
14253 | + raise |
---|
14254 | + |
---|
14255 | def yielding(self, sleep_time): |
---|
14256 | hunk ./src/allmydata/test/test_storage.py 3323 |
---|
14257 | - if not self.stop_after_first_bucket: |
---|
14258 | + if self.hook_ds is None: |
---|
14259 | self.cpu_slice = 500 |
---|
14260 | |
---|
14261 | hunk ./src/allmydata/test/test_storage.py 3326 |
---|
14262 | -class BrokenStatResults: |
---|
14263 | - pass |
---|
14264 | -class No_ST_BLOCKS_LeaseCheckingCrawler(LeaseCheckingCrawler): |
---|
14265 | - def stat(self, fn): |
---|
14266 | - s = os.stat(fn) |
---|
14267 | - bsr = BrokenStatResults() |
---|
14268 | - for attrname in dir(s): |
---|
14269 | - if attrname.startswith("_"): |
---|
14270 | - continue |
---|
14271 | - if attrname == "st_blocks": |
---|
14272 | - continue |
---|
14273 | - setattr(bsr, attrname, getattr(s, attrname)) |
---|
14274 | - return bsr |
---|
14275 | - |
---|
14276 | class InstrumentedStorageServer(StorageServer): |
---|
14277 | LeaseCheckerClass = InstrumentedLeaseCheckingCrawler |
---|
14278 | hunk ./src/allmydata/test/test_storage.py 3328 |
---|
14279 | -class No_ST_BLOCKS_StorageServer(StorageServer): |
---|
14280 | - LeaseCheckerClass = No_ST_BLOCKS_LeaseCheckingCrawler |
---|
14281 | + |
---|
14282 | |
---|
14283 | class LeaseCrawler(unittest.TestCase, pollmixin.PollMixin, WebRenderingMixin): |
---|
14284 | |
---|
14285 | hunk ./src/allmydata/test/test_storage.py 3350 |
---|
14286 | return (hashutil.tagged_hash("renew-%d" % num, si), |
---|
14287 | hashutil.tagged_hash("cancel-%d" % num, si)) |
---|
14288 | |
---|
14289 | + writev = ss.remote_slot_testv_and_readv_and_writev |
---|
14290 | + |
---|
14291 | immutable_si_0, rs0, cs0 = make("\x00" * 16) |
---|
14292 | immutable_si_1, rs1, cs1 = make("\x01" * 16) |
---|
14293 | rs1a, cs1a = make_extra_lease(immutable_si_1, 1) |
---|
14294 | hunk ./src/allmydata/test/test_storage.py 3364 |
---|
14295 | # inner contents are not a valid CHK share |
---|
14296 | data = "\xff" * 1000 |
---|
14297 | |
---|
14298 | - a,w = ss.remote_allocate_buckets(immutable_si_0, rs0, cs0, sharenums, |
---|
14299 | - 1000, canary) |
---|
14300 | - w[0].remote_write(0, data) |
---|
14301 | - w[0].remote_close() |
---|
14302 | - |
---|
14303 | - a,w = ss.remote_allocate_buckets(immutable_si_1, rs1, cs1, sharenums, |
---|
14304 | - 1000, canary) |
---|
14305 | - w[0].remote_write(0, data) |
---|
14306 | - w[0].remote_close() |
---|
14307 | - ss.remote_add_lease(immutable_si_1, rs1a, cs1a) |
---|
14308 | - |
---|
14309 | - writev = ss.remote_slot_testv_and_readv_and_writev |
---|
14310 | - writev(mutable_si_2, (we2, rs2, cs2), |
---|
14311 | - {0: ([], [(0,data)], len(data))}, []) |
---|
14312 | - writev(mutable_si_3, (we3, rs3, cs3), |
---|
14313 | - {0: ([], [(0,data)], len(data))}, []) |
---|
14314 | - ss.remote_add_lease(mutable_si_3, rs3a, cs3a) |
---|
14315 | - |
---|
14316 | self.sis = [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] |
---|
14317 | self.renew_secrets = [rs0, rs1, rs1a, rs2, rs3, rs3a] |
---|
14318 | self.cancel_secrets = [cs0, cs1, cs1a, cs2, cs3, cs3a] |
---|
14319 | hunk ./src/allmydata/test/test_storage.py 3368 |
---|
14320 | |
---|
14321 | + d = defer.succeed(None) |
---|
14322 | + d.addCallback(lambda ign: ss.remote_allocate_buckets(immutable_si_0, rs0, cs0, |
---|
14323 | + sharenums, 1000, canary)) |
---|
14324 | + def _allocated( (a, w) ): |
---|
14325 | + d2 = defer.succeed(None) |
---|
14326 | + d2.addCallback(lambda ign: w[0].remote_write(0, data)) |
---|
14327 | + d2.addCallback(lambda ign: w[0].remote_close()) |
---|
14328 | + d.addCallback(_allocated) |
---|
14329 | + |
---|
14330 | + d.addCallback(lambda ign: ss.remote_allocate_buckets(immutable_si_1, rs1, cs1, |
---|
14331 | + sharenums, 1000, canary)) |
---|
14332 | + d.addCallback(_allocated) |
---|
14333 | + d.addCallback(lambda ign: ss.remote_add_lease(immutable_si_1, rs1a, cs1a)) |
---|
14334 | + |
---|
14335 | + d.addCallback(lambda ign: writev(mutable_si_2, (we2, rs2, cs2), |
---|
14336 | + {0: ([], [(0,data)], len(data))}, [])) |
---|
14337 | + d.addCallback(lambda ign: writev(mutable_si_3, (we3, rs3, cs3), |
---|
14338 | + {0: ([], [(0,data)], len(data))}, [])) |
---|
14339 | + d.addCallback(lambda ign: ss.remote_add_lease(mutable_si_3, rs3a, cs3a)) |
---|
14340 | + return d |
---|
14341 | + |
---|
14342 | def test_basic(self): |
---|
14343 | basedir = "storage/LeaseCrawler/basic" |
---|
14344 | hunk ./src/allmydata/test/test_storage.py 3391 |
---|
14345 | - fileutil.make_dirs(basedir) |
---|
14346 | - ss = InstrumentedStorageServer(basedir, "\x00" * 20) |
---|
14347 | + fp = FilePath(basedir) |
---|
14348 | + backend = DiskBackend(fp) |
---|
14349 | + ss = InstrumentedStorageServer("\x00" * 20, backend, fp) |
---|
14350 | + |
---|
14351 | # make it start sooner than usual. |
---|
14352 | lc = ss.lease_checker |
---|
14353 | lc.slow_start = 0 |
---|
14354 | hunk ./src/allmydata/test/test_storage.py 3399 |
---|
14355 | lc.cpu_slice = 500 |
---|
14356 | - lc.stop_after_first_bucket = True |
---|
14357 | - webstatus = StorageStatus(ss) |
---|
14358 | |
---|
14359 | # create a few shares, with some leases on them |
---|
14360 | hunk ./src/allmydata/test/test_storage.py 3401 |
---|
14361 | - self.make_shares(ss) |
---|
14362 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
14363 | + d = self.make_shares(ss) |
---|
14364 | + def _do_test(ign): |
---|
14365 | + d2 = defer.Deferred() |
---|
14366 | + lc.hook_ds = [d2] |
---|
14367 | |
---|
14368 | hunk ./src/allmydata/test/test_storage.py 3406 |
---|
14369 | - # add a non-sharefile to exercise another code path |
---|
14370 | - fn = os.path.join(ss.sharedir, |
---|
14371 | - storage_index_to_dir(immutable_si_0), |
---|
14372 | - "not-a-share") |
---|
14373 | - f = open(fn, "wb") |
---|
14374 | - f.write("I am not a share.\n") |
---|
14375 | - f.close() |
---|
14376 | + DAY = 24*60*60 |
---|
14377 | |
---|
14378 | hunk ./src/allmydata/test/test_storage.py 3408 |
---|
14379 | - # this is before the crawl has started, so we're not in a cycle yet |
---|
14380 | - initial_state = lc.get_state() |
---|
14381 | - self.failIf(lc.get_progress()["cycle-in-progress"]) |
---|
14382 | - self.failIfIn("cycle-to-date", initial_state) |
---|
14383 | - self.failIfIn("estimated-remaining-cycle", initial_state) |
---|
14384 | - self.failIfIn("estimated-current-cycle", initial_state) |
---|
14385 | - self.failUnlessIn("history", initial_state) |
---|
14386 | - self.failUnlessEqual(initial_state["history"], {}) |
---|
14387 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
14388 | |
---|
14389 | hunk ./src/allmydata/test/test_storage.py 3410 |
---|
14390 | - ss.setServiceParent(self.s) |
---|
14391 | - |
---|
14392 | - DAY = 24*60*60 |
---|
14393 | + # add a non-sharefile to exercise another code path |
---|
14394 | + fp = ss.backend.get_shareset(immutable_si_0)._get_sharedir().child("not-a-share") |
---|
14395 | + fp.setContent("I am not a share.\n") |
---|
14396 | |
---|
14397 | hunk ./src/allmydata/test/test_storage.py 3414 |
---|
14398 | - d = fireEventually() |
---|
14399 | - |
---|
14400 | - # now examine the state right after the first bucket has been |
---|
14401 | - # processed. |
---|
14402 | - def _after_first_bucket(ignored): |
---|
14403 | + # this is before the crawl has started, so we're not in a cycle yet |
---|
14404 | initial_state = lc.get_state() |
---|
14405 | hunk ./src/allmydata/test/test_storage.py 3416 |
---|
14406 | - if "cycle-to-date" not in initial_state: |
---|
14407 | - d2 = fireEventually() |
---|
14408 | - d2.addCallback(_after_first_bucket) |
---|
14409 | - return d2 |
---|
14410 | - self.failUnlessIn("cycle-to-date", initial_state) |
---|
14411 | - self.failUnlessIn("estimated-remaining-cycle", initial_state) |
---|
14412 | - self.failUnlessIn("estimated-current-cycle", initial_state) |
---|
14413 | + self.failIf(lc.get_progress()["cycle-in-progress"]) |
---|
14414 | + self.failIfIn("cycle-to-date", initial_state) |
---|
14415 | + self.failIfIn("estimated-remaining-cycle", initial_state) |
---|
14416 | + self.failIfIn("estimated-current-cycle", initial_state) |
---|
14417 | self.failUnlessIn("history", initial_state) |
---|
14418 | self.failUnlessEqual(initial_state["history"], {}) |
---|
14419 | |
---|
14420 | hunk ./src/allmydata/test/test_storage.py 3423 |
---|
14421 | - so_far = initial_state["cycle-to-date"] |
---|
14422 | - self.failUnlessEqual(so_far["expiration-enabled"], False) |
---|
14423 | - self.failUnlessIn("configured-expiration-mode", so_far) |
---|
14424 | - self.failUnlessIn("lease-age-histogram", so_far) |
---|
14425 | - lah = so_far["lease-age-histogram"] |
---|
14426 | - self.failUnlessEqual(type(lah), list) |
---|
14427 | - self.failUnlessEqual(len(lah), 1) |
---|
14428 | - self.failUnlessEqual(lah, [ (0.0, DAY, 1) ] ) |
---|
14429 | - self.failUnlessEqual(so_far["leases-per-share-histogram"], {1: 1}) |
---|
14430 | - self.failUnlessEqual(so_far["corrupt-shares"], []) |
---|
14431 | - sr1 = so_far["space-recovered"] |
---|
14432 | - self.failUnlessEqual(sr1["examined-buckets"], 1) |
---|
14433 | - self.failUnlessEqual(sr1["examined-shares"], 1) |
---|
14434 | - self.failUnlessEqual(sr1["actual-shares"], 0) |
---|
14435 | - self.failUnlessEqual(sr1["configured-diskbytes"], 0) |
---|
14436 | - self.failUnlessEqual(sr1["original-sharebytes"], 0) |
---|
14437 | - left = initial_state["estimated-remaining-cycle"] |
---|
14438 | - sr2 = left["space-recovered"] |
---|
14439 | - self.failUnless(sr2["examined-buckets"] > 0, sr2["examined-buckets"]) |
---|
14440 | - self.failUnless(sr2["examined-shares"] > 0, sr2["examined-shares"]) |
---|
14441 | - self.failIfEqual(sr2["actual-shares"], None) |
---|
14442 | - self.failIfEqual(sr2["configured-diskbytes"], None) |
---|
14443 | - self.failIfEqual(sr2["original-sharebytes"], None) |
---|
14444 | - d.addCallback(_after_first_bucket) |
---|
14445 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
14446 | - def _check_html_in_cycle(html): |
---|
14447 | - s = remove_tags(html) |
---|
14448 | - self.failUnlessIn("So far, this cycle has examined " |
---|
14449 | - "1 shares in 1 buckets (0 mutable / 1 immutable) ", s) |
---|
14450 | - self.failUnlessIn("and has recovered: " |
---|
14451 | - "0 shares, 0 buckets (0 mutable / 0 immutable), " |
---|
14452 | - "0 B (0 B / 0 B)", s) |
---|
14453 | - self.failUnlessIn("If expiration were enabled, " |
---|
14454 | - "we would have recovered: " |
---|
14455 | - "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14456 | - " 0 B (0 B / 0 B) by now", s) |
---|
14457 | - self.failUnlessIn("and the remainder of this cycle " |
---|
14458 | - "would probably recover: " |
---|
14459 | - "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14460 | - " 0 B (0 B / 0 B)", s) |
---|
14461 | - self.failUnlessIn("and the whole cycle would probably recover: " |
---|
14462 | - "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14463 | - " 0 B (0 B / 0 B)", s) |
---|
14464 | - self.failUnlessIn("if we were strictly using each lease's default " |
---|
14465 | - "31-day lease lifetime", s) |
---|
14466 | - self.failUnlessIn("this cycle would be expected to recover: ", s) |
---|
14467 | - d.addCallback(_check_html_in_cycle) |
---|
14468 | + ss.setServiceParent(self.s) |
---|
14469 | |
---|
14470 | hunk ./src/allmydata/test/test_storage.py 3425 |
---|
14471 | - # wait for the crawler to finish the first cycle. Nothing should have |
---|
14472 | - # been removed. |
---|
14473 | - def _wait(): |
---|
14474 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
14475 | - d.addCallback(lambda ign: self.poll(_wait)) |
---|
14476 | + # now examine the state right after the first shareset has been |
---|
14477 | + # processed. |
---|
14478 | + def _after_first_shareset(ignored): |
---|
14479 | + initial_state = lc.get_state() |
---|
14480 | + self.failUnlessIn("cycle-to-date", initial_state) |
---|
14481 | + self.failUnlessIn("estimated-remaining-cycle", initial_state) |
---|
14482 | + self.failUnlessIn("estimated-current-cycle", initial_state) |
---|
14483 | + self.failUnlessIn("history", initial_state) |
---|
14484 | + self.failUnlessEqual(initial_state["history"], {}) |
---|
14485 | |
---|
14486 | hunk ./src/allmydata/test/test_storage.py 3435 |
---|
14487 | - def _after_first_cycle(ignored): |
---|
14488 | - s = lc.get_state() |
---|
14489 | - self.failIf("cycle-to-date" in s) |
---|
14490 | - self.failIf("estimated-remaining-cycle" in s) |
---|
14491 | - self.failIf("estimated-current-cycle" in s) |
---|
14492 | - last = s["history"][0] |
---|
14493 | - self.failUnlessIn("cycle-start-finish-times", last) |
---|
14494 | - self.failUnlessEqual(type(last["cycle-start-finish-times"]), tuple) |
---|
14495 | - self.failUnlessEqual(last["expiration-enabled"], False) |
---|
14496 | - self.failUnlessIn("configured-expiration-mode", last) |
---|
14497 | + so_far = initial_state["cycle-to-date"] |
---|
14498 | + self.failUnlessEqual(so_far["expiration-enabled"], False) |
---|
14499 | + self.failUnlessIn("configured-expiration-mode", so_far) |
---|
14500 | + self.failUnlessIn("lease-age-histogram", so_far) |
---|
14501 | + lah = so_far["lease-age-histogram"] |
---|
14502 | + self.failUnlessEqual(type(lah), list) |
---|
14503 | + self.failUnlessEqual(len(lah), 1) |
---|
14504 | + self.failUnlessEqual(lah, [ (0.0, DAY, 1) ] ) |
---|
14505 | + self.failUnlessEqual(so_far["leases-per-share-histogram"], {1: 1}) |
---|
14506 | + self.failUnlessEqual(so_far["corrupt-shares"], []) |
---|
14507 | + sr1 = so_far["space-recovered"] |
---|
14508 | + self.failUnlessEqual(sr1["examined-buckets"], 1) |
---|
14509 | + self.failUnlessEqual(sr1["examined-shares"], 1) |
---|
14510 | + self.failUnlessEqual(sr1["actual-shares"], 0) |
---|
14511 | + self.failUnlessEqual(sr1["configured-diskbytes"], 0) |
---|
14512 | + self.failUnlessEqual(sr1["original-sharebytes"], 0) |
---|
14513 | + left = initial_state["estimated-remaining-cycle"] |
---|
14514 | + sr2 = left["space-recovered"] |
---|
14515 | + self.failUnless(sr2["examined-buckets"] > 0, sr2["examined-buckets"]) |
---|
14516 | + self.failUnless(sr2["examined-shares"] > 0, sr2["examined-shares"]) |
---|
14517 | + self.failIfEqual(sr2["actual-shares"], None) |
---|
14518 | + self.failIfEqual(sr2["configured-diskbytes"], None) |
---|
14519 | + self.failIfEqual(sr2["original-sharebytes"], None) |
---|
14520 | + d2.addCallback(_after_first_shareset) |
---|
14521 | |
---|
14522 | hunk ./src/allmydata/test/test_storage.py 3460 |
---|
14523 | - self.failUnlessIn("lease-age-histogram", last) |
---|
14524 | - lah = last["lease-age-histogram"] |
---|
14525 | - self.failUnlessEqual(type(lah), list) |
---|
14526 | - self.failUnlessEqual(len(lah), 1) |
---|
14527 | - self.failUnlessEqual(lah, [ (0.0, DAY, 6) ] ) |
---|
14528 | + def _render(ign): |
---|
14529 | + webstatus = StorageStatus(ss) |
---|
14530 | + return self.render1(webstatus) |
---|
14531 | + d2.addCallback(_render) |
---|
14532 | + def _check_html_in_cycle(html): |
---|
14533 | + s = remove_tags(html) |
---|
14534 | + self.failUnlessIn("So far, this cycle has examined " |
---|
14535 | + "1 shares in 1 buckets (0 mutable / 1 immutable) ", s) |
---|
14536 | + self.failUnlessIn("and has recovered: " |
---|
14537 | + "0 shares, 0 buckets (0 mutable / 0 immutable), " |
---|
14538 | + "0 B (0 B / 0 B)", s) |
---|
14539 | + self.failUnlessIn("If expiration were enabled, " |
---|
14540 | + "we would have recovered: " |
---|
14541 | + "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14542 | + " 0 B (0 B / 0 B) by now", s) |
---|
14543 | + self.failUnlessIn("and the remainder of this cycle " |
---|
14544 | + "would probably recover: " |
---|
14545 | + "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14546 | + " 0 B (0 B / 0 B)", s) |
---|
14547 | + self.failUnlessIn("and the whole cycle would probably recover: " |
---|
14548 | + "0 shares, 0 buckets (0 mutable / 0 immutable)," |
---|
14549 | + " 0 B (0 B / 0 B)", s) |
---|
14550 | + self.failUnlessIn("if we were strictly using each lease's default " |
---|
14551 | + "31-day lease lifetime", s) |
---|
14552 | + self.failUnlessIn("this cycle would be expected to recover: ", s) |
---|
14553 | + d2.addCallback(_check_html_in_cycle) |
---|
14554 | |
---|
14555 | hunk ./src/allmydata/test/test_storage.py 3487 |
---|
14556 | - self.failUnlessEqual(last["leases-per-share-histogram"], {1: 2, 2: 2}) |
---|
14557 | - self.failUnlessEqual(last["corrupt-shares"], []) |
---|
14558 | + # wait for the crawler to finish the first cycle. Nothing should have |
---|
14559 | + # been removed. |
---|
14560 | + def _wait(): |
---|
14561 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
14562 | + d2.addCallback(lambda ign: self.poll(_wait)) |
---|
14563 | |
---|
14564 | hunk ./src/allmydata/test/test_storage.py 3493 |
---|
14565 | - rec = last["space-recovered"] |
---|
14566 | - self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
14567 | - self.failUnlessEqual(rec["examined-shares"], 4) |
---|
14568 | - self.failUnlessEqual(rec["actual-buckets"], 0) |
---|
14569 | - self.failUnlessEqual(rec["original-buckets"], 0) |
---|
14570 | - self.failUnlessEqual(rec["configured-buckets"], 0) |
---|
14571 | - self.failUnlessEqual(rec["actual-shares"], 0) |
---|
14572 | - self.failUnlessEqual(rec["original-shares"], 0) |
---|
14573 | - self.failUnlessEqual(rec["configured-shares"], 0) |
---|
14574 | - self.failUnlessEqual(rec["actual-diskbytes"], 0) |
---|
14575 | - self.failUnlessEqual(rec["original-diskbytes"], 0) |
---|
14576 | - self.failUnlessEqual(rec["configured-diskbytes"], 0) |
---|
14577 | - self.failUnlessEqual(rec["actual-sharebytes"], 0) |
---|
14578 | - self.failUnlessEqual(rec["original-sharebytes"], 0) |
---|
14579 | - self.failUnlessEqual(rec["configured-sharebytes"], 0) |
---|
14580 | + def _after_first_cycle(ignored): |
---|
14581 | + s = lc.get_state() |
---|
14582 | + self.failIf("cycle-to-date" in s) |
---|
14583 | + self.failIf("estimated-remaining-cycle" in s) |
---|
14584 | + self.failIf("estimated-current-cycle" in s) |
---|
14585 | + last = s["history"][0] |
---|
14586 | + self.failUnlessIn("cycle-start-finish-times", last) |
---|
14587 | + self.failUnlessEqual(type(last["cycle-start-finish-times"]), tuple) |
---|
14588 | + self.failUnlessEqual(last["expiration-enabled"], False) |
---|
14589 | + self.failUnlessIn("configured-expiration-mode", last) |
---|
14590 | |
---|
14591 | hunk ./src/allmydata/test/test_storage.py 3504 |
---|
14592 | - def _get_sharefile(si): |
---|
14593 | - return list(ss._iter_share_files(si))[0] |
---|
14594 | - def count_leases(si): |
---|
14595 | - return len(list(_get_sharefile(si).get_leases())) |
---|
14596 | - self.failUnlessEqual(count_leases(immutable_si_0), 1) |
---|
14597 | - self.failUnlessEqual(count_leases(immutable_si_1), 2) |
---|
14598 | - self.failUnlessEqual(count_leases(mutable_si_2), 1) |
---|
14599 | - self.failUnlessEqual(count_leases(mutable_si_3), 2) |
---|
14600 | - d.addCallback(_after_first_cycle) |
---|
14601 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
14602 | - def _check_html(html): |
---|
14603 | - s = remove_tags(html) |
---|
14604 | - self.failUnlessIn("recovered: 0 shares, 0 buckets " |
---|
14605 | - "(0 mutable / 0 immutable), 0 B (0 B / 0 B) ", s) |
---|
14606 | - self.failUnlessIn("and saw a total of 4 shares, 4 buckets " |
---|
14607 | - "(2 mutable / 2 immutable),", s) |
---|
14608 | - self.failUnlessIn("but expiration was not enabled", s) |
---|
14609 | - d.addCallback(_check_html) |
---|
14610 | - d.addCallback(lambda ign: self.render_json(webstatus)) |
---|
14611 | - def _check_json(json): |
---|
14612 | - data = simplejson.loads(json) |
---|
14613 | - self.failUnlessIn("lease-checker", data) |
---|
14614 | - self.failUnlessIn("lease-checker-progress", data) |
---|
14615 | - d.addCallback(_check_json) |
---|
14616 | + self.failUnlessIn("lease-age-histogram", last) |
---|
14617 | + lah = last["lease-age-histogram"] |
---|
14618 | + self.failUnlessEqual(type(lah), list) |
---|
14619 | + self.failUnlessEqual(len(lah), 1) |
---|
14620 | + self.failUnlessEqual(lah, [ (0.0, DAY, 6) ] ) |
---|
14621 | + |
---|
14622 | + self.failUnlessEqual(last["leases-per-share-histogram"], {1: 2, 2: 2}) |
---|
14623 | + self.failUnlessEqual(last["corrupt-shares"], []) |
---|
14624 | + |
---|
14625 | + rec = last["space-recovered"] |
---|
14626 | + self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
14627 | + self.failUnlessEqual(rec["examined-shares"], 4) |
---|
14628 | + self.failUnlessEqual(rec["actual-buckets"], 0) |
---|
14629 | + self.failUnlessEqual(rec["original-buckets"], 0) |
---|
14630 | + self.failUnlessEqual(rec["configured-buckets"], 0) |
---|
14631 | + self.failUnlessEqual(rec["actual-shares"], 0) |
---|
14632 | + self.failUnlessEqual(rec["original-shares"], 0) |
---|
14633 | + self.failUnlessEqual(rec["configured-shares"], 0) |
---|
14634 | + self.failUnlessEqual(rec["actual-diskbytes"], 0) |
---|
14635 | + self.failUnlessEqual(rec["original-diskbytes"], 0) |
---|
14636 | + self.failUnlessEqual(rec["configured-diskbytes"], 0) |
---|
14637 | + self.failUnlessEqual(rec["actual-sharebytes"], 0) |
---|
14638 | + self.failUnlessEqual(rec["original-sharebytes"], 0) |
---|
14639 | + self.failUnlessEqual(rec["configured-sharebytes"], 0) |
---|
14640 | + d2.addCallback(_after_first_cycle) |
---|
14641 | + |
---|
14642 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_0, 1)) |
---|
14643 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 2)) |
---|
14644 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_2, 1)) |
---|
14645 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 2)) |
---|
14646 | + |
---|
14647 | + d2.addCallback(_render) |
---|
14648 | + def _check_html(html): |
---|
14649 | + s = remove_tags(html) |
---|
14650 | + self.failUnlessIn("recovered: 0 shares, 0 buckets " |
---|
14651 | + "(0 mutable / 0 immutable), 0 B (0 B / 0 B) ", s) |
---|
14652 | + self.failUnlessIn("and saw a total of 4 shares, 4 buckets " |
---|
14653 | + "(2 mutable / 2 immutable),", s) |
---|
14654 | + self.failUnlessIn("but expiration was not enabled", s) |
---|
14655 | + d2.addCallback(_check_html) |
---|
14656 | + |
---|
14657 | + def _render_json(ign): |
---|
14658 | + webstatus = StorageStatus(ss) |
---|
14659 | + return self.render_json(webstatus) |
---|
14660 | + d2.addCallback(_render_json) |
---|
14661 | + def _check_json(json): |
---|
14662 | + data = simplejson.loads(json) |
---|
14663 | + self.failUnlessIn("lease-checker", data) |
---|
14664 | + self.failUnlessIn("lease-checker-progress", data) |
---|
14665 | + d2.addCallback(_check_json) |
---|
14666 | + return d2 |
---|
14667 | + d.addCallback(_do_test) |
---|
14668 | return d |
---|
14669 | |
---|
14670 | hunk ./src/allmydata/test/test_storage.py 3558 |
---|
14671 | - def backdate_lease(self, sf, renew_secret, new_expire_time): |
---|
14672 | - # ShareFile.renew_lease ignores attempts to back-date a lease (i.e. |
---|
14673 | - # "renew" a lease with a new_expire_time that is older than what the |
---|
14674 | - # current lease has), so we have to reach inside it. |
---|
14675 | - for i,lease in enumerate(sf.get_leases()): |
---|
14676 | - if lease.renew_secret == renew_secret: |
---|
14677 | - lease.expiration_time = new_expire_time |
---|
14678 | - f = open(sf.home, 'rb+') |
---|
14679 | - sf._write_lease_record(f, i, lease) |
---|
14680 | + def _backdate_leases(self, ss, si, renew_secrets, new_expire_time): |
---|
14681 | + # The renew_lease method on share files is specified to ignore attempts |
---|
14682 | + # to back-date a lease (i.e. "renew" a lease with a new_expire_time that |
---|
14683 | + # is older than what the current lease has), so we have to reach inside it. |
---|
14684 | + # This works only for shares implemented by the disk backend. |
---|
14685 | + |
---|
14686 | + d = defer.succeed(None) |
---|
14687 | + d.addCallback(lambda ign: ss.backend.get_shareset(si).get_share(0)) |
---|
14688 | + def _got_share(sf): |
---|
14689 | + f = sf._get_filepath().open('rb+') |
---|
14690 | + try: |
---|
14691 | + renewed = 0 |
---|
14692 | + for i, lease in enumerate(sf.get_leases()): |
---|
14693 | + if lease.renew_secret in renew_secrets: |
---|
14694 | + lease.expiration_time = new_expire_time |
---|
14695 | + sf._write_lease_record(f, i, lease) |
---|
14696 | + renewed += 1 |
---|
14697 | + if renewed != len(renew_secrets): |
---|
14698 | + raise IndexError("unable to backdate leases") |
---|
14699 | + finally: |
---|
14700 | f.close() |
---|
14701 | hunk ./src/allmydata/test/test_storage.py 3579 |
---|
14702 | - return |
---|
14703 | - raise IndexError("unable to renew non-existent lease") |
---|
14704 | + d.addCallback(_got_share) |
---|
14705 | + return d |
---|
14706 | + |
---|
14707 | + def _add_share_size(self, accum, ss, si): |
---|
14708 | + d = defer.succeed(None) |
---|
14709 | + d.addCallback(lambda ign: ss.backend.get_shareset(si).get_shares()) |
---|
14710 | + d.addCallback(lambda (shares, corrupted): accum + list(shares)[0].get_size()) |
---|
14711 | + return d |
---|
14712 | + |
---|
14713 | + def _assert_sharecount(self, ss, si, expected): |
---|
14714 | + d = defer.succeed(None) |
---|
14715 | + d.addCallback(lambda ign: ss.backend.get_shareset(si).get_shares()) |
---|
14716 | + def _got_shares( (shares, corrupted) ): |
---|
14717 | + self.failUnlessEqual(len(shares), expected, "share count for %r" % (si,)) |
---|
14718 | + self.failUnlessEqual(len(corrupted), 0, str(corrupted)) |
---|
14719 | + d.addCallback(_got_shares) |
---|
14720 | + return d |
---|
14721 | + |
---|
14722 | + def _assert_leasecount(self, ss, si, expected): |
---|
14723 | + d = defer.succeed(None) |
---|
14724 | + d.addCallback(lambda ign: ss.backend.get_shareset(si).get_shares()) |
---|
14725 | + def _got_shares( (shares, corrupted) ): |
---|
14726 | + share = shares[0] |
---|
14727 | + self.failUnlessEqual(len(list(share.get_leases())), expected, "lease count for %r" % (si,)) |
---|
14728 | + d.addCallback(_got_shares) |
---|
14729 | + return d |
---|
14730 | |
---|
14731 | def test_expire_age(self): |
---|
14732 | basedir = "storage/LeaseCrawler/expire_age" |
---|
14733 | hunk ./src/allmydata/test/test_storage.py 3608 |
---|
14734 | - fileutil.make_dirs(basedir) |
---|
14735 | - # setting expiration_time to 2000 means that any lease which is more |
---|
14736 | - # than 2000s old will be expired. |
---|
14737 | - ss = InstrumentedStorageServer(basedir, "\x00" * 20, |
---|
14738 | - expiration_enabled=True, |
---|
14739 | - expiration_mode="age", |
---|
14740 | - expiration_override_lease_duration=2000) |
---|
14741 | + fp = FilePath(basedir) |
---|
14742 | + backend = DiskBackend(fp) |
---|
14743 | + |
---|
14744 | + # setting 'override_lease_duration' to 2000 means that any lease that |
---|
14745 | + # is more than 2000 seconds old will be expired. |
---|
14746 | + expiration_policy = { |
---|
14747 | + 'enabled': True, |
---|
14748 | + 'mode': 'age', |
---|
14749 | + 'override_lease_duration': 2000, |
---|
14750 | + 'sharetypes': ('mutable', 'immutable'), |
---|
14751 | + } |
---|
14752 | + ss = InstrumentedStorageServer("\x00" * 20, backend, fp, expiration_policy=expiration_policy) |
---|
14753 | + |
---|
14754 | # make it start sooner than usual. |
---|
14755 | lc = ss.lease_checker |
---|
14756 | lc.slow_start = 0 |
---|
14757 | hunk ./src/allmydata/test/test_storage.py 3624 |
---|
14758 | - lc.stop_after_first_bucket = True |
---|
14759 | - webstatus = StorageStatus(ss) |
---|
14760 | |
---|
14761 | # create a few shares, with some leases on them |
---|
14762 | hunk ./src/allmydata/test/test_storage.py 3626 |
---|
14763 | - self.make_shares(ss) |
---|
14764 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
14765 | + d = self.make_shares(ss) |
---|
14766 | + def _do_test(ign): |
---|
14767 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
14768 | + now = time.time() |
---|
14769 | |
---|
14770 | hunk ./src/allmydata/test/test_storage.py 3631 |
---|
14771 | - def count_shares(si): |
---|
14772 | - return len(list(ss._iter_share_files(si))) |
---|
14773 | - def _get_sharefile(si): |
---|
14774 | - return list(ss._iter_share_files(si))[0] |
---|
14775 | - def count_leases(si): |
---|
14776 | - return len(list(_get_sharefile(si).get_leases())) |
---|
14777 | + d2 = defer.succeed(None) |
---|
14778 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 1)) |
---|
14779 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_0, 1)) |
---|
14780 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 1)) |
---|
14781 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 2)) |
---|
14782 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 1)) |
---|
14783 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_2, 1)) |
---|
14784 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 1)) |
---|
14785 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 2)) |
---|
14786 | |
---|
14787 | hunk ./src/allmydata/test/test_storage.py 3641 |
---|
14788 | - self.failUnlessEqual(count_shares(immutable_si_0), 1) |
---|
14789 | - self.failUnlessEqual(count_leases(immutable_si_0), 1) |
---|
14790 | - self.failUnlessEqual(count_shares(immutable_si_1), 1) |
---|
14791 | - self.failUnlessEqual(count_leases(immutable_si_1), 2) |
---|
14792 | - self.failUnlessEqual(count_shares(mutable_si_2), 1) |
---|
14793 | - self.failUnlessEqual(count_leases(mutable_si_2), 1) |
---|
14794 | - self.failUnlessEqual(count_shares(mutable_si_3), 1) |
---|
14795 | - self.failUnlessEqual(count_leases(mutable_si_3), 2) |
---|
14796 | + # artificially crank back the expiration time on the first lease of |
---|
14797 | + # each share, to make it look like it expired already (age=1000s). |
---|
14798 | + # Some shares have an extra lease which is set to expire at the |
---|
14799 | + # default time in 31 days from now (age=31days). We then run the |
---|
14800 | + # crawler, which will expire the first lease, making some shares get |
---|
14801 | + # deleted and others stay alive (with one remaining lease) |
---|
14802 | |
---|
14803 | hunk ./src/allmydata/test/test_storage.py 3648 |
---|
14804 | - # artificially crank back the expiration time on the first lease of |
---|
14805 | - # each share, to make it look like it expired already (age=1000s). |
---|
14806 | - # Some shares have an extra lease which is set to expire at the |
---|
14807 | - # default time in 31 days from now (age=31days). We then run the |
---|
14808 | - # crawler, which will expire the first lease, making some shares get |
---|
14809 | - # deleted and others stay alive (with one remaining lease) |
---|
14810 | - now = time.time() |
---|
14811 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_0, self.renew_secrets[0:1], now - 1000)) |
---|
14812 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_1, self.renew_secrets[1:2], now - 1000)) |
---|
14813 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_2, self.renew_secrets[3:4], now - 1000)) |
---|
14814 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_3, self.renew_secrets[4:5], now - 1000)) |
---|
14815 | |
---|
14816 | hunk ./src/allmydata/test/test_storage.py 3653 |
---|
14817 | - sf0 = _get_sharefile(immutable_si_0) |
---|
14818 | - self.backdate_lease(sf0, self.renew_secrets[0], now - 1000) |
---|
14819 | - sf0_size = os.stat(sf0.home).st_size |
---|
14820 | + d2.addCallback(lambda ign: 0) |
---|
14821 | + d2.addCallback(self._add_share_size, ss, immutable_si_0) |
---|
14822 | + d2.addCallback(self._add_share_size, ss, mutable_si_2) |
---|
14823 | |
---|
14824 | hunk ./src/allmydata/test/test_storage.py 3657 |
---|
14825 | - # immutable_si_1 gets an extra lease |
---|
14826 | - sf1 = _get_sharefile(immutable_si_1) |
---|
14827 | - self.backdate_lease(sf1, self.renew_secrets[1], now - 1000) |
---|
14828 | + def _got_total_size(total_size): |
---|
14829 | + d3 = defer.Deferred() |
---|
14830 | + lc.hook_ds = [d3] |
---|
14831 | + ss.setServiceParent(self.s) |
---|
14832 | |
---|
14833 | hunk ./src/allmydata/test/test_storage.py 3662 |
---|
14834 | - sf2 = _get_sharefile(mutable_si_2) |
---|
14835 | - self.backdate_lease(sf2, self.renew_secrets[3], now - 1000) |
---|
14836 | - sf2_size = os.stat(sf2.home).st_size |
---|
14837 | + # examine the state right after the first shareset has been processed |
---|
14838 | + webstatus = StorageStatus(ss) |
---|
14839 | + d3.addCallback(lambda ign: self.render1(webstatus)) |
---|
14840 | |
---|
14841 | hunk ./src/allmydata/test/test_storage.py 3666 |
---|
14842 | - # mutable_si_3 gets an extra lease |
---|
14843 | - sf3 = _get_sharefile(mutable_si_3) |
---|
14844 | - self.backdate_lease(sf3, self.renew_secrets[4], now - 1000) |
---|
14845 | - |
---|
14846 | - ss.setServiceParent(self.s) |
---|
14847 | + def _check_html_in_cycle(html): |
---|
14848 | + s = remove_tags(html) |
---|
14849 | + # the first shareset encountered gets deleted, and its prefix |
---|
14850 | + # happens to be about 1/5th of the way through the ring, so the |
---|
14851 | + # predictor thinks we'll have 5 shares and that we'll delete them |
---|
14852 | + # all. This part of the test depends upon the SIs landing right |
---|
14853 | + # where they do now. |
---|
14854 | + self.failUnlessIn("The remainder of this cycle is expected to " |
---|
14855 | + "recover: 4 shares, 4 buckets", s) |
---|
14856 | + self.failUnlessIn("The whole cycle is expected to examine " |
---|
14857 | + "5 shares in 5 buckets and to recover: " |
---|
14858 | + "5 shares, 5 buckets", s) |
---|
14859 | + d3.addCallback(_check_html_in_cycle) |
---|
14860 | |
---|
14861 | hunk ./src/allmydata/test/test_storage.py 3680 |
---|
14862 | - d = fireEventually() |
---|
14863 | - # examine the state right after the first bucket has been processed |
---|
14864 | - def _after_first_bucket(ignored): |
---|
14865 | - p = lc.get_progress() |
---|
14866 | - if not p["cycle-in-progress"]: |
---|
14867 | - d2 = fireEventually() |
---|
14868 | - d2.addCallback(_after_first_bucket) |
---|
14869 | - return d2 |
---|
14870 | - d.addCallback(_after_first_bucket) |
---|
14871 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
14872 | - def _check_html_in_cycle(html): |
---|
14873 | - s = remove_tags(html) |
---|
14874 | - # the first bucket encountered gets deleted, and its prefix |
---|
14875 | - # happens to be about 1/5th of the way through the ring, so the |
---|
14876 | - # predictor thinks we'll have 5 shares and that we'll delete them |
---|
14877 | - # all. This part of the test depends upon the SIs landing right |
---|
14878 | - # where they do now. |
---|
14879 | - self.failUnlessIn("The remainder of this cycle is expected to " |
---|
14880 | - "recover: 4 shares, 4 buckets", s) |
---|
14881 | - self.failUnlessIn("The whole cycle is expected to examine " |
---|
14882 | - "5 shares in 5 buckets and to recover: " |
---|
14883 | - "5 shares, 5 buckets", s) |
---|
14884 | - d.addCallback(_check_html_in_cycle) |
---|
14885 | + # wait for the crawler to finish the first cycle. Two shares should |
---|
14886 | + # have been removed |
---|
14887 | + def _wait(): |
---|
14888 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
14889 | + d3.addCallback(lambda ign: self.poll(_wait)) |
---|
14890 | |
---|
14891 | hunk ./src/allmydata/test/test_storage.py 3686 |
---|
14892 | - # wait for the crawler to finish the first cycle. Two shares should |
---|
14893 | - # have been removed |
---|
14894 | - def _wait(): |
---|
14895 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
14896 | - d.addCallback(lambda ign: self.poll(_wait)) |
---|
14897 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 0)) |
---|
14898 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 1)) |
---|
14899 | + d3.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 1)) |
---|
14900 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 0)) |
---|
14901 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 1)) |
---|
14902 | + d3.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 1)) |
---|
14903 | |
---|
14904 | hunk ./src/allmydata/test/test_storage.py 3693 |
---|
14905 | - def _after_first_cycle(ignored): |
---|
14906 | - self.failUnlessEqual(count_shares(immutable_si_0), 0) |
---|
14907 | - self.failUnlessEqual(count_shares(immutable_si_1), 1) |
---|
14908 | - self.failUnlessEqual(count_leases(immutable_si_1), 1) |
---|
14909 | - self.failUnlessEqual(count_shares(mutable_si_2), 0) |
---|
14910 | - self.failUnlessEqual(count_shares(mutable_si_3), 1) |
---|
14911 | - self.failUnlessEqual(count_leases(mutable_si_3), 1) |
---|
14912 | + def _after_first_cycle(ignored): |
---|
14913 | + s = lc.get_state() |
---|
14914 | + last = s["history"][0] |
---|
14915 | |
---|
14916 | hunk ./src/allmydata/test/test_storage.py 3697 |
---|
14917 | - s = lc.get_state() |
---|
14918 | - last = s["history"][0] |
---|
14919 | + self.failUnlessEqual(last["expiration-enabled"], True) |
---|
14920 | + self.failUnlessEqual(last["configured-expiration-mode"], |
---|
14921 | + ("age", 2000, None, ("mutable", "immutable"))) |
---|
14922 | + self.failUnlessEqual(last["leases-per-share-histogram"], {1: 2, 2: 2}) |
---|
14923 | |
---|
14924 | hunk ./src/allmydata/test/test_storage.py 3702 |
---|
14925 | - self.failUnlessEqual(last["expiration-enabled"], True) |
---|
14926 | - self.failUnlessEqual(last["configured-expiration-mode"], |
---|
14927 | - ("age", 2000, None, ("mutable", "immutable"))) |
---|
14928 | - self.failUnlessEqual(last["leases-per-share-histogram"], {1: 2, 2: 2}) |
---|
14929 | + rec = last["space-recovered"] |
---|
14930 | + self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
14931 | + self.failUnlessEqual(rec["examined-shares"], 4) |
---|
14932 | + self.failUnlessEqual(rec["actual-buckets"], 2) |
---|
14933 | + self.failUnlessEqual(rec["original-buckets"], 2) |
---|
14934 | + self.failUnlessEqual(rec["configured-buckets"], 2) |
---|
14935 | + self.failUnlessEqual(rec["actual-shares"], 2) |
---|
14936 | + self.failUnlessEqual(rec["original-shares"], 2) |
---|
14937 | + self.failUnlessEqual(rec["configured-shares"], 2) |
---|
14938 | + self.failUnlessEqual(rec["actual-sharebytes"], total_size) |
---|
14939 | + self.failUnlessEqual(rec["original-sharebytes"], total_size) |
---|
14940 | + self.failUnlessEqual(rec["configured-sharebytes"], total_size) |
---|
14941 | |
---|
14942 | hunk ./src/allmydata/test/test_storage.py 3715 |
---|
14943 | - rec = last["space-recovered"] |
---|
14944 | - self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
14945 | - self.failUnlessEqual(rec["examined-shares"], 4) |
---|
14946 | - self.failUnlessEqual(rec["actual-buckets"], 2) |
---|
14947 | - self.failUnlessEqual(rec["original-buckets"], 2) |
---|
14948 | - self.failUnlessEqual(rec["configured-buckets"], 2) |
---|
14949 | - self.failUnlessEqual(rec["actual-shares"], 2) |
---|
14950 | - self.failUnlessEqual(rec["original-shares"], 2) |
---|
14951 | - self.failUnlessEqual(rec["configured-shares"], 2) |
---|
14952 | - size = sf0_size + sf2_size |
---|
14953 | - self.failUnlessEqual(rec["actual-sharebytes"], size) |
---|
14954 | - self.failUnlessEqual(rec["original-sharebytes"], size) |
---|
14955 | - self.failUnlessEqual(rec["configured-sharebytes"], size) |
---|
14956 | - # different platforms have different notions of "blocks used by |
---|
14957 | - # this file", so merely assert that it's a number |
---|
14958 | - self.failUnless(rec["actual-diskbytes"] >= 0, |
---|
14959 | - rec["actual-diskbytes"]) |
---|
14960 | - self.failUnless(rec["original-diskbytes"] >= 0, |
---|
14961 | - rec["original-diskbytes"]) |
---|
14962 | - self.failUnless(rec["configured-diskbytes"] >= 0, |
---|
14963 | - rec["configured-diskbytes"]) |
---|
14964 | - d.addCallback(_after_first_cycle) |
---|
14965 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
14966 | - def _check_html(html): |
---|
14967 | - s = remove_tags(html) |
---|
14968 | - self.failUnlessIn("Expiration Enabled: expired leases will be removed", s) |
---|
14969 | - self.failUnlessIn("Leases created or last renewed more than 33 minutes ago will be considered expired.", s) |
---|
14970 | - self.failUnlessIn(" recovered: 2 shares, 2 buckets (1 mutable / 1 immutable), ", s) |
---|
14971 | - d.addCallback(_check_html) |
---|
14972 | + # different platforms have different notions of "blocks used by |
---|
14973 | + # this file", so merely assert that it's a number |
---|
14974 | + self.failUnless(rec["actual-diskbytes"] >= 0, |
---|
14975 | + rec["actual-diskbytes"]) |
---|
14976 | + self.failUnless(rec["original-diskbytes"] >= 0, |
---|
14977 | + rec["original-diskbytes"]) |
---|
14978 | + self.failUnless(rec["configured-diskbytes"] >= 0, |
---|
14979 | + rec["configured-diskbytes"]) |
---|
14980 | + d3.addCallback(_after_first_cycle) |
---|
14981 | + d3.addCallback(lambda ign: self.render1(webstatus)) |
---|
14982 | + def _check_html(html): |
---|
14983 | + s = remove_tags(html) |
---|
14984 | + self.failUnlessIn("Expiration Enabled: expired leases will be removed", s) |
---|
14985 | + self.failUnlessIn("Leases created or last renewed more than 33 minutes ago will be considered expired.", s) |
---|
14986 | + self.failUnlessIn(" recovered: 2 shares, 2 buckets (1 mutable / 1 immutable), ", s) |
---|
14987 | + d3.addCallback(_check_html) |
---|
14988 | + return d3 |
---|
14989 | + d2.addCallback(_got_total_size) |
---|
14990 | + return d2 |
---|
14991 | + d.addCallback(_do_test) |
---|
14992 | return d |
---|
14993 | |
---|
14994 | def test_expire_cutoff_date(self): |
---|
14995 | hunk ./src/allmydata/test/test_storage.py 3738 |
---|
14996 | + # FIXME too much duplicated code between this and test_expire_age |
---|
14997 | + |
---|
14998 | basedir = "storage/LeaseCrawler/expire_cutoff_date" |
---|
14999 | hunk ./src/allmydata/test/test_storage.py 3741 |
---|
15000 | - fileutil.make_dirs(basedir) |
---|
15001 | - # setting cutoff-date to 2000 seconds ago means that any lease which |
---|
15002 | - # is more than 2000s old will be expired. |
---|
15003 | + fp = FilePath(basedir) |
---|
15004 | + backend = DiskBackend(fp) |
---|
15005 | + |
---|
15006 | + # setting 'cutoff_date' to 2000 seconds ago means that any lease that |
---|
15007 | + # is more than 2000 seconds old will be expired. |
---|
15008 | now = time.time() |
---|
15009 | then = int(now - 2000) |
---|
15010 | hunk ./src/allmydata/test/test_storage.py 3748 |
---|
15011 | - ss = InstrumentedStorageServer(basedir, "\x00" * 20, |
---|
15012 | - expiration_enabled=True, |
---|
15013 | - expiration_mode="cutoff-date", |
---|
15014 | - expiration_cutoff_date=then) |
---|
15015 | + expiration_policy = { |
---|
15016 | + 'enabled': True, |
---|
15017 | + 'mode': 'cutoff-date', |
---|
15018 | + 'cutoff_date': then, |
---|
15019 | + 'sharetypes': ('mutable', 'immutable'), |
---|
15020 | + } |
---|
15021 | + ss = InstrumentedStorageServer("\x00" * 20, backend, fp, expiration_policy=expiration_policy) |
---|
15022 | + |
---|
15023 | # make it start sooner than usual. |
---|
15024 | lc = ss.lease_checker |
---|
15025 | lc.slow_start = 0 |
---|
15026 | hunk ./src/allmydata/test/test_storage.py 3759 |
---|
15027 | - lc.stop_after_first_bucket = True |
---|
15028 | - webstatus = StorageStatus(ss) |
---|
15029 | |
---|
15030 | # create a few shares, with some leases on them |
---|
15031 | hunk ./src/allmydata/test/test_storage.py 3761 |
---|
15032 | - self.make_shares(ss) |
---|
15033 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15034 | + d = self.make_shares(ss) |
---|
15035 | + def _do_test(ign): |
---|
15036 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15037 | |
---|
15038 | hunk ./src/allmydata/test/test_storage.py 3765 |
---|
15039 | - def count_shares(si): |
---|
15040 | - return len(list(ss._iter_share_files(si))) |
---|
15041 | - def _get_sharefile(si): |
---|
15042 | - return list(ss._iter_share_files(si))[0] |
---|
15043 | - def count_leases(si): |
---|
15044 | - return len(list(_get_sharefile(si).get_leases())) |
---|
15045 | + d2 = defer.succeed(None) |
---|
15046 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 1)) |
---|
15047 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_0, 1)) |
---|
15048 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 1)) |
---|
15049 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 2)) |
---|
15050 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 1)) |
---|
15051 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_2, 1)) |
---|
15052 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 1)) |
---|
15053 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 2)) |
---|
15054 | |
---|
15055 | hunk ./src/allmydata/test/test_storage.py 3775 |
---|
15056 | - self.failUnlessEqual(count_shares(immutable_si_0), 1) |
---|
15057 | - self.failUnlessEqual(count_leases(immutable_si_0), 1) |
---|
15058 | - self.failUnlessEqual(count_shares(immutable_si_1), 1) |
---|
15059 | - self.failUnlessEqual(count_leases(immutable_si_1), 2) |
---|
15060 | - self.failUnlessEqual(count_shares(mutable_si_2), 1) |
---|
15061 | - self.failUnlessEqual(count_leases(mutable_si_2), 1) |
---|
15062 | - self.failUnlessEqual(count_shares(mutable_si_3), 1) |
---|
15063 | - self.failUnlessEqual(count_leases(mutable_si_3), 2) |
---|
15064 | + # artificially crank back the expiration time on the first lease of |
---|
15065 | + # each share, to make it look like was renewed 3000s ago. To achieve |
---|
15066 | + # this, we need to set the expiration time to now-3000+31days. This |
---|
15067 | + # will change when the lease format is improved to contain both |
---|
15068 | + # create/renew time and duration. |
---|
15069 | + new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15070 | |
---|
15071 | hunk ./src/allmydata/test/test_storage.py 3782 |
---|
15072 | - # artificially crank back the expiration time on the first lease of |
---|
15073 | - # each share, to make it look like was renewed 3000s ago. To achieve |
---|
15074 | - # this, we need to set the expiration time to now-3000+31days. This |
---|
15075 | - # will change when the lease format is improved to contain both |
---|
15076 | - # create/renew time and duration. |
---|
15077 | - new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15078 | + # Some shares have an extra lease which is set to expire at the |
---|
15079 | + # default time in 31 days from now (age=31days). We then run the |
---|
15080 | + # crawler, which will expire the first lease, making some shares get |
---|
15081 | + # deleted and others stay alive (with one remaining lease) |
---|
15082 | |
---|
15083 | hunk ./src/allmydata/test/test_storage.py 3787 |
---|
15084 | - # Some shares have an extra lease which is set to expire at the |
---|
15085 | - # default time in 31 days from now (age=31days). We then run the |
---|
15086 | - # crawler, which will expire the first lease, making some shares get |
---|
15087 | - # deleted and others stay alive (with one remaining lease) |
---|
15088 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_0, self.renew_secrets[0:1], |
---|
15089 | + new_expiration_time)) |
---|
15090 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_1, self.renew_secrets[1:2], |
---|
15091 | + new_expiration_time)) |
---|
15092 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_2, self.renew_secrets[3:4], |
---|
15093 | + new_expiration_time)) |
---|
15094 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_3, self.renew_secrets[4:5], |
---|
15095 | + new_expiration_time)) |
---|
15096 | |
---|
15097 | hunk ./src/allmydata/test/test_storage.py 3796 |
---|
15098 | - sf0 = _get_sharefile(immutable_si_0) |
---|
15099 | - self.backdate_lease(sf0, self.renew_secrets[0], new_expiration_time) |
---|
15100 | - sf0_size = os.stat(sf0.home).st_size |
---|
15101 | + d2.addCallback(lambda ign: 0) |
---|
15102 | + d2.addCallback(self._add_share_size, ss, immutable_si_0) |
---|
15103 | + d2.addCallback(self._add_share_size, ss, mutable_si_2) |
---|
15104 | |
---|
15105 | hunk ./src/allmydata/test/test_storage.py 3800 |
---|
15106 | - # immutable_si_1 gets an extra lease |
---|
15107 | - sf1 = _get_sharefile(immutable_si_1) |
---|
15108 | - self.backdate_lease(sf1, self.renew_secrets[1], new_expiration_time) |
---|
15109 | + def _got_total_size(total_size): |
---|
15110 | + d3 = defer.Deferred() |
---|
15111 | + lc.hook_ds = [d3] |
---|
15112 | + ss.setServiceParent(self.s) |
---|
15113 | |
---|
15114 | hunk ./src/allmydata/test/test_storage.py 3805 |
---|
15115 | - sf2 = _get_sharefile(mutable_si_2) |
---|
15116 | - self.backdate_lease(sf2, self.renew_secrets[3], new_expiration_time) |
---|
15117 | - sf2_size = os.stat(sf2.home).st_size |
---|
15118 | + # examine the state right after the first shareset has been processed |
---|
15119 | + webstatus = StorageStatus(ss) |
---|
15120 | + d3.addCallback(lambda ign: self.render1(webstatus)) |
---|
15121 | |
---|
15122 | hunk ./src/allmydata/test/test_storage.py 3809 |
---|
15123 | - # mutable_si_3 gets an extra lease |
---|
15124 | - sf3 = _get_sharefile(mutable_si_3) |
---|
15125 | - self.backdate_lease(sf3, self.renew_secrets[4], new_expiration_time) |
---|
15126 | + def _check_html_in_cycle(html): |
---|
15127 | + s = remove_tags(html) |
---|
15128 | + # the first shareset encountered gets deleted, and its prefix |
---|
15129 | + # happens to be about 1/5th of the way through the ring, so the |
---|
15130 | + # predictor thinks we'll have 5 shares and that we'll delete them |
---|
15131 | + # all. This part of the test depends upon the SIs landing right |
---|
15132 | + # where they do now. |
---|
15133 | + self.failUnlessIn("The remainder of this cycle is expected to " |
---|
15134 | + "recover: 4 shares, 4 buckets", s) |
---|
15135 | + self.failUnlessIn("The whole cycle is expected to examine " |
---|
15136 | + "5 shares in 5 buckets and to recover: " |
---|
15137 | + "5 shares, 5 buckets", s) |
---|
15138 | + d3.addCallback(_check_html_in_cycle) |
---|
15139 | |
---|
15140 | hunk ./src/allmydata/test/test_storage.py 3823 |
---|
15141 | - ss.setServiceParent(self.s) |
---|
15142 | - |
---|
15143 | - d = fireEventually() |
---|
15144 | - # examine the state right after the first bucket has been processed |
---|
15145 | - def _after_first_bucket(ignored): |
---|
15146 | - p = lc.get_progress() |
---|
15147 | - if not p["cycle-in-progress"]: |
---|
15148 | - d2 = fireEventually() |
---|
15149 | - d2.addCallback(_after_first_bucket) |
---|
15150 | - return d2 |
---|
15151 | - d.addCallback(_after_first_bucket) |
---|
15152 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
15153 | - def _check_html_in_cycle(html): |
---|
15154 | - s = remove_tags(html) |
---|
15155 | - # the first bucket encountered gets deleted, and its prefix |
---|
15156 | - # happens to be about 1/5th of the way through the ring, so the |
---|
15157 | - # predictor thinks we'll have 5 shares and that we'll delete them |
---|
15158 | - # all. This part of the test depends upon the SIs landing right |
---|
15159 | - # where they do now. |
---|
15160 | - self.failUnlessIn("The remainder of this cycle is expected to " |
---|
15161 | - "recover: 4 shares, 4 buckets", s) |
---|
15162 | - self.failUnlessIn("The whole cycle is expected to examine " |
---|
15163 | - "5 shares in 5 buckets and to recover: " |
---|
15164 | - "5 shares, 5 buckets", s) |
---|
15165 | - d.addCallback(_check_html_in_cycle) |
---|
15166 | + # wait for the crawler to finish the first cycle. Two shares should |
---|
15167 | + # have been removed |
---|
15168 | + def _wait(): |
---|
15169 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
15170 | + d3.addCallback(lambda ign: self.poll(_wait)) |
---|
15171 | |
---|
15172 | hunk ./src/allmydata/test/test_storage.py 3829 |
---|
15173 | - # wait for the crawler to finish the first cycle. Two shares should |
---|
15174 | - # have been removed |
---|
15175 | - def _wait(): |
---|
15176 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
15177 | - d.addCallback(lambda ign: self.poll(_wait)) |
---|
15178 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 0)) |
---|
15179 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 1)) |
---|
15180 | + d3.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 1)) |
---|
15181 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 0)) |
---|
15182 | + d3.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 1)) |
---|
15183 | + d3.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 1)) |
---|
15184 | |
---|
15185 | hunk ./src/allmydata/test/test_storage.py 3836 |
---|
15186 | - def _after_first_cycle(ignored): |
---|
15187 | - self.failUnlessEqual(count_shares(immutable_si_0), 0) |
---|
15188 | - self.failUnlessEqual(count_shares(immutable_si_1), 1) |
---|
15189 | - self.failUnlessEqual(count_leases(immutable_si_1), 1) |
---|
15190 | - self.failUnlessEqual(count_shares(mutable_si_2), 0) |
---|
15191 | - self.failUnlessEqual(count_shares(mutable_si_3), 1) |
---|
15192 | - self.failUnlessEqual(count_leases(mutable_si_3), 1) |
---|
15193 | + def _after_first_cycle(ignored): |
---|
15194 | + s = lc.get_state() |
---|
15195 | + last = s["history"][0] |
---|
15196 | |
---|
15197 | hunk ./src/allmydata/test/test_storage.py 3840 |
---|
15198 | - s = lc.get_state() |
---|
15199 | - last = s["history"][0] |
---|
15200 | + self.failUnlessEqual(last["expiration-enabled"], True) |
---|
15201 | + self.failUnlessEqual(last["configured-expiration-mode"], |
---|
15202 | + ("cutoff-date", None, then, |
---|
15203 | + ("mutable", "immutable"))) |
---|
15204 | + self.failUnlessEqual(last["leases-per-share-histogram"], |
---|
15205 | + {1: 2, 2: 2}) |
---|
15206 | |
---|
15207 | hunk ./src/allmydata/test/test_storage.py 3847 |
---|
15208 | - self.failUnlessEqual(last["expiration-enabled"], True) |
---|
15209 | - self.failUnlessEqual(last["configured-expiration-mode"], |
---|
15210 | - ("cutoff-date", None, then, |
---|
15211 | - ("mutable", "immutable"))) |
---|
15212 | - self.failUnlessEqual(last["leases-per-share-histogram"], |
---|
15213 | - {1: 2, 2: 2}) |
---|
15214 | + rec = last["space-recovered"] |
---|
15215 | + self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
15216 | + self.failUnlessEqual(rec["examined-shares"], 4) |
---|
15217 | + self.failUnlessEqual(rec["actual-buckets"], 2) |
---|
15218 | + self.failUnlessEqual(rec["original-buckets"], 0) |
---|
15219 | + self.failUnlessEqual(rec["configured-buckets"], 2) |
---|
15220 | + self.failUnlessEqual(rec["actual-shares"], 2) |
---|
15221 | + self.failUnlessEqual(rec["original-shares"], 0) |
---|
15222 | + self.failUnlessEqual(rec["configured-shares"], 2) |
---|
15223 | + self.failUnlessEqual(rec["actual-sharebytes"], total_size) |
---|
15224 | + self.failUnlessEqual(rec["original-sharebytes"], 0) |
---|
15225 | + self.failUnlessEqual(rec["configured-sharebytes"], total_size) |
---|
15226 | |
---|
15227 | hunk ./src/allmydata/test/test_storage.py 3860 |
---|
15228 | - rec = last["space-recovered"] |
---|
15229 | - self.failUnlessEqual(rec["examined-buckets"], 4) |
---|
15230 | - self.failUnlessEqual(rec["examined-shares"], 4) |
---|
15231 | - self.failUnlessEqual(rec["actual-buckets"], 2) |
---|
15232 | - self.failUnlessEqual(rec["original-buckets"], 0) |
---|
15233 | - self.failUnlessEqual(rec["configured-buckets"], 2) |
---|
15234 | - self.failUnlessEqual(rec["actual-shares"], 2) |
---|
15235 | - self.failUnlessEqual(rec["original-shares"], 0) |
---|
15236 | - self.failUnlessEqual(rec["configured-shares"], 2) |
---|
15237 | - size = sf0_size + sf2_size |
---|
15238 | - self.failUnlessEqual(rec["actual-sharebytes"], size) |
---|
15239 | - self.failUnlessEqual(rec["original-sharebytes"], 0) |
---|
15240 | - self.failUnlessEqual(rec["configured-sharebytes"], size) |
---|
15241 | - # different platforms have different notions of "blocks used by |
---|
15242 | - # this file", so merely assert that it's a number |
---|
15243 | - self.failUnless(rec["actual-diskbytes"] >= 0, |
---|
15244 | - rec["actual-diskbytes"]) |
---|
15245 | - self.failUnless(rec["original-diskbytes"] >= 0, |
---|
15246 | - rec["original-diskbytes"]) |
---|
15247 | - self.failUnless(rec["configured-diskbytes"] >= 0, |
---|
15248 | - rec["configured-diskbytes"]) |
---|
15249 | - d.addCallback(_after_first_cycle) |
---|
15250 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
15251 | - def _check_html(html): |
---|
15252 | - s = remove_tags(html) |
---|
15253 | - self.failUnlessIn("Expiration Enabled:" |
---|
15254 | - " expired leases will be removed", s) |
---|
15255 | - date = time.strftime("%Y-%m-%d (%d-%b-%Y) UTC", time.gmtime(then)) |
---|
15256 | - substr = "Leases created or last renewed before %s will be considered expired." % date |
---|
15257 | - self.failUnlessIn(substr, s) |
---|
15258 | - self.failUnlessIn(" recovered: 2 shares, 2 buckets (1 mutable / 1 immutable), ", s) |
---|
15259 | - d.addCallback(_check_html) |
---|
15260 | + # different platforms have different notions of "blocks used by |
---|
15261 | + # this file", so merely assert that it's a number |
---|
15262 | + self.failUnless(rec["actual-diskbytes"] >= 0, |
---|
15263 | + rec["actual-diskbytes"]) |
---|
15264 | + self.failUnless(rec["original-diskbytes"] >= 0, |
---|
15265 | + rec["original-diskbytes"]) |
---|
15266 | + self.failUnless(rec["configured-diskbytes"] >= 0, |
---|
15267 | + rec["configured-diskbytes"]) |
---|
15268 | + d3.addCallback(_after_first_cycle) |
---|
15269 | + d3.addCallback(lambda ign: self.render1(webstatus)) |
---|
15270 | + def _check_html(html): |
---|
15271 | + s = remove_tags(html) |
---|
15272 | + self.failUnlessIn("Expiration Enabled:" |
---|
15273 | + " expired leases will be removed", s) |
---|
15274 | + date = time.strftime("%Y-%m-%d (%d-%b-%Y) UTC", time.gmtime(then)) |
---|
15275 | + substr = "Leases created or last renewed before %s will be considered expired." % date |
---|
15276 | + self.failUnlessIn(substr, s) |
---|
15277 | + self.failUnlessIn(" recovered: 2 shares, 2 buckets (1 mutable / 1 immutable), ", s) |
---|
15278 | + d3.addCallback(_check_html) |
---|
15279 | + return d3 |
---|
15280 | + d2.addCallback(_got_total_size) |
---|
15281 | + return d2 |
---|
15282 | + d.addCallback(_do_test) |
---|
15283 | return d |
---|
15284 | |
---|
15285 | def test_only_immutable(self): |
---|
15286 | hunk ./src/allmydata/test/test_storage.py 3887 |
---|
15287 | basedir = "storage/LeaseCrawler/only_immutable" |
---|
15288 | - fileutil.make_dirs(basedir) |
---|
15289 | + fp = FilePath(basedir) |
---|
15290 | + backend = DiskBackend(fp) |
---|
15291 | + |
---|
15292 | + # setting 'cutoff_date' to 2000 seconds ago means that any lease that |
---|
15293 | + # is more than 2000 seconds old will be expired. |
---|
15294 | now = time.time() |
---|
15295 | then = int(now - 2000) |
---|
15296 | hunk ./src/allmydata/test/test_storage.py 3894 |
---|
15297 | - ss = StorageServer(basedir, "\x00" * 20, |
---|
15298 | - expiration_enabled=True, |
---|
15299 | - expiration_mode="cutoff-date", |
---|
15300 | - expiration_cutoff_date=then, |
---|
15301 | - expiration_sharetypes=("immutable",)) |
---|
15302 | + expiration_policy = { |
---|
15303 | + 'enabled': True, |
---|
15304 | + 'mode': 'cutoff-date', |
---|
15305 | + 'cutoff_date': then, |
---|
15306 | + 'sharetypes': ('immutable',), |
---|
15307 | + } |
---|
15308 | + ss = StorageServer("\x00" * 20, backend, fp, expiration_policy=expiration_policy) |
---|
15309 | + |
---|
15310 | + # make it start sooner than usual. |
---|
15311 | lc = ss.lease_checker |
---|
15312 | lc.slow_start = 0 |
---|
15313 | hunk ./src/allmydata/test/test_storage.py 3905 |
---|
15314 | - webstatus = StorageStatus(ss) |
---|
15315 | |
---|
15316 | hunk ./src/allmydata/test/test_storage.py 3906 |
---|
15317 | - self.make_shares(ss) |
---|
15318 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15319 | - # set all leases to be expirable |
---|
15320 | - new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15321 | + # create a few shares, with some leases on them |
---|
15322 | + d = self.make_shares(ss) |
---|
15323 | + def _do_test(ign): |
---|
15324 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15325 | |
---|
15326 | hunk ./src/allmydata/test/test_storage.py 3911 |
---|
15327 | - def count_shares(si): |
---|
15328 | - return len(list(ss._iter_share_files(si))) |
---|
15329 | - def _get_sharefile(si): |
---|
15330 | - return list(ss._iter_share_files(si))[0] |
---|
15331 | - def count_leases(si): |
---|
15332 | - return len(list(_get_sharefile(si).get_leases())) |
---|
15333 | + # set all leases to be expirable |
---|
15334 | + new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15335 | |
---|
15336 | hunk ./src/allmydata/test/test_storage.py 3914 |
---|
15337 | - sf0 = _get_sharefile(immutable_si_0) |
---|
15338 | - self.backdate_lease(sf0, self.renew_secrets[0], new_expiration_time) |
---|
15339 | - sf1 = _get_sharefile(immutable_si_1) |
---|
15340 | - self.backdate_lease(sf1, self.renew_secrets[1], new_expiration_time) |
---|
15341 | - self.backdate_lease(sf1, self.renew_secrets[2], new_expiration_time) |
---|
15342 | - sf2 = _get_sharefile(mutable_si_2) |
---|
15343 | - self.backdate_lease(sf2, self.renew_secrets[3], new_expiration_time) |
---|
15344 | - sf3 = _get_sharefile(mutable_si_3) |
---|
15345 | - self.backdate_lease(sf3, self.renew_secrets[4], new_expiration_time) |
---|
15346 | - self.backdate_lease(sf3, self.renew_secrets[5], new_expiration_time) |
---|
15347 | + d2 = defer.succeed(None) |
---|
15348 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_0, self.renew_secrets[0:1], new_expiration_time)) |
---|
15349 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_1, self.renew_secrets[1:3], new_expiration_time)) |
---|
15350 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_2, self.renew_secrets[3:4], new_expiration_time)) |
---|
15351 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_3, self.renew_secrets[4:6], new_expiration_time)) |
---|
15352 | |
---|
15353 | hunk ./src/allmydata/test/test_storage.py 3920 |
---|
15354 | - ss.setServiceParent(self.s) |
---|
15355 | - def _wait(): |
---|
15356 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
15357 | - d = self.poll(_wait) |
---|
15358 | + d2.addCallback(lambda ign: ss.setServiceParent(self.s)) |
---|
15359 | |
---|
15360 | hunk ./src/allmydata/test/test_storage.py 3922 |
---|
15361 | - def _after_first_cycle(ignored): |
---|
15362 | - self.failUnlessEqual(count_shares(immutable_si_0), 0) |
---|
15363 | - self.failUnlessEqual(count_shares(immutable_si_1), 0) |
---|
15364 | - self.failUnlessEqual(count_shares(mutable_si_2), 1) |
---|
15365 | - self.failUnlessEqual(count_leases(mutable_si_2), 1) |
---|
15366 | - self.failUnlessEqual(count_shares(mutable_si_3), 1) |
---|
15367 | - self.failUnlessEqual(count_leases(mutable_si_3), 2) |
---|
15368 | - d.addCallback(_after_first_cycle) |
---|
15369 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
15370 | - def _check_html(html): |
---|
15371 | - s = remove_tags(html) |
---|
15372 | - self.failUnlessIn("The following sharetypes will be expired: immutable.", s) |
---|
15373 | - d.addCallback(_check_html) |
---|
15374 | + def _wait(): |
---|
15375 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
15376 | + d2.addCallback(lambda ign: self.poll(_wait)) |
---|
15377 | + |
---|
15378 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 0)) |
---|
15379 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 0)) |
---|
15380 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 1)) |
---|
15381 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_2, 1)) |
---|
15382 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 1)) |
---|
15383 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, mutable_si_3, 2)) |
---|
15384 | + |
---|
15385 | + def _render(ign): |
---|
15386 | + webstatus = StorageStatus(ss) |
---|
15387 | + return self.render1(webstatus) |
---|
15388 | + d2.addCallback(_render) |
---|
15389 | + def _check_html(html): |
---|
15390 | + s = remove_tags(html) |
---|
15391 | + self.failUnlessIn("The following sharetypes will be expired: immutable.", s) |
---|
15392 | + d2.addCallback(_check_html) |
---|
15393 | + return d2 |
---|
15394 | + d.addCallback(_do_test) |
---|
15395 | return d |
---|
15396 | |
---|
15397 | def test_only_mutable(self): |
---|
15398 | hunk ./src/allmydata/test/test_storage.py 3947 |
---|
15399 | basedir = "storage/LeaseCrawler/only_mutable" |
---|
15400 | - fileutil.make_dirs(basedir) |
---|
15401 | + fp = FilePath(basedir) |
---|
15402 | + backend = DiskBackend(fp) |
---|
15403 | + |
---|
15404 | + # setting 'cutoff_date' to 2000 seconds ago means that any lease that |
---|
15405 | + # is more than 2000 seconds old will be expired. |
---|
15406 | now = time.time() |
---|
15407 | then = int(now - 2000) |
---|
15408 | hunk ./src/allmydata/test/test_storage.py 3954 |
---|
15409 | - ss = StorageServer(basedir, "\x00" * 20, |
---|
15410 | - expiration_enabled=True, |
---|
15411 | - expiration_mode="cutoff-date", |
---|
15412 | - expiration_cutoff_date=then, |
---|
15413 | - expiration_sharetypes=("mutable",)) |
---|
15414 | + expiration_policy = { |
---|
15415 | + 'enabled': True, |
---|
15416 | + 'mode': 'cutoff-date', |
---|
15417 | + 'cutoff_date': then, |
---|
15418 | + 'sharetypes': ('mutable',), |
---|
15419 | + } |
---|
15420 | + ss = StorageServer("\x00" * 20, backend, fp, expiration_policy=expiration_policy) |
---|
15421 | + |
---|
15422 | + # make it start sooner than usual. |
---|
15423 | lc = ss.lease_checker |
---|
15424 | lc.slow_start = 0 |
---|
15425 | hunk ./src/allmydata/test/test_storage.py 3965 |
---|
15426 | - webstatus = StorageStatus(ss) |
---|
15427 | |
---|
15428 | hunk ./src/allmydata/test/test_storage.py 3966 |
---|
15429 | - self.make_shares(ss) |
---|
15430 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15431 | - # set all leases to be expirable |
---|
15432 | - new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15433 | + # create a few shares, with some leases on them |
---|
15434 | + d = self.make_shares(ss) |
---|
15435 | + def _do_test(ign): |
---|
15436 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15437 | + # set all leases to be expirable |
---|
15438 | + new_expiration_time = now - 3000 + 31*24*60*60 |
---|
15439 | |
---|
15440 | hunk ./src/allmydata/test/test_storage.py 3973 |
---|
15441 | - def count_shares(si): |
---|
15442 | - return len(list(ss._iter_share_files(si))) |
---|
15443 | - def _get_sharefile(si): |
---|
15444 | - return list(ss._iter_share_files(si))[0] |
---|
15445 | - def count_leases(si): |
---|
15446 | - return len(list(_get_sharefile(si).get_leases())) |
---|
15447 | + d2 = defer.succeed(None) |
---|
15448 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_0, self.renew_secrets[0:1], new_expiration_time)) |
---|
15449 | + d2.addCallback(lambda ign: self._backdate_leases(ss, immutable_si_1, self.renew_secrets[1:3], new_expiration_time)) |
---|
15450 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_2, self.renew_secrets[3:4], new_expiration_time)) |
---|
15451 | + d2.addCallback(lambda ign: self._backdate_leases(ss, mutable_si_3, self.renew_secrets[4:6], new_expiration_time)) |
---|
15452 | |
---|
15453 | hunk ./src/allmydata/test/test_storage.py 3979 |
---|
15454 | - sf0 = _get_sharefile(immutable_si_0) |
---|
15455 | - self.backdate_lease(sf0, self.renew_secrets[0], new_expiration_time) |
---|
15456 | - sf1 = _get_sharefile(immutable_si_1) |
---|
15457 | - self.backdate_lease(sf1, self.renew_secrets[1], new_expiration_time) |
---|
15458 | - self.backdate_lease(sf1, self.renew_secrets[2], new_expiration_time) |
---|
15459 | - sf2 = _get_sharefile(mutable_si_2) |
---|
15460 | - self.backdate_lease(sf2, self.renew_secrets[3], new_expiration_time) |
---|
15461 | - sf3 = _get_sharefile(mutable_si_3) |
---|
15462 | - self.backdate_lease(sf3, self.renew_secrets[4], new_expiration_time) |
---|
15463 | - self.backdate_lease(sf3, self.renew_secrets[5], new_expiration_time) |
---|
15464 | + d2.addCallback(lambda ign: ss.setServiceParent(self.s)) |
---|
15465 | |
---|
15466 | hunk ./src/allmydata/test/test_storage.py 3981 |
---|
15467 | - ss.setServiceParent(self.s) |
---|
15468 | - def _wait(): |
---|
15469 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
15470 | - d = self.poll(_wait) |
---|
15471 | + def _wait(): |
---|
15472 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
15473 | + d2.addCallback(lambda ign: self.poll(_wait)) |
---|
15474 | |
---|
15475 | hunk ./src/allmydata/test/test_storage.py 3985 |
---|
15476 | - def _after_first_cycle(ignored): |
---|
15477 | - self.failUnlessEqual(count_shares(immutable_si_0), 1) |
---|
15478 | - self.failUnlessEqual(count_leases(immutable_si_0), 1) |
---|
15479 | - self.failUnlessEqual(count_shares(immutable_si_1), 1) |
---|
15480 | - self.failUnlessEqual(count_leases(immutable_si_1), 2) |
---|
15481 | - self.failUnlessEqual(count_shares(mutable_si_2), 0) |
---|
15482 | - self.failUnlessEqual(count_shares(mutable_si_3), 0) |
---|
15483 | - d.addCallback(_after_first_cycle) |
---|
15484 | - d.addCallback(lambda ign: self.render1(webstatus)) |
---|
15485 | - def _check_html(html): |
---|
15486 | - s = remove_tags(html) |
---|
15487 | - self.failUnlessIn("The following sharetypes will be expired: mutable.", s) |
---|
15488 | - d.addCallback(_check_html) |
---|
15489 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_0, 1)) |
---|
15490 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_0, 1)) |
---|
15491 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, immutable_si_1, 1)) |
---|
15492 | + d2.addCallback(lambda ign: self._assert_leasecount(ss, immutable_si_1, 2)) |
---|
15493 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_2, 0)) |
---|
15494 | + d2.addCallback(lambda ign: self._assert_sharecount(ss, mutable_si_3, 0)) |
---|
15495 | + |
---|
15496 | + def _render(ign): |
---|
15497 | + webstatus = StorageStatus(ss) |
---|
15498 | + return self.render1(webstatus) |
---|
15499 | + d2.addCallback(_render) |
---|
15500 | + def _check_html(html): |
---|
15501 | + s = remove_tags(html) |
---|
15502 | + self.failUnlessIn("The following sharetypes will be expired: mutable.", s) |
---|
15503 | + d2.addCallback(_check_html) |
---|
15504 | + return d2 |
---|
15505 | + d.addCallback(_do_test) |
---|
15506 | return d |
---|
15507 | |
---|
15508 | def test_bad_mode(self): |
---|
15509 | hunk ./src/allmydata/test/test_storage.py 4006 |
---|
15510 | basedir = "storage/LeaseCrawler/bad_mode" |
---|
15511 | - fileutil.make_dirs(basedir) |
---|
15512 | + fp = FilePath(basedir) |
---|
15513 | + backend = DiskBackend(fp) |
---|
15514 | + |
---|
15515 | + expiration_policy = { |
---|
15516 | + 'enabled': True, |
---|
15517 | + 'mode': 'bogus', |
---|
15518 | + 'override_lease_duration': None, |
---|
15519 | + 'cutoff_date': None, |
---|
15520 | + 'sharetypes': ('mutable', 'immutable'), |
---|
15521 | + } |
---|
15522 | e = self.failUnlessRaises(ValueError, |
---|
15523 | hunk ./src/allmydata/test/test_storage.py 4017 |
---|
15524 | - StorageServer, basedir, "\x00" * 20, |
---|
15525 | - expiration_mode="bogus") |
---|
15526 | + StorageServer, "\x00" * 20, backend, fp, |
---|
15527 | + expiration_policy=expiration_policy) |
---|
15528 | self.failUnlessIn("GC mode 'bogus' must be 'age' or 'cutoff-date'", str(e)) |
---|
15529 | |
---|
15530 | def test_parse_duration(self): |
---|
15531 | hunk ./src/allmydata/test/test_storage.py 4042 |
---|
15532 | |
---|
15533 | def test_limited_history(self): |
---|
15534 | basedir = "storage/LeaseCrawler/limited_history" |
---|
15535 | - fileutil.make_dirs(basedir) |
---|
15536 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
15537 | + fp = FilePath(basedir) |
---|
15538 | + backend = DiskBackend(fp) |
---|
15539 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
15540 | + |
---|
15541 | # make it start sooner than usual. |
---|
15542 | lc = ss.lease_checker |
---|
15543 | lc.slow_start = 0 |
---|
15544 | hunk ./src/allmydata/test/test_storage.py 4052 |
---|
15545 | lc.cpu_slice = 500 |
---|
15546 | |
---|
15547 | # create a few shares, with some leases on them |
---|
15548 | - self.make_shares(ss) |
---|
15549 | - |
---|
15550 | - ss.setServiceParent(self.s) |
---|
15551 | + d = self.make_shares(ss) |
---|
15552 | + d.addCallback(lambda ign: ss.setServiceParent(self.s)) |
---|
15553 | |
---|
15554 | def _wait_until_15_cycles_done(): |
---|
15555 | last = lc.state["last-cycle-finished"] |
---|
15556 | hunk ./src/allmydata/test/test_storage.py 4062 |
---|
15557 | if lc.timer: |
---|
15558 | lc.timer.reset(0) |
---|
15559 | return False |
---|
15560 | - d = self.poll(_wait_until_15_cycles_done) |
---|
15561 | + d.addCallback(lambda ign: self.poll(_wait_until_15_cycles_done)) |
---|
15562 | |
---|
15563 | def _check(ignored): |
---|
15564 | s = lc.get_state() |
---|
15565 | hunk ./src/allmydata/test/test_storage.py 4075 |
---|
15566 | |
---|
15567 | def test_unpredictable_future(self): |
---|
15568 | basedir = "storage/LeaseCrawler/unpredictable_future" |
---|
15569 | - fileutil.make_dirs(basedir) |
---|
15570 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
15571 | + fp = FilePath(basedir) |
---|
15572 | + backend = DiskBackend(fp) |
---|
15573 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
15574 | + |
---|
15575 | # make it start sooner than usual. |
---|
15576 | lc = ss.lease_checker |
---|
15577 | lc.slow_start = 0 |
---|
15578 | hunk ./src/allmydata/test/test_storage.py 4084 |
---|
15579 | lc.cpu_slice = -1.0 # stop quickly |
---|
15580 | |
---|
15581 | - self.make_shares(ss) |
---|
15582 | - |
---|
15583 | - ss.setServiceParent(self.s) |
---|
15584 | - |
---|
15585 | - d = fireEventually() |
---|
15586 | + # create a few shares, with some leases on them |
---|
15587 | + d = self.make_shares(ss) |
---|
15588 | + d.addCallback(lambda ign: ss.setServiceParent(self.s)) |
---|
15589 | def _check(ignored): |
---|
15590 | hunk ./src/allmydata/test/test_storage.py 4088 |
---|
15591 | - # this should fire after the first bucket is complete, but before |
---|
15592 | + # this should fire after the first shareset is complete, but before |
---|
15593 | # the first prefix is complete, so the progress-measurer won't |
---|
15594 | # think we've gotten far enough to raise our percent-complete |
---|
15595 | # above 0%, triggering the cannot-predict-the-future code in |
---|
15596 | hunk ./src/allmydata/test/test_storage.py 4093 |
---|
15597 | # expirer.py . This will have to change if/when the |
---|
15598 | - # progress-measurer gets smart enough to count buckets (we'll |
---|
15599 | + # progress-measurer gets smart enough to count sharesets (we'll |
---|
15600 | # have to interrupt it even earlier, before it's finished the |
---|
15601 | # first shareset). |
---|
15602 | s = lc.get_state() |
---|
15603 | hunk ./src/allmydata/test/test_storage.py 4105 |
---|
15604 | self.failUnlessIn("estimated-remaining-cycle", s) |
---|
15605 | self.failUnlessIn("estimated-current-cycle", s) |
---|
15606 | |
---|
15607 | - left = s["estimated-remaining-cycle"]["space-recovered"] |
---|
15608 | - self.failUnlessEqual(left["actual-buckets"], None) |
---|
15609 | - self.failUnlessEqual(left["original-buckets"], None) |
---|
15610 | - self.failUnlessEqual(left["configured-buckets"], None) |
---|
15611 | - self.failUnlessEqual(left["actual-shares"], None) |
---|
15612 | - self.failUnlessEqual(left["original-shares"], None) |
---|
15613 | - self.failUnlessEqual(left["configured-shares"], None) |
---|
15614 | - self.failUnlessEqual(left["actual-diskbytes"], None) |
---|
15615 | - self.failUnlessEqual(left["original-diskbytes"], None) |
---|
15616 | - self.failUnlessEqual(left["configured-diskbytes"], None) |
---|
15617 | - self.failUnlessEqual(left["actual-sharebytes"], None) |
---|
15618 | - self.failUnlessEqual(left["original-sharebytes"], None) |
---|
15619 | - self.failUnlessEqual(left["configured-sharebytes"], None) |
---|
15620 | - |
---|
15621 | - full = s["estimated-remaining-cycle"]["space-recovered"] |
---|
15622 | - self.failUnlessEqual(full["actual-buckets"], None) |
---|
15623 | - self.failUnlessEqual(full["original-buckets"], None) |
---|
15624 | - self.failUnlessEqual(full["configured-buckets"], None) |
---|
15625 | - self.failUnlessEqual(full["actual-shares"], None) |
---|
15626 | - self.failUnlessEqual(full["original-shares"], None) |
---|
15627 | - self.failUnlessEqual(full["configured-shares"], None) |
---|
15628 | - self.failUnlessEqual(full["actual-diskbytes"], None) |
---|
15629 | - self.failUnlessEqual(full["original-diskbytes"], None) |
---|
15630 | - self.failUnlessEqual(full["configured-diskbytes"], None) |
---|
15631 | - self.failUnlessEqual(full["actual-sharebytes"], None) |
---|
15632 | - self.failUnlessEqual(full["original-sharebytes"], None) |
---|
15633 | - self.failUnlessEqual(full["configured-sharebytes"], None) |
---|
15634 | + def _do_check(cycle): |
---|
15635 | + self.failUnlessIn("space-recovered", cycle) |
---|
15636 | + rec = cycle["space-recovered"] |
---|
15637 | + self.failUnlessEqual(rec["actual-buckets"], None) |
---|
15638 | + self.failUnlessEqual(rec["original-buckets"], None) |
---|
15639 | + self.failUnlessEqual(rec["configured-buckets"], None) |
---|
15640 | + self.failUnlessEqual(rec["actual-shares"], None) |
---|
15641 | + self.failUnlessEqual(rec["original-shares"], None) |
---|
15642 | + self.failUnlessEqual(rec["configured-shares"], None) |
---|
15643 | + self.failUnlessEqual(rec["actual-diskbytes"], None) |
---|
15644 | + self.failUnlessEqual(rec["original-diskbytes"], None) |
---|
15645 | + self.failUnlessEqual(rec["configured-diskbytes"], None) |
---|
15646 | + self.failUnlessEqual(rec["actual-sharebytes"], None) |
---|
15647 | + self.failUnlessEqual(rec["original-sharebytes"], None) |
---|
15648 | + self.failUnlessEqual(rec["configured-sharebytes"], None) |
---|
15649 | |
---|
15650 | hunk ./src/allmydata/test/test_storage.py 4121 |
---|
15651 | + _do_check(s["estimated-remaining-cycle"]) |
---|
15652 | + _do_check(s["estimated-current-cycle"]) |
---|
15653 | d.addCallback(_check) |
---|
15654 | return d |
---|
15655 | |
---|
15656 | hunk ./src/allmydata/test/test_storage.py 4127 |
---|
15657 | def test_no_st_blocks(self): |
---|
15658 | - basedir = "storage/LeaseCrawler/no_st_blocks" |
---|
15659 | - fileutil.make_dirs(basedir) |
---|
15660 | - ss = No_ST_BLOCKS_StorageServer(basedir, "\x00" * 20, |
---|
15661 | - expiration_mode="age", |
---|
15662 | - expiration_override_lease_duration=-1000) |
---|
15663 | - # a negative expiration_time= means the "configured-" |
---|
15664 | - # space-recovered counts will be non-zero, since all shares will have |
---|
15665 | - # expired by then |
---|
15666 | + # TODO: replace with @patch that supports Deferreds. |
---|
15667 | |
---|
15668 | hunk ./src/allmydata/test/test_storage.py 4129 |
---|
15669 | - # make it start sooner than usual. |
---|
15670 | - lc = ss.lease_checker |
---|
15671 | - lc.slow_start = 0 |
---|
15672 | + class BrokenStatResults: |
---|
15673 | + pass |
---|
15674 | |
---|
15675 | hunk ./src/allmydata/test/test_storage.py 4132 |
---|
15676 | - self.make_shares(ss) |
---|
15677 | - ss.setServiceParent(self.s) |
---|
15678 | - def _wait(): |
---|
15679 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
15680 | - d = self.poll(_wait) |
---|
15681 | + def call_stat(fn): |
---|
15682 | + s = self.old_os_stat(fn) |
---|
15683 | + bsr = BrokenStatResults() |
---|
15684 | + for attrname in dir(s): |
---|
15685 | + if attrname.startswith("_"): |
---|
15686 | + continue |
---|
15687 | + if attrname == "st_blocks": |
---|
15688 | + continue |
---|
15689 | + setattr(bsr, attrname, getattr(s, attrname)) |
---|
15690 | |
---|
15691 | hunk ./src/allmydata/test/test_storage.py 4142 |
---|
15692 | - def _check(ignored): |
---|
15693 | - s = lc.get_state() |
---|
15694 | - last = s["history"][0] |
---|
15695 | - rec = last["space-recovered"] |
---|
15696 | - self.failUnlessEqual(rec["configured-buckets"], 4) |
---|
15697 | - self.failUnlessEqual(rec["configured-shares"], 4) |
---|
15698 | - self.failUnless(rec["configured-sharebytes"] > 0, |
---|
15699 | - rec["configured-sharebytes"]) |
---|
15700 | - # without the .st_blocks field in os.stat() results, we should be |
---|
15701 | - # reporting diskbytes==sharebytes |
---|
15702 | - self.failUnlessEqual(rec["configured-sharebytes"], |
---|
15703 | - rec["configured-diskbytes"]) |
---|
15704 | - d.addCallback(_check) |
---|
15705 | - return d |
---|
15706 | + # pretend that the directory overhead is zero |
---|
15707 | + if stat.S_ISDIR(bsr.st_mode): |
---|
15708 | + bsr.st_size = 0 |
---|
15709 | + return bsr |
---|
15710 | + |
---|
15711 | + def _cleanup(res): |
---|
15712 | + os.stat = self.old_os_stat |
---|
15713 | + return res |
---|
15714 | + |
---|
15715 | + self.old_os_stat = os.stat |
---|
15716 | + try: |
---|
15717 | + os.stat = call_stat |
---|
15718 | + |
---|
15719 | + basedir = "storage/LeaseCrawler/no_st_blocks" |
---|
15720 | + fp = FilePath(basedir) |
---|
15721 | + backend = DiskBackend(fp) |
---|
15722 | + |
---|
15723 | + # A negative 'override_lease_duration' means that the "configured-" |
---|
15724 | + # space-recovered counts will be non-zero, since all shares will have |
---|
15725 | + # expired by then. |
---|
15726 | + expiration_policy = { |
---|
15727 | + 'enabled': True, |
---|
15728 | + 'mode': 'age', |
---|
15729 | + 'override_lease_duration': -1000, |
---|
15730 | + 'sharetypes': ('mutable', 'immutable'), |
---|
15731 | + } |
---|
15732 | + ss = StorageServer("\x00" * 20, backend, fp, expiration_policy=expiration_policy) |
---|
15733 | + |
---|
15734 | + # make it start sooner than usual. |
---|
15735 | + lc = ss.lease_checker |
---|
15736 | + lc.slow_start = 0 |
---|
15737 | + |
---|
15738 | + d = self.make_shares(ss) |
---|
15739 | + d.addCallback(lambda ign: ss.setServiceParent(self.s)) |
---|
15740 | + def _wait(): |
---|
15741 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
15742 | + d.addCallback(lambda ign: self.poll(_wait)) |
---|
15743 | + |
---|
15744 | + def _check(ignored): |
---|
15745 | + s = lc.get_state() |
---|
15746 | + self.failUnlessIn("history", s) |
---|
15747 | + history = s["history"] |
---|
15748 | + self.failUnlessIn(0, history) |
---|
15749 | + last = history[0] |
---|
15750 | + self.failUnlessIn("space-recovered", last) |
---|
15751 | + rec = last["space-recovered"] |
---|
15752 | + self.failUnlessEqual(rec["configured-buckets"], 4, str(rec)) |
---|
15753 | + self.failUnlessEqual(rec["configured-shares"], 4, str(rec)) |
---|
15754 | + self.failUnless(rec["configured-sharebytes"] > 0, str(rec)) |
---|
15755 | + # without the .st_blocks field in os.stat() results, and with directory |
---|
15756 | + # overhead not counted, we should be reporting diskbytes==sharebytes |
---|
15757 | + self.failUnlessEqual(rec["configured-sharebytes"], |
---|
15758 | + rec["configured-diskbytes"], str(rec)) |
---|
15759 | + d.addCallback(_check) |
---|
15760 | + d.addBoth(_cleanup) |
---|
15761 | + return d |
---|
15762 | + except Exception: |
---|
15763 | + _cleanup(None) |
---|
15764 | + raise |
---|
15765 | |
---|
15766 | def test_share_corruption(self): |
---|
15767 | self._poll_should_ignore_these_errors = [ |
---|
15768 | hunk ./src/allmydata/test/test_storage.py 4208 |
---|
15769 | UnknownImmutableContainerVersionError, |
---|
15770 | ] |
---|
15771 | basedir = "storage/LeaseCrawler/share_corruption" |
---|
15772 | - fileutil.make_dirs(basedir) |
---|
15773 | - ss = InstrumentedStorageServer(basedir, "\x00" * 20) |
---|
15774 | - w = StorageStatus(ss) |
---|
15775 | + fp = FilePath(basedir) |
---|
15776 | + backend = DiskBackend(fp) |
---|
15777 | + ss = InstrumentedStorageServer("\x00" * 20, backend, fp) |
---|
15778 | + |
---|
15779 | # make it start sooner than usual. |
---|
15780 | lc = ss.lease_checker |
---|
15781 | hunk ./src/allmydata/test/test_storage.py 4214 |
---|
15782 | - lc.stop_after_first_bucket = True |
---|
15783 | lc.slow_start = 0 |
---|
15784 | lc.cpu_slice = 500 |
---|
15785 | |
---|
15786 | hunk ./src/allmydata/test/test_storage.py 4218 |
---|
15787 | # create a few shares, with some leases on them |
---|
15788 | - self.make_shares(ss) |
---|
15789 | + d = self.make_shares(ss) |
---|
15790 | + def _do_test(ign): |
---|
15791 | + [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15792 | |
---|
15793 | hunk ./src/allmydata/test/test_storage.py 4222 |
---|
15794 | - # now corrupt one, and make sure the lease-checker keeps going |
---|
15795 | - [immutable_si_0, immutable_si_1, mutable_si_2, mutable_si_3] = self.sis |
---|
15796 | - first = min(self.sis) |
---|
15797 | - first_b32 = base32.b2a(first) |
---|
15798 | - fn = os.path.join(ss.sharedir, storage_index_to_dir(first), "0") |
---|
15799 | - f = open(fn, "rb+") |
---|
15800 | - f.seek(0) |
---|
15801 | - f.write("BAD MAGIC") |
---|
15802 | - f.close() |
---|
15803 | - # if get_share_file() doesn't see the correct mutable magic, it |
---|
15804 | - # assumes the file is an immutable share, and then |
---|
15805 | - # immutable.ShareFile sees a bad version. So regardless of which kind |
---|
15806 | - # of share we corrupted, this will trigger an |
---|
15807 | - # UnknownImmutableContainerVersionError. |
---|
15808 | + # now corrupt one, and make sure the lease-checker keeps going |
---|
15809 | + first = min(self.sis) |
---|
15810 | + first_b32 = base32.b2a(first) |
---|
15811 | + fp = ss.backend.get_shareset(first)._get_sharedir().child("0") |
---|
15812 | + f = fp.open("rb+") |
---|
15813 | + try: |
---|
15814 | + f.seek(0) |
---|
15815 | + f.write("BAD MAGIC") |
---|
15816 | + finally: |
---|
15817 | + f.close() |
---|
15818 | |
---|
15819 | hunk ./src/allmydata/test/test_storage.py 4233 |
---|
15820 | - # also create an empty bucket |
---|
15821 | - empty_si = base32.b2a("\x04"*16) |
---|
15822 | - empty_bucket_dir = os.path.join(ss.sharedir, |
---|
15823 | - storage_index_to_dir(empty_si)) |
---|
15824 | - fileutil.make_dirs(empty_bucket_dir) |
---|
15825 | + # If the backend doesn't see the correct mutable magic, it |
---|
15826 | + # assumes the file is an immutable share, and then the immutable |
---|
15827 | + # share class will see a bad version. So regardless of which kind |
---|
15828 | + # of share we corrupted, this will trigger an |
---|
15829 | + # UnknownImmutableContainerVersionError. |
---|
15830 | |
---|
15831 | hunk ./src/allmydata/test/test_storage.py 4239 |
---|
15832 | - ss.setServiceParent(self.s) |
---|
15833 | + # also create an empty shareset |
---|
15834 | + empty_si = base32.b2a("\x04"*16) |
---|
15835 | + empty_si_dir = ss.backend.get_shareset(empty_si)._get_sharedir() |
---|
15836 | + fileutil.fp_make_dirs(empty_si_dir) |
---|
15837 | |
---|
15838 | hunk ./src/allmydata/test/test_storage.py 4244 |
---|
15839 | - d = fireEventually() |
---|
15840 | + d2 = defer.Deferred() |
---|
15841 | + lc.hook_ds = [d2] |
---|
15842 | + ss.setServiceParent(self.s) |
---|
15843 | |
---|
15844 | hunk ./src/allmydata/test/test_storage.py 4248 |
---|
15845 | - # now examine the state right after the first bucket has been |
---|
15846 | - # processed. |
---|
15847 | - def _after_first_bucket(ignored): |
---|
15848 | - s = lc.get_state() |
---|
15849 | - if "cycle-to-date" not in s: |
---|
15850 | - d2 = fireEventually() |
---|
15851 | - d2.addCallback(_after_first_bucket) |
---|
15852 | - return d2 |
---|
15853 | - so_far = s["cycle-to-date"] |
---|
15854 | - rec = so_far["space-recovered"] |
---|
15855 | - self.failUnlessEqual(rec["examined-buckets"], 1) |
---|
15856 | - self.failUnlessEqual(rec["examined-shares"], 0) |
---|
15857 | - self.failUnlessEqual(so_far["corrupt-shares"], [(first_b32, 0)]) |
---|
15858 | - d.addCallback(_after_first_bucket) |
---|
15859 | + # now examine the state right after the first shareset has been |
---|
15860 | + # processed. |
---|
15861 | + def _after_first_shareset(ignored): |
---|
15862 | + s = lc.get_state() |
---|
15863 | + self.failUnlessIn("cycle-to-date", s) |
---|
15864 | + so_far = s["cycle-to-date"] |
---|
15865 | + self.failUnlessIn("space-recovered", so_far) |
---|
15866 | + rec = so_far["space-recovered"] |
---|
15867 | + self.failUnlessEqual(rec["examined-buckets"], 1, str(rec)) |
---|
15868 | + self.failUnlessEqual(rec["examined-shares"], 0, str(rec)) |
---|
15869 | + self.failUnlessEqual(so_far["corrupt-shares"], [(first_b32, 0)]) |
---|
15870 | + d2.addCallback(_after_first_shareset) |
---|
15871 | |
---|
15872 | hunk ./src/allmydata/test/test_storage.py 4261 |
---|
15873 | - d.addCallback(lambda ign: self.render_json(w)) |
---|
15874 | - def _check_json(json): |
---|
15875 | - data = simplejson.loads(json) |
---|
15876 | - # grr. json turns all dict keys into strings. |
---|
15877 | - so_far = data["lease-checker"]["cycle-to-date"] |
---|
15878 | - corrupt_shares = so_far["corrupt-shares"] |
---|
15879 | - # it also turns all tuples into lists |
---|
15880 | - self.failUnlessEqual(corrupt_shares, [[first_b32, 0]]) |
---|
15881 | - d.addCallback(_check_json) |
---|
15882 | - d.addCallback(lambda ign: self.render1(w)) |
---|
15883 | - def _check_html(html): |
---|
15884 | - s = remove_tags(html) |
---|
15885 | - self.failUnlessIn("Corrupt shares: SI %s shnum 0" % first_b32, s) |
---|
15886 | - d.addCallback(_check_html) |
---|
15887 | + def _render_json(ign): |
---|
15888 | + webstatus = StorageStatus(ss) |
---|
15889 | + return self.render_json(webstatus) |
---|
15890 | + d2.addCallback(_render_json) |
---|
15891 | + def _check_json(json): |
---|
15892 | + data = simplejson.loads(json) |
---|
15893 | + # grr. json turns all dict keys into strings. |
---|
15894 | + self.failUnlessIn("lease-checker", data) |
---|
15895 | + s = data["lease-checker"] |
---|
15896 | + self.failUnlessIn("cycle-to-date", s) |
---|
15897 | + so_far = s["cycle-to-date"] |
---|
15898 | + corrupt_shares = so_far["corrupt-shares"] |
---|
15899 | + # it also turns all tuples into lists |
---|
15900 | + self.failUnlessEqual(corrupt_shares, [[first_b32, 0]]) |
---|
15901 | + d2.addCallback(_check_json) |
---|
15902 | |
---|
15903 | hunk ./src/allmydata/test/test_storage.py 4277 |
---|
15904 | - def _wait(): |
---|
15905 | - return bool(lc.get_state()["last-cycle-finished"] is not None) |
---|
15906 | - d.addCallback(lambda ign: self.poll(_wait)) |
---|
15907 | + def _render(ign): |
---|
15908 | + webstatus = StorageStatus(ss) |
---|
15909 | + return self.render1(webstatus) |
---|
15910 | + d2.addCallback(_render) |
---|
15911 | + def _check_html(html): |
---|
15912 | + s = remove_tags(html) |
---|
15913 | + self.failUnlessIn("Corrupt shares: SI %s shnum 0" % first_b32, s) |
---|
15914 | + d2.addCallback(_check_html) |
---|
15915 | |
---|
15916 | hunk ./src/allmydata/test/test_storage.py 4286 |
---|
15917 | - def _after_first_cycle(ignored): |
---|
15918 | - s = lc.get_state() |
---|
15919 | - last = s["history"][0] |
---|
15920 | - rec = last["space-recovered"] |
---|
15921 | - self.failUnlessEqual(rec["examined-buckets"], 5) |
---|
15922 | - self.failUnlessEqual(rec["examined-shares"], 3) |
---|
15923 | - self.failUnlessEqual(last["corrupt-shares"], [(first_b32, 0)]) |
---|
15924 | - d.addCallback(_after_first_cycle) |
---|
15925 | - d.addCallback(lambda ign: self.render_json(w)) |
---|
15926 | - def _check_json_history(json): |
---|
15927 | - data = simplejson.loads(json) |
---|
15928 | - last = data["lease-checker"]["history"]["0"] |
---|
15929 | - corrupt_shares = last["corrupt-shares"] |
---|
15930 | - self.failUnlessEqual(corrupt_shares, [[first_b32, 0]]) |
---|
15931 | - d.addCallback(_check_json_history) |
---|
15932 | - d.addCallback(lambda ign: self.render1(w)) |
---|
15933 | - def _check_html_history(html): |
---|
15934 | - s = remove_tags(html) |
---|
15935 | - self.failUnlessIn("Corrupt shares: SI %s shnum 0" % first_b32, s) |
---|
15936 | - d.addCallback(_check_html_history) |
---|
15937 | + def _wait(): |
---|
15938 | + return lc.get_state()["last-cycle-finished"] is not None |
---|
15939 | + d2.addCallback(lambda ign: self.poll(_wait)) |
---|
15940 | |
---|
15941 | hunk ./src/allmydata/test/test_storage.py 4290 |
---|
15942 | - def _cleanup(res): |
---|
15943 | - self.flushLoggedErrors(UnknownMutableContainerVersionError, |
---|
15944 | - UnknownImmutableContainerVersionError) |
---|
15945 | - return res |
---|
15946 | - d.addBoth(_cleanup) |
---|
15947 | + def _after_first_cycle(ignored): |
---|
15948 | + s = lc.get_state() |
---|
15949 | + last = s["history"][0] |
---|
15950 | + rec = last["space-recovered"] |
---|
15951 | + self.failUnlessEqual(rec["examined-buckets"], 5) |
---|
15952 | + self.failUnlessEqual(rec["examined-shares"], 3) |
---|
15953 | + self.failUnlessEqual(last["corrupt-shares"], [(first_b32, 0)]) |
---|
15954 | + d2.addCallback(_after_first_cycle) |
---|
15955 | + |
---|
15956 | + d2.addCallback(_render_json) |
---|
15957 | + def _check_json_history(json): |
---|
15958 | + data = simplejson.loads(json) |
---|
15959 | + last = data["lease-checker"]["history"]["0"] |
---|
15960 | + corrupt_shares = last["corrupt-shares"] |
---|
15961 | + self.failUnlessEqual(corrupt_shares, [[first_b32, 0]]) |
---|
15962 | + d2.addCallback(_check_json_history) |
---|
15963 | + |
---|
15964 | + d2.addCallback(_render) |
---|
15965 | + def _check_html_history(html): |
---|
15966 | + s = remove_tags(html) |
---|
15967 | + self.failUnlessIn("Corrupt shares: SI %s shnum 0" % first_b32, s) |
---|
15968 | + d2.addCallback(_check_html_history) |
---|
15969 | + |
---|
15970 | + def _cleanup(res): |
---|
15971 | + self.flushLoggedErrors(UnknownMutableContainerVersionError, |
---|
15972 | + UnknownImmutableContainerVersionError) |
---|
15973 | + return res |
---|
15974 | + d2.addBoth(_cleanup) |
---|
15975 | + return d2 |
---|
15976 | + d.addCallback(_do_test) |
---|
15977 | return d |
---|
15978 | |
---|
15979 | def render_json(self, page): |
---|
15980 | hunk ./src/allmydata/test/test_storage.py 4326 |
---|
15981 | d = self.render1(page, args={"t": ["json"]}) |
---|
15982 | return d |
---|
15983 | |
---|
15984 | +LeaseCrawler.skip = "takes too long" |
---|
15985 | + |
---|
15986 | + |
---|
15987 | class WebStatus(unittest.TestCase, pollmixin.PollMixin, WebRenderingMixin): |
---|
15988 | |
---|
15989 | def setUp(self): |
---|
15990 | hunk ./src/allmydata/test/test_storage.py 4344 |
---|
15991 | |
---|
15992 | def test_status(self): |
---|
15993 | basedir = "storage/WebStatus/status" |
---|
15994 | - fileutil.make_dirs(basedir) |
---|
15995 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
15996 | + fp = FilePath(basedir) |
---|
15997 | + backend = DiskBackend(fp) |
---|
15998 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
15999 | ss.setServiceParent(self.s) |
---|
16000 | w = StorageStatus(ss) |
---|
16001 | d = self.render1(w) |
---|
16002 | hunk ./src/allmydata/test/test_storage.py 4378 |
---|
16003 | # Some platforms may have no disk stats API. Make sure the code can handle that |
---|
16004 | # (test runs on all platforms). |
---|
16005 | basedir = "storage/WebStatus/status_no_disk_stats" |
---|
16006 | - fileutil.make_dirs(basedir) |
---|
16007 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
16008 | + fp = FilePath(basedir) |
---|
16009 | + backend = DiskBackend(fp) |
---|
16010 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
16011 | ss.setServiceParent(self.s) |
---|
16012 | w = StorageStatus(ss) |
---|
16013 | html = w.renderSynchronously() |
---|
16014 | hunk ./src/allmydata/test/test_storage.py 4398 |
---|
16015 | # If the API to get disk stats exists but a call to it fails, then the status should |
---|
16016 | # show that no shares will be accepted, and get_available_space() should be 0. |
---|
16017 | basedir = "storage/WebStatus/status_bad_disk_stats" |
---|
16018 | - fileutil.make_dirs(basedir) |
---|
16019 | - ss = StorageServer(basedir, "\x00" * 20) |
---|
16020 | + fp = FilePath(basedir) |
---|
16021 | + backend = DiskBackend(fp) |
---|
16022 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
16023 | ss.setServiceParent(self.s) |
---|
16024 | w = StorageStatus(ss) |
---|
16025 | html = w.renderSynchronously() |
---|
16026 | hunk ./src/allmydata/test/test_storage.py 4429 |
---|
16027 | } |
---|
16028 | |
---|
16029 | basedir = "storage/WebStatus/status_right_disk_stats" |
---|
16030 | - fileutil.make_dirs(basedir) |
---|
16031 | - ss = StorageServer(basedir, "\x00" * 20, reserved_space=reserved_space) |
---|
16032 | - expecteddir = ss.sharedir |
---|
16033 | + fp = FilePath(basedir) |
---|
16034 | + backend = DiskBackend(fp, readonly=False, reserved_space=reserved_space) |
---|
16035 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
16036 | + expecteddir = backend._sharedir |
---|
16037 | ss.setServiceParent(self.s) |
---|
16038 | w = StorageStatus(ss) |
---|
16039 | html = w.renderSynchronously() |
---|
16040 | hunk ./src/allmydata/test/test_storage.py 4452 |
---|
16041 | |
---|
16042 | def test_readonly(self): |
---|
16043 | basedir = "storage/WebStatus/readonly" |
---|
16044 | - fileutil.make_dirs(basedir) |
---|
16045 | - ss = StorageServer(basedir, "\x00" * 20, readonly_storage=True) |
---|
16046 | + fp = FilePath(basedir) |
---|
16047 | + backend = DiskBackend(fp, readonly=True) |
---|
16048 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
16049 | ss.setServiceParent(self.s) |
---|
16050 | w = StorageStatus(ss) |
---|
16051 | html = w.renderSynchronously() |
---|
16052 | hunk ./src/allmydata/test/test_storage.py 4464 |
---|
16053 | |
---|
16054 | def test_reserved(self): |
---|
16055 | basedir = "storage/WebStatus/reserved" |
---|
16056 | - fileutil.make_dirs(basedir) |
---|
16057 | - ss = StorageServer(basedir, "\x00" * 20, reserved_space=10e6) |
---|
16058 | - ss.setServiceParent(self.s) |
---|
16059 | - w = StorageStatus(ss) |
---|
16060 | - html = w.renderSynchronously() |
---|
16061 | - self.failUnlessIn("<h1>Storage Server Status</h1>", html) |
---|
16062 | - s = remove_tags(html) |
---|
16063 | - self.failUnlessIn("Reserved space: - 10.00 MB (10000000)", s) |
---|
16064 | - |
---|
16065 | - def test_huge_reserved(self): |
---|
16066 | - basedir = "storage/WebStatus/reserved" |
---|
16067 | - fileutil.make_dirs(basedir) |
---|
16068 | - ss = StorageServer(basedir, "\x00" * 20, reserved_space=10e6) |
---|
16069 | + fp = FilePath(basedir) |
---|
16070 | + backend = DiskBackend(fp, readonly=False, reserved_space=10e6) |
---|
16071 | + ss = StorageServer("\x00" * 20, backend, fp) |
---|
16072 | ss.setServiceParent(self.s) |
---|
16073 | w = StorageStatus(ss) |
---|
16074 | html = w.renderSynchronously() |
---|
16075 | hunk ./src/allmydata/test/test_system.py 7 |
---|
16076 | from twisted.trial import unittest |
---|
16077 | from twisted.internet import defer |
---|
16078 | from twisted.internet import threads # CLI tests use deferToThread |
---|
16079 | +from twisted.python.filepath import FilePath |
---|
16080 | |
---|
16081 | import allmydata |
---|
16082 | from allmydata import uri |
---|
16083 | hunk ./src/allmydata/test/test_system.py 11 |
---|
16084 | -from allmydata.storage.mutable import MutableShareFile |
---|
16085 | +from allmydata.storage.backends.disk.disk_backend import DiskBackend |
---|
16086 | +from allmydata.storage.backends.disk.mutable import load_mutable_disk_share |
---|
16087 | from allmydata.storage.server import si_a2b |
---|
16088 | from allmydata.immutable import offloaded, upload |
---|
16089 | from allmydata.immutable.literal import LiteralFileNode |
---|
16090 | hunk ./src/allmydata/test/test_system.py 57 |
---|
16091 | self.interrupt_after_d.callback(self) |
---|
16092 | return upload.Data.read(self, length) |
---|
16093 | |
---|
16094 | -class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): |
---|
16095 | + |
---|
16096 | +class SystemTest(SystemTestMixin, RunBinTahoeMixin): |
---|
16097 | timeout = 3600 # It takes longer than 960 seconds on Zandr's ARM box. |
---|
16098 | |
---|
16099 | def test_connections(self): |
---|
16100 | hunk ./src/allmydata/test/test_system.py 62 |
---|
16101 | - self.basedir = "system/SystemTest/test_connections" |
---|
16102 | + self.basedir = self.workdir("test_connections") |
---|
16103 | d = self.set_up_nodes() |
---|
16104 | self.extra_node = None |
---|
16105 | d.addCallback(lambda res: self.add_extra_node(self.numclients)) |
---|
16106 | hunk ./src/allmydata/test/test_system.py 90 |
---|
16107 | del test_connections |
---|
16108 | |
---|
16109 | def test_upload_and_download_random_key(self): |
---|
16110 | - self.basedir = "system/SystemTest/test_upload_and_download_random_key" |
---|
16111 | + self.basedir = self.workdir("test_upload_and_download_random_key") |
---|
16112 | return self._test_upload_and_download(convergence=None) |
---|
16113 | |
---|
16114 | def test_upload_and_download_convergent(self): |
---|
16115 | hunk ./src/allmydata/test/test_system.py 94 |
---|
16116 | - self.basedir = "system/SystemTest/test_upload_and_download_convergent" |
---|
16117 | + self.basedir = self.workdir("test_upload_and_download_convergent") |
---|
16118 | return self._test_upload_and_download(convergence="some convergence string") |
---|
16119 | |
---|
16120 | def _test_upload_and_download(self, convergence): |
---|
16121 | hunk ./src/allmydata/test/test_system.py 200 |
---|
16122 | facility="tahoe.tests") |
---|
16123 | d1 = download_to_data(badnode) |
---|
16124 | def _baduri_should_fail(res): |
---|
16125 | - log.msg("finished downloading non-existend URI", |
---|
16126 | + log.msg("finished downloading non-existent URI", |
---|
16127 | level=log.UNUSUAL, facility="tahoe.tests") |
---|
16128 | self.failUnless(isinstance(res, Failure)) |
---|
16129 | self.failUnless(res.check(NoSharesError), |
---|
16130 | hunk ./src/allmydata/test/test_system.py 423 |
---|
16131 | self.fail("unable to find any share files in %s" % basedir) |
---|
16132 | return shares |
---|
16133 | |
---|
16134 | - def _corrupt_mutable_share(self, filename, which): |
---|
16135 | - msf = MutableShareFile(filename) |
---|
16136 | - datav = msf.readv([ (0, 1000000) ]) |
---|
16137 | - final_share = datav[0] |
---|
16138 | - assert len(final_share) < 1000000 # ought to be truncated |
---|
16139 | - pieces = mutable_layout.unpack_share(final_share) |
---|
16140 | - (seqnum, root_hash, IV, k, N, segsize, datalen, |
---|
16141 | - verification_key, signature, share_hash_chain, block_hash_tree, |
---|
16142 | - share_data, enc_privkey) = pieces |
---|
16143 | + def _corrupt_mutable_share(self, ign, what, which): |
---|
16144 | + (storageindex, filename, shnum) = what |
---|
16145 | + d = defer.succeed(None) |
---|
16146 | + d.addCallback(lambda ign: load_mutable_disk_share(FilePath(filename), storageindex, shnum)) |
---|
16147 | + def _got_share(msf): |
---|
16148 | + d2 = msf.readv([ (0, 1000000) ]) |
---|
16149 | + def _got_data(datav): |
---|
16150 | + final_share = datav[0] |
---|
16151 | + assert len(final_share) < 1000000 # ought to be truncated |
---|
16152 | + pieces = mutable_layout.unpack_share(final_share) |
---|
16153 | + (seqnum, root_hash, IV, k, N, segsize, datalen, |
---|
16154 | + verification_key, signature, share_hash_chain, block_hash_tree, |
---|
16155 | + share_data, enc_privkey) = pieces |
---|
16156 | |
---|
16157 | hunk ./src/allmydata/test/test_system.py 437 |
---|
16158 | - if which == "seqnum": |
---|
16159 | - seqnum = seqnum + 15 |
---|
16160 | - elif which == "R": |
---|
16161 | - root_hash = self.flip_bit(root_hash) |
---|
16162 | - elif which == "IV": |
---|
16163 | - IV = self.flip_bit(IV) |
---|
16164 | - elif which == "segsize": |
---|
16165 | - segsize = segsize + 15 |
---|
16166 | - elif which == "pubkey": |
---|
16167 | - verification_key = self.flip_bit(verification_key) |
---|
16168 | - elif which == "signature": |
---|
16169 | - signature = self.flip_bit(signature) |
---|
16170 | - elif which == "share_hash_chain": |
---|
16171 | - nodenum = share_hash_chain.keys()[0] |
---|
16172 | - share_hash_chain[nodenum] = self.flip_bit(share_hash_chain[nodenum]) |
---|
16173 | - elif which == "block_hash_tree": |
---|
16174 | - block_hash_tree[-1] = self.flip_bit(block_hash_tree[-1]) |
---|
16175 | - elif which == "share_data": |
---|
16176 | - share_data = self.flip_bit(share_data) |
---|
16177 | - elif which == "encprivkey": |
---|
16178 | - enc_privkey = self.flip_bit(enc_privkey) |
---|
16179 | + if which == "seqnum": |
---|
16180 | + seqnum = seqnum + 15 |
---|
16181 | + elif which == "R": |
---|
16182 | + root_hash = self.flip_bit(root_hash) |
---|
16183 | + elif which == "IV": |
---|
16184 | + IV = self.flip_bit(IV) |
---|
16185 | + elif which == "segsize": |
---|
16186 | + segsize = segsize + 15 |
---|
16187 | + elif which == "pubkey": |
---|
16188 | + verification_key = self.flip_bit(verification_key) |
---|
16189 | + elif which == "signature": |
---|
16190 | + signature = self.flip_bit(signature) |
---|
16191 | + elif which == "share_hash_chain": |
---|
16192 | + nodenum = share_hash_chain.keys()[0] |
---|
16193 | + share_hash_chain[nodenum] = self.flip_bit(share_hash_chain[nodenum]) |
---|
16194 | + elif which == "block_hash_tree": |
---|
16195 | + block_hash_tree[-1] = self.flip_bit(block_hash_tree[-1]) |
---|
16196 | + elif which == "share_data": |
---|
16197 | + share_data = self.flip_bit(share_data) |
---|
16198 | + elif which == "encprivkey": |
---|
16199 | + enc_privkey = self.flip_bit(enc_privkey) |
---|
16200 | |
---|
16201 | hunk ./src/allmydata/test/test_system.py 459 |
---|
16202 | - prefix = mutable_layout.pack_prefix(seqnum, root_hash, IV, k, N, |
---|
16203 | - segsize, datalen) |
---|
16204 | - final_share = mutable_layout.pack_share(prefix, |
---|
16205 | - verification_key, |
---|
16206 | - signature, |
---|
16207 | - share_hash_chain, |
---|
16208 | - block_hash_tree, |
---|
16209 | - share_data, |
---|
16210 | - enc_privkey) |
---|
16211 | - msf.writev( [(0, final_share)], None) |
---|
16212 | + prefix = mutable_layout.pack_prefix(seqnum, root_hash, IV, k, N, |
---|
16213 | + segsize, datalen) |
---|
16214 | + final_share = mutable_layout.pack_share(prefix, |
---|
16215 | + verification_key, |
---|
16216 | + signature, |
---|
16217 | + share_hash_chain, |
---|
16218 | + block_hash_tree, |
---|
16219 | + share_data, |
---|
16220 | + enc_privkey) |
---|
16221 | |
---|
16222 | hunk ./src/allmydata/test/test_system.py 469 |
---|
16223 | + return msf.writev( [(0, final_share)], None) |
---|
16224 | + d2.addCallback(_got_data) |
---|
16225 | + return d2 |
---|
16226 | + d.addCallback(_got_share) |
---|
16227 | + return d |
---|
16228 | |
---|
16229 | def test_mutable(self): |
---|
16230 | hunk ./src/allmydata/test/test_system.py 476 |
---|
16231 | - self.basedir = "system/SystemTest/test_mutable" |
---|
16232 | + self.basedir = self.workdir("test_mutable") |
---|
16233 | DATA = "initial contents go here." # 25 bytes % 3 != 0 |
---|
16234 | DATA_uploadable = MutableData(DATA) |
---|
16235 | NEWDATA = "new contents yay" |
---|
16236 | hunk ./src/allmydata/test/test_system.py 511 |
---|
16237 | filename], |
---|
16238 | stdout=out, stderr=err) |
---|
16239 | output = out.getvalue() |
---|
16240 | + self.failUnlessEqual(err.getvalue(), "") |
---|
16241 | self.failUnlessEqual(rc, 0) |
---|
16242 | try: |
---|
16243 | hunk ./src/allmydata/test/test_system.py 514 |
---|
16244 | - self.failUnless("Mutable slot found:\n" in output) |
---|
16245 | - self.failUnless("share_type: SDMF\n" in output) |
---|
16246 | + self.failUnlessIn("Mutable slot found:\n", output) |
---|
16247 | + self.failUnlessIn("share_type: SDMF\n", output) |
---|
16248 | peerid = idlib.nodeid_b2a(self.clients[client_num].nodeid) |
---|
16249 | hunk ./src/allmydata/test/test_system.py 517 |
---|
16250 | - self.failUnless(" WE for nodeid: %s\n" % peerid in output) |
---|
16251 | - self.failUnless(" num_extra_leases: 0\n" in output) |
---|
16252 | - self.failUnless(" secrets are for nodeid: %s\n" % peerid |
---|
16253 | - in output) |
---|
16254 | - self.failUnless(" SDMF contents:\n" in output) |
---|
16255 | - self.failUnless(" seqnum: 1\n" in output) |
---|
16256 | - self.failUnless(" required_shares: 3\n" in output) |
---|
16257 | - self.failUnless(" total_shares: 10\n" in output) |
---|
16258 | - self.failUnless(" segsize: 27\n" in output, (output, filename)) |
---|
16259 | - self.failUnless(" datalen: 25\n" in output) |
---|
16260 | + self.failUnlessIn(" WE for nodeid: %s\n" % peerid, output) |
---|
16261 | + self.failUnlessIn(" num_extra_leases: 0\n", output) |
---|
16262 | + if isinstance(self.clients[client_num], DiskBackend): |
---|
16263 | + self.failUnlessIn(" secrets are for nodeid: %s\n" % peerid, output) |
---|
16264 | + self.failUnlessIn(" SDMF contents:\n", output) |
---|
16265 | + self.failUnlessIn(" seqnum: 1\n", output) |
---|
16266 | + self.failUnlessIn(" required_shares: 3\n", output) |
---|
16267 | + self.failUnlessIn(" total_shares: 10\n", output) |
---|
16268 | + self.failUnlessIn(" segsize: 27\n", output) |
---|
16269 | + self.failUnlessIn(" datalen: 25\n", output) |
---|
16270 | # the exact share_hash_chain nodes depends upon the sharenum, |
---|
16271 | # and is more of a hassle to compute than I want to deal with |
---|
16272 | # now |
---|
16273 | hunk ./src/allmydata/test/test_system.py 530 |
---|
16274 | - self.failUnless(" share_hash_chain: " in output) |
---|
16275 | - self.failUnless(" block_hash_tree: 1 nodes\n" in output) |
---|
16276 | + self.failUnlessIn(" share_hash_chain: ", output) |
---|
16277 | + self.failUnlessIn(" block_hash_tree: 1 nodes\n", output) |
---|
16278 | expected = (" verify-cap: URI:SSK-Verifier:%s:" % |
---|
16279 | base32.b2a(storage_index)) |
---|
16280 | self.failUnless(expected in output) |
---|
16281 | hunk ./src/allmydata/test/test_system.py 607 |
---|
16282 | shares = self._find_all_shares(self.basedir) |
---|
16283 | ## sort by share number |
---|
16284 | #shares.sort( lambda a,b: cmp(a[3], b[3]) ) |
---|
16285 | - where = dict([ (shnum, filename) |
---|
16286 | - for (client_num, storage_index, filename, shnum) |
---|
16287 | + where = dict([ (shnum, (storageindex, filename, shnum)) |
---|
16288 | + for (client_num, storageindex, filename, shnum) |
---|
16289 | in shares ]) |
---|
16290 | assert len(where) == 10 # this test is designed for 3-of-10 |
---|
16291 | hunk ./src/allmydata/test/test_system.py 611 |
---|
16292 | - for shnum, filename in where.items(): |
---|
16293 | + |
---|
16294 | + d2 = defer.succeed(None) |
---|
16295 | + for shnum, what in where.items(): |
---|
16296 | # shares 7,8,9 are left alone. read will check |
---|
16297 | # (share_hash_chain, block_hash_tree, share_data). New |
---|
16298 | # seqnum+R pairs will trigger a check of (seqnum, R, IV, |
---|
16299 | hunk ./src/allmydata/test/test_system.py 621 |
---|
16300 | if shnum == 0: |
---|
16301 | # read: this will trigger "pubkey doesn't match |
---|
16302 | # fingerprint". |
---|
16303 | - self._corrupt_mutable_share(filename, "pubkey") |
---|
16304 | - self._corrupt_mutable_share(filename, "encprivkey") |
---|
16305 | + d2.addCallback(self._corrupt_mutable_share, what, "pubkey") |
---|
16306 | + d2.addCallback(self._corrupt_mutable_share, what, "encprivkey") |
---|
16307 | elif shnum == 1: |
---|
16308 | # triggers "signature is invalid" |
---|
16309 | hunk ./src/allmydata/test/test_system.py 625 |
---|
16310 | - self._corrupt_mutable_share(filename, "seqnum") |
---|
16311 | + d2.addCallback(self._corrupt_mutable_share, what, "seqnum") |
---|
16312 | elif shnum == 2: |
---|
16313 | # triggers "signature is invalid" |
---|
16314 | hunk ./src/allmydata/test/test_system.py 628 |
---|
16315 | - self._corrupt_mutable_share(filename, "R") |
---|
16316 | + d2.addCallback(self._corrupt_mutable_share, what, "R") |
---|
16317 | elif shnum == 3: |
---|
16318 | # triggers "signature is invalid" |
---|
16319 | hunk ./src/allmydata/test/test_system.py 631 |
---|
16320 | - self._corrupt_mutable_share(filename, "segsize") |
---|
16321 | + d2.addCallback(self._corrupt_mutable_share, what, "segsize") |
---|
16322 | elif shnum == 4: |
---|
16323 | hunk ./src/allmydata/test/test_system.py 633 |
---|
16324 | - self._corrupt_mutable_share(filename, "share_hash_chain") |
---|
16325 | + d2.addCallback(self._corrupt_mutable_share, what, "share_hash_chain") |
---|
16326 | elif shnum == 5: |
---|
16327 | hunk ./src/allmydata/test/test_system.py 635 |
---|
16328 | - self._corrupt_mutable_share(filename, "block_hash_tree") |
---|
16329 | + d2.addCallback(self._corrupt_mutable_share, what, "block_hash_tree") |
---|
16330 | elif shnum == 6: |
---|
16331 | hunk ./src/allmydata/test/test_system.py 637 |
---|
16332 | - self._corrupt_mutable_share(filename, "share_data") |
---|
16333 | + d2.addCallback(self._corrupt_mutable_share, what, "share_data") |
---|
16334 | # other things to correct: IV, signature |
---|
16335 | # 7,8,9 are left alone |
---|
16336 | |
---|
16337 | hunk ./src/allmydata/test/test_system.py 653 |
---|
16338 | # for one failure mode at a time. |
---|
16339 | |
---|
16340 | # when we retrieve this, we should get three signature |
---|
16341 | - # failures (where we've mangled seqnum, R, and segsize). The |
---|
16342 | - # pubkey mangling |
---|
16343 | + # failures (where we've mangled seqnum, R, and segsize). |
---|
16344 | + return d2 |
---|
16345 | d.addCallback(_corrupt_shares) |
---|
16346 | |
---|
16347 | d.addCallback(lambda res: self._newnode3.download_best_version()) |
---|
16348 | hunk ./src/allmydata/test/test_system.py 729 |
---|
16349 | # plaintext_hash check. |
---|
16350 | |
---|
16351 | def test_filesystem(self): |
---|
16352 | - self.basedir = "system/SystemTest/test_filesystem" |
---|
16353 | + self.basedir = self.workdir("test_filesystem") |
---|
16354 | self.data = LARGE_DATA |
---|
16355 | d = self.set_up_nodes(use_stats_gatherer=True) |
---|
16356 | def _new_happy_semantics(ign): |
---|
16357 | hunk ./src/allmydata/test/test_system.py 1342 |
---|
16358 | unicode_to_argv(filename)], |
---|
16359 | stdout=out, stderr=err) |
---|
16360 | output = out.getvalue() |
---|
16361 | + self.failUnlessEqual(err.getvalue(), "") |
---|
16362 | self.failUnlessEqual(rc, 0) |
---|
16363 | |
---|
16364 | # we only upload a single file, so we can assert some things about |
---|
16365 | hunk ./src/allmydata/test/test_system.py 1348 |
---|
16366 | # its size and shares. |
---|
16367 | self.failUnlessIn("share filename: %s" % quote_output(abspath_expanduser_unicode(filename)), output) |
---|
16368 | - self.failUnlessIn("size: %d\n" % len(self.data), output) |
---|
16369 | - self.failUnlessIn("num_segments: 1\n", output) |
---|
16370 | + self.failUnlessIn(" file_size: %d\n" % len(self.data), output) |
---|
16371 | + self.failUnlessIn(" num_segments: 1\n", output) |
---|
16372 | # segment_size is always a multiple of needed_shares |
---|
16373 | hunk ./src/allmydata/test/test_system.py 1351 |
---|
16374 | - self.failUnlessIn("segment_size: %d\n" % mathutil.next_multiple(len(self.data), 3), output) |
---|
16375 | - self.failUnlessIn("total_shares: 10\n", output) |
---|
16376 | + self.failUnlessIn(" segment_size: %d\n" % mathutil.next_multiple(len(self.data), 3), output) |
---|
16377 | + self.failUnlessIn(" total_shares: 10\n", output) |
---|
16378 | # keys which are supposed to be present |
---|
16379 | hunk ./src/allmydata/test/test_system.py 1354 |
---|
16380 | - for key in ("size", "num_segments", "segment_size", |
---|
16381 | + for key in ("file_size", "num_segments", "segment_size", |
---|
16382 | "needed_shares", "total_shares", |
---|
16383 | "codec_name", "codec_params", "tail_codec_params", |
---|
16384 | #"plaintext_hash", "plaintext_root_hash", |
---|
16385 | hunk ./src/allmydata/test/test_system.py 1360 |
---|
16386 | "crypttext_hash", "crypttext_root_hash", |
---|
16387 | "share_root_hash", "UEB_hash"): |
---|
16388 | - self.failUnlessIn("%s: " % key, output) |
---|
16389 | + self.failUnlessIn(" %s: " % key, output) |
---|
16390 | self.failUnlessIn(" verify-cap: URI:CHK-Verifier:", output) |
---|
16391 | |
---|
16392 | # now use its storage index to find the other shares using the |
---|
16393 | hunk ./src/allmydata/test/test_system.py 1372 |
---|
16394 | nodedirs = [self.getdir("client%d" % i) for i in range(self.numclients)] |
---|
16395 | cmd = ["debug", "find-shares", storage_index_s] + nodedirs |
---|
16396 | rc = runner.runner(cmd, stdout=out, stderr=err) |
---|
16397 | + self.failUnlessEqual(err.getvalue(), "") |
---|
16398 | self.failUnlessEqual(rc, 0) |
---|
16399 | out.seek(0) |
---|
16400 | sharefiles = [sfn.strip() for sfn in out.readlines()] |
---|
16401 | hunk ./src/allmydata/test/test_system.py 1383 |
---|
16402 | nodedirs = [self.getdir("client%d" % i) for i in range(self.numclients)] |
---|
16403 | cmd = ["debug", "catalog-shares"] + nodedirs |
---|
16404 | rc = runner.runner(cmd, stdout=out, stderr=err) |
---|
16405 | + self.failUnlessEqual(err.getvalue(), "") |
---|
16406 | self.failUnlessEqual(rc, 0) |
---|
16407 | out.seek(0) |
---|
16408 | descriptions = [sfn.strip() for sfn in out.readlines()] |
---|
16409 | hunk ./src/allmydata/test/test_system.py 1387 |
---|
16410 | - self.failUnlessEqual(len(descriptions), 30) |
---|
16411 | + self.failUnlessEqual(len(descriptions), 30, repr((cmd, descriptions))) |
---|
16412 | matching = [line |
---|
16413 | for line in descriptions |
---|
16414 | if line.startswith("CHK %s " % storage_index_s)] |
---|
16415 | hunk ./src/allmydata/test/test_system.py 1766 |
---|
16416 | def test_filesystem_with_cli_in_subprocess(self): |
---|
16417 | # We do this in a separate test so that test_filesystem doesn't skip if we can't run bin/tahoe. |
---|
16418 | |
---|
16419 | - self.basedir = "system/SystemTest/test_filesystem_with_cli_in_subprocess" |
---|
16420 | + self.basedir = self.workdir("test_filesystem_with_cli_in_subprocess") |
---|
16421 | d = self.set_up_nodes() |
---|
16422 | def _new_happy_semantics(ign): |
---|
16423 | for c in self.clients: |
---|
16424 | hunk ./src/allmydata/test/test_system.py 1892 |
---|
16425 | return d |
---|
16426 | d.addCallback(_got_lit_filenode) |
---|
16427 | return d |
---|
16428 | + |
---|
16429 | + |
---|
16430 | +class SystemWithDiskBackend(SystemTest, unittest.TestCase): |
---|
16431 | + # The disk backend can use default options. |
---|
16432 | + pass |
---|
16433 | + |
---|
16434 | + |
---|
16435 | +class SystemWithS3Backend(SystemTest, unittest.TestCase): |
---|
16436 | + def _get_extra_config(self, i): |
---|
16437 | + # all nodes are storage servers |
---|
16438 | + return ("[storage]\n" |
---|
16439 | + "backend = mock_s3\n") |
---|
16440 | hunk ./src/allmydata/test/test_upload.py 3 |
---|
16441 | # -*- coding: utf-8 -*- |
---|
16442 | |
---|
16443 | -import os, shutil |
---|
16444 | +import os |
---|
16445 | from cStringIO import StringIO |
---|
16446 | from twisted.trial import unittest |
---|
16447 | from twisted.python.failure import Failure |
---|
16448 | hunk ./src/allmydata/test/test_upload.py 14 |
---|
16449 | from allmydata import uri, monitor, client |
---|
16450 | from allmydata.immutable import upload, encode |
---|
16451 | from allmydata.interfaces import FileTooLargeError, UploadUnhappinessError |
---|
16452 | -from allmydata.util import log, base32 |
---|
16453 | +from allmydata.util import log, base32, fileutil |
---|
16454 | from allmydata.util.assertutil import precondition |
---|
16455 | from allmydata.util.deferredutil import DeferredListShouldSucceed |
---|
16456 | from allmydata.test.no_network import GridTestMixin |
---|
16457 | hunk ./src/allmydata/test/test_upload.py 22 |
---|
16458 | from allmydata.util.happinessutil import servers_of_happiness, \ |
---|
16459 | shares_by_server, merge_servers |
---|
16460 | from allmydata.storage_client import StorageFarmBroker |
---|
16461 | -from allmydata.storage.server import storage_index_to_dir |
---|
16462 | |
---|
16463 | MiB = 1024*1024 |
---|
16464 | |
---|
16465 | hunk ./src/allmydata/test/test_upload.py 746 |
---|
16466 | servertoshnums = {} # k: server, v: set(shnum) |
---|
16467 | |
---|
16468 | for i, c in self.g.servers_by_number.iteritems(): |
---|
16469 | - for (dirp, dirns, fns) in os.walk(c.sharedir): |
---|
16470 | + for (dirp, dirns, fns) in os.walk(c.backend._sharedir.path): |
---|
16471 | for fn in fns: |
---|
16472 | try: |
---|
16473 | sharenum = int(fn) |
---|
16474 | hunk ./src/allmydata/test/test_upload.py 820 |
---|
16475 | if share_number is not None: |
---|
16476 | self._copy_share_to_server(share_number, server_number) |
---|
16477 | |
---|
16478 | - |
---|
16479 | def _copy_share_to_server(self, share_number, server_number): |
---|
16480 | ss = self.g.servers_by_number[server_number] |
---|
16481 | hunk ./src/allmydata/test/test_upload.py 822 |
---|
16482 | - # Copy share i from the directory associated with the first |
---|
16483 | - # storage server to the directory associated with this one. |
---|
16484 | - assert self.g, "I tried to find a grid at self.g, but failed" |
---|
16485 | - assert self.shares, "I tried to find shares at self.shares, but failed" |
---|
16486 | - old_share_location = self.shares[share_number][2] |
---|
16487 | - new_share_location = os.path.join(ss.storedir, "shares") |
---|
16488 | - si = uri.from_string(self.uri).get_storage_index() |
---|
16489 | - new_share_location = os.path.join(new_share_location, |
---|
16490 | - storage_index_to_dir(si)) |
---|
16491 | - if not os.path.exists(new_share_location): |
---|
16492 | - os.makedirs(new_share_location) |
---|
16493 | - new_share_location = os.path.join(new_share_location, |
---|
16494 | - str(share_number)) |
---|
16495 | - if old_share_location != new_share_location: |
---|
16496 | - shutil.copy(old_share_location, new_share_location) |
---|
16497 | - shares = self.find_uri_shares(self.uri) |
---|
16498 | - # Make sure that the storage server has the share. |
---|
16499 | - self.failUnless((share_number, ss.my_nodeid, new_share_location) |
---|
16500 | - in shares) |
---|
16501 | + self.copy_share(self.shares[share_number], self.uri, ss) |
---|
16502 | |
---|
16503 | def _setup_grid(self): |
---|
16504 | """ |
---|
16505 | hunk ./src/allmydata/test/test_upload.py 974 |
---|
16506 | readonly=True)) |
---|
16507 | # Remove the first share from server 0. |
---|
16508 | def _remove_share_0_from_server_0(): |
---|
16509 | - share_location = self.shares[0][2] |
---|
16510 | - os.remove(share_location) |
---|
16511 | + self.shares[0][2].remove() |
---|
16512 | d.addCallback(lambda ign: |
---|
16513 | _remove_share_0_from_server_0()) |
---|
16514 | # Set happy = 4 in the client. |
---|
16515 | hunk ./src/allmydata/test/test_upload.py 1103 |
---|
16516 | self._copy_share_to_server(i, 2) |
---|
16517 | d.addCallback(_copy_shares) |
---|
16518 | # Remove the first server, and add a placeholder with share 0 |
---|
16519 | - d.addCallback(lambda ign: |
---|
16520 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16521 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16522 | d.addCallback(lambda ign: |
---|
16523 | self._add_server_with_share(server_number=4, share_number=0)) |
---|
16524 | # Now try uploading. |
---|
16525 | hunk ./src/allmydata/test/test_upload.py 1134 |
---|
16526 | d.addCallback(lambda ign: |
---|
16527 | self._add_server(server_number=4)) |
---|
16528 | d.addCallback(_copy_shares) |
---|
16529 | - d.addCallback(lambda ign: |
---|
16530 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16531 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16532 | d.addCallback(_reset_encoding_parameters) |
---|
16533 | d.addCallback(lambda client: |
---|
16534 | client.upload(upload.Data("data" * 10000, convergence=""))) |
---|
16535 | hunk ./src/allmydata/test/test_upload.py 1196 |
---|
16536 | self._copy_share_to_server(i, 2) |
---|
16537 | d.addCallback(_copy_shares) |
---|
16538 | # Remove server 0, and add another in its place |
---|
16539 | - d.addCallback(lambda ign: |
---|
16540 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16541 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16542 | d.addCallback(lambda ign: |
---|
16543 | self._add_server_with_share(server_number=4, share_number=0, |
---|
16544 | readonly=True)) |
---|
16545 | hunk ./src/allmydata/test/test_upload.py 1237 |
---|
16546 | for i in xrange(1, 10): |
---|
16547 | self._copy_share_to_server(i, 2) |
---|
16548 | d.addCallback(_copy_shares) |
---|
16549 | - d.addCallback(lambda ign: |
---|
16550 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16551 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16552 | def _reset_encoding_parameters(ign, happy=4): |
---|
16553 | client = self.g.clients[0] |
---|
16554 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy |
---|
16555 | hunk ./src/allmydata/test/test_upload.py 1273 |
---|
16556 | # remove the original server |
---|
16557 | # (necessary to ensure that the Tahoe2ServerSelector will distribute |
---|
16558 | # all the shares) |
---|
16559 | - def _remove_server(ign): |
---|
16560 | - server = self.g.servers_by_number[0] |
---|
16561 | - self.g.remove_server(server.my_nodeid) |
---|
16562 | - d.addCallback(_remove_server) |
---|
16563 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16564 | # This should succeed; we still have 4 servers, and the |
---|
16565 | # happiness of the upload is 4. |
---|
16566 | d.addCallback(lambda ign: |
---|
16567 | hunk ./src/allmydata/test/test_upload.py 1285 |
---|
16568 | d.addCallback(lambda ign: |
---|
16569 | self._setup_and_upload()) |
---|
16570 | d.addCallback(_do_server_setup) |
---|
16571 | - d.addCallback(_remove_server) |
---|
16572 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16573 | d.addCallback(lambda ign: |
---|
16574 | self.shouldFail(UploadUnhappinessError, |
---|
16575 | "test_dropped_servers_in_encoder", |
---|
16576 | hunk ./src/allmydata/test/test_upload.py 1307 |
---|
16577 | self._add_server_with_share(4, 7, readonly=True) |
---|
16578 | self._add_server_with_share(5, 8, readonly=True) |
---|
16579 | d.addCallback(_do_server_setup_2) |
---|
16580 | - d.addCallback(_remove_server) |
---|
16581 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16582 | d.addCallback(lambda ign: |
---|
16583 | self._do_upload_with_broken_servers(1)) |
---|
16584 | d.addCallback(_set_basedir) |
---|
16585 | hunk ./src/allmydata/test/test_upload.py 1314 |
---|
16586 | d.addCallback(lambda ign: |
---|
16587 | self._setup_and_upload()) |
---|
16588 | d.addCallback(_do_server_setup_2) |
---|
16589 | - d.addCallback(_remove_server) |
---|
16590 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16591 | d.addCallback(lambda ign: |
---|
16592 | self.shouldFail(UploadUnhappinessError, |
---|
16593 | "test_dropped_servers_in_encoder", |
---|
16594 | hunk ./src/allmydata/test/test_upload.py 1528 |
---|
16595 | for i in xrange(1, 10): |
---|
16596 | self._copy_share_to_server(i, 1) |
---|
16597 | d.addCallback(_copy_shares) |
---|
16598 | - d.addCallback(lambda ign: |
---|
16599 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16600 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16601 | def _prepare_client(ign): |
---|
16602 | client = self.g.clients[0] |
---|
16603 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4 |
---|
16604 | hunk ./src/allmydata/test/test_upload.py 1550 |
---|
16605 | def _setup(ign): |
---|
16606 | for i in xrange(1, 11): |
---|
16607 | self._add_server(server_number=i) |
---|
16608 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16609 | + self.remove_server(0) |
---|
16610 | c = self.g.clients[0] |
---|
16611 | # We set happy to an unsatisfiable value so that we can check the |
---|
16612 | # counting in the exception message. The same progress message |
---|
16613 | hunk ./src/allmydata/test/test_upload.py 1577 |
---|
16614 | self._add_server(server_number=i) |
---|
16615 | self._add_server(server_number=11, readonly=True) |
---|
16616 | self._add_server(server_number=12, readonly=True) |
---|
16617 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16618 | + self.remove_server(0) |
---|
16619 | c = self.g.clients[0] |
---|
16620 | c.DEFAULT_ENCODING_PARAMETERS['happy'] = 45 |
---|
16621 | return c |
---|
16622 | hunk ./src/allmydata/test/test_upload.py 1605 |
---|
16623 | # the first one that the selector sees. |
---|
16624 | for i in xrange(10): |
---|
16625 | self._copy_share_to_server(i, 9) |
---|
16626 | - # Remove server 0, and its contents |
---|
16627 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16628 | + self.remove_server(0) |
---|
16629 | # Make happiness unsatisfiable |
---|
16630 | c = self.g.clients[0] |
---|
16631 | c.DEFAULT_ENCODING_PARAMETERS['happy'] = 45 |
---|
16632 | hunk ./src/allmydata/test/test_upload.py 1625 |
---|
16633 | def _then(ign): |
---|
16634 | for i in xrange(1, 11): |
---|
16635 | self._add_server(server_number=i, readonly=True) |
---|
16636 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16637 | + self.remove_server(0) |
---|
16638 | c = self.g.clients[0] |
---|
16639 | c.DEFAULT_ENCODING_PARAMETERS['k'] = 2 |
---|
16640 | c.DEFAULT_ENCODING_PARAMETERS['happy'] = 4 |
---|
16641 | hunk ./src/allmydata/test/test_upload.py 1661 |
---|
16642 | self._add_server(server_number=4, readonly=True)) |
---|
16643 | d.addCallback(lambda ign: |
---|
16644 | self._add_server(server_number=5, readonly=True)) |
---|
16645 | - d.addCallback(lambda ign: |
---|
16646 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16647 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16648 | def _reset_encoding_parameters(ign, happy=4): |
---|
16649 | client = self.g.clients[0] |
---|
16650 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = happy |
---|
16651 | hunk ./src/allmydata/test/test_upload.py 1696 |
---|
16652 | d.addCallback(lambda ign: |
---|
16653 | self._add_server(server_number=2)) |
---|
16654 | def _break_server_2(ign): |
---|
16655 | - serverid = self.g.servers_by_number[2].my_nodeid |
---|
16656 | + serverid = self.get_server(2).get_serverid() |
---|
16657 | self.g.break_server(serverid) |
---|
16658 | d.addCallback(_break_server_2) |
---|
16659 | d.addCallback(lambda ign: |
---|
16660 | hunk ./src/allmydata/test/test_upload.py 1705 |
---|
16661 | self._add_server(server_number=4, readonly=True)) |
---|
16662 | d.addCallback(lambda ign: |
---|
16663 | self._add_server(server_number=5, readonly=True)) |
---|
16664 | - d.addCallback(lambda ign: |
---|
16665 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid)) |
---|
16666 | + d.addCallback(lambda ign: self.remove_server(0)) |
---|
16667 | d.addCallback(_reset_encoding_parameters) |
---|
16668 | d.addCallback(lambda client: |
---|
16669 | self.shouldFail(UploadUnhappinessError, "test_selection_exceptions", |
---|
16670 | hunk ./src/allmydata/test/test_upload.py 1816 |
---|
16671 | # Copy shares |
---|
16672 | self._copy_share_to_server(1, 1) |
---|
16673 | self._copy_share_to_server(2, 1) |
---|
16674 | - # Remove server 0 |
---|
16675 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16676 | + self.remove_server(0) |
---|
16677 | client = self.g.clients[0] |
---|
16678 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = 3 |
---|
16679 | return client |
---|
16680 | hunk ./src/allmydata/test/test_upload.py 1849 |
---|
16681 | self._copy_share_to_server(3, 1) |
---|
16682 | storedir = self.get_serverdir(0) |
---|
16683 | # remove the storedir, wiping out any existing shares |
---|
16684 | - shutil.rmtree(storedir) |
---|
16685 | + fileutil.fp_remove(storedir) |
---|
16686 | # create an empty storedir to replace the one we just removed |
---|
16687 | hunk ./src/allmydata/test/test_upload.py 1851 |
---|
16688 | - os.mkdir(storedir) |
---|
16689 | + storedir.makedirs() |
---|
16690 | client = self.g.clients[0] |
---|
16691 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4 |
---|
16692 | return client |
---|
16693 | hunk ./src/allmydata/test/test_upload.py 1890 |
---|
16694 | self._copy_share_to_server(3, 1) |
---|
16695 | storedir = self.get_serverdir(0) |
---|
16696 | # remove the storedir, wiping out any existing shares |
---|
16697 | - shutil.rmtree(storedir) |
---|
16698 | + fileutil.fp_remove(storedir) |
---|
16699 | # create an empty storedir to replace the one we just removed |
---|
16700 | hunk ./src/allmydata/test/test_upload.py 1892 |
---|
16701 | - os.mkdir(storedir) |
---|
16702 | + storedir.makedirs() |
---|
16703 | client = self.g.clients[0] |
---|
16704 | client.DEFAULT_ENCODING_PARAMETERS['happy'] = 4 |
---|
16705 | return client |
---|
16706 | hunk ./src/allmydata/test/test_upload.py 1930 |
---|
16707 | readonly=True) |
---|
16708 | self._add_server_with_share(server_number=4, share_number=3, |
---|
16709 | readonly=True) |
---|
16710 | - # Remove server 0. |
---|
16711 | - self.g.remove_server(self.g.servers_by_number[0].my_nodeid) |
---|
16712 | + self.remove_server(0) |
---|
16713 | # Set the client appropriately |
---|
16714 | c = self.g.clients[0] |
---|
16715 | c.DEFAULT_ENCODING_PARAMETERS['happy'] = 4 |
---|
16716 | hunk ./src/allmydata/test/test_util.py 9 |
---|
16717 | from twisted.trial import unittest |
---|
16718 | from twisted.internet import defer, reactor |
---|
16719 | from twisted.python.failure import Failure |
---|
16720 | +from twisted.python.filepath import FilePath |
---|
16721 | from twisted.python import log |
---|
16722 | from pycryptopp.hash.sha256 import SHA256 as _hash |
---|
16723 | |
---|
16724 | hunk ./src/allmydata/test/test_util.py 508 |
---|
16725 | os.chdir(saved_cwd) |
---|
16726 | |
---|
16727 | def test_disk_stats(self): |
---|
16728 | - avail = fileutil.get_available_space('.', 2**14) |
---|
16729 | + avail = fileutil.get_available_space(FilePath('.'), 2**14) |
---|
16730 | if avail == 0: |
---|
16731 | raise unittest.SkipTest("This test will spuriously fail there is no disk space left.") |
---|
16732 | |
---|
16733 | hunk ./src/allmydata/test/test_util.py 512 |
---|
16734 | - disk = fileutil.get_disk_stats('.', 2**13) |
---|
16735 | + disk = fileutil.get_disk_stats(FilePath('.'), 2**13) |
---|
16736 | self.failUnless(disk['total'] > 0, disk['total']) |
---|
16737 | self.failUnless(disk['used'] > 0, disk['used']) |
---|
16738 | self.failUnless(disk['free_for_root'] > 0, disk['free_for_root']) |
---|
16739 | hunk ./src/allmydata/test/test_util.py 521 |
---|
16740 | |
---|
16741 | def test_disk_stats_avail_nonnegative(self): |
---|
16742 | # This test will spuriously fail if you have more than 2^128 |
---|
16743 | - # bytes of available space on your filesystem. |
---|
16744 | - disk = fileutil.get_disk_stats('.', 2**128) |
---|
16745 | + # bytes of available space on your filesystem (lucky you). |
---|
16746 | + disk = fileutil.get_disk_stats(FilePath('.'), 2**128) |
---|
16747 | self.failUnlessEqual(disk['avail'], 0) |
---|
16748 | |
---|
16749 | class PollMixinTests(unittest.TestCase): |
---|
16750 | hunk ./src/allmydata/test/test_web.py 12 |
---|
16751 | from twisted.python import failure, log |
---|
16752 | from nevow import rend |
---|
16753 | from allmydata import interfaces, uri, webish, dirnode |
---|
16754 | -from allmydata.storage.shares import get_share_file |
---|
16755 | from allmydata.storage_client import StorageFarmBroker |
---|
16756 | from allmydata.immutable import upload |
---|
16757 | from allmydata.immutable.downloader.status import DownloadStatus |
---|
16758 | hunk ./src/allmydata/test/test_web.py 3998 |
---|
16759 | self.fileurls[which] = "uri/" + urllib.quote(self.uris[which]) |
---|
16760 | d.addCallback(_compute_fileurls) |
---|
16761 | |
---|
16762 | - def _clobber_shares(ignored): |
---|
16763 | - good_shares = self.find_uri_shares(self.uris["good"]) |
---|
16764 | - self.failUnlessReallyEqual(len(good_shares), 10) |
---|
16765 | - sick_shares = self.find_uri_shares(self.uris["sick"]) |
---|
16766 | - os.unlink(sick_shares[0][2]) |
---|
16767 | - dead_shares = self.find_uri_shares(self.uris["dead"]) |
---|
16768 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["good"])) |
---|
16769 | + d.addCallback(lambda good_shares: self.failUnlessReallyEqual(len(good_shares), 10)) |
---|
16770 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["sick"])) |
---|
16771 | + d.addCallback(lambda sick_shares: sick_shares[0][2].remove()) |
---|
16772 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["dead"])) |
---|
16773 | + def _remove_dead_shares(dead_shares): |
---|
16774 | for i in range(1, 10): |
---|
16775 | hunk ./src/allmydata/test/test_web.py 4005 |
---|
16776 | - os.unlink(dead_shares[i][2]) |
---|
16777 | - c_shares = self.find_uri_shares(self.uris["corrupt"]) |
---|
16778 | + dead_shares[i][2].remove() |
---|
16779 | + d.addCallback(_remove_dead_shares) |
---|
16780 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["corrupt"])) |
---|
16781 | + def _corrupt_shares(c_shares): |
---|
16782 | cso = CorruptShareOptions() |
---|
16783 | cso.stdout = StringIO() |
---|
16784 | hunk ./src/allmydata/test/test_web.py 4011 |
---|
16785 | - cso.parseOptions([c_shares[0][2]]) |
---|
16786 | + cso.parseOptions([c_shares[0][2].path]) |
---|
16787 | corrupt_share(cso) |
---|
16788 | hunk ./src/allmydata/test/test_web.py 4013 |
---|
16789 | - d.addCallback(_clobber_shares) |
---|
16790 | + d.addCallback(_corrupt_shares) |
---|
16791 | |
---|
16792 | d.addCallback(self.CHECK, "good", "t=check") |
---|
16793 | def _got_html_good(res): |
---|
16794 | hunk ./src/allmydata/test/test_web.py 4142 |
---|
16795 | self.fileurls[which] = "uri/" + urllib.quote(self.uris[which]) |
---|
16796 | d.addCallback(_compute_fileurls) |
---|
16797 | |
---|
16798 | - def _clobber_shares(ignored): |
---|
16799 | - good_shares = self.find_uri_shares(self.uris["good"]) |
---|
16800 | - self.failUnlessReallyEqual(len(good_shares), 10) |
---|
16801 | - sick_shares = self.find_uri_shares(self.uris["sick"]) |
---|
16802 | - os.unlink(sick_shares[0][2]) |
---|
16803 | - dead_shares = self.find_uri_shares(self.uris["dead"]) |
---|
16804 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["good"])) |
---|
16805 | + d.addCallback(lambda good_shares: self.failUnlessReallyEqual(len(good_shares), 10)) |
---|
16806 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["sick"])) |
---|
16807 | + d.addCallback(lambda sick_shares: sick_shares[0][2].remove()) |
---|
16808 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["dead"])) |
---|
16809 | + def _remove_dead_shares(dead_shares): |
---|
16810 | for i in range(1, 10): |
---|
16811 | hunk ./src/allmydata/test/test_web.py 4149 |
---|
16812 | - os.unlink(dead_shares[i][2]) |
---|
16813 | - c_shares = self.find_uri_shares(self.uris["corrupt"]) |
---|
16814 | + dead_shares[i][2].remove() |
---|
16815 | + d.addCallback(_remove_dead_shares) |
---|
16816 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["corrupt"])) |
---|
16817 | + def _corrupt_shares(c_shares): |
---|
16818 | cso = CorruptShareOptions() |
---|
16819 | cso.stdout = StringIO() |
---|
16820 | hunk ./src/allmydata/test/test_web.py 4155 |
---|
16821 | - cso.parseOptions([c_shares[0][2]]) |
---|
16822 | + cso.parseOptions([c_shares[0][2].path]) |
---|
16823 | corrupt_share(cso) |
---|
16824 | hunk ./src/allmydata/test/test_web.py 4157 |
---|
16825 | - d.addCallback(_clobber_shares) |
---|
16826 | + d.addCallback(_corrupt_shares) |
---|
16827 | |
---|
16828 | d.addCallback(self.CHECK, "good", "t=check&repair=true") |
---|
16829 | def _got_html_good(res): |
---|
16830 | hunk ./src/allmydata/test/test_web.py 4212 |
---|
16831 | self.fileurls[which] = "uri/" + urllib.quote(self.uris[which]) |
---|
16832 | d.addCallback(_compute_fileurls) |
---|
16833 | |
---|
16834 | - def _clobber_shares(ignored): |
---|
16835 | - sick_shares = self.find_uri_shares(self.uris["sick"]) |
---|
16836 | - os.unlink(sick_shares[0][2]) |
---|
16837 | - d.addCallback(_clobber_shares) |
---|
16838 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["sick"])) |
---|
16839 | + d.addCallback(lambda sick_shares: sick_shares[0][2].remove()) |
---|
16840 | |
---|
16841 | d.addCallback(self.CHECK, "sick", "t=check&repair=true&output=json") |
---|
16842 | def _got_json_sick(res): |
---|
16843 | hunk ./src/allmydata/test/test_web.py 4526 |
---|
16844 | future_node = UnknownNode(unknown_rwcap, unknown_rocap) |
---|
16845 | d.addCallback(lambda ign: self.rootnode.set_node(u"future", future_node)) |
---|
16846 | |
---|
16847 | - def _clobber_shares(ignored): |
---|
16848 | - self.delete_shares_numbered(self.uris["sick"], [0,1]) |
---|
16849 | - d.addCallback(_clobber_shares) |
---|
16850 | + d.addCallback(lambda ign: self.delete_shares_numbered(self.uris["sick"], [0,1])) |
---|
16851 | |
---|
16852 | # root |
---|
16853 | # root/good |
---|
16854 | hunk ./src/allmydata/test/test_web.py 4698 |
---|
16855 | #d.addCallback(lambda fn: self.rootnode.set_node(u"corrupt", fn)) |
---|
16856 | #d.addCallback(_stash_uri, "corrupt") |
---|
16857 | |
---|
16858 | - def _clobber_shares(ignored): |
---|
16859 | - good_shares = self.find_uri_shares(self.uris["good"]) |
---|
16860 | - self.failUnlessReallyEqual(len(good_shares), 10) |
---|
16861 | - sick_shares = self.find_uri_shares(self.uris["sick"]) |
---|
16862 | - os.unlink(sick_shares[0][2]) |
---|
16863 | - #dead_shares = self.find_uri_shares(self.uris["dead"]) |
---|
16864 | - #for i in range(1, 10): |
---|
16865 | - # os.unlink(dead_shares[i][2]) |
---|
16866 | - |
---|
16867 | - #c_shares = self.find_uri_shares(self.uris["corrupt"]) |
---|
16868 | - #cso = CorruptShareOptions() |
---|
16869 | - #cso.stdout = StringIO() |
---|
16870 | - #cso.parseOptions([c_shares[0][2]]) |
---|
16871 | - #corrupt_share(cso) |
---|
16872 | - d.addCallback(_clobber_shares) |
---|
16873 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["good"])) |
---|
16874 | + d.addCallback(lambda good_shares: self.failUnlessReallyEqual(len(good_shares), 10)) |
---|
16875 | + d.addCallback(lambda ign: self.find_uri_shares(self.uris["sick"])) |
---|
16876 | + d.addCallback(lambda sick_shares: sick_shares[0][2].remove()) |
---|
16877 | + #d.addCallback(lambda ign: self.find_uri_shares(self.uris["dead"])) |
---|
16878 | + #def _remove_dead_shares(dead_shares): |
---|
16879 | + # for i in range(1, 10): |
---|
16880 | + # dead_shares[i][2].remove() |
---|
16881 | + #d.addCallback(_remove_dead_shares) |
---|
16882 | + #d.addCallback(lambda ign: self.find_uri_shares(self.uris["corrupt"])) |
---|
16883 | + #def _corrupt_shares(c_shares): |
---|
16884 | + # cso = CorruptShareOptions() |
---|
16885 | + # cso.stdout = StringIO() |
---|
16886 | + # cso.parseOptions([c_shares[0][2].path]) |
---|
16887 | + # corrupt_share(cso) |
---|
16888 | + #d.addCallback(_corrupt_shares) |
---|
16889 | |
---|
16890 | # root |
---|
16891 | # root/good CHK, 10 shares |
---|
16892 | hunk ./src/allmydata/test/test_web.py 4762 |
---|
16893 | d.addErrback(self.explain_web_error) |
---|
16894 | return d |
---|
16895 | |
---|
16896 | - def _count_leases(self, ignored, which): |
---|
16897 | - u = self.uris[which] |
---|
16898 | - shares = self.find_uri_shares(u) |
---|
16899 | - lease_counts = [] |
---|
16900 | - for shnum, serverid, fn in shares: |
---|
16901 | - sf = get_share_file(fn) |
---|
16902 | - num_leases = len(list(sf.get_leases())) |
---|
16903 | - lease_counts.append( (fn, num_leases) ) |
---|
16904 | - return lease_counts |
---|
16905 | - |
---|
16906 | - def _assert_leasecount(self, lease_counts, expected): |
---|
16907 | - for (fn, num_leases) in lease_counts: |
---|
16908 | - if num_leases != expected: |
---|
16909 | - self.fail("expected %d leases, have %d, on %s" % |
---|
16910 | - (expected, num_leases, fn)) |
---|
16911 | + def _assert_leasecount(self, which, expected): |
---|
16912 | + d = self.count_leases(self.uris[which]) |
---|
16913 | + def _got_counts(lease_counts): |
---|
16914 | + for (fn, num_leases) in lease_counts: |
---|
16915 | + if num_leases != expected: |
---|
16916 | + self.fail("expected %d leases, have %d, on %s" % |
---|
16917 | + (expected, num_leases, fn)) |
---|
16918 | + d.addCallback(_got_counts) |
---|
16919 | + return d |
---|
16920 | |
---|
16921 | def test_add_lease(self): |
---|
16922 | self.basedir = "web/Grid/add_lease" |
---|
16923 | hunk ./src/allmydata/test/test_web.py 4798 |
---|
16924 | self.fileurls[which] = "uri/" + urllib.quote(self.uris[which]) |
---|
16925 | d.addCallback(_compute_fileurls) |
---|
16926 | |
---|
16927 | - d.addCallback(self._count_leases, "one") |
---|
16928 | - d.addCallback(self._assert_leasecount, 1) |
---|
16929 | - d.addCallback(self._count_leases, "two") |
---|
16930 | - d.addCallback(self._assert_leasecount, 1) |
---|
16931 | - d.addCallback(self._count_leases, "mutable") |
---|
16932 | - d.addCallback(self._assert_leasecount, 1) |
---|
16933 | + d.addCallback(lambda ign: self._assert_leasecount("one", 1)) |
---|
16934 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
16935 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
16936 | |
---|
16937 | d.addCallback(self.CHECK, "one", "t=check") # no add-lease |
---|
16938 | def _got_html_good(res): |
---|
16939 | hunk ./src/allmydata/test/test_web.py 4808 |
---|
16940 | self.failIf("Not Healthy" in res, res) |
---|
16941 | d.addCallback(_got_html_good) |
---|
16942 | |
---|
16943 | - d.addCallback(self._count_leases, "one") |
---|
16944 | - d.addCallback(self._assert_leasecount, 1) |
---|
16945 | - d.addCallback(self._count_leases, "two") |
---|
16946 | - d.addCallback(self._assert_leasecount, 1) |
---|
16947 | - d.addCallback(self._count_leases, "mutable") |
---|
16948 | - d.addCallback(self._assert_leasecount, 1) |
---|
16949 | + d.addCallback(lambda ign: self._assert_leasecount("one", 1)) |
---|
16950 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
16951 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
16952 | |
---|
16953 | # this CHECK uses the original client, which uses the same |
---|
16954 | # lease-secrets, so it will just renew the original lease |
---|
16955 | hunk ./src/allmydata/test/test_web.py 4817 |
---|
16956 | d.addCallback(self.CHECK, "one", "t=check&add-lease=true") |
---|
16957 | d.addCallback(_got_html_good) |
---|
16958 | |
---|
16959 | - d.addCallback(self._count_leases, "one") |
---|
16960 | - d.addCallback(self._assert_leasecount, 1) |
---|
16961 | - d.addCallback(self._count_leases, "two") |
---|
16962 | - d.addCallback(self._assert_leasecount, 1) |
---|
16963 | - d.addCallback(self._count_leases, "mutable") |
---|
16964 | - d.addCallback(self._assert_leasecount, 1) |
---|
16965 | + d.addCallback(lambda ign: self._assert_leasecount("one", 1)) |
---|
16966 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
16967 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
16968 | |
---|
16969 | # this CHECK uses an alternate client, which adds a second lease |
---|
16970 | d.addCallback(self.CHECK, "one", "t=check&add-lease=true", clientnum=1) |
---|
16971 | hunk ./src/allmydata/test/test_web.py 4825 |
---|
16972 | d.addCallback(_got_html_good) |
---|
16973 | |
---|
16974 | - d.addCallback(self._count_leases, "one") |
---|
16975 | - d.addCallback(self._assert_leasecount, 2) |
---|
16976 | - d.addCallback(self._count_leases, "two") |
---|
16977 | - d.addCallback(self._assert_leasecount, 1) |
---|
16978 | - d.addCallback(self._count_leases, "mutable") |
---|
16979 | - d.addCallback(self._assert_leasecount, 1) |
---|
16980 | + d.addCallback(lambda ign: self._assert_leasecount("one", 2)) |
---|
16981 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
16982 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
16983 | |
---|
16984 | d.addCallback(self.CHECK, "mutable", "t=check&add-lease=true") |
---|
16985 | d.addCallback(_got_html_good) |
---|
16986 | hunk ./src/allmydata/test/test_web.py 4832 |
---|
16987 | |
---|
16988 | - d.addCallback(self._count_leases, "one") |
---|
16989 | - d.addCallback(self._assert_leasecount, 2) |
---|
16990 | - d.addCallback(self._count_leases, "two") |
---|
16991 | - d.addCallback(self._assert_leasecount, 1) |
---|
16992 | - d.addCallback(self._count_leases, "mutable") |
---|
16993 | - d.addCallback(self._assert_leasecount, 1) |
---|
16994 | + d.addCallback(lambda ign: self._assert_leasecount("one", 2)) |
---|
16995 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
16996 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
16997 | |
---|
16998 | d.addCallback(self.CHECK, "mutable", "t=check&add-lease=true", |
---|
16999 | clientnum=1) |
---|
17000 | hunk ./src/allmydata/test/test_web.py 4840 |
---|
17001 | d.addCallback(_got_html_good) |
---|
17002 | |
---|
17003 | - d.addCallback(self._count_leases, "one") |
---|
17004 | - d.addCallback(self._assert_leasecount, 2) |
---|
17005 | - d.addCallback(self._count_leases, "two") |
---|
17006 | - d.addCallback(self._assert_leasecount, 1) |
---|
17007 | - d.addCallback(self._count_leases, "mutable") |
---|
17008 | - d.addCallback(self._assert_leasecount, 2) |
---|
17009 | + d.addCallback(lambda ign: self._assert_leasecount("one", 2)) |
---|
17010 | + d.addCallback(lambda ign: self._assert_leasecount("two", 1)) |
---|
17011 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 2)) |
---|
17012 | |
---|
17013 | d.addErrback(self.explain_web_error) |
---|
17014 | return d |
---|
17015 | hunk ./src/allmydata/test/test_web.py 4884 |
---|
17016 | self.failUnlessReallyEqual(len(units), 4+1) |
---|
17017 | d.addCallback(_done) |
---|
17018 | |
---|
17019 | - d.addCallback(self._count_leases, "root") |
---|
17020 | - d.addCallback(self._assert_leasecount, 1) |
---|
17021 | - d.addCallback(self._count_leases, "one") |
---|
17022 | - d.addCallback(self._assert_leasecount, 1) |
---|
17023 | - d.addCallback(self._count_leases, "mutable") |
---|
17024 | - d.addCallback(self._assert_leasecount, 1) |
---|
17025 | + d.addCallback(lambda ign: self._assert_leasecount("root", 1)) |
---|
17026 | + d.addCallback(lambda ign: self._assert_leasecount("one", 1)) |
---|
17027 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
17028 | |
---|
17029 | d.addCallback(self.CHECK, "root", "t=stream-deep-check&add-lease=true") |
---|
17030 | d.addCallback(_done) |
---|
17031 | hunk ./src/allmydata/test/test_web.py 4891 |
---|
17032 | |
---|
17033 | - d.addCallback(self._count_leases, "root") |
---|
17034 | - d.addCallback(self._assert_leasecount, 1) |
---|
17035 | - d.addCallback(self._count_leases, "one") |
---|
17036 | - d.addCallback(self._assert_leasecount, 1) |
---|
17037 | - d.addCallback(self._count_leases, "mutable") |
---|
17038 | - d.addCallback(self._assert_leasecount, 1) |
---|
17039 | + d.addCallback(lambda ign: self._assert_leasecount("root", 1)) |
---|
17040 | + d.addCallback(lambda ign: self._assert_leasecount("one", 1)) |
---|
17041 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 1)) |
---|
17042 | |
---|
17043 | d.addCallback(self.CHECK, "root", "t=stream-deep-check&add-lease=true", |
---|
17044 | clientnum=1) |
---|
17045 | hunk ./src/allmydata/test/test_web.py 4899 |
---|
17046 | d.addCallback(_done) |
---|
17047 | |
---|
17048 | - d.addCallback(self._count_leases, "root") |
---|
17049 | - d.addCallback(self._assert_leasecount, 2) |
---|
17050 | - d.addCallback(self._count_leases, "one") |
---|
17051 | - d.addCallback(self._assert_leasecount, 2) |
---|
17052 | - d.addCallback(self._count_leases, "mutable") |
---|
17053 | - d.addCallback(self._assert_leasecount, 2) |
---|
17054 | + d.addCallback(lambda ign: self._assert_leasecount("root", 2)) |
---|
17055 | + d.addCallback(lambda ign: self._assert_leasecount("one", 2)) |
---|
17056 | + d.addCallback(lambda ign: self._assert_leasecount("mutable", 2)) |
---|
17057 | |
---|
17058 | d.addErrback(self.explain_web_error) |
---|
17059 | return d |
---|
17060 | hunk ./src/allmydata/util/deferredutil.py 1 |
---|
17061 | + |
---|
17062 | +from foolscap.api import fireEventually |
---|
17063 | from twisted.internet import defer |
---|
17064 | |
---|
17065 | # utility wrapper for DeferredList |
---|
17066 | hunk ./src/allmydata/util/deferredutil.py 38 |
---|
17067 | d.addCallbacks(_parseDListResult, _unwrapFirstError) |
---|
17068 | return d |
---|
17069 | |
---|
17070 | + |
---|
17071 | +def async_iterate(process, iterable): |
---|
17072 | + """ |
---|
17073 | + I iterate over the elements of 'iterable' (which may be deferred), eventually |
---|
17074 | + applying 'process' to each one. 'process' should return a (possibly deferred) |
---|
17075 | + boolean: True to continue the iteration, False to stop. |
---|
17076 | + |
---|
17077 | + I return a Deferred that fires with True if all elements of the iterable |
---|
17078 | + were processed (i.e. 'process' only returned True values); with False if |
---|
17079 | + the iteration was stopped by 'process' returning False; or that fails with |
---|
17080 | + the first failure of either 'process' or the iterator. |
---|
17081 | + """ |
---|
17082 | + iterator = iter(iterable) |
---|
17083 | + |
---|
17084 | + d = defer.succeed(None) |
---|
17085 | + def _iterate(ign): |
---|
17086 | + d2 = defer.maybeDeferred(iterator.next) |
---|
17087 | + def _cb(item): |
---|
17088 | + d3 = defer.maybeDeferred(process, item) |
---|
17089 | + def _maybe_iterate(res): |
---|
17090 | + if res: |
---|
17091 | + d4 = fireEventually() |
---|
17092 | + d4.addCallback(_iterate) |
---|
17093 | + return d4 |
---|
17094 | + return False |
---|
17095 | + d3.addCallback(_maybe_iterate) |
---|
17096 | + return d3 |
---|
17097 | + def _eb(f): |
---|
17098 | + if f.trap(StopIteration): |
---|
17099 | + return True |
---|
17100 | + return f |
---|
17101 | + d2.addCallbacks(_cb, _eb) |
---|
17102 | + return d2 |
---|
17103 | + d.addCallback(_iterate) |
---|
17104 | + return d |
---|
17105 | + |
---|
17106 | + |
---|
17107 | +def for_items(cb, mapping): |
---|
17108 | + """ |
---|
17109 | + For each (key, value) pair in a mapping, I add a callback to cb(None, key, value) |
---|
17110 | + to a Deferred that fires immediately. I return that Deferred. |
---|
17111 | + """ |
---|
17112 | + d = defer.succeed(None) |
---|
17113 | + for k, v in mapping.items(): |
---|
17114 | + d.addCallback(lambda ign, k=k, v=v: cb(None, k, v)) |
---|
17115 | + return d |
---|
17116 | hunk ./src/allmydata/util/encodingutil.py 221 |
---|
17117 | def quote_path(path, quotemarks=True): |
---|
17118 | return quote_output("/".join(map(to_str, path)), quotemarks=quotemarks) |
---|
17119 | |
---|
17120 | +def quote_filepath(fp, quotemarks=True, encoding=None): |
---|
17121 | + path = fp.path |
---|
17122 | + if isinstance(path, str): |
---|
17123 | + try: |
---|
17124 | + path = path.decode(filesystem_encoding) |
---|
17125 | + except UnicodeDecodeError: |
---|
17126 | + return 'b"%s"' % (ESCAPABLE_8BIT.sub(_str_escape, path),) |
---|
17127 | + |
---|
17128 | + return quote_output(path, quotemarks=quotemarks, encoding=encoding) |
---|
17129 | + |
---|
17130 | |
---|
17131 | def unicode_platform(): |
---|
17132 | """ |
---|
17133 | hunk ./src/allmydata/util/fileutil.py 5 |
---|
17134 | Futz with files like a pro. |
---|
17135 | """ |
---|
17136 | |
---|
17137 | -import sys, exceptions, os, stat, tempfile, time, binascii |
---|
17138 | +import errno, sys, exceptions, os, stat, tempfile, time, binascii |
---|
17139 | + |
---|
17140 | +from allmydata.util.assertutil import precondition |
---|
17141 | |
---|
17142 | from twisted.python import log |
---|
17143 | hunk ./src/allmydata/util/fileutil.py 10 |
---|
17144 | +from twisted.python.filepath import FilePath, UnlistableError |
---|
17145 | |
---|
17146 | from pycryptopp.cipher.aes import AES |
---|
17147 | |
---|
17148 | hunk ./src/allmydata/util/fileutil.py 189 |
---|
17149 | raise tx |
---|
17150 | raise exceptions.IOError, "unknown error prevented creation of directory, or deleted the directory immediately after creation: %s" % dirname # careful not to construct an IOError with a 2-tuple, as that has a special meaning... |
---|
17151 | |
---|
17152 | -def rm_dir(dirname): |
---|
17153 | +def fp_make_dirs(dirfp): |
---|
17154 | + """ |
---|
17155 | + An idempotent version of FilePath.makedirs(). If the dir already |
---|
17156 | + exists, do nothing and return without raising an exception. If this |
---|
17157 | + call creates the dir, return without raising an exception. If there is |
---|
17158 | + an error that prevents creation or if the directory gets deleted after |
---|
17159 | + fp_make_dirs() creates it and before fp_make_dirs() checks that it |
---|
17160 | + exists, raise an exception. |
---|
17161 | + """ |
---|
17162 | + log.msg( "xxx 0 %s" % (dirfp,)) |
---|
17163 | + tx = None |
---|
17164 | + try: |
---|
17165 | + dirfp.makedirs() |
---|
17166 | + except OSError, x: |
---|
17167 | + tx = x |
---|
17168 | + |
---|
17169 | + if not dirfp.isdir(): |
---|
17170 | + if tx: |
---|
17171 | + raise tx |
---|
17172 | + raise exceptions.IOError, "unknown error prevented creation of directory, or deleted the directory immediately after creation: %s" % dirfp # careful not to construct an IOError with a 2-tuple, as that has a special meaning... |
---|
17173 | + |
---|
17174 | +def fp_rmdir_if_empty(dirfp): |
---|
17175 | + """ Remove the directory if it is empty. """ |
---|
17176 | + try: |
---|
17177 | + os.rmdir(dirfp.path) |
---|
17178 | + except OSError, e: |
---|
17179 | + if e.errno != errno.ENOTEMPTY: |
---|
17180 | + raise |
---|
17181 | + else: |
---|
17182 | + dirfp.changed() |
---|
17183 | + |
---|
17184 | +def rmtree(dirname): |
---|
17185 | """ |
---|
17186 | A threadsafe and idempotent version of shutil.rmtree(). If the dir is |
---|
17187 | already gone, do nothing and return without raising an exception. If this |
---|
17188 | hunk ./src/allmydata/util/fileutil.py 239 |
---|
17189 | else: |
---|
17190 | remove(fullname) |
---|
17191 | os.rmdir(dirname) |
---|
17192 | - except Exception, le: |
---|
17193 | - # Ignore "No such file or directory" |
---|
17194 | - if (not isinstance(le, OSError)) or le.args[0] != 2: |
---|
17195 | + except EnvironmentError, le: |
---|
17196 | + # Ignore "No such file or directory", collect any other exception. |
---|
17197 | + if (le.args[0] != 2 and le.args[0] != 3) or (le.args[0] != errno.ENOENT): |
---|
17198 | excs.append(le) |
---|
17199 | hunk ./src/allmydata/util/fileutil.py 243 |
---|
17200 | + except Exception, le: |
---|
17201 | + excs.append(le) |
---|
17202 | |
---|
17203 | # Okay, now we've recursively removed everything, ignoring any "No |
---|
17204 | # such file or directory" errors, and collecting any other errors. |
---|
17205 | hunk ./src/allmydata/util/fileutil.py 256 |
---|
17206 | raise OSError, "Failed to remove dir for unknown reason." |
---|
17207 | raise OSError, excs |
---|
17208 | |
---|
17209 | +def fp_remove(fp): |
---|
17210 | + """ |
---|
17211 | + An idempotent version of shutil.rmtree(). If the file/dir is already |
---|
17212 | + gone, do nothing and return without raising an exception. If this call |
---|
17213 | + removes the file/dir, return without raising an exception. If there is |
---|
17214 | + an error that prevents removal, or if a file or directory at the same |
---|
17215 | + path gets created again by someone else after this deletes it and before |
---|
17216 | + this checks that it is gone, raise an exception. |
---|
17217 | + """ |
---|
17218 | + try: |
---|
17219 | + fp.remove() |
---|
17220 | + except UnlistableError, e: |
---|
17221 | + if e.originalException.errno != errno.ENOENT: |
---|
17222 | + raise |
---|
17223 | + except OSError, e: |
---|
17224 | + if e.errno != errno.ENOENT: |
---|
17225 | + raise |
---|
17226 | + |
---|
17227 | +def rm_dir(dirname): |
---|
17228 | + # Renamed to be like shutil.rmtree and unlike rmdir. |
---|
17229 | + return rmtree(dirname) |
---|
17230 | |
---|
17231 | def remove_if_possible(f): |
---|
17232 | try: |
---|
17233 | hunk ./src/allmydata/util/fileutil.py 284 |
---|
17234 | except: |
---|
17235 | pass |
---|
17236 | |
---|
17237 | +def fp_list(fp): |
---|
17238 | + """ |
---|
17239 | + If fp exists and is a listable directory, return a list of FilePath objects |
---|
17240 | + corresponding to its children. If it does not exist, return an empty list. |
---|
17241 | + If it is not listable for any other reason than not existing (or a parent |
---|
17242 | + directory not existing), raise an exception. |
---|
17243 | + """ |
---|
17244 | + try: |
---|
17245 | + return fp.children() |
---|
17246 | + except UnlistableError, e: |
---|
17247 | + if e.originalException.errno != errno.ENOENT: |
---|
17248 | + raise |
---|
17249 | + return [] |
---|
17250 | + except OSError, e: |
---|
17251 | + if e.errno != errno.ENOENT: |
---|
17252 | + raise |
---|
17253 | + return [] |
---|
17254 | + |
---|
17255 | def open_or_create(fname, binarymode=True): |
---|
17256 | try: |
---|
17257 | return open(fname, binarymode and "r+b" or "r+") |
---|
17258 | hunk ./src/allmydata/util/fileutil.py 405 |
---|
17259 | import traceback |
---|
17260 | traceback.print_exc() |
---|
17261 | |
---|
17262 | -def get_disk_stats(whichdir, reserved_space=0): |
---|
17263 | +def get_disk_stats(whichdirfp, reserved_space=0): |
---|
17264 | """Return disk statistics for the storage disk, in the form of a dict |
---|
17265 | with the following fields. |
---|
17266 | total: total bytes on disk |
---|
17267 | hunk ./src/allmydata/util/fileutil.py 426 |
---|
17268 | you can pass how many bytes you would like to leave unused on this |
---|
17269 | filesystem as reserved_space. |
---|
17270 | """ |
---|
17271 | + precondition(isinstance(whichdirfp, FilePath), whichdirfp) |
---|
17272 | |
---|
17273 | if have_GetDiskFreeSpaceExW: |
---|
17274 | # If this is a Windows system and GetDiskFreeSpaceExW is available, use it. |
---|
17275 | hunk ./src/allmydata/util/fileutil.py 437 |
---|
17276 | n_free_for_nonroot = c_ulonglong(0) |
---|
17277 | n_total = c_ulonglong(0) |
---|
17278 | n_free_for_root = c_ulonglong(0) |
---|
17279 | - retval = GetDiskFreeSpaceExW(whichdir, byref(n_free_for_nonroot), |
---|
17280 | - byref(n_total), |
---|
17281 | - byref(n_free_for_root)) |
---|
17282 | + retval = GetDiskFreeSpaceExW(whichdirfp.path, byref(n_free_for_nonroot), |
---|
17283 | + byref(n_total), |
---|
17284 | + byref(n_free_for_root)) |
---|
17285 | if retval == 0: |
---|
17286 | raise OSError("Windows error %d attempting to get disk statistics for %r" |
---|
17287 | hunk ./src/allmydata/util/fileutil.py 442 |
---|
17288 | - % (GetLastError(), whichdir)) |
---|
17289 | + % (GetLastError(), whichdirfp.path)) |
---|
17290 | free_for_nonroot = n_free_for_nonroot.value |
---|
17291 | total = n_total.value |
---|
17292 | free_for_root = n_free_for_root.value |
---|
17293 | hunk ./src/allmydata/util/fileutil.py 451 |
---|
17294 | # <http://docs.python.org/library/os.html#os.statvfs> |
---|
17295 | # <http://opengroup.org/onlinepubs/7990989799/xsh/fstatvfs.html> |
---|
17296 | # <http://opengroup.org/onlinepubs/7990989799/xsh/sysstatvfs.h.html> |
---|
17297 | - s = os.statvfs(whichdir) |
---|
17298 | + s = os.statvfs(whichdirfp.path) |
---|
17299 | |
---|
17300 | # on my mac laptop: |
---|
17301 | # statvfs(2) is a wrapper around statfs(2). |
---|
17302 | hunk ./src/allmydata/util/fileutil.py 478 |
---|
17303 | 'avail': avail, |
---|
17304 | } |
---|
17305 | |
---|
17306 | -def get_available_space(whichdir, reserved_space): |
---|
17307 | + |
---|
17308 | +def get_available_space(whichdirfp, reserved_space): |
---|
17309 | """Returns available space for share storage in bytes, or None if no |
---|
17310 | API to get this information is available. |
---|
17311 | |
---|
17312 | hunk ./src/allmydata/util/fileutil.py 491 |
---|
17313 | you can pass how many bytes you would like to leave unused on this |
---|
17314 | filesystem as reserved_space. |
---|
17315 | """ |
---|
17316 | + precondition(isinstance(whichdirfp, FilePath), whichdirfp) |
---|
17317 | try: |
---|
17318 | hunk ./src/allmydata/util/fileutil.py 493 |
---|
17319 | - return get_disk_stats(whichdir, reserved_space)['avail'] |
---|
17320 | + return get_disk_stats(whichdirfp, reserved_space)['avail'] |
---|
17321 | except AttributeError: |
---|
17322 | return None |
---|
17323 | hunk ./src/allmydata/util/fileutil.py 496 |
---|
17324 | - except EnvironmentError: |
---|
17325 | - log.msg("OS call to get disk statistics failed") |
---|
17326 | + |
---|
17327 | + |
---|
17328 | +def get_used_space(fp): |
---|
17329 | + if fp is None: |
---|
17330 | return 0 |
---|
17331 | hunk ./src/allmydata/util/fileutil.py 501 |
---|
17332 | + try: |
---|
17333 | + s = os.stat(fp.path) |
---|
17334 | + except EnvironmentError: |
---|
17335 | + if not fp.exists(): |
---|
17336 | + return 0 |
---|
17337 | + raise |
---|
17338 | + else: |
---|
17339 | + # POSIX defines st_blocks (originally a BSDism): |
---|
17340 | + # <http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html> |
---|
17341 | + # but does not require stat() to give it a "meaningful value" |
---|
17342 | + # <http://pubs.opengroup.org/onlinepubs/009695399/functions/stat.html> |
---|
17343 | + # and says: |
---|
17344 | + # "The unit for the st_blocks member of the stat structure is not defined |
---|
17345 | + # within IEEE Std 1003.1-2001. In some implementations it is 512 bytes. |
---|
17346 | + # It may differ on a file system basis. There is no correlation between |
---|
17347 | + # values of the st_blocks and st_blksize, and the f_bsize (from <sys/statvfs.h>) |
---|
17348 | + # structure members." |
---|
17349 | + # |
---|
17350 | + # The Linux docs define it as "the number of blocks allocated to the file, |
---|
17351 | + # [in] 512-byte units." It is also defined that way on MacOS X. Python does |
---|
17352 | + # not set the attribute on Windows. |
---|
17353 | + # |
---|
17354 | + # We consider platforms that define st_blocks but give it a wrong value, or |
---|
17355 | + # measure it in a unit other than 512 bytes, to be broken. See also |
---|
17356 | + # <http://bugs.python.org/issue12350>. |
---|
17357 | + |
---|
17358 | + if hasattr(s, 'st_blocks'): |
---|
17359 | + return s.st_blocks * 512 |
---|
17360 | + else: |
---|
17361 | + return s.st_size |
---|
17362 | } |
---|
17363 | |
---|
17364 | Context: |
---|
17365 | |
---|
17366 | [setup.py: stop putting pyutil.version_class/etc in _version.py |
---|
17367 | Brian Warner <warner@lothar.com>**20111205055049 |
---|
17368 | Ignore-this: 926fa9a8a34a04f24ee6e006423e9c1 |
---|
17369 | |
---|
17370 | allmydata.__version__ can just be a string, it doesn't need to be an instance |
---|
17371 | of some fancy NormalizedVersion class. Everything inside Tahoe uses |
---|
17372 | str(__version__) anyways. |
---|
17373 | |
---|
17374 | Also add .dev0 when a git tree is dirty. |
---|
17375 | |
---|
17376 | Closes #1466 |
---|
17377 | ] |
---|
17378 | [setup.py: get version from git or darcs |
---|
17379 | Brian Warner <warner@lothar.com>**20111205044001 |
---|
17380 | Ignore-this: 5a406b33000446d85edc722298391220 |
---|
17381 | |
---|
17382 | This replaces the setup.cfg aliases that run "darcsver" before each major |
---|
17383 | command with the new "update_version". update_version is defined in setup.py, |
---|
17384 | and tries to get a version string from either darcs or git (or leaves the |
---|
17385 | existing _version.py alone if neither VC metadata is available). |
---|
17386 | |
---|
17387 | Also clean up a tiny typo in verlib.py that messed up syntax hilighting. |
---|
17388 | ] |
---|
17389 | [Munge the umids in introducer/{client,server}.py so that check-umids doesn't complain about them being duplicates of the ones in introducer/old.py. refs #466 |
---|
17390 | david-sarah@jacaranda.org**20111129234057 |
---|
17391 | Ignore-this: da053d962ccb32d197ef0f123013acbb |
---|
17392 | ] |
---|
17393 | [new introducer: tests for signed extensible dictionary-based messages. refs #466 |
---|
17394 | david-sarah@jacaranda.org**20111129231920 |
---|
17395 | Ignore-this: 751ed1c993688f838d343423ff68b716 |
---|
17396 | ] |
---|
17397 | [new introducer: signed extensible dictionary-based messages! This patch does not include the tests. refs #466 |
---|
17398 | david-sarah@jacaranda.org**20111129231756 |
---|
17399 | Ignore-this: 18bc491a44f7627202667ef681f2d948 |
---|
17400 | |
---|
17401 | This introduces new client and server halves to the Introducer (renaming |
---|
17402 | the old one with a _V1 suffix). Both have fallbacks to accomodate talking to |
---|
17403 | a different version: the publishing client switches on whether the server's |
---|
17404 | .get_version() advertises V2 support, the server switches on which |
---|
17405 | subscription method was invoked by the subscribing client. |
---|
17406 | |
---|
17407 | The V2 protocol sends a three-tuple of (serialized announcement dictionary, |
---|
17408 | signature, pubkey) for each announcement. The V2 server dispatches messages |
---|
17409 | to subscribers according to the service-name, and throws errors for invalid |
---|
17410 | signatures, but does not otherwise examine the messages. The V2 receiver's |
---|
17411 | subscription callback will receive a (serverid, ann_dict) pair. The |
---|
17412 | 'serverid' will be equal to the pubkey if all of the following are true: |
---|
17413 | |
---|
17414 | the originating client is V2, and was told a privkey to use |
---|
17415 | the announcement went through a V2 server |
---|
17416 | the signature is valid |
---|
17417 | |
---|
17418 | If not, 'serverid' will be equal to the tubid portion of the announced FURL, |
---|
17419 | as was the case for V1 receivers. |
---|
17420 | |
---|
17421 | Servers will create a keypair if one does not exist yet, stored in |
---|
17422 | private/server.privkey . |
---|
17423 | |
---|
17424 | The signed announcement dictionary puts the server FURL in a key named |
---|
17425 | "anonymous-storage-FURL", which anticipates upcoming Accounting-related |
---|
17426 | changes in the server advertisements. It also provides a key named |
---|
17427 | "permutation-seed-base32" to tell clients what permutation seed to use. |
---|
17428 | This is computed at startup, using tubid if there are existing shares, |
---|
17429 | otherwise the pubkey, to retain share-order compatibility for existing |
---|
17430 | servers. |
---|
17431 | ] |
---|
17432 | [docs/known_issues.rst: describe when the unauthorized access attack is known to be possible, and fix a link. |
---|
17433 | david-sarah@jacaranda.org**20111118002013 |
---|
17434 | Ignore-this: d89b1f1040a0a7ee0bde893d23612049 |
---|
17435 | ] |
---|
17436 | [more tiny buildbot-testing whitespace changes |
---|
17437 | warner@lothar.com**20111118002041 |
---|
17438 | Ignore-this: e816e2a5ab939e2f7a89ef12b8a157d8 |
---|
17439 | ] |
---|
17440 | [more tiny buildbot-testing whitespace changes |
---|
17441 | warner@lothar.com**20111118001828 |
---|
17442 | Ignore-this: 57bb52cba83ea9a19728ba0a8ffadb69 |
---|
17443 | ] |
---|
17444 | [tiny change to exercise the buildbot hook |
---|
17445 | warner@lothar.com**20111118001511 |
---|
17446 | Ignore-this: 7220b7790b39f19f9721d9e93b755030 |
---|
17447 | ] |
---|
17448 | [Strengthen description of unauthorized access attack in known_issues.rst. |
---|
17449 | david-sarah@jacaranda.org**20111118000030 |
---|
17450 | Ignore-this: e2f68f621fe666b6201542623aa4d182 |
---|
17451 | ] |
---|
17452 | [remove remaining uses of nevow's "formless" module |
---|
17453 | Brian Warner <warner@lothar.com>**20111117225423 |
---|
17454 | Ignore-this: a128dea91a1c63b3bbefa34729344d69 |
---|
17455 | |
---|
17456 | We're slowly moving away from Nevow, and marcusw's previous patch removed |
---|
17457 | uses of the formless CSS file, so now we can stop testing that nevow can find |
---|
17458 | that file, and remove the lingering unused "import formless" call. |
---|
17459 | ] |
---|
17460 | [1585-webui.darcs.patch |
---|
17461 | Marcus Wanner <marcus@wanners.net>**20111117214923 |
---|
17462 | Ignore-this: 23cf2a06c545be5f821c071d652178ee |
---|
17463 | ] |
---|
17464 | [Remove duplicate tahoe_css links from manifest.xhtml and rename-form.xhtml |
---|
17465 | Brian Warner <warner@lothar.com>**20111116224225 |
---|
17466 | Ignore-this: 12024fff17964607799928928b9aadf3 |
---|
17467 | |
---|
17468 | They were probably meant to be links to webform_css, but we aren't really |
---|
17469 | using Nevow's form-generation code anyways, so they can just be removed. |
---|
17470 | Thanks to 'marcusw' for the catch. |
---|
17471 | ] |
---|
17472 | [iputil: handle openbsd5 (just like openbsd4) |
---|
17473 | Brian Warner <warner@lothar.com>**20111115220423 |
---|
17474 | Ignore-this: 64b28bd2fd06eb5230ea41d91540dd05 |
---|
17475 | |
---|
17476 | Patch by 'sickness'. Closes #1584 |
---|
17477 | ] |
---|
17478 | [Makefile count-lines: let it work on OS-X (-l not --lines), add XXX |
---|
17479 | Brian Warner <warner@lothar.com>**20111109184227 |
---|
17480 | Ignore-this: 204ace1dadc9ed27543c62965b4e6757 |
---|
17481 | |
---|
17482 | OS-X's simple-minded /usr/bin/wc doesn't understand --lines, but everyone |
---|
17483 | understands -l . |
---|
17484 | ] |
---|
17485 | [setup.py: umask=022 for 'sdist', to avoid depending on environment |
---|
17486 | Brian Warner <warner@lothar.com>**20111109183632 |
---|
17487 | Ignore-this: acd5db88ba8f1972d618b14f9e5b803c |
---|
17488 | |
---|
17489 | The new tarball-building buildslave had a bogus umask set, causing the 1.9.0 |
---|
17490 | tarballs to be non-other-user-readable (go-rwx), which is a hassle for |
---|
17491 | packaging. (The umask was correct on the old buildslave, but it was moved to |
---|
17492 | a new host shortly before the release). This should make sure tarballs are |
---|
17493 | correct despite the host's setting. |
---|
17494 | |
---|
17495 | Note to others: processes run under twistd get umask=077 unless you arrange |
---|
17496 | otherwise. |
---|
17497 | ] |
---|
17498 | [_auto_deps.py: blacklist PyCrypto 2.4. |
---|
17499 | david-sarah@jacaranda.org**20111105022457 |
---|
17500 | Ignore-this: 876cb24bc71589e735f48bf449cad81e |
---|
17501 | ] |
---|
17502 | [check-miscaptures.py: report the number of files that were not analysed due to syntax errors (and don't count them in the number of suspicious captures). refs #1555 |
---|
17503 | david-sarah@jacaranda.org**20111009050301 |
---|
17504 | Ignore-this: 62ee03f4b8a96c292e75c097ad87d52e |
---|
17505 | ] |
---|
17506 | [check-miscaptures.py: handle corner cases around default arguments correctly. Also make a minor optimization when there are no assigned variables to consider. refs #1555 |
---|
17507 | david-sarah@jacaranda.org**20111009045023 |
---|
17508 | Ignore-this: f49ece515620081da1d745ae6da19d21 |
---|
17509 | ] |
---|
17510 | [check-miscaptures.py: Python doesn't really have declarations; report the topmost assignment. refs #1555 |
---|
17511 | david-sarah@jacaranda.org**20111009044800 |
---|
17512 | Ignore-this: 4905c9dfe7726f433333e216a6760a4b |
---|
17513 | ] |
---|
17514 | [check-miscaptures.py: handle destructuring function arguments correctly. refs #1555 |
---|
17515 | david-sarah@jacaranda.org**20111009044710 |
---|
17516 | Ignore-this: f9de7d95e94446507a206c88d3f98a23 |
---|
17517 | ] |
---|
17518 | [check-miscaptures.py: check while loops and list comprehensions as well as for loops. Also fix a pyflakes warning. refs #1555 |
---|
17519 | david-sarah@jacaranda.org**20111009044022 |
---|
17520 | Ignore-this: 6526e4e315ca6461b1fbc2da5568e444 |
---|
17521 | ] |
---|
17522 | [Add misc/coding_tools/check-miscaptures.py to detect incorrect captures of variables declared in a for loop, and a 'make check-miscaptures' Makefile target to run it. (It is also run by 'make code-checks'.) This is a rewritten version that reports much fewer false positives, by determining captured variables more accurately. fixes #1555 |
---|
17523 | david-sarah@jacaranda.org**20111007074121 |
---|
17524 | Ignore-this: 51318e9678d132c374ea557ab955e79e |
---|
17525 | ] |
---|
17526 | [Fix pyflakes warnings in misc/ directories other than misc/build_helpers. refs #1557 |
---|
17527 | david-sarah@jacaranda.org**20111007033031 |
---|
17528 | Ignore-this: 7daf5862469732d8cabc355266622b74 |
---|
17529 | ] |
---|
17530 | [Makefile: include misc/ directories other than misc/build_helpers in SOURCES. refs #1557 |
---|
17531 | david-sarah@jacaranda.org**20111007032958 |
---|
17532 | Ignore-this: 31376ec01401df7972e83341dc65aa05 |
---|
17533 | ] |
---|
17534 | [show-tool-versions: tolerate missing setuptools |
---|
17535 | Brian Warner <warner@lothar.com>**20111101080010 |
---|
17536 | Ignore-this: 72d4e440565273992beb4f010cbca699 |
---|
17537 | ] |
---|
17538 | [show-tool-versions.py: condense output, hide file-not-found exceptions |
---|
17539 | Brian Warner <warner@lothar.com>**20111101074532 |
---|
17540 | Ignore-this: a15381a76077ef46a74a4ac40c9ae956 |
---|
17541 | ] |
---|
17542 | [relnotes.txt: fix footnotes |
---|
17543 | Brian Warner <warner@lothar.com>**20111101071935 |
---|
17544 | Ignore-this: 668c1bd8618e21beed9bc6b23f048189 |
---|
17545 | ] |
---|
17546 | [Rewrite download-status-timeline visualizer ('viz') with d3.js |
---|
17547 | Brian Warner <warner@lothar.com>**20111101061821 |
---|
17548 | Ignore-this: 6149b027bbae52c559ef5a8167240cab |
---|
17549 | |
---|
17550 | * use d3.js v2.4.6 |
---|
17551 | * add a "toggle misc events" button, to get hash/bitmap-checking details |
---|
17552 | * only draw data that's on screen, for speed |
---|
17553 | * add fragment-arg to fetch timeline data.json from somewhere else |
---|
17554 | ] |
---|
17555 | [IServer refactoring: pass IServer instances around, instead of peerids |
---|
17556 | Brian Warner <warner@lothar.com>**20111101040319 |
---|
17557 | Ignore-this: 35e4698a0273a0311fe0ccedcc7881b5 |
---|
17558 | |
---|
17559 | refs #1363 |
---|
17560 | |
---|
17561 | This collapses 88 small incremental changes (each of which passes all tests) |
---|
17562 | into one big patch. The development process for the long path started with |
---|
17563 | adding some temporary scaffolding, changing one method at a time, then |
---|
17564 | removing the scaffolding. The individual pieces are as follows, in reverse |
---|
17565 | chronological order (the first patch is at the end of this comment): |
---|
17566 | |
---|
17567 | commit 9bbe4174fd0d98a6cf47a8ef96e85d9ef34b2f9a |
---|
17568 | Author: Brian Warner <warner@lothar.com> |
---|
17569 | Date: Tue Oct 4 16:05:00 2011 -0400 |
---|
17570 | |
---|
17571 | immutable/downloader/status.py: correct comment |
---|
17572 | |
---|
17573 | src/allmydata/immutable/downloader/status.py | 2 +- |
---|
17574 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
17575 | |
---|
17576 | commit 72146a7c7c91eac2f7c3ceb801eb7a1721376889 |
---|
17577 | Author: Brian Warner <warner@lothar.com> |
---|
17578 | Date: Tue Oct 4 15:46:20 2011 -0400 |
---|
17579 | |
---|
17580 | remove temporary ServerMap._storage_broker |
---|
17581 | |
---|
17582 | src/allmydata/mutable/checker.py | 2 +- |
---|
17583 | src/allmydata/mutable/filenode.py | 2 +- |
---|
17584 | src/allmydata/mutable/publish.py | 2 +- |
---|
17585 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
17586 | src/allmydata/test/test_mutable.py | 8 ++++---- |
---|
17587 | 5 files changed, 9 insertions(+), 10 deletions(-) |
---|
17588 | |
---|
17589 | commit d703096b41632c47d76414b12672e076a422ff5c |
---|
17590 | Author: Brian Warner <warner@lothar.com> |
---|
17591 | Date: Tue Oct 4 15:37:05 2011 -0400 |
---|
17592 | |
---|
17593 | remove temporary storage_broker.get_server_for_id() |
---|
17594 | |
---|
17595 | src/allmydata/storage_client.py | 3 --- |
---|
17596 | src/allmydata/test/no_network.py | 13 ------------- |
---|
17597 | 2 files changed, 0 insertions(+), 16 deletions(-) |
---|
17598 | |
---|
17599 | commit 620cc5d80882ef6f7decfd26af8a6c7c1ddf80d1 |
---|
17600 | Author: Brian Warner <warner@lothar.com> |
---|
17601 | Date: Tue Oct 4 12:50:06 2011 -0400 |
---|
17602 | |
---|
17603 | API of Retrieve._try_to_validate_privkey(), trying to remove reader.server |
---|
17604 | |
---|
17605 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
17606 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
17607 | |
---|
17608 | commit 92f43f856f4a8b36c207d1b190ed8699b5a4ecb4 |
---|
17609 | Author: Brian Warner <warner@lothar.com> |
---|
17610 | Date: Tue Oct 4 12:48:08 2011 -0400 |
---|
17611 | |
---|
17612 | API of Retrieve._validate_block(), trying to remove reader.server |
---|
17613 | |
---|
17614 | src/allmydata/mutable/retrieve.py | 14 +++++++------- |
---|
17615 | 1 files changed, 7 insertions(+), 7 deletions(-) |
---|
17616 | |
---|
17617 | commit 572d5070761861a2190349d1ed8d85dbc25698a5 |
---|
17618 | Author: Brian Warner <warner@lothar.com> |
---|
17619 | Date: Tue Oct 4 12:36:58 2011 -0400 |
---|
17620 | |
---|
17621 | API of Retrieve._mark_bad_share(), trying to remove reader.server |
---|
17622 | |
---|
17623 | src/allmydata/mutable/retrieve.py | 21 +++++++++------------ |
---|
17624 | 1 files changed, 9 insertions(+), 12 deletions(-) |
---|
17625 | |
---|
17626 | commit a793ff00c0de1e2eec7b46288fdf388c7a2bec89 |
---|
17627 | Author: Brian Warner <warner@lothar.com> |
---|
17628 | Date: Tue Oct 4 12:06:13 2011 -0400 |
---|
17629 | |
---|
17630 | remove now-unused get_rref_for_serverid() |
---|
17631 | |
---|
17632 | src/allmydata/mutable/servermap.py | 3 --- |
---|
17633 | 1 files changed, 0 insertions(+), 3 deletions(-) |
---|
17634 | |
---|
17635 | commit 1b9827cc9366bf90b93297fdd6832f2ad0480ce7 |
---|
17636 | Author: Brian Warner <warner@lothar.com> |
---|
17637 | Date: Tue Oct 4 12:03:09 2011 -0400 |
---|
17638 | |
---|
17639 | Retrieve: stop adding .serverid attributes to readers |
---|
17640 | |
---|
17641 | src/allmydata/mutable/retrieve.py | 1 - |
---|
17642 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
17643 | |
---|
17644 | commit 5d4e9d491b19e49d2e443a1dfff2c672842c36ef |
---|
17645 | Author: Brian Warner <warner@lothar.com> |
---|
17646 | Date: Tue Oct 4 12:03:34 2011 -0400 |
---|
17647 | |
---|
17648 | return value of Retrieve(verify=True) |
---|
17649 | |
---|
17650 | src/allmydata/mutable/checker.py | 11 ++++++----- |
---|
17651 | src/allmydata/mutable/retrieve.py | 3 +-- |
---|
17652 | 2 files changed, 7 insertions(+), 7 deletions(-) |
---|
17653 | |
---|
17654 | commit e9ab7978c384e1f677cb7779dc449b1044face82 |
---|
17655 | Author: Brian Warner <warner@lothar.com> |
---|
17656 | Date: Tue Oct 4 11:54:23 2011 -0400 |
---|
17657 | |
---|
17658 | Retrieve._bad_shares (but not return value, used by Verifier) |
---|
17659 | |
---|
17660 | src/allmydata/mutable/retrieve.py | 7 ++++--- |
---|
17661 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
17662 | |
---|
17663 | commit 2d91926de233ec5c881f30e36b4a30ad92ab42a9 |
---|
17664 | Author: Brian Warner <warner@lothar.com> |
---|
17665 | Date: Tue Oct 4 11:51:23 2011 -0400 |
---|
17666 | |
---|
17667 | Publish: stop adding .serverid attributes to writers |
---|
17668 | |
---|
17669 | src/allmydata/mutable/publish.py | 9 ++------- |
---|
17670 | 1 files changed, 2 insertions(+), 7 deletions(-) |
---|
17671 | |
---|
17672 | commit 47c7a0105dec7cbf4f7e0a3ce800bbb85b15df4a |
---|
17673 | Author: Brian Warner <warner@lothar.com> |
---|
17674 | Date: Tue Oct 4 11:56:33 2011 -0400 |
---|
17675 | |
---|
17676 | API of get_write_enabler() |
---|
17677 | |
---|
17678 | src/allmydata/mutable/filenode.py | 7 ++++--- |
---|
17679 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
17680 | src/allmydata/test/no_network.py | 3 +++ |
---|
17681 | 3 files changed, 9 insertions(+), 5 deletions(-) |
---|
17682 | |
---|
17683 | commit 9196a5c6590fdbfd660325ea8358b345887d3db0 |
---|
17684 | Author: Brian Warner <warner@lothar.com> |
---|
17685 | Date: Tue Oct 4 11:46:24 2011 -0400 |
---|
17686 | |
---|
17687 | API of get_(renewal|cancel)_secret() |
---|
17688 | |
---|
17689 | src/allmydata/mutable/filenode.py | 14 ++++++++------ |
---|
17690 | src/allmydata/mutable/publish.py | 8 ++++---- |
---|
17691 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
17692 | 3 files changed, 14 insertions(+), 13 deletions(-) |
---|
17693 | |
---|
17694 | commit de7c1552f8c163eff5b6d820b5fb3b21c1b47cb5 |
---|
17695 | Author: Brian Warner <warner@lothar.com> |
---|
17696 | Date: Tue Oct 4 11:41:52 2011 -0400 |
---|
17697 | |
---|
17698 | API of CorruptShareError. Also comment out some related+unused test_web.py code |
---|
17699 | |
---|
17700 | src/allmydata/mutable/common.py | 13 +++++-------- |
---|
17701 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
17702 | src/allmydata/mutable/servermap.py | 8 +++----- |
---|
17703 | src/allmydata/test/common.py | 13 ++++++++----- |
---|
17704 | 4 files changed, 21 insertions(+), 23 deletions(-) |
---|
17705 | |
---|
17706 | commit 2c1c314046b620c16f1e66d030c150d768b7d01e |
---|
17707 | Author: Brian Warner <warner@lothar.com> |
---|
17708 | Date: Tue Oct 4 12:01:46 2011 -0400 |
---|
17709 | |
---|
17710 | API of ServerMap.mark_bad_share() |
---|
17711 | |
---|
17712 | src/allmydata/mutable/publish.py | 2 +- |
---|
17713 | src/allmydata/mutable/retrieve.py | 6 +++--- |
---|
17714 | src/allmydata/mutable/servermap.py | 6 ++---- |
---|
17715 | src/allmydata/test/test_mutable.py | 3 +-- |
---|
17716 | 4 files changed, 7 insertions(+), 10 deletions(-) |
---|
17717 | |
---|
17718 | commit 1bed349030779fd0c378ae4e821384f953c6f6ff |
---|
17719 | Author: Brian Warner <warner@lothar.com> |
---|
17720 | Date: Tue Oct 4 11:11:17 2011 -0400 |
---|
17721 | |
---|
17722 | API+name of ServerMap.shares_on_server() : only for tests, so debug_ prefix |
---|
17723 | |
---|
17724 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
17725 | src/allmydata/test/test_mutable.py | 6 +++--- |
---|
17726 | 2 files changed, 5 insertions(+), 8 deletions(-) |
---|
17727 | |
---|
17728 | commit 2d32e448677d6b818692e801045d4115b29abf21 |
---|
17729 | Author: Brian Warner <warner@lothar.com> |
---|
17730 | Date: Tue Oct 4 11:07:10 2011 -0400 |
---|
17731 | |
---|
17732 | API of ServerMap.all_servers_for_version() |
---|
17733 | |
---|
17734 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
17735 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
17736 | |
---|
17737 | commit 48f3204d1889c3e7179578125c4bdef515af3d6a |
---|
17738 | Author: Brian Warner <warner@lothar.com> |
---|
17739 | Date: Tue Oct 4 11:04:50 2011 -0400 |
---|
17740 | |
---|
17741 | internals of ServerMap methods that use make_versionmap(), remove temp copy |
---|
17742 | |
---|
17743 | src/allmydata/mutable/servermap.py | 28 +++++++++---------------- |
---|
17744 | 1 files changed, 10 insertions(+), 18 deletions(-) |
---|
17745 | |
---|
17746 | commit 5c3da77b6c777a145bd5ddfaa4db849dc9495548 |
---|
17747 | Author: Brian Warner <warner@lothar.com> |
---|
17748 | Date: Tue Oct 4 11:01:28 2011 -0400 |
---|
17749 | |
---|
17750 | API of ServerMap.make_versionmap() |
---|
17751 | |
---|
17752 | src/allmydata/mutable/checker.py | 4 ++-- |
---|
17753 | src/allmydata/mutable/retrieve.py | 5 ++--- |
---|
17754 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
17755 | src/allmydata/test/test_mutable.py | 7 ++++--- |
---|
17756 | 4 files changed, 10 insertions(+), 10 deletions(-) |
---|
17757 | |
---|
17758 | commit b6882ece49afb4c507d118af2db346fa329209dc |
---|
17759 | Author: Brian Warner <warner@lothar.com> |
---|
17760 | Date: Tue Oct 4 10:53:38 2011 -0400 |
---|
17761 | |
---|
17762 | make a copy of ServerMap.make_versionmap() (_make_versionmap2) for internal use |
---|
17763 | |
---|
17764 | src/allmydata/mutable/servermap.py | 18 +++++++++++++----- |
---|
17765 | 1 files changed, 13 insertions(+), 5 deletions(-) |
---|
17766 | |
---|
17767 | commit 963f8e63faf32b950eb1b8103cd2ff16fe8f0151 |
---|
17768 | Author: Brian Warner <warner@lothar.com> |
---|
17769 | Date: Tue Oct 4 00:45:58 2011 -0400 |
---|
17770 | |
---|
17771 | API of RetrieveStatus.add_problem() |
---|
17772 | |
---|
17773 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
17774 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
17775 | |
---|
17776 | commit 4976d29ffae565a048851601c29013bbae2976d8 |
---|
17777 | Author: Brian Warner <warner@lothar.com> |
---|
17778 | Date: Tue Oct 4 00:45:05 2011 -0400 |
---|
17779 | |
---|
17780 | API of RetrieveStatus.add_fetch_timing() |
---|
17781 | |
---|
17782 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
17783 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
17784 | |
---|
17785 | commit d057d3bbba72663ee148a8b916bc2d52be2e3982 |
---|
17786 | Author: Brian Warner <warner@lothar.com> |
---|
17787 | Date: Tue Oct 4 00:44:04 2011 -0400 |
---|
17788 | |
---|
17789 | API of Retrieve.notify_server_corruption() |
---|
17790 | |
---|
17791 | src/allmydata/mutable/retrieve.py | 6 +++--- |
---|
17792 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
17793 | |
---|
17794 | commit 8a2a81e46671c860610e0e96d6add1a57551f22d |
---|
17795 | Author: Brian Warner <warner@lothar.com> |
---|
17796 | Date: Tue Oct 4 00:42:32 2011 -0400 |
---|
17797 | |
---|
17798 | remove unused _outstanding_queries |
---|
17799 | |
---|
17800 | src/allmydata/mutable/retrieve.py | 1 - |
---|
17801 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
17802 | |
---|
17803 | commit 56d12cc9968d03ccd53764455c671122c4f391d1 |
---|
17804 | Author: Brian Warner <warner@lothar.com> |
---|
17805 | Date: Tue Oct 4 00:40:57 2011 -0400 |
---|
17806 | |
---|
17807 | change Retrieve.remaining_sharemap |
---|
17808 | |
---|
17809 | src/allmydata/mutable/retrieve.py | 4 ++-- |
---|
17810 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
17811 | |
---|
17812 | commit 4f0b7af4821f43290bfc70f2b1fc30149ad81281 |
---|
17813 | Author: Brian Warner <warner@lothar.com> |
---|
17814 | Date: Tue Oct 4 10:40:18 2011 -0400 |
---|
17815 | |
---|
17816 | accessor for PublishStatus._problems |
---|
17817 | |
---|
17818 | src/allmydata/mutable/publish.py | 4 +++- |
---|
17819 | src/allmydata/web/status.py | 2 +- |
---|
17820 | 2 files changed, 4 insertions(+), 2 deletions(-) |
---|
17821 | |
---|
17822 | commit 627087cf66d0b8cc519f4d551a967a7bd9b6a741 |
---|
17823 | Author: Brian Warner <warner@lothar.com> |
---|
17824 | Date: Tue Oct 4 10:36:39 2011 -0400 |
---|
17825 | |
---|
17826 | accessor for RetrieveStatus._problems |
---|
17827 | |
---|
17828 | src/allmydata/mutable/retrieve.py | 8 ++++++-- |
---|
17829 | src/allmydata/web/status.py | 2 +- |
---|
17830 | 2 files changed, 7 insertions(+), 3 deletions(-) |
---|
17831 | |
---|
17832 | commit ca7dea81f03801b1c7353fc00ecba689268109cf |
---|
17833 | Author: Brian Warner <warner@lothar.com> |
---|
17834 | Date: Tue Oct 4 00:35:32 2011 -0400 |
---|
17835 | |
---|
17836 | add .server to "reader", so we can get at it later |
---|
17837 | |
---|
17838 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
17839 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
17840 | |
---|
17841 | commit 6ef516e24908ec195af084a7550d1921a5e983b0 |
---|
17842 | Author: Brian Warner <warner@lothar.com> |
---|
17843 | Date: Tue Oct 4 00:32:32 2011 -0400 |
---|
17844 | |
---|
17845 | temporarily give Retrieve a _storage_broker, so it can map serverids to servers |
---|
17846 | |
---|
17847 | src/allmydata/mutable/checker.py | 3 ++- |
---|
17848 | src/allmydata/mutable/filenode.py | 6 ++++-- |
---|
17849 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
17850 | src/allmydata/test/test_mutable.py | 4 ++-- |
---|
17851 | 4 files changed, 11 insertions(+), 7 deletions(-) |
---|
17852 | |
---|
17853 | commit afe08e4dd3f4ff9ff7e8a2a8d28b181e3625bcc9 |
---|
17854 | Author: Brian Warner <warner@lothar.com> |
---|
17855 | Date: Tue Oct 4 00:21:51 2011 -0400 |
---|
17856 | |
---|
17857 | mutable/retrieve.py: s/peer/server/ |
---|
17858 | |
---|
17859 | src/allmydata/mutable/retrieve.py | 82 +++++++++++++------------- |
---|
17860 | src/allmydata/test/test_mutable.py | 6 +- |
---|
17861 | 2 files changed, 44 insertions(+), 44 deletions(-) |
---|
17862 | |
---|
17863 | commit 910afcb5d7f274880f68dd6cdb5b05f2bbc29adc |
---|
17864 | Author: Brian Warner <warner@lothar.com> |
---|
17865 | Date: Tue Oct 4 00:16:01 2011 -0400 |
---|
17866 | |
---|
17867 | web.status.PublishStatusPage: add comment, I think .problems isn't exercised |
---|
17868 | |
---|
17869 | src/allmydata/web/status.py | 2 ++ |
---|
17870 | 1 files changed, 2 insertions(+), 0 deletions(-) |
---|
17871 | |
---|
17872 | commit 311466dd8c931bbba40d590ade867704282e7f1a |
---|
17873 | Author: Brian Warner <warner@lothar.com> |
---|
17874 | Date: Mon Oct 3 23:48:16 2011 -0400 |
---|
17875 | |
---|
17876 | API of PublishStatus.add_per_server_time() |
---|
17877 | |
---|
17878 | src/allmydata/mutable/publish.py | 5 +++-- |
---|
17879 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
17880 | |
---|
17881 | commit 2df5faa1b6cbfbaded520d2320305a62fe961118 |
---|
17882 | Author: Brian Warner <warner@lothar.com> |
---|
17883 | Date: Mon Oct 3 23:46:37 2011 -0400 |
---|
17884 | |
---|
17885 | more simplifications |
---|
17886 | |
---|
17887 | src/allmydata/mutable/publish.py | 4 +--- |
---|
17888 | 1 files changed, 1 insertions(+), 3 deletions(-) |
---|
17889 | |
---|
17890 | commit 6ac4544a3da385f2aad9392f906b90192f4f919a |
---|
17891 | Author: Brian Warner <warner@lothar.com> |
---|
17892 | Date: Mon Oct 3 23:44:08 2011 -0400 |
---|
17893 | |
---|
17894 | API of ServerMap.version_on_server() |
---|
17895 | |
---|
17896 | src/allmydata/mutable/publish.py | 2 +- |
---|
17897 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
17898 | src/allmydata/test/test_mutable.py | 5 ++--- |
---|
17899 | 3 files changed, 5 insertions(+), 6 deletions(-) |
---|
17900 | |
---|
17901 | commit 3e187e322511072e4683329df6b2c6c733a66dba |
---|
17902 | Author: Brian Warner <warner@lothar.com> |
---|
17903 | Date: Tue Oct 4 00:16:32 2011 -0400 |
---|
17904 | |
---|
17905 | API of ServerMap.make_sharemap() |
---|
17906 | |
---|
17907 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
17908 | src/allmydata/test/test_mutable.py | 7 ++++--- |
---|
17909 | src/allmydata/web/status.py | 4 ++-- |
---|
17910 | 3 files changed, 8 insertions(+), 7 deletions(-) |
---|
17911 | |
---|
17912 | commit 318feed8437bdd8d4943c6569d38f7b54b6313cc |
---|
17913 | Author: Brian Warner <warner@lothar.com> |
---|
17914 | Date: Mon Oct 3 23:36:19 2011 -0400 |
---|
17915 | |
---|
17916 | small cleanups |
---|
17917 | |
---|
17918 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
17919 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
17920 | |
---|
17921 | commit bd459ed5714e1db5a7163935c54b7b0b56db8349 |
---|
17922 | Author: Brian Warner <warner@lothar.com> |
---|
17923 | Date: Mon Oct 3 23:33:39 2011 -0400 |
---|
17924 | |
---|
17925 | API of ServerMap.add_new_share() |
---|
17926 | |
---|
17927 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
17928 | src/allmydata/mutable/servermap.py | 6 ++---- |
---|
17929 | 2 files changed, 4 insertions(+), 6 deletions(-) |
---|
17930 | |
---|
17931 | commit f2804fb6ed11d80088e0da8ed48e6c2922f2ffef |
---|
17932 | Author: Brian Warner <warner@lothar.com> |
---|
17933 | Date: Mon Oct 3 23:30:26 2011 -0400 |
---|
17934 | |
---|
17935 | API of ServerMap.get_bad_shares() |
---|
17936 | |
---|
17937 | src/allmydata/mutable/publish.py | 3 +-- |
---|
17938 | src/allmydata/mutable/servermap.py | 9 ++++----- |
---|
17939 | 2 files changed, 5 insertions(+), 7 deletions(-) |
---|
17940 | |
---|
17941 | commit 965074a47b3ce1431cb46d9a233840afcf9105f5 |
---|
17942 | Author: Brian Warner <warner@lothar.com> |
---|
17943 | Date: Mon Oct 3 23:26:58 2011 -0400 |
---|
17944 | |
---|
17945 | more small cleanups |
---|
17946 | |
---|
17947 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
17948 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
17949 | |
---|
17950 | commit 38020da34f034f8889947dd3dc05e087ffff7106 |
---|
17951 | Author: Brian Warner <warner@lothar.com> |
---|
17952 | Date: Mon Oct 3 23:18:47 2011 -0400 |
---|
17953 | |
---|
17954 | change Publish.bad_share_checkstrings |
---|
17955 | |
---|
17956 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
17957 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
17958 | |
---|
17959 | commit 5efebcbd2ee0c2f299ea86f7591d856c0f265304 |
---|
17960 | Author: Brian Warner <warner@lothar.com> |
---|
17961 | Date: Mon Oct 3 23:16:31 2011 -0400 |
---|
17962 | |
---|
17963 | change internals of Publish.update_goal() |
---|
17964 | |
---|
17965 | src/allmydata/mutable/publish.py | 8 +++----- |
---|
17966 | 1 files changed, 3 insertions(+), 5 deletions(-) |
---|
17967 | |
---|
17968 | commit e91b55ff4c2a69165b71f2c7b217ac319ff4c527 |
---|
17969 | Author: Brian Warner <warner@lothar.com> |
---|
17970 | Date: Mon Oct 3 23:11:42 2011 -0400 |
---|
17971 | |
---|
17972 | get rid of Publish.connections |
---|
17973 | |
---|
17974 | src/allmydata/mutable/publish.py | 27 +++++---------------------- |
---|
17975 | 1 files changed, 5 insertions(+), 22 deletions(-) |
---|
17976 | |
---|
17977 | commit 64e9a53b3229ebe2f9ebf7ed502d539311d0e037 |
---|
17978 | Author: Brian Warner <warner@lothar.com> |
---|
17979 | Date: Mon Oct 3 23:05:32 2011 -0400 |
---|
17980 | |
---|
17981 | change Publish.bad_servers |
---|
17982 | |
---|
17983 | src/allmydata/mutable/publish.py | 10 +++++----- |
---|
17984 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
17985 | |
---|
17986 | commit b85a934bef315a06bcfe00c9c12a3627fed2b918 |
---|
17987 | Author: Brian Warner <warner@lothar.com> |
---|
17988 | Date: Mon Oct 3 23:03:07 2011 -0400 |
---|
17989 | |
---|
17990 | Publish.bad_servers: fix bug, this should be a set of serverids, not writers |
---|
17991 | |
---|
17992 | src/allmydata/mutable/publish.py | 2 +- |
---|
17993 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
17994 | |
---|
17995 | commit 605ea15ec15ed671513819003ccd211cdb9761e0 |
---|
17996 | Author: Brian Warner <warner@lothar.com> |
---|
17997 | Date: Mon Oct 3 23:00:21 2011 -0400 |
---|
17998 | |
---|
17999 | change .placed |
---|
18000 | |
---|
18001 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
18002 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18003 | |
---|
18004 | commit f7aba37b1b345d5b6d5cb16e3b3f6f3c1afb658e |
---|
18005 | Author: Brian Warner <warner@lothar.com> |
---|
18006 | Date: Mon Oct 3 22:59:22 2011 -0400 |
---|
18007 | |
---|
18008 | temporarily stash IServer as .server on the "writer" object |
---|
18009 | |
---|
18010 | src/allmydata/mutable/publish.py | 2 ++ |
---|
18011 | 1 files changed, 2 insertions(+), 0 deletions(-) |
---|
18012 | |
---|
18013 | commit f9b551d788e7db1f187fce5ab98ab5d5fe4e1c36 |
---|
18014 | Author: Brian Warner <warner@lothar.com> |
---|
18015 | Date: Mon Oct 3 22:48:18 2011 -0400 |
---|
18016 | |
---|
18017 | change Publish.goal and API of log_goal() to use IServer, not serverid |
---|
18018 | |
---|
18019 | src/allmydata/mutable/publish.py | 48 ++++++++++++++-------------- |
---|
18020 | 1 files changed, 24 insertions(+), 24 deletions(-) |
---|
18021 | |
---|
18022 | commit 75f20616558e4900b8b1f685dd99aa838de6d452 |
---|
18023 | Author: Brian Warner <warner@lothar.com> |
---|
18024 | Date: Mon Oct 3 15:27:02 2011 -0400 |
---|
18025 | |
---|
18026 | API of ServerMap.get_known_shares() |
---|
18027 | |
---|
18028 | src/allmydata/mutable/publish.py | 16 ++++++++++------ |
---|
18029 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
18030 | 2 files changed, 12 insertions(+), 11 deletions(-) |
---|
18031 | |
---|
18032 | commit 1c38c9d37bb08221b4418762234b1a62397b3b4b |
---|
18033 | Author: Brian Warner <warner@lothar.com> |
---|
18034 | Date: Mon Oct 3 15:20:29 2011 -0400 |
---|
18035 | |
---|
18036 | Publish.full_serverlist |
---|
18037 | |
---|
18038 | src/allmydata/mutable/publish.py | 10 +++++----- |
---|
18039 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
18040 | |
---|
18041 | commit b6cbd215a04b9cde31a7d92a97a7f048622b16f1 |
---|
18042 | Author: Brian Warner <warner@lothar.com> |
---|
18043 | Date: Mon Oct 3 15:12:31 2011 -0400 |
---|
18044 | |
---|
18045 | API of ServerMap.all_servers() |
---|
18046 | |
---|
18047 | src/allmydata/mutable/servermap.py | 19 ++++++------------- |
---|
18048 | 1 files changed, 6 insertions(+), 13 deletions(-) |
---|
18049 | |
---|
18050 | commit e63cd0315fae65357b1727ec6d5ff3c6e0d27c98 |
---|
18051 | Author: Brian Warner <warner@lothar.com> |
---|
18052 | Date: Mon Oct 3 15:10:18 2011 -0400 |
---|
18053 | |
---|
18054 | remove ServerMap.connections, set_rref_for_serverid() |
---|
18055 | |
---|
18056 | src/allmydata/mutable/servermap.py | 11 +---------- |
---|
18057 | 1 files changed, 1 insertions(+), 10 deletions(-) |
---|
18058 | |
---|
18059 | commit 4df52db2f80eb12eefa5d57103c24893cde89553 |
---|
18060 | Author: Brian Warner <warner@lothar.com> |
---|
18061 | Date: Mon Oct 3 15:04:06 2011 -0400 |
---|
18062 | |
---|
18063 | API of ServerMap.mark_server_reachable() |
---|
18064 | |
---|
18065 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
18066 | 1 files changed, 2 insertions(+), 5 deletions(-) |
---|
18067 | |
---|
18068 | commit 69c715bde77944dc25181b3dbbeb042c816f9a1b |
---|
18069 | Author: Brian Warner <warner@lothar.com> |
---|
18070 | Date: Mon Oct 3 15:03:21 2011 -0400 |
---|
18071 | |
---|
18072 | API of ServerMap.mark_server_unreachable() |
---|
18073 | |
---|
18074 | src/allmydata/mutable/servermap.py | 9 +++------ |
---|
18075 | 1 files changed, 3 insertions(+), 6 deletions(-) |
---|
18076 | |
---|
18077 | commit 3d784d60eec1c508858e3a617e4411ffbcc3c1fa |
---|
18078 | Author: Brian Warner <warner@lothar.com> |
---|
18079 | Date: Mon Oct 3 15:02:03 2011 -0400 |
---|
18080 | |
---|
18081 | API of status.set_privkey_from() |
---|
18082 | |
---|
18083 | src/allmydata/mutable/servermap.py | 7 +++---- |
---|
18084 | 1 files changed, 3 insertions(+), 4 deletions(-) |
---|
18085 | |
---|
18086 | commit 544ed3ea29bed7e66da7fd29ca3f6f076f27a9e6 |
---|
18087 | Author: Brian Warner <warner@lothar.com> |
---|
18088 | Date: Mon Oct 3 15:01:15 2011 -0400 |
---|
18089 | |
---|
18090 | API of status.add_per_server_time() |
---|
18091 | |
---|
18092 | src/allmydata/mutable/servermap.py | 7 ++++--- |
---|
18093 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
18094 | |
---|
18095 | commit fffe5008b6320bd1e04c3c68389a2bf2ee383fa8 |
---|
18096 | Author: Brian Warner <warner@lothar.com> |
---|
18097 | Date: Mon Oct 3 14:59:02 2011 -0400 |
---|
18098 | |
---|
18099 | remove unused .versionmap |
---|
18100 | |
---|
18101 | src/allmydata/mutable/servermap.py | 7 ------- |
---|
18102 | 1 files changed, 0 insertions(+), 7 deletions(-) |
---|
18103 | |
---|
18104 | commit 2816562e090d2294179db3588dafcca18de1bc2b |
---|
18105 | Author: Brian Warner <warner@lothar.com> |
---|
18106 | Date: Mon Oct 3 14:57:51 2011 -0400 |
---|
18107 | |
---|
18108 | remove serverid from all log messages. Also one unused lambda. |
---|
18109 | |
---|
18110 | src/allmydata/mutable/servermap.py | 30 +++++++++++++------------- |
---|
18111 | 1 files changed, 15 insertions(+), 15 deletions(-) |
---|
18112 | |
---|
18113 | commit 28fa6b1a2738fa98c1f1dbd3d0e01ae98912d11f |
---|
18114 | Author: Brian Warner <warner@lothar.com> |
---|
18115 | Date: Mon Oct 3 14:54:30 2011 -0400 |
---|
18116 | |
---|
18117 | removed unused _readers |
---|
18118 | |
---|
18119 | src/allmydata/mutable/servermap.py | 3 --- |
---|
18120 | 1 files changed, 0 insertions(+), 3 deletions(-) |
---|
18121 | |
---|
18122 | commit a8e4ed3d645ab592d1add6a1e69b6d1ebfb77817 |
---|
18123 | Author: Brian Warner <warner@lothar.com> |
---|
18124 | Date: Mon Oct 3 14:54:16 2011 -0400 |
---|
18125 | |
---|
18126 | remove unused _sharemap |
---|
18127 | |
---|
18128 | src/allmydata/mutable/servermap.py | 1 - |
---|
18129 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
18130 | |
---|
18131 | commit 3f072e55cf1d0700f9fffe23f8f3a475725df588 |
---|
18132 | Author: Brian Warner <warner@lothar.com> |
---|
18133 | Date: Mon Oct 3 14:49:03 2011 -0400 |
---|
18134 | |
---|
18135 | _must_query |
---|
18136 | |
---|
18137 | src/allmydata/mutable/servermap.py | 8 ++++---- |
---|
18138 | 1 files changed, 4 insertions(+), 4 deletions(-) |
---|
18139 | |
---|
18140 | commit c599a059b8df3f5785e4bf89fb6ecc6d8dcd708b |
---|
18141 | Author: Brian Warner <warner@lothar.com> |
---|
18142 | Date: Mon Oct 3 14:48:05 2011 -0400 |
---|
18143 | |
---|
18144 | _queries_outstanding |
---|
18145 | |
---|
18146 | src/allmydata/mutable/servermap.py | 16 +++++++--------- |
---|
18147 | 1 files changed, 7 insertions(+), 9 deletions(-) |
---|
18148 | |
---|
18149 | commit 7743759f98ac2c07926b2fdbd80bf52dfab33085 |
---|
18150 | Author: Brian Warner <warner@lothar.com> |
---|
18151 | Date: Mon Oct 3 14:46:17 2011 -0400 |
---|
18152 | |
---|
18153 | _empty_servers |
---|
18154 | |
---|
18155 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
18156 | 1 files changed, 2 insertions(+), 3 deletions(-) |
---|
18157 | |
---|
18158 | commit 6bb1825916828a713a32cdf7f7411fa3ea2e1e5d |
---|
18159 | Author: Brian Warner <warner@lothar.com> |
---|
18160 | Date: Mon Oct 3 14:45:39 2011 -0400 |
---|
18161 | |
---|
18162 | _good_servers |
---|
18163 | |
---|
18164 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
18165 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
18166 | |
---|
18167 | commit 1768fab1b51d8dd93ecabbaaabfadfa20cf6c3d4 |
---|
18168 | Author: Brian Warner <warner@lothar.com> |
---|
18169 | Date: Mon Oct 3 14:44:59 2011 -0400 |
---|
18170 | |
---|
18171 | _bad_servers |
---|
18172 | |
---|
18173 | src/allmydata/mutable/servermap.py | 14 +++++++------- |
---|
18174 | 1 files changed, 7 insertions(+), 7 deletions(-) |
---|
18175 | |
---|
18176 | commit dccbaef30f0ba714c746bf6d4a1a803c36e17b65 |
---|
18177 | Author: Brian Warner <warner@lothar.com> |
---|
18178 | Date: Mon Oct 3 14:41:54 2011 -0400 |
---|
18179 | |
---|
18180 | API of _try_to_set_pubkey() |
---|
18181 | |
---|
18182 | src/allmydata/mutable/servermap.py | 7 ++++--- |
---|
18183 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
18184 | |
---|
18185 | commit 0481ea70042ba3575f15eac7fd0780f8ece580cc |
---|
18186 | Author: Brian Warner <warner@lothar.com> |
---|
18187 | Date: Mon Oct 3 14:35:02 2011 -0400 |
---|
18188 | |
---|
18189 | API of notify_server_corruption() |
---|
18190 | |
---|
18191 | src/allmydata/mutable/servermap.py | 6 +++--- |
---|
18192 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18193 | |
---|
18194 | commit bea9cba18fb3b9c11bb22f18356a263ecec7351e |
---|
18195 | Author: Brian Warner <warner@lothar.com> |
---|
18196 | Date: Mon Oct 3 14:34:09 2011 -0400 |
---|
18197 | |
---|
18198 | API of _got_signature_one_share() |
---|
18199 | |
---|
18200 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
18201 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
18202 | |
---|
18203 | commit 1520123583cf78650706e114b15bb5b0ac1f4a14 |
---|
18204 | Author: Brian Warner <warner@lothar.com> |
---|
18205 | Date: Mon Oct 3 14:32:33 2011 -0400 |
---|
18206 | |
---|
18207 | API of _try_to_validate_privkey() |
---|
18208 | |
---|
18209 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
18210 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
18211 | |
---|
18212 | commit 938852c9c8519c7a078f58a9b1f4dd8ec8b6715e |
---|
18213 | Author: Brian Warner <warner@lothar.com> |
---|
18214 | Date: Mon Oct 3 14:31:48 2011 -0400 |
---|
18215 | |
---|
18216 | API and internals of _add_lease_failed() |
---|
18217 | |
---|
18218 | src/allmydata/mutable/servermap.py | 8 ++++---- |
---|
18219 | 1 files changed, 4 insertions(+), 4 deletions(-) |
---|
18220 | |
---|
18221 | commit 3843dba367e3c19e176a622ab853cb51d2472ddf |
---|
18222 | Author: Brian Warner <warner@lothar.com> |
---|
18223 | Date: Mon Oct 3 14:30:37 2011 -0400 |
---|
18224 | |
---|
18225 | API of _privkey_query_failed() |
---|
18226 | |
---|
18227 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
18228 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18229 | |
---|
18230 | commit 2219a710e1633cd57d0ca0786490de87b3e19ba7 |
---|
18231 | Author: Brian Warner <warner@lothar.com> |
---|
18232 | Date: Mon Oct 3 14:29:43 2011 -0400 |
---|
18233 | |
---|
18234 | fix bug in call to _privkey_query_failed, unrelated to refactoring |
---|
18235 | |
---|
18236 | src/allmydata/mutable/servermap.py | 2 +- |
---|
18237 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
18238 | |
---|
18239 | commit ae615bec7d0d1b269710b6902797b12f9592ad62 |
---|
18240 | Author: Brian Warner <warner@lothar.com> |
---|
18241 | Date: Mon Oct 3 14:27:17 2011 -0400 |
---|
18242 | |
---|
18243 | API of _got_corrupt_share() |
---|
18244 | |
---|
18245 | src/allmydata/mutable/servermap.py | 17 +++++++++-------- |
---|
18246 | 1 files changed, 9 insertions(+), 8 deletions(-) |
---|
18247 | |
---|
18248 | commit cb51c95a6f4e077278157a77dab060c8c1ad7a81 |
---|
18249 | Author: Brian Warner <warner@lothar.com> |
---|
18250 | Date: Mon Oct 3 14:23:16 2011 -0400 |
---|
18251 | |
---|
18252 | API of _got_results() |
---|
18253 | |
---|
18254 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
18255 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
18256 | |
---|
18257 | commit bac9154fe0af18f226999a58ffc2362d8cf4b802 |
---|
18258 | Author: Brian Warner <warner@lothar.com> |
---|
18259 | Date: Mon Oct 3 14:19:19 2011 -0400 |
---|
18260 | |
---|
18261 | API of _query_failed() |
---|
18262 | |
---|
18263 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
18264 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18265 | |
---|
18266 | commit fdc29a8ca95d4b5c503e5382b9e5d4d02141ba12 |
---|
18267 | Author: Brian Warner <warner@lothar.com> |
---|
18268 | Date: Mon Oct 3 14:17:20 2011 -0400 |
---|
18269 | |
---|
18270 | API of _do_read() |
---|
18271 | |
---|
18272 | src/allmydata/mutable/servermap.py | 6 ++++-- |
---|
18273 | 1 files changed, 4 insertions(+), 2 deletions(-) |
---|
18274 | |
---|
18275 | commit e7e9e338f28d004aa4d423d11c65f1e271ac7322 |
---|
18276 | Author: Brian Warner <warner@lothar.com> |
---|
18277 | Date: Mon Oct 3 14:20:21 2011 -0400 |
---|
18278 | |
---|
18279 | API of _do_query() |
---|
18280 | |
---|
18281 | src/allmydata/mutable/servermap.py | 15 +++++++-------- |
---|
18282 | 1 files changed, 7 insertions(+), 8 deletions(-) |
---|
18283 | |
---|
18284 | commit 330625b9dac4cdbe72a11464a893065b9aeed453 |
---|
18285 | Author: Brian Warner <warner@lothar.com> |
---|
18286 | Date: Mon Oct 3 14:43:05 2011 -0400 |
---|
18287 | |
---|
18288 | next step: first batch of updates to ServermapUpdater |
---|
18289 | |
---|
18290 | updates: |
---|
18291 | most method-local variables in update() |
---|
18292 | API of _build_initial_querylist() |
---|
18293 | API of _send_initial_requests() |
---|
18294 | .full_serverlist |
---|
18295 | .extra_servers |
---|
18296 | |
---|
18297 | src/allmydata/mutable/servermap.py | 39 ++++++++++++++------------ |
---|
18298 | 1 files changed, 21 insertions(+), 18 deletions(-) |
---|
18299 | |
---|
18300 | commit 4aadc584fa7dcb2daa86b048c81dee0049ba26d9 |
---|
18301 | Author: Brian Warner <warner@lothar.com> |
---|
18302 | Date: Mon Oct 3 15:07:00 2011 -0400 |
---|
18303 | |
---|
18304 | internal change: index _bad_shares with IServer |
---|
18305 | |
---|
18306 | src/allmydata/mutable/servermap.py | 20 ++++++++++---------- |
---|
18307 | 1 files changed, 10 insertions(+), 10 deletions(-) |
---|
18308 | |
---|
18309 | commit 16d4e6fa82a9907dbdc92094213387c6a4164e41 |
---|
18310 | Author: Brian Warner <warner@lothar.com> |
---|
18311 | Date: Mon Oct 3 18:20:47 2011 +0100 |
---|
18312 | |
---|
18313 | internal change: index _known_shares with IServer instead of serverid |
---|
18314 | |
---|
18315 | callers are unchanged |
---|
18316 | |
---|
18317 | src/allmydata/mutable/servermap.py | 42 +++++++++++++++---------- |
---|
18318 | 1 files changed, 25 insertions(+), 17 deletions(-) |
---|
18319 | |
---|
18320 | commit ceeb5f4938cc814a0c75d1b8f4018aed965c2176 |
---|
18321 | Author: Brian Warner <warner@lothar.com> |
---|
18322 | Date: Mon Oct 3 18:11:43 2011 +0100 |
---|
18323 | |
---|
18324 | accessors and name cleanup for servermap.Servermap.last_update_mode/time |
---|
18325 | |
---|
18326 | src/allmydata/mutable/filenode.py | 6 +++--- |
---|
18327 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
18328 | src/allmydata/mutable/servermap.py | 17 +++++++++++------ |
---|
18329 | 3 files changed, 16 insertions(+), 11 deletions(-) |
---|
18330 | |
---|
18331 | commit 8d3cbda82661c0a7e5c3d3b65cf7a5d5ab7e32c0 |
---|
18332 | Author: Brian Warner <warner@lothar.com> |
---|
18333 | Date: Mon Oct 3 18:11:14 2011 +0100 |
---|
18334 | |
---|
18335 | accessors and name cleanup for servermap.Servermap.problems |
---|
18336 | |
---|
18337 | src/allmydata/mutable/servermap.py | 21 +++++++++++++-------- |
---|
18338 | src/allmydata/test/test_mutable.py | 6 +++--- |
---|
18339 | 2 files changed, 16 insertions(+), 11 deletions(-) |
---|
18340 | |
---|
18341 | commit 348f57988f79389db0aab7672e6eaa9a6d8e3219 |
---|
18342 | Author: Brian Warner <warner@lothar.com> |
---|
18343 | Date: Mon Oct 3 18:10:41 2011 +0100 |
---|
18344 | |
---|
18345 | accessors and name cleanup for servermap.Servermap.bad_shares |
---|
18346 | |
---|
18347 | src/allmydata/mutable/publish.py | 2 +- |
---|
18348 | src/allmydata/mutable/servermap.py | 30 ++++++++++++++----------- |
---|
18349 | 2 files changed, 18 insertions(+), 14 deletions(-) |
---|
18350 | |
---|
18351 | commit 520c9368134673cdf76c653c5e1bb91c2ab5d51e |
---|
18352 | Author: Brian Warner <warner@lothar.com> |
---|
18353 | Date: Mon Oct 3 18:10:05 2011 +0100 |
---|
18354 | |
---|
18355 | accessors and name cleanup for servermap.Servermap.servermap . |
---|
18356 | |
---|
18357 | src/allmydata/mutable/publish.py | 14 +++++---- |
---|
18358 | src/allmydata/mutable/servermap.py | 38 ++++++++++++++----------- |
---|
18359 | 2 files changed, 29 insertions(+), 23 deletions(-) |
---|
18360 | |
---|
18361 | commit b8b8dc38287a91dbdf494426ac801d9381ce5841 |
---|
18362 | Author: Brian Warner <warner@lothar.com> |
---|
18363 | Date: Mon Oct 3 18:08:02 2011 +0100 |
---|
18364 | |
---|
18365 | fix reachable_servers |
---|
18366 | |
---|
18367 | src/allmydata/mutable/checker.py | 3 ++- |
---|
18368 | src/allmydata/mutable/publish.py | 4 +++- |
---|
18369 | src/allmydata/mutable/servermap.py | 12 ++++++++++-- |
---|
18370 | 3 files changed, 15 insertions(+), 4 deletions(-) |
---|
18371 | |
---|
18372 | commit cb0cfd1adfefad357c187aaaf690c3df68b622bc |
---|
18373 | Author: Brian Warner <warner@lothar.com> |
---|
18374 | Date: Mon Oct 3 18:06:03 2011 +0100 |
---|
18375 | |
---|
18376 | fix Servermap.unreachable_servers |
---|
18377 | |
---|
18378 | src/allmydata/mutable/servermap.py | 11 ++++++++--- |
---|
18379 | 1 files changed, 8 insertions(+), 3 deletions(-) |
---|
18380 | |
---|
18381 | commit 2d9ea79b94bd4db674d40386fda90825785ac495 |
---|
18382 | Author: Brian Warner <warner@lothar.com> |
---|
18383 | Date: Mon Oct 3 18:03:48 2011 +0100 |
---|
18384 | |
---|
18385 | give ServerMap a StorageFarmBroker, temporary |
---|
18386 | |
---|
18387 | this makes it possible for the ServerMap to accept bare serverids and still |
---|
18388 | build data structures with IServers |
---|
18389 | |
---|
18390 | src/allmydata/mutable/checker.py | 2 +- |
---|
18391 | src/allmydata/mutable/filenode.py | 2 +- |
---|
18392 | src/allmydata/mutable/publish.py | 2 +- |
---|
18393 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
18394 | src/allmydata/test/test_mutable.py | 8 ++++---- |
---|
18395 | 5 files changed, 10 insertions(+), 9 deletions(-) |
---|
18396 | |
---|
18397 | commit 718d1aeff6fded893f65397806d22ece928b0dd4 |
---|
18398 | Author: Brian Warner <warner@lothar.com> |
---|
18399 | Date: Mon Oct 3 13:43:30 2011 -0400 |
---|
18400 | |
---|
18401 | add StorageFarmBroker.get_server_for_id(), temporary helper |
---|
18402 | |
---|
18403 | This will go away once we're passing IServers everywhere. |
---|
18404 | |
---|
18405 | src/allmydata/storage_client.py | 2 ++ |
---|
18406 | src/allmydata/test/no_network.py | 13 +++++++++++++ |
---|
18407 | 2 files changed, 15 insertions(+), 0 deletions(-) |
---|
18408 | |
---|
18409 | commit ece20231d7fda0d503704842a4aa068dfbc2e54e |
---|
18410 | Author: Brian Warner <warner@lothar.com> |
---|
18411 | Date: Sun Oct 2 01:11:50 2011 +0100 |
---|
18412 | |
---|
18413 | add proper accessors for Servermap.connections, to make refactoring easier |
---|
18414 | |
---|
18415 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
18416 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
18417 | src/allmydata/mutable/servermap.py | 17 +++++++++++------ |
---|
18418 | 3 files changed, 19 insertions(+), 14 deletions(-) |
---|
18419 | |
---|
18420 | commit 3b943d6bf302ff702668081a612fc4fe2604cf9c |
---|
18421 | Author: Brian Warner <warner@lothar.com> |
---|
18422 | Date: Fri Sep 23 10:34:30 2011 -0700 |
---|
18423 | |
---|
18424 | mutable/servermap.py and neighbors: s/peer/server/ |
---|
18425 | |
---|
18426 | src/allmydata/mutable/checker.py | 22 +- |
---|
18427 | src/allmydata/mutable/publish.py | 204 +++++++------- |
---|
18428 | src/allmydata/mutable/servermap.py | 402 +++++++++++++------------- |
---|
18429 | src/allmydata/test/test_mutable.py | 18 +- |
---|
18430 | 4 files changed, 323 insertions(+), 323 deletions(-) |
---|
18431 | IServer refactoring: pass IServer instances around, instead of peerids |
---|
18432 | |
---|
18433 | refs #1363 |
---|
18434 | |
---|
18435 | This collapses 88 small incremental changes (each of which passes all tests) |
---|
18436 | into one big patch. The development process for the long path started with |
---|
18437 | adding some temporary scaffolding, changing one method at a time, then |
---|
18438 | removing the scaffolding. The individual pieces are as follows, in reverse |
---|
18439 | chronological order (the first patch is at the end of this comment): |
---|
18440 | |
---|
18441 | commit 9bbe4174fd0d98a6cf47a8ef96e85d9ef34b2f9a |
---|
18442 | Author: Brian Warner <warner@lothar.com> |
---|
18443 | Date: Tue Oct 4 16:05:00 2011 -0400 |
---|
18444 | |
---|
18445 | immutable/downloader/status.py: correct comment |
---|
18446 | |
---|
18447 | src/allmydata/immutable/downloader/status.py | 2 +- |
---|
18448 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
18449 | |
---|
18450 | commit 72146a7c7c91eac2f7c3ceb801eb7a1721376889 |
---|
18451 | Author: Brian Warner <warner@lothar.com> |
---|
18452 | Date: Tue Oct 4 15:46:20 2011 -0400 |
---|
18453 | |
---|
18454 | remove temporary ServerMap._storage_broker |
---|
18455 | |
---|
18456 | src/allmydata/mutable/checker.py | 2 +- |
---|
18457 | src/allmydata/mutable/filenode.py | 2 +- |
---|
18458 | src/allmydata/mutable/publish.py | 2 +- |
---|
18459 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
18460 | src/allmydata/test/test_mutable.py | 8 ++++---- |
---|
18461 | 5 files changed, 9 insertions(+), 10 deletions(-) |
---|
18462 | |
---|
18463 | commit d703096b41632c47d76414b12672e076a422ff5c |
---|
18464 | Author: Brian Warner <warner@lothar.com> |
---|
18465 | Date: Tue Oct 4 15:37:05 2011 -0400 |
---|
18466 | |
---|
18467 | remove temporary storage_broker.get_server_for_id() |
---|
18468 | |
---|
18469 | src/allmydata/storage_client.py | 3 --- |
---|
18470 | src/allmydata/test/no_network.py | 13 ------------- |
---|
18471 | 2 files changed, 0 insertions(+), 16 deletions(-) |
---|
18472 | |
---|
18473 | commit 620cc5d80882ef6f7decfd26af8a6c7c1ddf80d1 |
---|
18474 | Author: Brian Warner <warner@lothar.com> |
---|
18475 | Date: Tue Oct 4 12:50:06 2011 -0400 |
---|
18476 | |
---|
18477 | API of Retrieve._try_to_validate_privkey(), trying to remove reader.server |
---|
18478 | |
---|
18479 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
18480 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
18481 | |
---|
18482 | commit 92f43f856f4a8b36c207d1b190ed8699b5a4ecb4 |
---|
18483 | Author: Brian Warner <warner@lothar.com> |
---|
18484 | Date: Tue Oct 4 12:48:08 2011 -0400 |
---|
18485 | |
---|
18486 | API of Retrieve._validate_block(), trying to remove reader.server |
---|
18487 | |
---|
18488 | src/allmydata/mutable/retrieve.py | 14 +++++++------- |
---|
18489 | 1 files changed, 7 insertions(+), 7 deletions(-) |
---|
18490 | |
---|
18491 | commit 572d5070761861a2190349d1ed8d85dbc25698a5 |
---|
18492 | Author: Brian Warner <warner@lothar.com> |
---|
18493 | Date: Tue Oct 4 12:36:58 2011 -0400 |
---|
18494 | |
---|
18495 | API of Retrieve._mark_bad_share(), trying to remove reader.server |
---|
18496 | |
---|
18497 | src/allmydata/mutable/retrieve.py | 21 +++++++++------------ |
---|
18498 | 1 files changed, 9 insertions(+), 12 deletions(-) |
---|
18499 | |
---|
18500 | commit a793ff00c0de1e2eec7b46288fdf388c7a2bec89 |
---|
18501 | Author: Brian Warner <warner@lothar.com> |
---|
18502 | Date: Tue Oct 4 12:06:13 2011 -0400 |
---|
18503 | |
---|
18504 | remove now-unused get_rref_for_serverid() |
---|
18505 | |
---|
18506 | src/allmydata/mutable/servermap.py | 3 --- |
---|
18507 | 1 files changed, 0 insertions(+), 3 deletions(-) |
---|
18508 | |
---|
18509 | commit 1b9827cc9366bf90b93297fdd6832f2ad0480ce7 |
---|
18510 | Author: Brian Warner <warner@lothar.com> |
---|
18511 | Date: Tue Oct 4 12:03:09 2011 -0400 |
---|
18512 | |
---|
18513 | Retrieve: stop adding .serverid attributes to readers |
---|
18514 | |
---|
18515 | src/allmydata/mutable/retrieve.py | 1 - |
---|
18516 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
18517 | |
---|
18518 | commit 5d4e9d491b19e49d2e443a1dfff2c672842c36ef |
---|
18519 | Author: Brian Warner <warner@lothar.com> |
---|
18520 | Date: Tue Oct 4 12:03:34 2011 -0400 |
---|
18521 | |
---|
18522 | return value of Retrieve(verify=True) |
---|
18523 | |
---|
18524 | src/allmydata/mutable/checker.py | 11 ++++++----- |
---|
18525 | src/allmydata/mutable/retrieve.py | 3 +-- |
---|
18526 | 2 files changed, 7 insertions(+), 7 deletions(-) |
---|
18527 | |
---|
18528 | commit e9ab7978c384e1f677cb7779dc449b1044face82 |
---|
18529 | Author: Brian Warner <warner@lothar.com> |
---|
18530 | Date: Tue Oct 4 11:54:23 2011 -0400 |
---|
18531 | |
---|
18532 | Retrieve._bad_shares (but not return value, used by Verifier) |
---|
18533 | |
---|
18534 | src/allmydata/mutable/retrieve.py | 7 ++++--- |
---|
18535 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
18536 | |
---|
18537 | commit 2d91926de233ec5c881f30e36b4a30ad92ab42a9 |
---|
18538 | Author: Brian Warner <warner@lothar.com> |
---|
18539 | Date: Tue Oct 4 11:51:23 2011 -0400 |
---|
18540 | |
---|
18541 | Publish: stop adding .serverid attributes to writers |
---|
18542 | |
---|
18543 | src/allmydata/mutable/publish.py | 9 ++------- |
---|
18544 | 1 files changed, 2 insertions(+), 7 deletions(-) |
---|
18545 | |
---|
18546 | commit 47c7a0105dec7cbf4f7e0a3ce800bbb85b15df4a |
---|
18547 | Author: Brian Warner <warner@lothar.com> |
---|
18548 | Date: Tue Oct 4 11:56:33 2011 -0400 |
---|
18549 | |
---|
18550 | API of get_write_enabler() |
---|
18551 | |
---|
18552 | src/allmydata/mutable/filenode.py | 7 ++++--- |
---|
18553 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
18554 | src/allmydata/test/no_network.py | 3 +++ |
---|
18555 | 3 files changed, 9 insertions(+), 5 deletions(-) |
---|
18556 | |
---|
18557 | commit 9196a5c6590fdbfd660325ea8358b345887d3db0 |
---|
18558 | Author: Brian Warner <warner@lothar.com> |
---|
18559 | Date: Tue Oct 4 11:46:24 2011 -0400 |
---|
18560 | |
---|
18561 | API of get_(renewal|cancel)_secret() |
---|
18562 | |
---|
18563 | src/allmydata/mutable/filenode.py | 14 ++++++++------ |
---|
18564 | src/allmydata/mutable/publish.py | 8 ++++---- |
---|
18565 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
18566 | 3 files changed, 14 insertions(+), 13 deletions(-) |
---|
18567 | |
---|
18568 | commit de7c1552f8c163eff5b6d820b5fb3b21c1b47cb5 |
---|
18569 | Author: Brian Warner <warner@lothar.com> |
---|
18570 | Date: Tue Oct 4 11:41:52 2011 -0400 |
---|
18571 | |
---|
18572 | API of CorruptShareError. Also comment out some related+unused test_web.py code |
---|
18573 | |
---|
18574 | src/allmydata/mutable/common.py | 13 +++++-------- |
---|
18575 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
18576 | src/allmydata/mutable/servermap.py | 8 +++----- |
---|
18577 | src/allmydata/test/common.py | 13 ++++++++----- |
---|
18578 | 4 files changed, 21 insertions(+), 23 deletions(-) |
---|
18579 | |
---|
18580 | commit 2c1c314046b620c16f1e66d030c150d768b7d01e |
---|
18581 | Author: Brian Warner <warner@lothar.com> |
---|
18582 | Date: Tue Oct 4 12:01:46 2011 -0400 |
---|
18583 | |
---|
18584 | API of ServerMap.mark_bad_share() |
---|
18585 | |
---|
18586 | src/allmydata/mutable/publish.py | 2 +- |
---|
18587 | src/allmydata/mutable/retrieve.py | 6 +++--- |
---|
18588 | src/allmydata/mutable/servermap.py | 6 ++---- |
---|
18589 | src/allmydata/test/test_mutable.py | 3 +-- |
---|
18590 | 4 files changed, 7 insertions(+), 10 deletions(-) |
---|
18591 | |
---|
18592 | commit 1bed349030779fd0c378ae4e821384f953c6f6ff |
---|
18593 | Author: Brian Warner <warner@lothar.com> |
---|
18594 | Date: Tue Oct 4 11:11:17 2011 -0400 |
---|
18595 | |
---|
18596 | API+name of ServerMap.shares_on_server() : only for tests, so debug_ prefix |
---|
18597 | |
---|
18598 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
18599 | src/allmydata/test/test_mutable.py | 6 +++--- |
---|
18600 | 2 files changed, 5 insertions(+), 8 deletions(-) |
---|
18601 | |
---|
18602 | commit 2d32e448677d6b818692e801045d4115b29abf21 |
---|
18603 | Author: Brian Warner <warner@lothar.com> |
---|
18604 | Date: Tue Oct 4 11:07:10 2011 -0400 |
---|
18605 | |
---|
18606 | API of ServerMap.all_servers_for_version() |
---|
18607 | |
---|
18608 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
18609 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
18610 | |
---|
18611 | commit 48f3204d1889c3e7179578125c4bdef515af3d6a |
---|
18612 | Author: Brian Warner <warner@lothar.com> |
---|
18613 | Date: Tue Oct 4 11:04:50 2011 -0400 |
---|
18614 | |
---|
18615 | internals of ServerMap methods that use make_versionmap(), remove temp copy |
---|
18616 | |
---|
18617 | src/allmydata/mutable/servermap.py | 28 +++++++++---------------- |
---|
18618 | 1 files changed, 10 insertions(+), 18 deletions(-) |
---|
18619 | |
---|
18620 | commit 5c3da77b6c777a145bd5ddfaa4db849dc9495548 |
---|
18621 | Author: Brian Warner <warner@lothar.com> |
---|
18622 | Date: Tue Oct 4 11:01:28 2011 -0400 |
---|
18623 | |
---|
18624 | API of ServerMap.make_versionmap() |
---|
18625 | |
---|
18626 | src/allmydata/mutable/checker.py | 4 ++-- |
---|
18627 | src/allmydata/mutable/retrieve.py | 5 ++--- |
---|
18628 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
18629 | src/allmydata/test/test_mutable.py | 7 ++++--- |
---|
18630 | 4 files changed, 10 insertions(+), 10 deletions(-) |
---|
18631 | |
---|
18632 | commit b6882ece49afb4c507d118af2db346fa329209dc |
---|
18633 | Author: Brian Warner <warner@lothar.com> |
---|
18634 | Date: Tue Oct 4 10:53:38 2011 -0400 |
---|
18635 | |
---|
18636 | make a copy of ServerMap.make_versionmap() (_make_versionmap2) for internal use |
---|
18637 | |
---|
18638 | src/allmydata/mutable/servermap.py | 18 +++++++++++++----- |
---|
18639 | 1 files changed, 13 insertions(+), 5 deletions(-) |
---|
18640 | |
---|
18641 | commit 963f8e63faf32b950eb1b8103cd2ff16fe8f0151 |
---|
18642 | Author: Brian Warner <warner@lothar.com> |
---|
18643 | Date: Tue Oct 4 00:45:58 2011 -0400 |
---|
18644 | |
---|
18645 | API of RetrieveStatus.add_problem() |
---|
18646 | |
---|
18647 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
18648 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18649 | |
---|
18650 | commit 4976d29ffae565a048851601c29013bbae2976d8 |
---|
18651 | Author: Brian Warner <warner@lothar.com> |
---|
18652 | Date: Tue Oct 4 00:45:05 2011 -0400 |
---|
18653 | |
---|
18654 | API of RetrieveStatus.add_fetch_timing() |
---|
18655 | |
---|
18656 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
18657 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18658 | |
---|
18659 | commit d057d3bbba72663ee148a8b916bc2d52be2e3982 |
---|
18660 | Author: Brian Warner <warner@lothar.com> |
---|
18661 | Date: Tue Oct 4 00:44:04 2011 -0400 |
---|
18662 | |
---|
18663 | API of Retrieve.notify_server_corruption() |
---|
18664 | |
---|
18665 | src/allmydata/mutable/retrieve.py | 6 +++--- |
---|
18666 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18667 | |
---|
18668 | commit 8a2a81e46671c860610e0e96d6add1a57551f22d |
---|
18669 | Author: Brian Warner <warner@lothar.com> |
---|
18670 | Date: Tue Oct 4 00:42:32 2011 -0400 |
---|
18671 | |
---|
18672 | remove unused _outstanding_queries |
---|
18673 | |
---|
18674 | src/allmydata/mutable/retrieve.py | 1 - |
---|
18675 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
18676 | |
---|
18677 | commit 56d12cc9968d03ccd53764455c671122c4f391d1 |
---|
18678 | Author: Brian Warner <warner@lothar.com> |
---|
18679 | Date: Tue Oct 4 00:40:57 2011 -0400 |
---|
18680 | |
---|
18681 | change Retrieve.remaining_sharemap |
---|
18682 | |
---|
18683 | src/allmydata/mutable/retrieve.py | 4 ++-- |
---|
18684 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
18685 | |
---|
18686 | commit 4f0b7af4821f43290bfc70f2b1fc30149ad81281 |
---|
18687 | Author: Brian Warner <warner@lothar.com> |
---|
18688 | Date: Tue Oct 4 10:40:18 2011 -0400 |
---|
18689 | |
---|
18690 | accessor for PublishStatus._problems |
---|
18691 | |
---|
18692 | src/allmydata/mutable/publish.py | 4 +++- |
---|
18693 | src/allmydata/web/status.py | 2 +- |
---|
18694 | 2 files changed, 4 insertions(+), 2 deletions(-) |
---|
18695 | |
---|
18696 | commit 627087cf66d0b8cc519f4d551a967a7bd9b6a741 |
---|
18697 | Author: Brian Warner <warner@lothar.com> |
---|
18698 | Date: Tue Oct 4 10:36:39 2011 -0400 |
---|
18699 | |
---|
18700 | accessor for RetrieveStatus._problems |
---|
18701 | |
---|
18702 | src/allmydata/mutable/retrieve.py | 8 ++++++-- |
---|
18703 | src/allmydata/web/status.py | 2 +- |
---|
18704 | 2 files changed, 7 insertions(+), 3 deletions(-) |
---|
18705 | |
---|
18706 | commit ca7dea81f03801b1c7353fc00ecba689268109cf |
---|
18707 | Author: Brian Warner <warner@lothar.com> |
---|
18708 | Date: Tue Oct 4 00:35:32 2011 -0400 |
---|
18709 | |
---|
18710 | add .server to "reader", so we can get at it later |
---|
18711 | |
---|
18712 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
18713 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18714 | |
---|
18715 | commit 6ef516e24908ec195af084a7550d1921a5e983b0 |
---|
18716 | Author: Brian Warner <warner@lothar.com> |
---|
18717 | Date: Tue Oct 4 00:32:32 2011 -0400 |
---|
18718 | |
---|
18719 | temporarily give Retrieve a _storage_broker, so it can map serverids to servers |
---|
18720 | |
---|
18721 | src/allmydata/mutable/checker.py | 3 ++- |
---|
18722 | src/allmydata/mutable/filenode.py | 6 ++++-- |
---|
18723 | src/allmydata/mutable/retrieve.py | 5 +++-- |
---|
18724 | src/allmydata/test/test_mutable.py | 4 ++-- |
---|
18725 | 4 files changed, 11 insertions(+), 7 deletions(-) |
---|
18726 | |
---|
18727 | commit afe08e4dd3f4ff9ff7e8a2a8d28b181e3625bcc9 |
---|
18728 | Author: Brian Warner <warner@lothar.com> |
---|
18729 | Date: Tue Oct 4 00:21:51 2011 -0400 |
---|
18730 | |
---|
18731 | mutable/retrieve.py: s/peer/server/ |
---|
18732 | |
---|
18733 | src/allmydata/mutable/retrieve.py | 82 +++++++++++++------------- |
---|
18734 | src/allmydata/test/test_mutable.py | 6 +- |
---|
18735 | 2 files changed, 44 insertions(+), 44 deletions(-) |
---|
18736 | |
---|
18737 | commit 910afcb5d7f274880f68dd6cdb5b05f2bbc29adc |
---|
18738 | Author: Brian Warner <warner@lothar.com> |
---|
18739 | Date: Tue Oct 4 00:16:01 2011 -0400 |
---|
18740 | |
---|
18741 | web.status.PublishStatusPage: add comment, I think .problems isn't exercised |
---|
18742 | |
---|
18743 | src/allmydata/web/status.py | 2 ++ |
---|
18744 | 1 files changed, 2 insertions(+), 0 deletions(-) |
---|
18745 | |
---|
18746 | commit 311466dd8c931bbba40d590ade867704282e7f1a |
---|
18747 | Author: Brian Warner <warner@lothar.com> |
---|
18748 | Date: Mon Oct 3 23:48:16 2011 -0400 |
---|
18749 | |
---|
18750 | API of PublishStatus.add_per_server_time() |
---|
18751 | |
---|
18752 | src/allmydata/mutable/publish.py | 5 +++-- |
---|
18753 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
18754 | |
---|
18755 | commit 2df5faa1b6cbfbaded520d2320305a62fe961118 |
---|
18756 | Author: Brian Warner <warner@lothar.com> |
---|
18757 | Date: Mon Oct 3 23:46:37 2011 -0400 |
---|
18758 | |
---|
18759 | more simplifications |
---|
18760 | |
---|
18761 | src/allmydata/mutable/publish.py | 4 +--- |
---|
18762 | 1 files changed, 1 insertions(+), 3 deletions(-) |
---|
18763 | |
---|
18764 | commit 6ac4544a3da385f2aad9392f906b90192f4f919a |
---|
18765 | Author: Brian Warner <warner@lothar.com> |
---|
18766 | Date: Mon Oct 3 23:44:08 2011 -0400 |
---|
18767 | |
---|
18768 | API of ServerMap.version_on_server() |
---|
18769 | |
---|
18770 | src/allmydata/mutable/publish.py | 2 +- |
---|
18771 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
18772 | src/allmydata/test/test_mutable.py | 5 ++--- |
---|
18773 | 3 files changed, 5 insertions(+), 6 deletions(-) |
---|
18774 | |
---|
18775 | commit 3e187e322511072e4683329df6b2c6c733a66dba |
---|
18776 | Author: Brian Warner <warner@lothar.com> |
---|
18777 | Date: Tue Oct 4 00:16:32 2011 -0400 |
---|
18778 | |
---|
18779 | API of ServerMap.make_sharemap() |
---|
18780 | |
---|
18781 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
18782 | src/allmydata/test/test_mutable.py | 7 ++++--- |
---|
18783 | src/allmydata/web/status.py | 4 ++-- |
---|
18784 | 3 files changed, 8 insertions(+), 7 deletions(-) |
---|
18785 | |
---|
18786 | commit 318feed8437bdd8d4943c6569d38f7b54b6313cc |
---|
18787 | Author: Brian Warner <warner@lothar.com> |
---|
18788 | Date: Mon Oct 3 23:36:19 2011 -0400 |
---|
18789 | |
---|
18790 | small cleanups |
---|
18791 | |
---|
18792 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
18793 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
18794 | |
---|
18795 | commit bd459ed5714e1db5a7163935c54b7b0b56db8349 |
---|
18796 | Author: Brian Warner <warner@lothar.com> |
---|
18797 | Date: Mon Oct 3 23:33:39 2011 -0400 |
---|
18798 | |
---|
18799 | API of ServerMap.add_new_share() |
---|
18800 | |
---|
18801 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
18802 | src/allmydata/mutable/servermap.py | 6 ++---- |
---|
18803 | 2 files changed, 4 insertions(+), 6 deletions(-) |
---|
18804 | |
---|
18805 | commit f2804fb6ed11d80088e0da8ed48e6c2922f2ffef |
---|
18806 | Author: Brian Warner <warner@lothar.com> |
---|
18807 | Date: Mon Oct 3 23:30:26 2011 -0400 |
---|
18808 | |
---|
18809 | API of ServerMap.get_bad_shares() |
---|
18810 | |
---|
18811 | src/allmydata/mutable/publish.py | 3 +-- |
---|
18812 | src/allmydata/mutable/servermap.py | 9 ++++----- |
---|
18813 | 2 files changed, 5 insertions(+), 7 deletions(-) |
---|
18814 | |
---|
18815 | commit 965074a47b3ce1431cb46d9a233840afcf9105f5 |
---|
18816 | Author: Brian Warner <warner@lothar.com> |
---|
18817 | Date: Mon Oct 3 23:26:58 2011 -0400 |
---|
18818 | |
---|
18819 | more small cleanups |
---|
18820 | |
---|
18821 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
18822 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18823 | |
---|
18824 | commit 38020da34f034f8889947dd3dc05e087ffff7106 |
---|
18825 | Author: Brian Warner <warner@lothar.com> |
---|
18826 | Date: Mon Oct 3 23:18:47 2011 -0400 |
---|
18827 | |
---|
18828 | change Publish.bad_share_checkstrings |
---|
18829 | |
---|
18830 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
18831 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18832 | |
---|
18833 | commit 5efebcbd2ee0c2f299ea86f7591d856c0f265304 |
---|
18834 | Author: Brian Warner <warner@lothar.com> |
---|
18835 | Date: Mon Oct 3 23:16:31 2011 -0400 |
---|
18836 | |
---|
18837 | change internals of Publish.update_goal() |
---|
18838 | |
---|
18839 | src/allmydata/mutable/publish.py | 8 +++----- |
---|
18840 | 1 files changed, 3 insertions(+), 5 deletions(-) |
---|
18841 | |
---|
18842 | commit e91b55ff4c2a69165b71f2c7b217ac319ff4c527 |
---|
18843 | Author: Brian Warner <warner@lothar.com> |
---|
18844 | Date: Mon Oct 3 23:11:42 2011 -0400 |
---|
18845 | |
---|
18846 | get rid of Publish.connections |
---|
18847 | |
---|
18848 | src/allmydata/mutable/publish.py | 27 +++++---------------------- |
---|
18849 | 1 files changed, 5 insertions(+), 22 deletions(-) |
---|
18850 | |
---|
18851 | commit 64e9a53b3229ebe2f9ebf7ed502d539311d0e037 |
---|
18852 | Author: Brian Warner <warner@lothar.com> |
---|
18853 | Date: Mon Oct 3 23:05:32 2011 -0400 |
---|
18854 | |
---|
18855 | change Publish.bad_servers |
---|
18856 | |
---|
18857 | src/allmydata/mutable/publish.py | 10 +++++----- |
---|
18858 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
18859 | |
---|
18860 | commit b85a934bef315a06bcfe00c9c12a3627fed2b918 |
---|
18861 | Author: Brian Warner <warner@lothar.com> |
---|
18862 | Date: Mon Oct 3 23:03:07 2011 -0400 |
---|
18863 | |
---|
18864 | Publish.bad_servers: fix bug, this should be a set of serverids, not writers |
---|
18865 | |
---|
18866 | src/allmydata/mutable/publish.py | 2 +- |
---|
18867 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
18868 | |
---|
18869 | commit 605ea15ec15ed671513819003ccd211cdb9761e0 |
---|
18870 | Author: Brian Warner <warner@lothar.com> |
---|
18871 | Date: Mon Oct 3 23:00:21 2011 -0400 |
---|
18872 | |
---|
18873 | change .placed |
---|
18874 | |
---|
18875 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
18876 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
18877 | |
---|
18878 | commit f7aba37b1b345d5b6d5cb16e3b3f6f3c1afb658e |
---|
18879 | Author: Brian Warner <warner@lothar.com> |
---|
18880 | Date: Mon Oct 3 22:59:22 2011 -0400 |
---|
18881 | |
---|
18882 | temporarily stash IServer as .server on the "writer" object |
---|
18883 | |
---|
18884 | src/allmydata/mutable/publish.py | 2 ++ |
---|
18885 | 1 files changed, 2 insertions(+), 0 deletions(-) |
---|
18886 | |
---|
18887 | commit f9b551d788e7db1f187fce5ab98ab5d5fe4e1c36 |
---|
18888 | Author: Brian Warner <warner@lothar.com> |
---|
18889 | Date: Mon Oct 3 22:48:18 2011 -0400 |
---|
18890 | |
---|
18891 | change Publish.goal and API of log_goal() to use IServer, not serverid |
---|
18892 | |
---|
18893 | src/allmydata/mutable/publish.py | 48 ++++++++++++++-------------- |
---|
18894 | 1 files changed, 24 insertions(+), 24 deletions(-) |
---|
18895 | |
---|
18896 | commit 75f20616558e4900b8b1f685dd99aa838de6d452 |
---|
18897 | Author: Brian Warner <warner@lothar.com> |
---|
18898 | Date: Mon Oct 3 15:27:02 2011 -0400 |
---|
18899 | |
---|
18900 | API of ServerMap.get_known_shares() |
---|
18901 | |
---|
18902 | src/allmydata/mutable/publish.py | 16 ++++++++++------ |
---|
18903 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
18904 | 2 files changed, 12 insertions(+), 11 deletions(-) |
---|
18905 | |
---|
18906 | commit 1c38c9d37bb08221b4418762234b1a62397b3b4b |
---|
18907 | Author: Brian Warner <warner@lothar.com> |
---|
18908 | Date: Mon Oct 3 15:20:29 2011 -0400 |
---|
18909 | |
---|
18910 | Publish.full_serverlist |
---|
18911 | |
---|
18912 | src/allmydata/mutable/publish.py | 10 +++++----- |
---|
18913 | 1 files changed, 5 insertions(+), 5 deletions(-) |
---|
18914 | |
---|
18915 | commit b6cbd215a04b9cde31a7d92a97a7f048622b16f1 |
---|
18916 | Author: Brian Warner <warner@lothar.com> |
---|
18917 | Date: Mon Oct 3 15:12:31 2011 -0400 |
---|
18918 | |
---|
18919 | API of ServerMap.all_servers() |
---|
18920 | |
---|
18921 | src/allmydata/mutable/servermap.py | 19 ++++++------------- |
---|
18922 | 1 files changed, 6 insertions(+), 13 deletions(-) |
---|
18923 | |
---|
18924 | commit e63cd0315fae65357b1727ec6d5ff3c6e0d27c98 |
---|
18925 | Author: Brian Warner <warner@lothar.com> |
---|
18926 | Date: Mon Oct 3 15:10:18 2011 -0400 |
---|
18927 | |
---|
18928 | remove ServerMap.connections, set_rref_for_serverid() |
---|
18929 | |
---|
18930 | src/allmydata/mutable/servermap.py | 11 +---------- |
---|
18931 | 1 files changed, 1 insertions(+), 10 deletions(-) |
---|
18932 | |
---|
18933 | commit 4df52db2f80eb12eefa5d57103c24893cde89553 |
---|
18934 | Author: Brian Warner <warner@lothar.com> |
---|
18935 | Date: Mon Oct 3 15:04:06 2011 -0400 |
---|
18936 | |
---|
18937 | API of ServerMap.mark_server_reachable() |
---|
18938 | |
---|
18939 | src/allmydata/mutable/servermap.py | 7 ++----- |
---|
18940 | 1 files changed, 2 insertions(+), 5 deletions(-) |
---|
18941 | |
---|
18942 | commit 69c715bde77944dc25181b3dbbeb042c816f9a1b |
---|
18943 | Author: Brian Warner <warner@lothar.com> |
---|
18944 | Date: Mon Oct 3 15:03:21 2011 -0400 |
---|
18945 | |
---|
18946 | API of ServerMap.mark_server_unreachable() |
---|
18947 | |
---|
18948 | src/allmydata/mutable/servermap.py | 9 +++------ |
---|
18949 | 1 files changed, 3 insertions(+), 6 deletions(-) |
---|
18950 | |
---|
18951 | commit 3d784d60eec1c508858e3a617e4411ffbcc3c1fa |
---|
18952 | Author: Brian Warner <warner@lothar.com> |
---|
18953 | Date: Mon Oct 3 15:02:03 2011 -0400 |
---|
18954 | |
---|
18955 | API of status.set_privkey_from() |
---|
18956 | |
---|
18957 | src/allmydata/mutable/servermap.py | 7 +++---- |
---|
18958 | 1 files changed, 3 insertions(+), 4 deletions(-) |
---|
18959 | |
---|
18960 | commit 544ed3ea29bed7e66da7fd29ca3f6f076f27a9e6 |
---|
18961 | Author: Brian Warner <warner@lothar.com> |
---|
18962 | Date: Mon Oct 3 15:01:15 2011 -0400 |
---|
18963 | |
---|
18964 | API of status.add_per_server_time() |
---|
18965 | |
---|
18966 | src/allmydata/mutable/servermap.py | 7 ++++--- |
---|
18967 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
18968 | |
---|
18969 | commit fffe5008b6320bd1e04c3c68389a2bf2ee383fa8 |
---|
18970 | Author: Brian Warner <warner@lothar.com> |
---|
18971 | Date: Mon Oct 3 14:59:02 2011 -0400 |
---|
18972 | |
---|
18973 | remove unused .versionmap |
---|
18974 | |
---|
18975 | src/allmydata/mutable/servermap.py | 7 ------- |
---|
18976 | 1 files changed, 0 insertions(+), 7 deletions(-) |
---|
18977 | |
---|
18978 | commit 2816562e090d2294179db3588dafcca18de1bc2b |
---|
18979 | Author: Brian Warner <warner@lothar.com> |
---|
18980 | Date: Mon Oct 3 14:57:51 2011 -0400 |
---|
18981 | |
---|
18982 | remove serverid from all log messages. Also one unused lambda. |
---|
18983 | |
---|
18984 | src/allmydata/mutable/servermap.py | 30 +++++++++++++------------- |
---|
18985 | 1 files changed, 15 insertions(+), 15 deletions(-) |
---|
18986 | |
---|
18987 | commit 28fa6b1a2738fa98c1f1dbd3d0e01ae98912d11f |
---|
18988 | Author: Brian Warner <warner@lothar.com> |
---|
18989 | Date: Mon Oct 3 14:54:30 2011 -0400 |
---|
18990 | |
---|
18991 | removed unused _readers |
---|
18992 | |
---|
18993 | src/allmydata/mutable/servermap.py | 3 --- |
---|
18994 | 1 files changed, 0 insertions(+), 3 deletions(-) |
---|
18995 | |
---|
18996 | commit a8e4ed3d645ab592d1add6a1e69b6d1ebfb77817 |
---|
18997 | Author: Brian Warner <warner@lothar.com> |
---|
18998 | Date: Mon Oct 3 14:54:16 2011 -0400 |
---|
18999 | |
---|
19000 | remove unused _sharemap |
---|
19001 | |
---|
19002 | src/allmydata/mutable/servermap.py | 1 - |
---|
19003 | 1 files changed, 0 insertions(+), 1 deletions(-) |
---|
19004 | |
---|
19005 | commit 3f072e55cf1d0700f9fffe23f8f3a475725df588 |
---|
19006 | Author: Brian Warner <warner@lothar.com> |
---|
19007 | Date: Mon Oct 3 14:49:03 2011 -0400 |
---|
19008 | |
---|
19009 | _must_query |
---|
19010 | |
---|
19011 | src/allmydata/mutable/servermap.py | 8 ++++---- |
---|
19012 | 1 files changed, 4 insertions(+), 4 deletions(-) |
---|
19013 | |
---|
19014 | commit c599a059b8df3f5785e4bf89fb6ecc6d8dcd708b |
---|
19015 | Author: Brian Warner <warner@lothar.com> |
---|
19016 | Date: Mon Oct 3 14:48:05 2011 -0400 |
---|
19017 | |
---|
19018 | _queries_outstanding |
---|
19019 | |
---|
19020 | src/allmydata/mutable/servermap.py | 16 +++++++--------- |
---|
19021 | 1 files changed, 7 insertions(+), 9 deletions(-) |
---|
19022 | |
---|
19023 | commit 7743759f98ac2c07926b2fdbd80bf52dfab33085 |
---|
19024 | Author: Brian Warner <warner@lothar.com> |
---|
19025 | Date: Mon Oct 3 14:46:17 2011 -0400 |
---|
19026 | |
---|
19027 | _empty_servers |
---|
19028 | |
---|
19029 | src/allmydata/mutable/servermap.py | 5 ++--- |
---|
19030 | 1 files changed, 2 insertions(+), 3 deletions(-) |
---|
19031 | |
---|
19032 | commit 6bb1825916828a713a32cdf7f7411fa3ea2e1e5d |
---|
19033 | Author: Brian Warner <warner@lothar.com> |
---|
19034 | Date: Mon Oct 3 14:45:39 2011 -0400 |
---|
19035 | |
---|
19036 | _good_servers |
---|
19037 | |
---|
19038 | src/allmydata/mutable/servermap.py | 4 ++-- |
---|
19039 | 1 files changed, 2 insertions(+), 2 deletions(-) |
---|
19040 | |
---|
19041 | commit 1768fab1b51d8dd93ecabbaaabfadfa20cf6c3d4 |
---|
19042 | Author: Brian Warner <warner@lothar.com> |
---|
19043 | Date: Mon Oct 3 14:44:59 2011 -0400 |
---|
19044 | |
---|
19045 | _bad_servers |
---|
19046 | |
---|
19047 | src/allmydata/mutable/servermap.py | 14 +++++++------- |
---|
19048 | 1 files changed, 7 insertions(+), 7 deletions(-) |
---|
19049 | |
---|
19050 | commit dccbaef30f0ba714c746bf6d4a1a803c36e17b65 |
---|
19051 | Author: Brian Warner <warner@lothar.com> |
---|
19052 | Date: Mon Oct 3 14:41:54 2011 -0400 |
---|
19053 | |
---|
19054 | API of _try_to_set_pubkey() |
---|
19055 | |
---|
19056 | src/allmydata/mutable/servermap.py | 7 ++++--- |
---|
19057 | 1 files changed, 4 insertions(+), 3 deletions(-) |
---|
19058 | |
---|
19059 | commit 0481ea70042ba3575f15eac7fd0780f8ece580cc |
---|
19060 | Author: Brian Warner <warner@lothar.com> |
---|
19061 | Date: Mon Oct 3 14:35:02 2011 -0400 |
---|
19062 | |
---|
19063 | API of notify_server_corruption() |
---|
19064 | |
---|
19065 | src/allmydata/mutable/servermap.py | 6 +++--- |
---|
19066 | 1 files changed, 3 insertions(+), 3 deletions(-) |
---|
19067 | |
---|
19068 | commit bea9cba18fb3b9c11bb22f18356a263ecec7351e |
---|
19069 | Author: Brian Warner <warner@lothar.com> |
---|
19070 | Date: Mon Oct 3 14:34:09 2011 -0400 |
---|
19071 | |
---|
19072 | API of _got_signature_one_share() |
---|
19073 | |
---|
19074 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
19075 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
19076 | |
---|
19077 | commit 1520123583cf78650706e114b15bb5b0ac1f4a14 |
---|
19078 | Author: Brian Warner <warner@lothar.com> |
---|
19079 | Date: Mon Oct 3 14:32:33 2011 -0400 |
---|
19080 | |
---|
19081 | API of _try_to_validate_privkey() |
---|
19082 | |
---|
19083 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
19084 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
19085 | |
---|
19086 | commit 938852c9c8519c7a078f58a9b1f4dd8ec8b6715e |
---|
19087 | Author: Brian Warner <warner@lothar.com> |
---|
19088 | Date: Mon Oct 3 14:31:48 2011 -0400 |
---|
19089 | |
---|
19090 | API and internals of _add_lease_failed() |
---|
19091 | |
---|
19092 | src/allmydata/mutable/servermap.py | 8 ++++---- |
---|
19093 | 1 files changed, 4 insertions(+), 4 deletions(-) |
---|
19094 | |
---|
19095 | commit 3843dba367e3c19e176a622ab853cb51d2472ddf |
---|
19096 | Author: Brian Warner <warner@lothar.com> |
---|
19097 | Date: Mon Oct 3 14:30:37 2011 -0400 |
---|
19098 | |
---|
19099 | API of _privkey_query_failed() |
---|
19100 | |
---|
19101 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
19102 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
19103 | |
---|
19104 | commit 2219a710e1633cd57d0ca0786490de87b3e19ba7 |
---|
19105 | Author: Brian Warner <warner@lothar.com> |
---|
19106 | Date: Mon Oct 3 14:29:43 2011 -0400 |
---|
19107 | |
---|
19108 | fix bug in call to _privkey_query_failed, unrelated to refactoring |
---|
19109 | |
---|
19110 | src/allmydata/mutable/servermap.py | 2 +- |
---|
19111 | 1 files changed, 1 insertions(+), 1 deletions(-) |
---|
19112 | |
---|
19113 | commit ae615bec7d0d1b269710b6902797b12f9592ad62 |
---|
19114 | Author: Brian Warner <warner@lothar.com> |
---|
19115 | Date: Mon Oct 3 14:27:17 2011 -0400 |
---|
19116 | |
---|
19117 | API of _got_corrupt_share() |
---|
19118 | |
---|
19119 | src/allmydata/mutable/servermap.py | 17 +++++++++-------- |
---|
19120 | 1 files changed, 9 insertions(+), 8 deletions(-) |
---|
19121 | |
---|
19122 | commit cb51c95a6f4e077278157a77dab060c8c1ad7a81 |
---|
19123 | Author: Brian Warner <warner@lothar.com> |
---|
19124 | Date: Mon Oct 3 14:23:16 2011 -0400 |
---|
19125 | |
---|
19126 | API of _got_results() |
---|
19127 | |
---|
19128 | src/allmydata/mutable/servermap.py | 9 +++++---- |
---|
19129 | 1 files changed, 5 insertions(+), 4 deletions(-) |
---|
19130 | |
---|
19131 | commit bac9154fe0af18f226999a58ffc2362d8cf4b802 |
---|
19132 | Author: Brian Warner <warner@lothar.com> |
---|
19133 | Date: Mon Oct 3 14:19:19 2011 -0400 |
---|
19134 | |
---|
19135 | API of _query_failed() |
---|
19136 | |
---|
19137 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
19138 | 1 files changed, 3 insertions(+), 2 deletions(-) |
---|
19139 | |
---|
19140 | commit fdc29a8ca95d4b5c503e5382b9e5d4d02141ba12 |
---|
19141 | Author: Brian Warner <warner@lothar.com> |
---|
19142 | Date: Mon Oct 3 14:17:20 2011 -0400 |
---|
19143 | |
---|
19144 | API of _do_read() |
---|
19145 | |
---|
19146 | src/allmydata/mutable/servermap.py | 6 ++++-- |
---|
19147 | 1 files changed, 4 insertions(+), 2 deletions(-) |
---|
19148 | |
---|
19149 | commit e7e9e338f28d004aa4d423d11c65f1e271ac7322 |
---|
19150 | Author: Brian Warner <warner@lothar.com> |
---|
19151 | Date: Mon Oct 3 14:20:21 2011 -0400 |
---|
19152 | |
---|
19153 | API of _do_query() |
---|
19154 | |
---|
19155 | src/allmydata/mutable/servermap.py | 15 +++++++-------- |
---|
19156 | 1 files changed, 7 insertions(+), 8 deletions(-) |
---|
19157 | |
---|
19158 | commit 330625b9dac4cdbe72a11464a893065b9aeed453 |
---|
19159 | Author: Brian Warner <warner@lothar.com> |
---|
19160 | Date: Mon Oct 3 14:43:05 2011 -0400 |
---|
19161 | |
---|
19162 | next step: first batch of updates to ServermapUpdater |
---|
19163 | |
---|
19164 | updates: |
---|
19165 | most method-local variables in update() |
---|
19166 | API of _build_initial_querylist() |
---|
19167 | API of _send_initial_requests() |
---|
19168 | .full_serverlist |
---|
19169 | .extra_servers |
---|
19170 | |
---|
19171 | src/allmydata/mutable/servermap.py | 39 ++++++++++++++------------ |
---|
19172 | 1 files changed, 21 insertions(+), 18 deletions(-) |
---|
19173 | |
---|
19174 | commit 4aadc584fa7dcb2daa86b048c81dee0049ba26d9 |
---|
19175 | Author: Brian Warner <warner@lothar.com> |
---|
19176 | Date: Mon Oct 3 15:07:00 2011 -0400 |
---|
19177 | |
---|
19178 | internal change: index _bad_shares with IServer |
---|
19179 | |
---|
19180 | src/allmydata/mutable/servermap.py | 20 ++++++++++---------- |
---|
19181 | 1 files changed, 10 insertions(+), 10 deletions(-) |
---|
19182 | |
---|
19183 | commit 16d4e6fa82a9907dbdc92094213387c6a4164e41 |
---|
19184 | Author: Brian Warner <warner@lothar.com> |
---|
19185 | Date: Mon Oct 3 18:20:47 2011 +0100 |
---|
19186 | |
---|
19187 | internal change: index _known_shares with IServer instead of serverid |
---|
19188 | |
---|
19189 | callers are unchanged |
---|
19190 | |
---|
19191 | src/allmydata/mutable/servermap.py | 42 +++++++++++++++---------- |
---|
19192 | 1 files changed, 25 insertions(+), 17 deletions(-) |
---|
19193 | |
---|
19194 | commit ceeb5f4938cc814a0c75d1b8f4018aed965c2176 |
---|
19195 | Author: Brian Warner <warner@lothar.com> |
---|
19196 | Date: Mon Oct 3 18:11:43 2011 +0100 |
---|
19197 | |
---|
19198 | accessors and name cleanup for servermap.Servermap.last_update_mode/time |
---|
19199 | |
---|
19200 | src/allmydata/mutable/filenode.py | 6 +++--- |
---|
19201 | src/allmydata/mutable/publish.py | 4 ++-- |
---|
19202 | src/allmydata/mutable/servermap.py | 17 +++++++++++------ |
---|
19203 | 3 files changed, 16 insertions(+), 11 deletions(-) |
---|
19204 | |
---|
19205 | commit 8d3cbda82661c0a7e5c3d3b65cf7a5d5ab7e32c0 |
---|
19206 | Author: Brian Warner <warner@lothar.com> |
---|
19207 | Date: Mon Oct 3 18:11:14 2011 +0100 |
---|
19208 | |
---|
19209 | accessors and name cleanup for servermap.Servermap.problems |
---|
19210 | |
---|
19211 | src/allmydata/mutable/servermap.py | 21 +++++++++++++-------- |
---|
19212 | src/allmydata/test/test_mutable.py | 6 +++--- |
---|
19213 | 2 files changed, 16 insertions(+), 11 deletions(-) |
---|
19214 | |
---|
19215 | commit 348f57988f79389db0aab7672e6eaa9a6d8e3219 |
---|
19216 | Author: Brian Warner <warner@lothar.com> |
---|
19217 | Date: Mon Oct 3 18:10:41 2011 +0100 |
---|
19218 | |
---|
19219 | accessors and name cleanup for servermap.Servermap.bad_shares |
---|
19220 | |
---|
19221 | src/allmydata/mutable/publish.py | 2 +- |
---|
19222 | src/allmydata/mutable/servermap.py | 30 ++++++++++++++----------- |
---|
19223 | 2 files changed, 18 insertions(+), 14 deletions(-) |
---|
19224 | |
---|
19225 | commit 520c9368134673cdf76c653c5e1bb91c2ab5d51e |
---|
19226 | Author: Brian Warner <warner@lothar.com> |
---|
19227 | Date: Mon Oct 3 18:10:05 2011 +0100 |
---|
19228 | |
---|
19229 | accessors and name cleanup for servermap.Servermap.servermap . |
---|
19230 | |
---|
19231 | src/allmydata/mutable/publish.py | 14 +++++---- |
---|
19232 | src/allmydata/mutable/servermap.py | 38 ++++++++++++++----------- |
---|
19233 | 2 files changed, 29 insertions(+), 23 deletions(-) |
---|
19234 | |
---|
19235 | commit b8b8dc38287a91dbdf494426ac801d9381ce5841 |
---|
19236 | Author: Brian Warner <warner@lothar.com> |
---|
19237 | Date: Mon Oct 3 18:08:02 2011 +0100 |
---|
19238 | |
---|
19239 | fix reachable_servers |
---|
19240 | |
---|
19241 | src/allmydata/mutable/checker.py | 3 ++- |
---|
19242 | src/allmydata/mutable/publish.py | 4 +++- |
---|
19243 | src/allmydata/mutable/servermap.py | 12 ++++++++++-- |
---|
19244 | 3 files changed, 15 insertions(+), 4 deletions(-) |
---|
19245 | |
---|
19246 | commit cb0cfd1adfefad357c187aaaf690c3df68b622bc |
---|
19247 | Author: Brian Warner <warner@lothar.com> |
---|
19248 | Date: Mon Oct 3 18:06:03 2011 +0100 |
---|
19249 | |
---|
19250 | fix Servermap.unreachable_servers |
---|
19251 | |
---|
19252 | src/allmydata/mutable/servermap.py | 11 ++++++++--- |
---|
19253 | 1 files changed, 8 insertions(+), 3 deletions(-) |
---|
19254 | |
---|
19255 | commit 2d9ea79b94bd4db674d40386fda90825785ac495 |
---|
19256 | Author: Brian Warner <warner@lothar.com> |
---|
19257 | Date: Mon Oct 3 18:03:48 2011 +0100 |
---|
19258 | |
---|
19259 | give ServerMap a StorageFarmBroker, temporary |
---|
19260 | |
---|
19261 | this makes it possible for the ServerMap to accept bare serverids and still |
---|
19262 | build data structures with IServers |
---|
19263 | |
---|
19264 | src/allmydata/mutable/checker.py | 2 +- |
---|
19265 | src/allmydata/mutable/filenode.py | 2 +- |
---|
19266 | src/allmydata/mutable/publish.py | 2 +- |
---|
19267 | src/allmydata/mutable/servermap.py | 5 +++-- |
---|
19268 | src/allmydata/test/test_mutable.py | 8 ++++---- |
---|
19269 | 5 files changed, 10 insertions(+), 9 deletions(-) |
---|
19270 | |
---|
19271 | commit 718d1aeff6fded893f65397806d22ece928b0dd4 |
---|
19272 | Author: Brian Warner <warner@lothar.com> |
---|
19273 | Date: Mon Oct 3 13:43:30 2011 -0400 |
---|
19274 | |
---|
19275 | add StorageFarmBroker.get_server_for_id(), temporary helper |
---|
19276 | |
---|
19277 | This will go away once we're passing IServers everywhere. |
---|
19278 | |
---|
19279 | src/allmydata/storage_client.py | 2 ++ |
---|
19280 | src/allmydata/test/no_network.py | 13 +++++++++++++ |
---|
19281 | 2 files changed, 15 insertions(+), 0 deletions(-) |
---|
19282 | |
---|
19283 | commit ece20231d7fda0d503704842a4aa068dfbc2e54e |
---|
19284 | Author: Brian Warner <warner@lothar.com> |
---|
19285 | Date: Sun Oct 2 01:11:50 2011 +0100 |
---|
19286 | |
---|
19287 | add proper accessors for Servermap.connections, to make refactoring easier |
---|
19288 | |
---|
19289 | src/allmydata/mutable/publish.py | 6 +++--- |
---|
19290 | src/allmydata/mutable/retrieve.py | 10 +++++----- |
---|
19291 | src/allmydata/mutable/servermap.py | 17 +++++++++++------ |
---|
19292 | 3 files changed, 19 insertions(+), 14 deletions(-) |
---|
19293 | |
---|
19294 | commit 3b943d6bf302ff702668081a612fc4fe2604cf9c |
---|
19295 | Author: Brian Warner <warner@lothar.com> |
---|
19296 | Date: Fri Sep 23 10:34:30 2011 -0700 |
---|
19297 | |
---|
19298 | mutable/servermap.py and neighbors: s/peer/server/ |
---|
19299 | |
---|
19300 | src/allmydata/mutable/checker.py | 22 +- |
---|
19301 | src/allmydata/mutable/publish.py | 204 +++++++------- |
---|
19302 | src/allmydata/mutable/servermap.py | 402 +++++++++++++------------- |
---|
19303 | src/allmydata/test/test_mutable.py | 18 +- |
---|
19304 | 4 files changed, 323 insertions(+), 323 deletions(-) |
---|
19305 | ] |
---|
19306 | [TAG allmydata-tahoe-1.9.0 |
---|
19307 | warner@lothar.com**20111031052301 |
---|
19308 | Ignore-this: cf598210dd1f314a1a121bf29a3d5918 |
---|
19309 | ] |
---|
19310 | Patch bundle hash: |
---|
19311 | bc4f1843530a92623bd1c70ed4fa82b103d252a2 |
---|