]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/garbage-collection.txt
8543a3fb383f65903b0eb188ae9a769a63cdd171
[tahoe-lafs/tahoe-lafs.git] / docs / garbage-collection.txt
1 = Garbage Collection in Tahoe =
2
3 1. Overview
4 2. Client-side Renewal
5 3. Server Side Expiration
6 4. Expiration Progress
7 5. Future Directions
8
9 == Overview ==
10
11 When a file or directory in the virtual filesystem is no longer referenced,
12 the space that its shares occupied on each storage server can be freed,
13 making room for other shares. Tahoe currently uses a garbage collection
14 ("GC") mechanism to implement this space-reclamation process. Each share has
15 one or more "leases", which are managed by clients who want the
16 file/directory to be retained. The storage server accepts each share for a
17 pre-defined period of time, and is allowed to delete the share if all of the
18 leases are cancelled or allowed to expire.
19
20 Garbage collection is not enabled by default: storage servers will not delete
21 shares without being explicitly configured to do so. When GC is enabled,
22 clients are responsible for renewing their leases on a periodic basis at
23 least frequently enough to prevent any of the leases from expiring before the
24 next renewal pass.
25
26 There are several tradeoffs to be considered when choosing the renewal timer
27 and the lease duration, and there is no single optimal pair of values. See
28 the "lease-tradeoffs.svg" diagram to get an idea for the tradeoffs involved.
29 If lease renewal occurs quickly and with 100% reliability, than any renewal
30 time that is shorter than the lease duration will suffice, but a larger ratio
31 of duration-over-renewal-time will be more robust in the face of occasional
32 delays or failures.
33
34 The current recommended values for a small Tahoe grid are to renew the leases
35 once a week, and to give each lease a duration of 31 days. Renewing leases
36 can be expected to take about one second per file/directory, depending upon
37 the number of servers and the network speeds involved. Note that in the
38 current release, the server code enforces a 31 day lease duration: there is
39 not yet a way for the client to request a different duration (however the
40 server can use the "expire.override_lease_duration" configuration setting to
41 increase or decrease the effective duration to something other than 31 days).
42
43 == Client-side Renewal ==
44
45 If all of the files and directories which you care about are reachable from a
46 single starting point (usually referred to as a "rootcap"), and you store
47 that rootcap as an alias (via "tahoe create-alias"), then the simplest way to
48 renew these leases is with the following CLI command:
49
50   tahoe deep-check --add-lease ALIAS:
51
52 This will recursively walk every directory under the given alias and renew
53 the leases on all files and directories. (You may want to add a --repair flag
54 to perform repair at the same time). Simply run this command once a week (or
55 whatever other renewal period your grid recommends) and make sure it
56 completes successfully. As a side effect, a manifest of all unique files and
57 directories will be emitted to stdout, as well as a summary of file sizes and
58 counts. It may be useful to track these statistics over time.
59
60 Note that newly uploaded files (and newly created directories) get an initial
61 lease too: the --add-lease process is only needed to ensure that all older
62 objects have up-to-date leases on them.
63
64 For larger systems (such as a commercial grid), a separate "maintenance
65 daemon" is under development. This daemon will acquire manifests from
66 rootcaps on a periodic basis, keep track of checker results, manage
67 lease-addition, and prioritize repair needs, using multiple worker nodes to
68 perform these jobs in parallel. Eventually, this daemon will be made
69 appropriate for use by individual users as well, and may be incorporated
70 directly into the client node.
71
72 == Server Side Expiration ==
73
74 Expiration must be explicitly enabled on each storage server, since the
75 default behavior is to never expire shares. Expiration is enabled by adding
76 config keys to the "[storage]" section of the tahoe.cfg file (as described
77 below) and restarting the server node.
78
79 Each lease has two parameters: a create/renew timestamp and a duration. The
80 timestamp is updated when the share is first uploaded (i.e. the file or
81 directory is created), and updated again each time the lease is renewed (i.e.
82 "tahoe check --add-lease" is performed). The duration is currently fixed at
83 31 days, and the "nominal lease expiration time" is simply $duration seconds
84 after the $create_renew timestamp. (In a future release of Tahoe, the client
85 will get to request a specific duration, and the server will accept or reject
86 the request depending upon its local configuration, so that servers can
87 achieve better control over their storage obligations).
88
89 The lease-expiration code has two modes of operation. The first is age-based:
90 leases are expired when their age is greater than their duration. This is the
91 preferred mode: as long as clients consistently update their leases on a
92 periodic basis, and that period is shorter than the lease duration, then all
93 active files and directories will be preserved, and the garbage will
94 collected in a timely fashion.
95
96 Since there is not yet a way for clients to request a lease duration of other
97 than 31 days, there is a tahoe.cfg setting to override the duration of all
98 leases. If, for example, this alternative duration is set to 60 days, then
99 clients could safely renew their leases with an add-lease operation perhaps
100 once every 50 days: even though nominally their leases would expire 31 days
101 after the renewal, the server would not actually expire the leases until 60
102 days after renewal.
103
104 The other mode is an absolute-date-cutoff: it compares the create/renew
105 timestamp against some absolute date, and expires any lease which was not
106 created or renewed since the cutoff date. If all clients have performed an
107 add-lease some time after March 20th, you could tell the storage server to
108 expire all leases that were created or last renewed on March 19th or earlier.
109 This is most useful if you have a manual (non-periodic) add-lease process.
110 Note that there is not much point to running a storage server in this mode
111 for a long period of time: once the lease-checker has examined all shares and
112 expired whatever it is going to expire, the second and subsequent passes are
113 not going to find any new leases to remove.
114
115 The tahoe.cfg file uses the following keys to control lease expiration:
116
117 [storage]
118
119 expire.enabled = (boolean, optional)
120
121  If this is True, the storage server will delete shares on which all leases
122  have expired. Other controls dictate when leases are considered to have
123  expired. The default is False.
124
125 expire.mode = (string, "age" or "cutoff-date", required if expiration enabled)
126
127  If this string is "age", the age-based expiration scheme is used, and the
128  "expire.override_lease_duration" setting can be provided to influence the
129  lease ages. If it is "cutoff-date", the absolute-date-cutoff mode is used,
130  and the "expire.cutoff_date" setting must be provided to specify the cutoff
131  date. The mode setting currently has no default: you must provide a value.
132
133  In a future release, this setting is likely to default to "age", but in this
134  release it was deemed safer to require an explicit mode specification.
135
136 expire.override_lease_duration = (duration string, optional)
137
138  When age-based expiration is in use, a lease will be expired if its
139  "lease.create_renew" timestamp plus its "lease.duration" time is
140  earlier/older than the current time. This key, if present, overrides the
141  duration value for all leases, changing the algorithm from:
142
143    if (lease.create_renew_timestamp + lease.duration) < now:
144        expire_lease()
145
146  to:
147
148    if (lease.create_renew_timestamp + override_lease_duration) < now:
149        expire_lease()
150
151  The value of this setting is a "duration string", which is a number of days,
152  months, or years, followed by a units suffix, and optionally separated by a
153  space, such as one of the following:
154
155   7days
156   31day
157   60 days
158   2mo
159   3 month
160   12 months
161   2years
162
163  This key is meant to compensate for the fact that clients do not yet have
164  the ability to ask for leases that last longer than 31 days. A grid which
165  wants to use faster or slower GC than a 31-day lease timer permits can use
166  this parameter to implement it. The current fixed 31-day lease duration
167  makes the server behave as if "lease.override_lease_duration = 31days" had
168  been passed.
169
170  This key is only valid when age-based expiration is in use (i.e. when
171  "expire.mode = age" is used). It will be rejected if cutoff-date expiration
172  is in use.
173
174 expire.cutoff_date = (date string, required if mode=cutoff-date)
175
176  When cutoff-date expiration is in use, a lease will be expired if its
177  create/renew timestamp is older than the cutoff date. This string will be a
178  date in the following format:
179
180   2009-01-16   (January 16th, 2009)
181   2008-02-02
182   2007-12-25
183
184  The actual cutoff time shall be midnight UTC at the beginning of the given
185  day. Lease timers should naturally be generous enough to not depend upon
186  differences in timezone: there should be at least a few days between the
187  last renewal time and the cutoff date.
188
189  This key is only valid when cutoff-based expiration is in use (i.e. when
190  "expire.mode = cutoff-date"). It will be rejected if age-based expiration is
191  in use.
192
193 expire.immutable = (boolean, optional)
194
195  If this is False, then immutable shares will never be deleted, even if their
196  leases have expired. This can be used in special situations to perform GC on
197  mutable files but not immutable ones. The default is True.
198
199 expire.mutable = (boolean, optional)
200
201  If this is False, then mutable shares will never be deleted, even if their
202  leases have expired. This can be used in special situations to perform GC on
203  immutable files but not mutable ones. The default is True.
204
205 == Expiration Progress ==
206
207 In the current release, leases are stored as metadata in each share file, and
208 no separate database is maintained. As a result, checking and expiring leases
209 on a large server may require multiple reads from each of several million
210 share files. This process can take a long time and be very disk-intensive, so
211 a "share crawler" is used. The crawler limits the amount of time looking at
212 shares to a reasonable percentage of the storage server's overall usage: by
213 default it uses no more than 10% CPU, and yields to other code after 100ms. A
214 typical server with 1.1M shares was observed to take 3.5 days to perform this
215 rate-limited crawl through the whole set of shares, with expiration disabled.
216 It is expected to take perhaps 4 or 5 days to do the crawl with expiration
217 turned on.
218
219 The crawler's status is displayed on the "Storage Server Status Page", a web
220 page dedicated to the storage server. This page resides at $NODEURL/storage,
221 and there is a link to it from the front "welcome" page. The "Lease
222 Expiration crawler" section of the status page shows the progress of the
223 current crawler cycle, expected completion time, amount of space recovered,
224 and details of how many shares have been examined.
225
226 The crawler's state is persistent: restarting the node will not cause it to
227 lose significant progress. The state file is located in two files
228 ($BASEDIR/storage/lease_checker.state and lease_checker.history), and the
229 crawler can be forcibly reset by stopping the node, deleting these two files,
230 then restarting the node.
231
232 == Future Directions ==
233
234 Tahoe's GC mechanism is undergoing significant changes. The global
235 mark-and-sweep garbage-collection scheme can require considerable network
236 traffic for large grids, interfering with the bandwidth available for regular
237 uploads and downloads (and for non-Tahoe users of the network).
238
239 A preferable method might be to have a timer-per-client instead of a
240 timer-per-lease: the leases would not be expired until/unless the client had
241 not checked in with the server for a pre-determined duration. This would
242 reduce the network traffic considerably (one message per week instead of
243 thousands), but retain the same general failure characteristics.
244
245 In addition, using timers is not fail-safe (from the client's point of view),
246 in that a client which leaves the network for an extended period of time may
247 return to discover that all of their files have been garbage-collected. (It
248 *is* fail-safe from the server's point of view, in that a server is not
249 obligated to provide disk space in perpetuity to an unresponsive client). It
250 may be useful to create a "renewal agent" to which a client can pass a list
251 of renewal-caps: the agent then takes the responsibility for keeping these
252 leases renewed, so the client can go offline safely. Of course, this requires
253 a certain amount of coordination: the renewal agent should not be keeping
254 files alive that the client has actually deleted. The client can send the
255 renewal-agent a manifest of renewal caps, and each new manifest should
256 replace the previous set.
257
258 The GC mechanism is also not immediate: a client which deletes a file will
259 nevertheless be consuming extra disk space (and might be charged or otherwise
260 held accountable for it) until the ex-file's leases finally expire on their
261 own. If the client is certain that they've removed their last reference to
262 the file, they could accelerate the GC process by cancelling their lease. The
263 current storage server API provides a method to cancel a lease, but the
264 client must be careful to coordinate with anyone else who might be
265 referencing the same lease (perhaps a second directory in the same virtual
266 drive), otherwise they might accidentally remove a lease that should have
267 been retained.
268
269 In the current release, these leases are each associated with a single "node
270 secret" (stored in $BASEDIR/private/secret), which is used to generate
271 renewal- and cancel- secrets for each lease. Two nodes with different secrets
272 will produce separate leases, and will not be able to renew or cancel each
273 others' leases.
274
275 Once the Accounting project is in place, leases will be scoped by a
276 sub-delegatable "account id" instead of a node secret, so clients will be able
277 to manage multiple leases per file. In addition, servers will be able to
278 identify which shares are leased by which clients, so that clients can safely
279 reconcile their idea of which files/directories are active against the
280 server's list, and explicitly cancel leases on objects that aren't on the
281 active list.
282
283 By reducing the size of the "lease scope", the coordination problem is made
284 easier. In general, mark-and-sweep is easier to implement (it requires mere
285 vigilance, rather than coordination), so unless the space used by deleted
286 files is not expiring fast enough, the renew/expire timed lease approach is
287 recommended.
288