OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
parsec/ticket_machine/state_machine.cpp
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#include "state_machine.hpp"
7
8#include "util/rpc/format.hpp"
10
12 state_machine::state_machine(std::shared_ptr<logging::log> logger,
13 ticket_number_type batch_size)
14 : m_logger(std::move(logger)) {
16 return process_request(req);
17 });
18 m_ticket_machine = std::make_unique<impl>(m_logger, batch_size);
19 }
20
21 auto state_machine::commit(uint64_t log_idx, nuraft::buffer& data)
22 -> nuraft::ptr<nuraft::buffer> {
23 m_last_committed_idx = log_idx;
24
25 auto resp = blocking_call(data);
26 if(!resp.has_value()) {
27 // TODO: This would only happen if there was a deserialization
28 // error with the request. Maybe we should abort here as such an
29 // event would imply a bug in the coordinator.
30 return nullptr;
31 }
32
33 return resp.value();
34 }
35
36 auto state_machine::apply_snapshot(nuraft::snapshot& /* s */) -> bool {
37 return false;
38 }
39
40 auto state_machine::last_snapshot() -> nuraft::ptr<nuraft::snapshot> {
41 return nullptr;
42 }
43
45 return m_last_committed_idx;
46 }
47
49 nuraft::snapshot& /* s */,
50 nuraft::async_result<bool>::handler_type& when_done) {
51 nuraft::ptr<std::exception> except(nullptr);
52 bool ret = false;
53 when_done(ret, except);
54 }
55
56 auto state_machine::process_request(rpc::request /* req */)
57 -> rpc::response {
58 auto ret = rpc::response();
59 [[maybe_unused]] auto success = m_ticket_machine->get_ticket_number(
61 ret = tkts;
62 });
63 assert(success);
64 return ret;
65 }
66}
std::variant< ticket_number_range_type, error_code > get_ticket_number_return_type
Return value from the ticket machine.
auto commit(uint64_t log_idx, nuraft::buffer &data) -> nuraft::ptr< nuraft::buffer > override
Commit the given raft log entry at the given log index, and return the result.
void create_snapshot(nuraft::snapshot &, nuraft::async_result< bool >::handler_type &) override
Not implemented for ticket machine.
auto apply_snapshot(nuraft::snapshot &) -> bool override
Not implemented for ticket machine.
state_machine(std::shared_ptr< logging::log > logger, ticket_number_type batch_size)
Constructor.
auto last_commit_index() -> uint64_t override
Returns the most recently committed log entry index.
auto last_snapshot() -> nuraft::ptr< nuraft::snapshot > override
Not implemented for ticket machine.
std::variant< std::monostate > request
Ticket machine RPC request type.
interface::get_ticket_number_return_type response
Ticket machine RPC response type.
uint64_t ticket_number_type
Type alias for a ticket number.