LineairDB
0.1.0
|
#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 | |
Database & | operator= (const Database &)=delete |
Database (Database &&)=delete | |
Database & | operator= (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... | |
Transaction & | 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. 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 |
using LineairDB::Database::CallbackType = std::function<void(const TxStatus)> |
using LineairDB::Database::ProcedureType = std::function<void(Transaction&)> |
|
noexcept |
|
noexcept |
|
noexcept |
|
delete |
|
delete |
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.
bool LineairDB::Database::EndTransaction | ( | Transaction & | tx, |
CallbackType | clbk | ||
) |
Terminates the transaction. If Transaction::Abort has not been called, LineairDB tries to commit tx
.
tx
might have been deleted. [in] | tx | A transaction wants to terminate. |
[out] | clbk | A callback function accepts a result (Committed or |
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. tx
. In contrast with the true case, this result will not be overturned. 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.
[in] | proc | A transaction procedure processed by LineairDB. |
[out] | commit_clbk | A callback function accepts a result (Committed or Aborted) of this transaction. |
[out] | precommit_clbk | A 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. |
|
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.
|
noexcept |
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).
|
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.
|
friend |