LineairDB  0.1.0
LineairDB::Transaction Class Reference

We adopt "the page model" [Vossen95] as the model of transaction processing. For each transaction, the page model provides us four operations: two data operations and two termination operations. More...

#include <transaction.h>

Public Member Functions

TxStatus GetCurrentStatus ()
 Get the current transaction status. For transactions such that GetCurrentStatus() returns TxStatus::Aborted, it is not guaranteed for subsequent read operations returns the correct values. More...
 
bool IsRunning ()
 
bool IsCommitted ()
 
bool IsAborted ()
 
const std::pair< const std::byte *const, const size_t > Read (const std::string_view key)
 If the database contains a data item for "key", returns a pair (a pointer of value, the size of value). More...
 
template<typename T >
const std::optional< T > Read (const std::string_view key)
 Reads a value as user-defined type. T must be same as one on writing the value with Write(). More...
 
void Write (const std::string_view key, const std::byte value[], const size_t size)
 Writes a value with a given key. More...
 
template<typename T >
void Write (const std::string_view key, const T &value)
 Writes an user-defined value with a given key. More...
 
const std::optional< size_t > Scan (const std::string_view begin, const std::string_view end, std::function< bool(std::string_view, const std::pair< const void *, const size_t >)> operation)
 Get all data items that match the range from the "begin" key to the "end" key in the lexical order. The term "get" here means that it is equivalent to the Read operation: this operation performs read operations for all the keys. More...
 
template<typename T >
const std::optional< size_t > Scan (const std::string_view begin, const std::string_view end, std::function< bool(std::string_view, T)> operation)
 Scan operation with user-defined template type. More...
 
void Abort ()
 Abort this transaction manually. More...
 

Friends

class Database
 

Detailed Description

We adopt "the page model" [Vossen95] as the model of transaction processing. For each transaction, the page model provides us four operations: two data operations and two termination operations.

Data operations: read: read a data item. Scan consists of multiple read operations.

write: generate a new version of a data item. Termination operations: commit: commit this transaction. abort: abort this transaction.

Note that the commit operation is implicitly executed by the worker threads running in LineairDB, only when the transaction satisfies Strict Serializability and Recoverability. All methods are thread-safe.

See also
[Vossen95] https://doi.org/10.1007/BFb0015267

Member Function Documentation

◆ Abort()

void LineairDB::Transaction::Abort ( )

Abort this transaction manually.

◆ GetCurrentStatus()

TxStatus LineairDB::Transaction::GetCurrentStatus ( )

Get the current transaction status. For transactions such that GetCurrentStatus() returns TxStatus::Aborted, it is not guaranteed for subsequent read operations returns the correct values.

Returns
TxStatus

◆ IsAborted()

bool LineairDB::Transaction::IsAborted ( )
inline

◆ IsCommitted()

bool LineairDB::Transaction::IsCommitted ( )
inline

◆ IsRunning()

bool LineairDB::Transaction::IsRunning ( )
inline

◆ Read() [1/2]

const std::pair<const std::byte* const, const size_t> LineairDB::Transaction::Read ( const std::string_view  key)

If the database contains a data item for "key", returns a pair (a pointer of value, the size of value).

Parameters
keyAn identifier for a data item
Returns
std::pair<void*, size_t> A pointer to the value of the requested data item and the size of the value. If there does not exists the data item of given key, it returns the pair (nullptr, 0).

◆ Read() [2/2]

template<typename T >
const std::optional<T> LineairDB::Transaction::Read ( const std::string_view  key)
inline

Reads a value as user-defined type. T must be same as one on writing the value with Write().

Template Parameters
TT must be Trivially Copyable and Constructable. This is because LineairDB is a Key-value storage but not a object storage.
Parameters
key
Returns
const std::optional<T>

◆ Scan() [1/2]

const std::optional<size_t> LineairDB::Transaction::Scan ( const std::string_view  begin,
const std::string_view  end,
std::function< bool(std::string_view, const std::pair< const void *, const size_t >)>  operation 
)

Get all data items that match the range from the "begin" key to the "end" key in the lexical order. The term "get" here means that it is equivalent to the Read operation: this operation performs read operations for all the keys.

Parameters
beginAn identifier of the starting point of the range search. This key is included in the range: if there exists a data item with this key, LineairDB returns the data item.
endAn identifier of the ending point of the range search. This key is included in the range: if there exists a data item with this key, LineairDB returns the data item.
operationA bool function to be executed iteratively on data items matching the input range. The arguments of the function are key (std::string_view) and value (std::pair). Return value (boolean) forces LineairDB to cancel the scanning operation; when a function returns true at some key, this function will never be invoked with the next key.
Returns
std::optional<size_t> returns the total number of rows that match the inputted range, if succeed. Concurrent transactions may aborts this scan operation and returns std::nullopt_t.

◆ Scan() [2/2]

template<typename T >
const std::optional<size_t> LineairDB::Transaction::Scan ( const std::string_view  begin,
const std::string_view  end,
std::function< bool(std::string_view, T)>  operation 
)
inline

Scan operation with user-defined template type.

Template Parameters
TT must be Trivially Copyable and Constructable. This is because LineairDB is a Key-value storage but not a object storage.
Parameters
begin
end
operation
Returns
std::optional<size_t>

◆ Write() [1/2]

void LineairDB::Transaction::Write ( const std::string_view  key,
const std::byte  value[],
const size_t  size 
)

Writes a value with a given key.

Parameters
key
value
size

◆ Write() [2/2]

template<typename T >
void LineairDB::Transaction::Write ( const std::string_view  key,
const T &  value 
)
inline

Writes an user-defined value with a given key.

Template Parameters
TT must be Trivially Copyable. This is because LineairDB is a Key-value storage but not a object storage.
Parameters
key
value

Friends And Related Function Documentation

◆ Database

friend class Database
friend

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