OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
parsec/broker/interface.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_PARSEC_BROKER_INTERFACE_H_
7#define OPENCBDC_TX_SRC_PARSEC_BROKER_INTERFACE_H_
8
11
12namespace cbdc::parsec::broker {
24 using held_locks_set_type = std::
25 unordered_map<key_type, lock_type, hashing::const_sip_hash<key_type>>;
26
31 class interface {
32 public:
33 virtual ~interface() = default;
34
35 interface() = default;
36 interface(const interface&) = delete;
37 auto operator=(const interface&) -> interface& = delete;
38 interface(interface&&) = delete;
39 auto operator=(interface&&) -> interface& = delete;
40
84
88 = std::variant<ticket_number_type, error_code>;
91 = std::function<void(ticketnum_or_errcode_type)>;
92
96 [[nodiscard]] virtual auto begin(begin_callback_type result_callback)
97 -> bool
98 = 0;
99
103 = std::variant<value_type,
108 = std::function<void(try_lock_return_type)>;
109
116 [[nodiscard]] virtual auto
117 try_lock(ticket_number_type ticket_number,
118 key_type key,
119 lock_type locktype,
120 try_lock_callback_type result_callback) -> bool
121 = 0;
122
125 using commit_return_type = std::optional<
126 std::variant<error_code, runtime_locking_shard::shard_error>>;
128 using commit_callback_type = std::function<void(commit_return_type)>;
129
135 [[nodiscard]] virtual auto commit(ticket_number_type ticket_number,
136 state_update_type state_updates,
137 commit_callback_type result_callback)
138 -> bool
139 = 0;
140
143 using finish_return_type = std::optional<error_code>;
145 using finish_callback_type = std::function<void(finish_return_type)>;
146
151 [[nodiscard]] virtual auto finish(ticket_number_type ticket_number,
152 finish_callback_type result_callback)
153 -> bool
154 = 0;
155
158 using rollback_return_type = std::optional<
159 std::variant<error_code, runtime_locking_shard::error_code>>;
162 = std::function<void(rollback_return_type)>;
163
168 [[nodiscard]] virtual auto
169 rollback(ticket_number_type ticket_number,
170 rollback_callback_type result_callback) -> bool
171 = 0;
175 using recover_return_type = std::optional<error_code>;
177 using recover_callback_type = std::function<void(recover_return_type)>;
178
184 [[nodiscard]] virtual auto
185 recover(recover_callback_type result_callback) -> bool
186 = 0;
187
193 virtual auto highest_ticket() -> ticket_number_type = 0;
194 };
195}
196
197#endif
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
virtual auto try_lock(ticket_number_type ticket_number, key_type key, lock_type locktype, try_lock_callback_type result_callback) -> bool=0
Attempts to acquire the given lock on the appropriate shard.
interface(const interface &)=delete
std::function< void(recover_return_type)> recover_callback_type
Callback function type for a recovery operation.
virtual auto recover(recover_callback_type result_callback) -> bool=0
Retrieves tickets associated with this broker from all shards and completes partially committed ticke...
auto operator=(const interface &) -> interface &=delete
virtual auto rollback(ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool=0
Rollback a ticket on all shards involved in the ticket.
std::function< void(rollback_return_type)> rollback_callback_type
Callback function type for a rollback operation.
virtual auto finish(ticket_number_type ticket_number, finish_callback_type result_callback) -> bool=0
Finishes a ticket on all shards involved in the ticket.
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.
interface(interface &&)=delete
std::optional< error_code > finish_return_type
Return type from a finish operation.
virtual auto begin(begin_callback_type result_callback) -> bool=0
Acquires a new ticket number to begin a transaction.
error_code
Error codes returned by broker operations.
@ rollback_error
Shard error during rollback.
@ commit_error
Shard error during commit.
@ directory_unreachable
Request failed because directory was unreachable.
@ get_tickets_error
Shard error during get tickets.
@ prepare_error
Shard error during prepare.
@ finish_error
Shard error during finish.
@ shard_unreachable
Request failed because a shard was unreachable.
@ prepared
Request invalid because ticket is prepared.
@ commit_hazard
A commit is attempted without associating update keys with ticket.
@ waiting_for_locks
Cannot prepare because ticket still waiting for locks to be acquired.
@ ticket_number_assignment
Error during ticket number assignment.
@ invalid_shard_state
Request failed because shard was in an invalid state for the given ticket.
@ begun
Request invalid because ticket is not committed or rolled back.
@ ticket_machine_unreachable
Request failed because the ticket machine was unreachable.
@ aborted
Request invalid because ticket is rolled back.
@ not_prepared
Request invalid because ticket is not prepared.
@ unknown_ticket
Request for an unknown ticket.
@ committed
Reqeust invalid because ticket is committed.
std::function< void(finish_return_type)> finish_callback_type
Callback function type for a finish operation.
virtual auto highest_ticket() -> ticket_number_type=0
Get the highest ticket number that was used.
auto operator=(interface &&) -> interface &=delete
std::function< void(commit_return_type)> commit_callback_type
Callback function type for a commit operation.
std::optional< error_code > recover_return_type
Return type from a recover operation.
virtual auto commit(ticket_number_type ticket_number, state_update_type state_updates, commit_callback_type result_callback) -> bool=0
Prepares and commits a ticket on all shards involved in the ticket.
std::variant< ticket_number_type, error_code > ticketnum_or_errcode_type
Return type from a begin 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.
runtime_locking_shard::value_type value_type
Shard value type.
runtime_locking_shard::state_update_type state_update_type
Shard state updates type.
ticket_machine::ticket_number_type ticket_number_type
Ticket number type.
std:: unordered_map< key_type, lock_type, hashing::const_sip_hash< key_type > > held_locks_set_type
Set of held locks.
std:: unordered_map< key_type, value_type, hashing::const_sip_hash< key_type > > state_update_type
Type for state updates to a shard. A map of keys and their new values.
uint64_t ticket_number_type
Type alias for a ticket number.