OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
replicated_shard.cpp
Go to the documentation of this file.
1// Copyright (c) 2022 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
7
10 broker_id_type broker_id,
11 state_type state_update,
12 callback_type result_callback) -> bool {
13 auto ret = [&]() {
14 std::unique_lock l(m_mut);
15 m_tickets.emplace(ticket_number,
16 ticket_type{broker_id,
17 std::move(state_update),
19 return std::nullopt;
20 }();
21 result_callback(ret);
22 return true;
23 }
24
26 callback_type result_callback) -> bool {
27 auto ret = [&]() -> return_type {
28 std::unique_lock l(m_mut);
29 auto it = m_tickets.find(ticket_number);
30 if(it == m_tickets.end()) {
32 }
33 auto& t = it->second;
34 t.m_state = ticket_state::committed;
35 for(auto&& [k, v] : t.m_state_update) {
36 m_state[k] = std::move(v);
37 }
38 return std::nullopt;
39 }();
40 result_callback(ret);
41 return true;
42 }
43
45 callback_type result_callback) -> bool {
46 auto ret = [&]() -> return_type {
47 std::unique_lock l(m_mut);
48 m_tickets.erase(ticket_number);
49 return std::nullopt;
50 }();
51 result_callback(ret);
52 return true;
53 }
54
56 get_tickets_callback_type result_callback) const -> bool {
57 auto ret = [&]() -> get_tickets_return_type {
58 std::unique_lock l(m_mut);
59 return m_tickets;
60 }();
61 result_callback(std::move(ret));
62 return true;
63 }
64
66 std::unique_lock l(m_mut);
67 return m_state;
68 }
69}
std::function< void(get_tickets_return_type)> get_tickets_callback_type
Callback function type for the result of a get tickets operation.
std::variant< tickets_type, error_code > get_tickets_return_type
Return type from a get tickets operation.
std::function< void(return_type)> callback_type
Callback function type for the result of a prepare operation.
std::unordered_map< key_type, value_type, hashing::const_sip_hash< key_type > > state_type
Type for state updates to a shard.
std::optional< error_code > return_type
Return type from a prepare operation. An error, if applicable.
auto get_tickets(get_tickets_callback_type result_callback) const -> bool override
Retrieves unfinished tickets from the state machine.
auto get_state() const -> state_type
Return the keys and values stored by the shard.
auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_type state_update, callback_type result_callback) -> bool override
Stores a prepare request for a ticket in the state machine.
auto commit(ticket_number_type ticket_number, callback_type result_callback) -> bool override
Stores a commit request in the state machine.
auto finish(ticket_number_type ticket_number, callback_type result_callback) -> bool override
Stores a finish request in the state machine.
parsec::ticket_machine::ticket_number_type ticket_number_type
Type for a ticket number.
@ unknown_ticket
The given ticket number is not known to this shard.
@ committed
Committed, not holding any locks.