LineairDB  0.1.0
LineairDB::Database Class Reference

#include <database.h>

Public Types

using ProcedureType = std::function< void(Transaction &)>
 
using CallbackType = std::function< void(const TxStatus)>
 

Public Member Functions

 Database () noexcept
 Construct a new Database object. Thread-safe. Note that a default-constructed Config object will be passed. More...
 
 Database (const Config &config) noexcept
 Construct a new Database object. Thread-safe. More...
 
 ~Database () noexcept
 
 Database (const Database &)=delete
 
Databaseoperator= (const Database &)=delete
 
 Database (Database &&)=delete
 
Databaseoperator= (Database &&)=delete
 
const Config GetConfig () const noexcept
 Return the Config object set by constructor. More...
 
void ExecuteTransaction (ProcedureType proc, CallbackType commit_clbk, std::optional< CallbackType > precommit_clbk=std::nullopt)
 Processes a transaction given by a transaction procedure proc, and afterwards process callback function with the resulting TxStatus. It enqueues these two functions into LineairDB's thread pool. Thread-safe. More...
 
TransactionBeginTransaction ()
 Creates a new transaction. Via this interface, the callee thread of this method can manipulate LineairDB's key-value storage directly. Note that the behavior and performance characteristics will affect from the selected callback manager and log manager; For example, if you have set Config::CallbackManager to ThreadLocal, the callee thread of this method may have to call Database::RequestCommit more frequently, in order to resolve the congestion of the thread-local commit callback queue. More...
 
bool EndTransaction (Transaction &tx, CallbackType clbk)
 Terminates the transaction. If Transaction::Abort has not been called, LineairDB tries to commit tx. More...
 
void Fence () const noexcept
 Fence() waits termination of transactions which is currently in progress. You can execute transactions in the order you want by interleaving Fence() between ExecuteTransaction functions. Note that no Fence() call may result in a execution sequence which is not same as the program (invoking) order of the ExecuteTransaction functions. If you know some dependency of transactions (e.g., database population), use this method to order them. Thread-safe. More...
 
void WaitForCheckpoint () const noexcept
 WaitForCheckpoint Waits for the completion of the next checkpoint. Note that this method may take longer than the time specified in LineairDB::Config.checkpoint_period (default value: 30 seconds) in the worst cases. When the WAL (logging) is disabled and durability is guaranteed by only checkpointing, this interface is preferable; it ensures that the currently active transactions are durable. More...
 
void RequestCallbacks ()
 Requests executions of callback functions of already completed (committed or (aborted) transactions. Note that LineairDB's callback queues may be overloading in some combination of configurations (e.g., too long epoch size, too small thread-pool size, or weird implementation of the selected CallbackManager). More...
 

Friends

class Transaction
 

Member Typedef Documentation

◆ CallbackType

using LineairDB::Database::CallbackType = std::function<void(const TxStatus)>

◆ ProcedureType

using LineairDB::Database::ProcedureType = std::function<void(Transaction&)>

Constructor & Destructor Documentation

◆ Database() [1/4]

LineairDB::Database::Database ( )
noexcept

Construct a new Database object. Thread-safe. Note that a default-constructed Config object will be passed.

◆ Database() [2/4]

LineairDB::Database::Database ( const Config config)
noexcept

Construct a new Database object. Thread-safe.

Parameters
configSee Config for more details of configuration.

◆ ~Database()

LineairDB::Database::~Database ( )
noexcept

◆ Database() [3/4]

LineairDB::Database::Database ( const Database )
delete

◆ Database() [4/4]

LineairDB::Database::Database ( Database &&  )
delete

Member Function Documentation

◆ BeginTransaction()

Transaction& LineairDB::Database::BeginTransaction ( )

Creates a new transaction. Via this interface, the callee thread of this method can manipulate LineairDB's key-value storage directly. Note that the behavior and performance characteristics will affect from the selected callback manager and log manager; For example, if you have set Config::CallbackManager to ThreadLocal, the callee thread of this method may have to call Database::RequestCommit more frequently, in order to resolve the congestion of the thread-local commit callback queue.

Returns
Transaction

◆ EndTransaction()

bool LineairDB::Database::EndTransaction ( Transaction tx,
CallbackType  clbk 
)

Terminates the transaction. If Transaction::Abort has not been called, LineairDB tries to commit tx.

Precondition
To achieve user abort, Transaction::Abort must be called before this method.
Postcondition
The first argument tx might have been deleted.
Parameters
[in]txA transaction wants to terminate.
[out]clbkA callback function accepts a result (Committed or
Returns
true if the LineairDB's concurrency control protocol decides to commit the given tx. Note that it does not mean that tx has been committed; tx will be committed if it goes without crash, disaster, or something accident, however, the commit cannot be determined until recoverability is guaranteed by persistent logs. Use clbk to find out whether you have really committed or not.
false if the LineairDB's concurrency control protocol decides to abort the given tx. In contrast with the true case, this result will not be overturned.

◆ ExecuteTransaction()

void LineairDB::Database::ExecuteTransaction ( ProcedureType  proc,
CallbackType  commit_clbk,
std::optional< CallbackType precommit_clbk = std::nullopt 
)

Processes a transaction given by a transaction procedure proc, and afterwards process callback function with the resulting TxStatus. It enqueues these two functions into LineairDB's thread pool. Thread-safe.

Parameters
[in]procA transaction procedure processed by LineairDB.
[out]commit_clbkA callback function accepts a result (Committed or Aborted) of this transaction.
[out]precommit_clbkA callback function accepts a result (Precommitted or Aborted) of this transaction. Note that pre-committed transactions have not been committed. Since the recovery log has not been persisted, this transaction may be aborted. The callback is good for describing transaction dependencies. If a transaction is aborted, it is guaranteed that the other transactions, that are executed after checking the pre-commit of the transaction, will abort.

◆ Fence()

void LineairDB::Database::Fence ( ) const
noexcept

Fence() waits termination of transactions which is currently in progress. You can execute transactions in the order you want by interleaving Fence() between ExecuteTransaction functions. Note that no Fence() call may result in a execution sequence which is not same as the program (invoking) order of the ExecuteTransaction functions. If you know some dependency of transactions (e.g., database population), use this method to order them. Thread-safe.

◆ GetConfig()

const Config LineairDB::Database::GetConfig ( ) const
noexcept

Return the Config object set by constructor.

Returns
Config object. Note that it is not an lvalue reference and you cannot change the configuration with it. Thread-safe.

◆ operator=() [1/2]

Database& LineairDB::Database::operator= ( const Database )
delete

◆ operator=() [2/2]

Database& LineairDB::Database::operator= ( Database &&  )
delete

◆ RequestCallbacks()

void LineairDB::Database::RequestCallbacks ( )

Requests executions of callback functions of already completed (committed or (aborted) transactions. Note that LineairDB's callback queues may be overloading in some combination of configurations (e.g., too long epoch size, too small thread-pool size, or weird implementation of the selected CallbackManager).

◆ WaitForCheckpoint()

void LineairDB::Database::WaitForCheckpoint ( ) const
noexcept

WaitForCheckpoint Waits for the completion of the next checkpoint. Note that this method may take longer than the time specified in LineairDB::Config.checkpoint_period (default value: 30 seconds) in the worst cases. When the WAL (logging) is disabled and durability is guaranteed by only checkpointing, this interface is preferable; it ensures that the currently active transactions are durable.

Friends And Related Function Documentation

◆ Transaction

friend class Transaction
friend

The documentation for this class was generated from the following file: