15 std::shared_ptr<raft::node> raft_node)
16 : m_raft(std::move(raft_node)) {}
25 std::move(state_update)};
26 auto success = replicate_request(
29 std::optional<rpc::replicated_response> maybe_res) {
30 if(!maybe_res.has_value()) {
34 auto&& res = maybe_res.value();
35 assert(std::holds_alternative<
38 = std::get<replicated_shard_interface::return_type>(res);
39 result_callback(resp_val);
48 auto success = replicate_request(
51 std::optional<rpc::replicated_response> maybe_res) {
52 if(!maybe_res.has_value()) {
56 auto&& res = maybe_res.value();
57 assert(std::holds_alternative<
60 = std::get<replicated_shard_interface::return_type>(res);
61 result_callback(resp_val);
70 auto success = replicate_request(
73 std::optional<rpc::replicated_response> maybe_res) {
74 if(!maybe_res.has_value()) {
78 auto&& res = maybe_res.value();
79 assert(std::holds_alternative<
82 = std::get<replicated_shard_interface::return_type>(res);
83 result_callback(resp_val);
91 auto success = replicate_request(
94 std::optional<rpc::replicated_response> maybe_res) {
95 if(!maybe_res.has_value()) {
99 auto&& res = maybe_res.value();
100 assert(std::holds_alternative<
103 auto&& resp_val = std::get<
105 result_callback(std::move(resp_val));
110 auto replicated_shard_client::replicate_request(
112 const std::function<
void(std::optional<rpc::replicated_response>)>&
113 result_callback)
const ->
bool {
114 if(!m_raft->is_leader()) {
118 nuraft::ptr<nuraft::buffer>>(req);
119 auto success = m_raft->replicate(
122 nuraft::ptr<std::exception>& err) {
124 result_callback(std::nullopt);
128 const auto res = r.get();
130 result_callback(std::nullopt);
135 assert(maybe_resp.has_value());
136 auto&& resp = maybe_resp.value();
137 result_callback(std::move(resp));
auto finish(ticket_number_type ticket_number, callback_type result_callback) -> bool override
Replicates a finish request in the state machine and returns the response via a callback function.
auto commit(ticket_number_type ticket_number, callback_type result_callback) -> bool override
Replicates a commit request in the state machine and returns the response via a callback function.
auto get_tickets(get_tickets_callback_type result_callback) const -> bool override
Replicates a get tickets request in the state machine and returns the response via a callback functio...
replicated_shard_client(std::shared_ptr< raft::node > raft_node)
Constructs a shard client.
auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_type state_update, callback_type result_callback) -> bool override
Replicates a prepare request in the state machine and returns the response via a callback function.
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.
std::variant< replicated_prepare_request, commit_request, finish_request, replicated_get_tickets_request > replicated_request
Shard replicated state machine request type.
parsec::ticket_machine::ticket_number_type ticket_number_type
Type for a ticket number.
size_t broker_id_type
Type for the ID of a broker.
@ internal_error
Request failed because of a transient internal error.
nuraft::cmd_result< nuraft::ptr< nuraft::buffer > > result_type
A NuRaft state machine execution result.
auto from_buffer(nuraft::buffer &buf) -> std::optional< T >
Deserialize object of given type from a nuraft::buffer.
auto make_buffer(const T &obj) -> std::enable_if_t< std::is_same_v< B, nuraft::ptr< nuraft::buffer > >, nuraft::ptr< nuraft::buffer > >
Serialize object into nuraft::buffer using a cbdc::nuraft_serializer.
Message for retrieving unfinished tickets from the replicated state machine.
Message for replicating a prepare request.