6#ifndef OPENCBDC_TX_SRC_PARSEC_BROKER_IMPL_H_
7#define OPENCBDC_TX_SRC_PARSEC_BROKER_IMPL_H_
27 std::vector<std::shared_ptr<runtime_locking_shard::interface>>
29 std::shared_ptr<ticket_machine::interface> ticketer,
30 std::shared_ptr<directory::interface> directory,
31 std::shared_ptr<logging::log> logger);
91 enum class ticket_state : uint8_t {
99 std::vector<std::shared_ptr<runtime_locking_shard::interface>>
101 std::shared_ptr<ticket_machine::interface> m_ticketer;
102 std::shared_ptr<directory::interface> m_directory;
103 std::shared_ptr<logging::log> m_log;
105 mutable std::recursive_mutex m_mut;
108 enum class shard_state_type : uint8_t {
121 enum class key_state : uint8_t {
126 struct key_state_type {
127 key_state m_key_state{};
129 std::optional<value_type> m_value;
137 shard_state_type m_state{};
140 using shard_states = std::unordered_map<size_t, shard_state>;
143 ticket_state m_state{};
144 shard_states m_shard_states;
147 std::unordered_map<ticket_number_type, std::shared_ptr<state>>
175 void handle_ticket_number(
178 get_ticket_number_return_type> res);
180 void handle_rollback(
187 void handle_find_key(
203 const parsec::runtime_locking_shard::
204 interface::get_tickets_return_type& res);
222 const std::shared_ptr<state>& ts)
223 -> std::optional<error_code>;
227 const std::shared_ptr<state>& ts,
230 prepare_return_type& res)
231 -> std::optional<commit_return_type>;
235 const std::shared_ptr<state>& t_state,
237 -> std::optional<error_code>;
240 -> std::optional<error_code>;
Buffer to store and retrieve byte data.
Implementation of a broker.
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 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 highest_ticket() -> ticket_number_type override
Get the highest ticket number that was used.
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,...
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.
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.
std::function< void(recover_return_type)> recover_callback_type
Callback function type for a recovery operation.
std::function< void(rollback_return_type)> rollback_callback_type
Callback function type for a rollback operation.
std::function< void(ticketnum_or_errcode_type)> begin_callback_type
Callback function type for a begin operation.
std::variant< value_type, error_code, runtime_locking_shard::shard_error > try_lock_return_type
Return type from a try lock operation.
std::optional< std::variant< error_code, runtime_locking_shard::shard_error > > commit_return_type
Return type from a commit operation.
std::optional< error_code > finish_return_type
Return type from a finish operation.
std::function< void(finish_return_type)> finish_callback_type
Callback function type for a finish operation.
std::function< void(commit_return_type)> commit_callback_type
Callback function type for a commit operation.
std::function< void(try_lock_return_type)> try_lock_callback_type
Callback function type for a try lock operation.
std::optional< std::variant< error_code, runtime_locking_shard::error_code > > rollback_return_type
Return type from a rollback operation.
uint64_t key_location_return_type
Key location return type. Shard ID where key is located.
Interface for a runtime locking shard.
std::optional< shard_error > prepare_return_type
Return type from a prepare operation. An error, if applicable.
std::optional< shard_error > commit_return_type
Return type from a commit operation. An error code, if applicable.
std::optional< shard_error > finish_return_type
Return type from a finish operation. An error code, if applicable.
std::optional< shard_error > rollback_return_type
Return type from a rollback operation.
Ticket machine interface.
runtime_locking_shard::state_update_type state_update_type
Shard state updates type.
ticket_machine::ticket_number_type ticket_number_type
Ticket number type.
runtime_locking_shard::key_type key_type
Shard key type.
size_t broker_id_type
Type for the ID of a broker.
ticket_state
Ticket states returned by shards for broker recovery purposes.
lock_type
Types of key lock supported by shards.
SipHash function to generate STL data structure hash keys for system IDs.