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

Implementation of a broker. More...

#include <impl.hpp>

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

Public Member Functions

 impl (runtime_locking_shard::broker_id_type broker_id, std::vector< std::shared_ptr< runtime_locking_shard::interface > > shards, std::shared_ptr< ticket_machine::interface > ticketer, std::shared_ptr< directory::interface > directory, std::shared_ptr< logging::log > logger)
 Constructor.
 
auto begin (begin_callback_type result_callback) -> bool override
 Requests a new ticket number from the ticket machine.
 
auto try_lock (ticket_number_type ticket_number, key_type key, lock_type locktype, try_lock_callback_type result_callback) -> bool override
 Determines the shard responsible for the given key and issues a try lock request for the key.
 
auto commit (ticket_number_type ticket_number, state_update_type state_updates, commit_callback_type result_callback) -> bool override
 Commits the ticket on all shards involved in the ticket.
 
auto finish (ticket_number_type ticket_number, finish_callback_type result_callback) -> bool override
 Finishes the ticket on all shards involved in the ticket.
 
auto rollback (ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool override
 Rolls back the ticket on all shards involved in the ticket.
 
auto recover (recover_callback_type result_callback) -> bool override
 Requests tickets managed by this broker ID from all shards and completes partially committed tickets, and rolls back all other tickets.
 
auto highest_ticket () -> ticket_number_type override
 Get the highest ticket number that was used.
 
- Public Member Functions inherited from cbdc::parsec::broker::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::broker::interface
enum class  error_code : uint8_t {
  ticket_number_assignment , unknown_ticket , prepared , shard_unreachable ,
  ticket_machine_unreachable , committed , not_prepared , begun ,
  aborted , directory_unreachable , invalid_shard_state , waiting_for_locks ,
  commit_error , rollback_error , prepare_error , finish_error ,
  get_tickets_error , commit_hazard
}
 Error codes returned by broker operations. More...
 
using ticketnum_or_errcode_type = std::variant<ticket_number_type, error_code>
 Return type from a begin operation.
 
using begin_callback_type = std::function<void(ticketnum_or_errcode_type)>
 Callback function type for a begin operation.
 
using try_lock_return_type
 Return type from a try lock operation.
 
using try_lock_callback_type = std::function<void(try_lock_return_type)>
 Callback function type for a try lock operation.
 
using commit_return_type
 Return type from a commit operation.
 
using commit_callback_type = std::function<void(commit_return_type)>
 Callback function type for a commit operation.
 
using finish_return_type = std::optional<error_code>
 Return type from a finish operation.
 
using finish_callback_type = std::function<void(finish_return_type)>
 Callback function type for a finish operation.
 
using rollback_return_type
 Return type from a rollback operation.
 
using rollback_callback_type = std::function<void(rollback_return_type)>
 Callback function type for a rollback operation.
 
using recover_return_type = std::optional<error_code>
 Return type from a recover operation.
 
using recover_callback_type = std::function<void(recover_return_type)>
 Callback function type for a recovery operation.
 

Detailed Description

Implementation of a broker.

Stores ticket states in memory. Thread-safe.

Definition at line 18 of file broker/impl.hpp.

Constructor & Destructor Documentation

◆ impl()

cbdc::parsec::broker::impl::impl ( runtime_locking_shard::broker_id_type broker_id,
std::vector< std::shared_ptr< runtime_locking_shard::interface > > shards,
std::shared_ptr< ticket_machine::interface > ticketer,
std::shared_ptr< directory::interface > directory,
std::shared_ptr< logging::log > logger )

Constructor.

Parameters
broker_idunique ID of this broker instance.
shardsvector of shard instances.
ticketerticket machine instance.
directorydirectory instance.
loggerlog instance.

Definition at line 13 of file broker/impl.cpp.

Member Function Documentation

◆ begin()

auto cbdc::parsec::broker::impl::begin ( begin_callback_type result_callback) -> bool
overridevirtual

Requests a new ticket number from the ticket machine.

Parameters
result_callbackfunction to call with the begin result.
Returns
true if the request to the ticket machine was initiated successfully.

Implements cbdc::parsec::broker::interface.

Definition at line 25 of file broker/impl.cpp.

◆ commit()

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

Commits the ticket on all shards involved in the ticket.

Parameters
ticket_numberticket number.
state_updatesstate updates to apply if ticket commits.
result_callbackfunction to call with commit result.
Returns
true if all requests to shards were initiated successfully.

We should fail here, because if this transaction has made it to the commit step without attempting to lock the keys, something signficant has gone wrong, likely associated with the contract itself.

Implements cbdc::parsec::broker::interface.

Definition at line 376 of file broker/impl.cpp.

References cbdc::buffer.

◆ finish()

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

Finishes the ticket on all shards involved in the ticket.

Parameters
ticket_numberticket number.
result_callbackfunction to call with finish result.
Returns
true if requests to all shards were initiated successfully.

Implements cbdc::parsec::broker::interface.

Definition at line 492 of file broker/impl.cpp.

◆ highest_ticket()

auto cbdc::parsec::broker::impl::highest_ticket ( ) -> ticket_number_type
overridevirtual

Get the highest ticket number that was used.

This is not to be used for calculating a next ticket number, but is used to calculate the pretend height of the chain in the evm runner, which is derived from ticket numbers

Returns
highest ticket number that was used

Implements cbdc::parsec::broker::interface.

Definition at line 70 of file broker/impl.cpp.

◆ recover()

auto cbdc::parsec::broker::impl::recover ( recover_callback_type result_callback) -> bool
overridevirtual

Requests tickets managed by this broker ID from all shards and completes partially committed tickets, and rolls back all other tickets.

Finishes all tickets.

Parameters
result_callbackfunction to call with recovery result.
Returns
true if requests to all shards were initiated successfully.

Implements cbdc::parsec::broker::interface.

Definition at line 882 of file broker/impl.cpp.

◆ rollback()

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

Rolls back the ticket on all shards involved in the ticket.

Parameters
ticket_numberticket number.
result_callbackfunction to call with rollback result.
Returns
true if requests to all shard were initiated successfully.

Implements cbdc::parsec::broker::interface.

Definition at line 571 of file broker/impl.cpp.

◆ try_lock()

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

Determines the shard responsible for the given key and issues a try lock request for the key.

Parameters
ticket_numberticket number.
keykey to lock.
locktypetype of lock to acquire.
result_callbackfunction to call with try_lock request.
Returns
true: if request to the directory was initiated successfully. false: only if an unexpected exception was encountered

Implements cbdc::parsec::broker::interface.

Definition at line 132 of file broker/impl.cpp.


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