# Block availability is not file availability

A high probability of reading each block does not give the same probability of
reading all blocks together. Replica placement determines which events can be
multiplied. The examples below are exact calculations on constructed inputs,
not storage measurements or a durability forecast.

## Historical context

[TotalRecall (NSDI 2004)](https://www.usenix.org/conference/nsdi-04/total-recall-system-support-automated-availability-management)
made availability targets inputs to adaptive redundancy and repair.
Equations 1-3 in its [paper](https://cseweb.ucsd.edu/~ktati/Papers/nsdi04.pdf)
motivate this calculation. This note does not reproduce its prototype,
availability predictor, erasure coder, trace replay or repair policy.

## Declare the event first

Let p be each host's probability of being accessible at the observation instant.
Let c be the number of copies of a required block and b the number of required
blocks. Each host holds a correct copy when up. Host states are independent.
The event of interest is **every required block has at least one accessible copy**.

One block succeeds with probability `1 - (1-p)^c`.
If block-success events are also independent, the file succeeds with probability
`[1 - (1-p)^c]^b`. Disjoint host groups provide that independence in this model.
There is no sample size or confidence interval: these are probabilities derived
from assumed Bernoulli states, not estimates fitted to a population.

At p = 1/2, the generated [results](results.json) are:

| Required blocks | Copies per block | File availability (%) | Meets 99.9%? |
| --- | --- | --- | --- |
| 1 | 10 | 99.902344 | yes |
| 1024 | 10 | 36.769974 | no |
| 1024 | 19 | 99.804878 | no |
| 1024 | 20 | 99.902391 | yes |

Ten whole-file replicas have the same success event as the first row.
The 1,024-block rows require independent block groups, not those same ten hosts
holding every block. Copies per block must be integers: the model checks the
target by exact rational comparison. Nineteen copies fail and twenty pass.
Decimal percentages are rounded to six places only after the decision.

## Shared hosts change the joint event

For two required blocks, each with two replicas and p = 1/2:

| Placement of block A; block B | Exact file probability | File availability (%) |
| --- | --- | --- |
| {0,1}; {2,3} | 9/16 | 56.250000 |
| {0,1}; {1,2} | 5/8 | 62.500000 |
| {0,1}; {0,1} | 3/4 | 75.000000 |

Each block has probability 3/4 in every row. Their conjunction does not.
For the overlapping row, A fails when hosts 0 and 1 are down; B fails when
1 and 2 are down. Both fail when all three hosts are down.
Inclusion-exclusion gives `1 - 1/4 - 1/4 + 1/8 = 5/8`.

This is a qualification of the formula's applicability, not evidence that
TotalRecall's experiment was wrong. It is also not a recommendation to
co-locate every block. The rows change host count and placement while keeping
payload replication constant; load balancing, correlated host failures,
partial reads, performance and recovery costs are outside this example.

## What the percentages leave out

A client still needs functioning metadata, credentials, networking and enough
time to read the bytes. An offline copy can return without losing its contents.
Conversely, permanent departure can destroy redundancy unless repair succeeds.
The model has no time evolution and says nothing about annual loss probability.

The [HotOS IX bandwidth analysis](https://static.usenix.org/events/hotos03/tech/full_papers/blake/blake_html/index.html)
examines the traffic cost of maintaining redundancy as membership changes.
Its assumptions and historical population differ from TotalRecall's evaluation.
Neither paper licenses treating spare disk bytes as unlimited repair capacity.

## Reproduce and audit

[model.py](model.py) uses Python's standard-library Fraction arithmetic.
[test_model.py](test_model.py) independently enumerates host up/down states.
There are 900 exhaustive two-block configurations over four hosts at probabilities
0, 1/4, 1/2 and 1, plus multi-block, endpoint, invalid-input and minimum-copy tests.
No random seed, external package, trace download or network access is needed.

```sh
python3 -B model.py --check
python3 -B -m unittest discover -s . -p test_model.py -v
python3 -B -O -m unittest discover -s . -p test_model.py -v
```

Run `python3 -B model.py` to regenerate results. The intentionally bounded API
accepts exact Fraction probabilities, 1-64 copies and 1-4,096 blocks for the
independent formula. The placement calculation accepts up to ten blocks with
distinct host IDs 0-11 per block; repeated IDs are rejected, not counted as
additional replicas. Unreachable targets raise an error.

See [source provenance](sources.json), the [TotalRecall record](../../terms/totalrecall/),
[storage availability](../../terms/storage-availability/) and
[erasure coding](../../terms/erasure-coding/). These new example files are
released under the [MIT license](LICENSE); third-party papers retain their rights.
