OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
replicated_shard_interface.hpp
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
6#ifndef OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_REPLICATED_SHARD_INTERFACE_H_
7#define OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_REPLICATED_SHARD_INTERFACE_H_
8
9#include "interface.hpp"
10
15 public:
17 enum class error_code : uint8_t {
22 };
23
25 enum class ticket_state : uint8_t {
30 };
31
41
45 = std::unordered_map<key_type,
48
50 using tickets_type
51 = std::unordered_map<ticket_number_type, ticket_type>;
54 using return_type = std::optional<error_code>;
56 using callback_type = std::function<void(return_type)>;
57
58 virtual ~replicated_shard_interface() = default;
62 = default;
67 -> replicated_shard_interface& = default;
68
75 virtual auto prepare(ticket_number_type ticket_number,
76 broker_id_type broker_id,
77 state_type state_update,
78 callback_type result_callback) -> bool
79 = 0;
80
85 virtual auto commit(ticket_number_type ticket_number,
86 callback_type result_callback) -> bool
87 = 0;
88
93 virtual auto finish(ticket_number_type ticket_number,
94 callback_type result_callback) -> bool
95 = 0;
96
99 using get_tickets_return_type = std::variant<tickets_type, error_code>;
102 = std::function<void(get_tickets_return_type)>;
103
108 [[nodiscard]] virtual auto
109 get_tickets(get_tickets_callback_type result_callback) const -> bool
110 = 0;
111 };
112}
113
114#endif
Interface for replicating internal state for prepared and committed tickets managed by a locking shar...
std::function< void(get_tickets_return_type)> get_tickets_callback_type
Callback function type for the result of a get tickets operation.
virtual auto finish(ticket_number_type ticket_number, callback_type result_callback) -> bool=0
Stores a finish request in the state machine.
virtual auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_type state_update, callback_type result_callback) -> bool=0
Stores a prepare request for a ticket in the state machine.
std::unordered_map< ticket_number_type, ticket_type > tickets_type
Type for the tickets list returned by the state machine.
std::variant< tickets_type, error_code > get_tickets_return_type
Return type from a get tickets operation.
ticket_state
Ticket states returned by shards for broker recovery purposes.
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.
auto operator=(const replicated_shard_interface &) -> replicated_shard_interface &=default
virtual auto get_tickets(get_tickets_callback_type result_callback) const -> bool=0
Retrieves unfinished tickets from the state machine.
std::optional< error_code > return_type
Return type from a prepare operation. An error, if applicable.
virtual auto commit(ticket_number_type ticket_number, callback_type result_callback) -> bool=0
Stores a commit request in the state machine.
parsec::ticket_machine::ticket_number_type ticket_number_type
Type for a ticket number.
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.
SipHash function to generate STL data structure hash keys for system IDs.
Definition hashmap.hpp:27