OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::parsec::runtime_locking_shard::impl Class Reference

Implementation of a runtime locking shard. More...

#include <impl.hpp>

Inheritance diagram for cbdc::parsec::runtime_locking_shard::impl:
Collaboration diagram for cbdc::parsec::runtime_locking_shard::impl:

Public Member Functions

 impl (std::shared_ptr< logging::log > logger)
 Constructor.
 
auto try_lock (ticket_number_type ticket_number, broker_id_type broker_id, key_type key, lock_type locktype, bool first_lock, try_lock_callback_type result_callback) -> bool override
 Locks the given key for a ticket and returns the associated value.
 
auto prepare (ticket_number_type ticket_number, broker_id_type broker_id, state_update_type state_update, prepare_callback_type result_callback) -> bool override
 Prepares a ticket with the given state updates.
 
auto commit (ticket_number_type ticket_number, commit_callback_type result_callback) -> bool override
 Commits a previously prepared ticket.
 
auto rollback (ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool override
 Rolls back an uncommitted ticket.
 
auto finish (ticket_number_type ticket_number, finish_callback_type result_callback) -> bool override
 Deletes a committed or rolled-back ticket.
 
auto get_tickets (broker_id_type broker_id, get_tickets_callback_type result_callback) -> bool override
 Returns tickets managed by the given broker.
 
auto recover (const replicated_shard::state_type &state, const replicated_shard::tickets_type &tickets) -> bool
 Restores the state of another shard instance.
 
- Public Member Functions inherited from cbdc::parsec::runtime_locking_shard::interface
virtual ~interface ()=default
 
 interface ()=default
 
 interface (const interface &)=delete
 
auto operator= (const interface &) -> interface &=delete
 
 interface (interface &&)=delete
 
auto operator= (interface &&) -> interface &=delete
 

Additional Inherited Members

- Public Types inherited from cbdc::parsec::runtime_locking_shard::interface
using try_lock_return_type = std::variant<value_type, shard_error>
 Return type from a try lock operation.
 
using try_lock_callback_type = std::function<void(try_lock_return_type)>
 Function type for try lock operation results.
 
using prepare_return_type = std::optional<shard_error>
 Return type from a prepare operation. An error, if applicable.
 
using prepare_callback_type = std::function<void(prepare_return_type)>
 Callback function type for the result of a prepare operation.
 
using commit_return_type = std::optional<shard_error>
 Return type from a commit operation. An error code, if applicable.
 
using commit_callback_type = std::function<void(commit_return_type)>
 Callback function type for the result of a commit operation.
 
using rollback_return_type = std::optional<shard_error>
 Return type from a rollback operation.
 
using rollback_callback_type = std::function<void(rollback_return_type)>
 Callback function type for the result of a rollback operation.
 
using finish_return_type = std::optional<shard_error>
 Return type from a finish operation. An error code, if applicable.
 
using finish_callback_type = std::function<void(finish_return_type)>
 Callback function type for the result of a finish operation.
 
using get_tickets_success_type = std::unordered_map<ticket_number_type, ticket_state>
 Return type from a successful get tickets operation.
 
using get_tickets_return_type = std::variant<get_tickets_success_type, error_code>
 Return type from a get tickets operation.
 
using get_tickets_callback_type = std::function<void(get_tickets_return_type)>
 Callback function type for the result of a get tickets operation.
 

Detailed Description

Implementation of a runtime locking shard.

Stores keys in memory using a hash map. Thread-safe.

Definition at line 22 of file runtime_locking_shard/impl.hpp.

Constructor & Destructor Documentation

◆ impl()

cbdc::parsec::runtime_locking_shard::impl::impl ( std::shared_ptr< logging::log > logger)
explicit

Constructor.

Parameters
loggerlog instance.

Definition at line 11 of file runtime_locking_shard/impl.cpp.

Member Function Documentation

◆ commit()

auto cbdc::parsec::runtime_locking_shard::impl::commit ( ticket_number_type ticket_number,
commit_callback_type result_callback ) -> bool
overridevirtual

Commits a previously prepared ticket.

Releases any locks held by the ticket and assigns the locks to tickets queuing for the lock.

Parameters
ticket_numberticket number.
result_callbackfunction to call with commit result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 247 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::committed, cbdc::parsec::runtime_locking_shard::not_prepared, cbdc::parsec::runtime_locking_shard::prepared, and cbdc::parsec::runtime_locking_shard::unknown_ticket.

◆ finish()

auto cbdc::parsec::runtime_locking_shard::impl::finish ( ticket_number_type ticket_number,
finish_callback_type result_callback ) -> bool
overridevirtual

Deletes a committed or rolled-back ticket.

Parameters
ticket_numberticket number.
result_callbackfunction to call with finish result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 398 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::committed, cbdc::parsec::runtime_locking_shard::not_committed, and cbdc::parsec::runtime_locking_shard::unknown_ticket.

◆ get_tickets()

auto cbdc::parsec::runtime_locking_shard::impl::get_tickets ( broker_id_type broker_id,
get_tickets_callback_type result_callback ) -> bool
overridevirtual

Returns tickets managed by the given broker.

Parameters
broker_idbroker ID.
result_callbackfunction to call with get_tickets result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 431 of file runtime_locking_shard/impl.cpp.

◆ prepare()

auto cbdc::parsec::runtime_locking_shard::impl::prepare ( ticket_number_type ticket_number,
broker_id_type broker_id,
state_update_type state_update,
prepare_callback_type result_callback ) -> bool
overridevirtual

Prepares a ticket with the given state updates.

Parameters
ticket_numberticket number.
broker_idID of broker managing ticket.
state_updatestate changes to apply if ticket is committed.
result_callbackfunction to call with prepare result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 180 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::committed, cbdc::parsec::runtime_locking_shard::lock_not_held, cbdc::parsec::runtime_locking_shard::lock_queued, cbdc::parsec::runtime_locking_shard::prepared, cbdc::parsec::runtime_locking_shard::state_update_with_read_lock, cbdc::parsec::runtime_locking_shard::unknown_ticket, cbdc::parsec::runtime_locking_shard::wounded, and cbdc::parsec::runtime_locking_shard::write.

◆ recover()

auto cbdc::parsec::runtime_locking_shard::impl::recover ( const replicated_shard::state_type & state,
const replicated_shard::tickets_type & tickets ) -> bool

Restores the state of another shard instance.

Parameters
statekeys and values to store.
ticketsunfinished tickets that have reached the prepare or commit phase.
Returns
true if the provided state was applied successfully.

Definition at line 449 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::replicated_shard_interface::committed, cbdc::parsec::runtime_locking_shard::committed, cbdc::parsec::runtime_locking_shard::replicated_shard_interface::prepared, cbdc::parsec::runtime_locking_shard::prepared, and cbdc::parsec::runtime_locking_shard::write.

◆ rollback()

auto cbdc::parsec::runtime_locking_shard::impl::rollback ( ticket_number_type ticket_number,
rollback_callback_type result_callback ) -> bool
overridevirtual

Rolls back an uncommitted ticket.

Releases any locks held by the ticket and assigns the locks to tickets queuing for the lock.

Parameters
ticket_numberticket number.
result_callbackfunction to call with rollback result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 357 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::unknown_ticket.

◆ try_lock()

auto cbdc::parsec::runtime_locking_shard::impl::try_lock ( ticket_number_type ticket_number,
broker_id_type broker_id,
key_type key,
lock_type locktype,
bool first_lock,
try_lock_callback_type result_callback ) -> bool
overridevirtual

Locks the given key for a ticket and returns the associated value.

If lock is unavailable, lock will be queued. May wound other tickets to acquire the lock.

Parameters
ticket_numberticket number.
broker_idID of broker managing ticket.
keykey to lock.
locktypetype of lock to acquire.
first_locktrue if this is the first lock.
result_callbackfunction to call with try lock result.
Returns
true.

Implements cbdc::parsec::runtime_locking_shard::interface.

Definition at line 14 of file runtime_locking_shard/impl.cpp.

References cbdc::parsec::runtime_locking_shard::committed, cbdc::parsec::runtime_locking_shard::lock_held, cbdc::parsec::runtime_locking_shard::lock_queued, cbdc::parsec::runtime_locking_shard::prepared, cbdc::parsec::runtime_locking_shard::unknown_ticket, and cbdc::parsec::runtime_locking_shard::wounded.


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