Copyright | (c) 2015 Călin Ardelean |
---|---|
License | MIT |
Maintainer | Călin Ardelean <calinucs@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Extensions |
|
Asynchronous garbage collector for the database.
The GC creates fresh copies of both the log and the data (abstract) files,
fully cleaned, respectively compacted, and finally takes a master lock,
appends the transaction data that was added in the mean time, and uses the
swapDb
function to make the new files current. No expensive lock needs
to be taken in the beginning, since all indexes are purely functional and
we just take some pointers.
Cleaning means removal of all versions of deleted records, and all but the most recent version for the rest.
Compacting means all records are reallocated contiguously starting from
DocAddress
0. In particular, it creates a fresh empty gaps
index with the
help of buildExtra
.
The complete operation takes O(n*log(n)) time, but the lock is held only for O(k*log(n)) at the end, where k represents the number of new records, which is similar to a normal query. For this reason it is safe to run the GC at any time.
The database does not call performGC
by itself,
but leaves this to the user. Programs that only rarely
delete
or update
records
don't even need to run the GC, or they can make it an admin action.