muesli-0.1.0.1: A simple document-oriented database

Copyright(c) 2015 Călin Ardelean
LicenseMIT
MaintainerCălin Ardelean <calinucs@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010
Extensions
  • ScopedTypeVariables
  • ExplicitForAll

Database.Muesli.GC

Description

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.

Synopsis

Documentation

gcThread :: forall l. LogState l => Handle l -> IO () Source

Code for the GC thread forked by open.

It listens for messages sent by performGC through gcState, and performs the GC operation.