]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/specifications/servers-of-happiness.txt
Add a specification for servers of happiness.
[tahoe-lafs/tahoe-lafs.git] / docs / specifications / servers-of-happiness.txt
1 = Servers of Happiness =
2
3 When you upload a file to a Tahoe-LAFS grid, you expect that it will
4 stay there for a while, and that it will do so even if a few of the
5 peers on the grid stop working, or if something else goes wrong. An
6 upload health metric helps to make sure that this actually happens. An
7 upload health metric is essentially a test that looks at a file on a
8 Tahoe-LAFS grid and says whether or not that file is healthy; that is,
9 whether it is distributed on the grid in such a way as to ensure that it
10 will probably survive in good enough shape to be recoverable even if a
11 few things go wrong between the time of the test and the time that it is
12 recovered. Our current upload health metric for immutable files is called
13 'servers-of-happiness'; its predecessor was called 'shares-of-happiness'.
14
15 shares-of-happiness used the number of encoded shares generated by a
16 file upload to say whether or not it was healthy. If there were more
17 shares than a user-configurable threshold, the file was reported to be
18 healthy; otherwise, it was reported to be unhealthy. In normal
19 situations, the upload process would distribute shares fairly evenly
20 over the peers in the grid, and in that case shares-of-happiness
21 worked fine. However, because it only considered the number of shares,
22 and not where they were on the grid, it could not detect situations
23 where a file was unhealthy because most or all of the shares generated
24 from the file were stored on one or two peers. 
25
26 servers-of-happiness addresses this by extending the share-focused
27 upload health metric to also consider the location of the shares on
28 grid. servers-of-happiness looks at the mapping of peers to the shares
29 that they hold, and compares the cardinality of the largest happy subset
30 of those with a user-configurable threshold (A happy subset of peers has
31 the property that any k (where k is as in k-of-n encoding) peers within
32 the subset can reconstruct the source file). This definition of file
33 health provides a stronger assurance of file availability over time;
34 with 3-of-10 encoding, and happy=7, a healthy file is still guaranteed
35 to be available even if 4 peers fail.
36
37 == Measuring Servers of Happiness ==
38
39 We calculate servers-of-happiness by computing a matching on a
40 bipartite graph that is related to the layout of shares on the grid.
41 One set of vertices is the peers on the grid, and one set of vertices is
42 the shares. An edge connects a peer and a share if the peer will (or
43 does, for existing shares) hold the share. The size of the maximum
44 matching on this graph is the size of the largest happy peer set that
45 exists for the upload.
46
47 First, note that a bipartite matching of size n corresponds to a happy
48 subset of size n. This is because a bipartite matching of size n implies
49 that there are n peers such that each peer holds a share that no other
50 peer holds. Then any k of those peers collectively hold k distinct
51 shares, and can restore the file.
52
53 A bipartite matching of size n is not necessary for a happy subset of
54 size n, however (so it is not correct to say that the size of the
55 maximum matching on this graph is the size of the largest happy subset
56 of peers that exists for the upload). For example, consider a file with
57 k = 3, and suppose that each peer has all three of those pieces.  Then,
58 since any peer from the original upload can restore the file, if there
59 are 10 peers holding shares, and the happiness threshold is 7, the
60 upload should be declared happy, because there is a happy subset of size
61 10, and 10 > 7. However, since a maximum matching on the bipartite graph
62 related to this layout has only 3 edges, Tahoe-LAFS declares the upload
63 unhealthy. Though it is not unhealthy, a share layout like this example
64 is inefficient; for k = 3, and if there are n peers, it corresponds to
65 an expansion factor of 10x. Layouts that are declared healthy by the
66 bipartite graph matching approach have the property that they correspond
67 to uploads that are either already relatively efficient in their
68 utilization of space, or can be made to be so by deleting shares, and
69 that place all of the shares that they generate, enabling redistribution
70 of shares later without having to re-encode the file.  Also, it is
71 computationally reasonable to compute a maximum matching in a bipartite
72 graph, and there are well-studied algorithms to do that.
73
74 == Issues ==
75
76 The uploader is good at detecting unhealthy upload layouts, but it
77 doesn't always know how to make an unhealthy upload into a healthy
78 upload if it is possible to do so; it attempts to redistribute shares to
79 achieve happiness, but only in certain circumstances. The redistribution
80 algorithm isn't optimal, either, so even in these cases it will not
81 always find a happy layout if one can be arrived at through
82 redistribution. We are investigating improvements to address these
83 issues.
84
85 We don't use servers-of-happiness for mutable files yet; this fix will 
86 likely come in Tahoe-LAFS version 1.8.