muesli-0.1.0.0: A simple document-oriented database

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

Database.Muesli.State

Contents

Description

The internal state of the database.

Synopsis

Documentation

Database state

newtype Handle l Source

Handle used for database management operations.

The l parameter stands for a LogState backend.

Constructors

Handle 

Fields

unHandle :: DBState l
 

Instances

data DBState l Source

The internal state of the database.

Constructors

DBState 

Fields

logDbPath :: DbPath
 
dataDbPath :: DbPath
 
commitDelay :: Int
 
masterState :: MVar (MasterState l)
 
dataState :: MVar (DataState l)
 
commitSgn :: MVar Bool

Used to send the kill signal to the commitThread

gcState :: MVar GCState

Used to communicate with the gcThread

Instances

data MasterState l Source

Type of the master state, holding all indexes.

When talking about master lock in other parts, we mean taking the masterState MVar.

Constructors

MasterState 

Fields

logState :: !l

The LogState backend.

topTid :: !TransactionId

Auto-incremented global value for generating TransactionIds.

idSupply :: !IdSupply

Suppy for generating unique DocumentKeys.

keepTrans :: !Bool

This flag is set during GC, so that logComp is not cleared as normal, since we need at the end of the GC to find the transactions that completed in the mean time, and we don't want to do log file IO for that.

gaps :: !GapsIndex
 
logPend :: !PendingIndex
 
logComp :: !CompletedIndex
 
mainIdx :: !MainIndex
 
unqIdx :: !UniqueIndex
 
sortIdx :: !SortIndex
 
refIdx :: !FilterIndex
 

data DataState l Source

The state coresponding to the data file.

Constructors

DataState 

data GCState Source

Type for the state of the GC thread used for messaging.

Constructors

IdleGC 
PerformGC 
KillGC 

Instances

Allocation table

type MainIndex = IntMap [LogRecord] Source

Type of the allocation table of the database.

The key of the IntMap is the DocumentKey of the corresponding document.

type GapsIndex = Map DocSize [DocAddress] Source

A map from gap size to a list of addresses where gaps of that size start.

Inverted indexes

type SortIndex = IntMap (IntMap IntSet) Source

Type of the sort index, which an inverted index.

First key is PropertyKey, second is SortableKey, and the IntSet contains all DocumentKeys for the documents whose fields have the values specified by the first two keys.

type FilterIndex = IntMap (IntMap SortIndex) Source

Type of the filter index, which is a 2-level nested inverted index.

First key is the PropertyKey for the filter field, second is the DocumentKey of the filter field value, and then an entire SortIndex containing the ordered subset for all sortable fields.

type UniqueIndex = IntMap (IntMap Int) Source

Type of the unique index, which is a simpler inverted index.

First key is PropertyKey, second is the UniqueKey, and then the unique DocumentKey corresponding to that UniqueKey.

Transaction log

type PendingIndex = Map TransactionId [(LogRecord, ByteString)] Source

The type of the pending transaction log.

update serializes the document before adding it to transUpdateList, and later commitThread moves it in the pending log.

type CompletedIndex = Map TransactionId [LogRecord] Source

The type of the completed transaction log.

Bracket functions

withMasterLock :: MonadIO m => Handle l -> (MasterState l -> IO a) -> m a Source

Standard bracket function for the masterState lock.

withMaster :: MonadIO m => Handle l -> (MasterState l -> IO (MasterState l, a)) -> m a Source

Standard bracket function for the masterState lock that also allows updating the MasterState.

withDataLock :: MonadIO m => Handle l -> (DataState l -> IO a) -> m a Source

Standard bracket function for the dataState lock.

withData :: MonadIO m => Handle l -> (DataState l -> IO (DataState l, a)) -> m a Source

Standard bracket function for the dataState lock that also allows updating the DataState.

withGC :: MonadIO m => Handle l -> (GCState -> IO (GCState, a)) -> m a Source

Standard bracket function for the gcState lock that also allows updating the GCState.

withCommitSgn :: MonadIO m => Handle l -> (Bool -> IO (Bool, a)) -> m a Source

Standard bracket function for the commitSgn lock that also allows updating the Bool.

Utilities

mkNewTransactionId :: MonadIO m => Handle l -> m TransactionId Source

Generates a new TransactionId by incrementing the topTid under master lock.

mkNewDocumentKey :: MonadIO m => Handle l -> m DocumentKey Source

Generates a new DocumentKey by calling alloc under master lock.

findUnique :: PropertyKey -> UniqueKey -> [(LogRecord, a)] -> Maybe DocumentKey Source

Utility function for searching into a list of LogRecords and into their recUniques for a particular UniqueKey.