OpenCBDC Transaction Processor
|
Implementation of a runtime locking shard. More...
#include <impl.hpp>
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. | |
![]() | |
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 | |
![]() | |
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. | |
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.
|
explicit |
Constructor.
logger | log instance. |
Definition at line 11 of file runtime_locking_shard/impl.cpp.
|
overridevirtual |
Commits a previously prepared ticket.
Releases any locks held by the ticket and assigns the locks to tickets queuing for the lock.
ticket_number | ticket number. |
result_callback | function to call with commit result. |
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.
|
overridevirtual |
Deletes a committed or rolled-back ticket.
ticket_number | ticket number. |
result_callback | function to call with finish result. |
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.
|
overridevirtual |
Returns tickets managed by the given broker.
broker_id | broker ID. |
result_callback | function to call with get_tickets result. |
Implements cbdc::parsec::runtime_locking_shard::interface.
Definition at line 431 of file runtime_locking_shard/impl.cpp.
|
overridevirtual |
Prepares a ticket with the given state updates.
ticket_number | ticket number. |
broker_id | ID of broker managing ticket. |
state_update | state changes to apply if ticket is committed. |
result_callback | function to call with prepare result. |
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.
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.
state | keys and values to store. |
tickets | unfinished tickets that have reached the prepare or commit phase. |
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.
|
overridevirtual |
Rolls back an uncommitted ticket.
Releases any locks held by the ticket and assigns the locks to tickets queuing for the lock.
ticket_number | ticket number. |
result_callback | function to call with rollback result. |
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.
|
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.
ticket_number | ticket number. |
broker_id | ID of broker managing ticket. |
key | key to lock. |
locktype | type of lock to acquire. |
first_lock | true if this is the first lock. |
result_callback | function to call with try lock result. |
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.