Artifact 849df9860df602dc2c55163d658c6b138213122f
File
www/selfcheck.html
part of check-in
[b807acf62e]
- Documentation updates
by
drh on
2007-07-24 12:52:32.
<html>
<head>
<title>Fossil Repository Integrity Self-Checks</title>
</head>
<body bgcolor="white">
<h1 align="center">
Fossil Repository Integrity Self-Checks
</h1>
<p>
Even though fossil is a relatively new project and still contains
many bugs, it is designed with features to give it a high level
of integrity so that you can have confidence that you will not
lose your files. This note describes the defensive measures that
fossil uses to help prevent file loss due to bugs.
</p>
<h2>Atomic Check-ins With Rollback</h2>
<p>
The fossil repository is an
<a href="http://www.sqlite.org/">SQLite version 3</a> database file.
SQLite is very mature and stable and has been in wide-spread use for many
years, so we have little worries that it might cause repository
corruption. SQLite
databases do not corrupt even if a program or system crash or power
failure occurs in the middle of the update. If some kind of crash
does occur in the middle of a change, then all the changes are rolled
back the next time that the database is accessed.
</p>
<p>
A check-in operation in fossil makes many changes to the repository
database. But all these changes happen within a single transaction.
If something goes wrong in the middle of the commit, then the transaction
is rolled back and the database is unchanged.
</p>
<h2>Verification Of Delta Encodings Prior To Transaction Commit</h2>
<p>
The content files that comprise the global state of a fossil respository
are stored in the repository as a tree. The leaves of the tree are
stored as zlib-compressed BLOBs. Interior nodes are deltas from their
decendents. There is a lot of encoding going on here. There is
zlib-compression which is relatively well-tested but still might
cause corruption if used improperly. And there is the relatively
new delta-encoding mechanism designed expressly for fossil. We want
to make sure that bugs in these encoding mechanisms do not lead to
loss of data.
</p>
<p>
To increase our confidence that everything in the repository is
recoverable, fossil makes sure it can extract an exact replicate
of every content file that it changes just prior to transaction
commit. So during the course of check-in, many different files
in the repository might be modified. Some files are simply
compressed. Other files are delta encoded and then compressed.
While all this is going on, fossil makes a record of every file
that is encoded and the SHA1 hash of the original content of that
file. Then just before transaction commit, fossil re-extracts
the original content of all files that were written, computes
the SHA1 checksum again, and verifies that the checksums match.
If anything does not match up, an error
message is printed and the transaction rolls back.
</p>
<p>
So, in other words, fossil always checks to make sure it can
re-extract a file before it commits a check-in of that file.
Hence bugs in fossil are unlikely to corrupt the repository in
a way that prevents us from extracting historical versions of
files.
</p>
<h2>Checksum Over All Files In A Baseline</h2>
<p>
Manifest files that define a baseline have two fields (the
R-line and Z-line) that record MD5 hashs of the manifest itself
and of all other files in the manifest. Prior to any check-in
commit, these checksums are verified to ensure that the baseline
checked in agrees exactly with what is on disk. Similarly,
the repository checksum is verified after a checkout to make
sure that the entire repository was checked out correctly.
Note that these added checks use a different hash (MD5 instead
of SHA1) in order to avoid common-mode failures in the hash
algorithm implementation.
</p>