OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
agent/impl.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_AGENT_IMPL_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_IMPL_H_
8
9#include "interface.hpp"
13
14namespace cbdc::parsec::agent {
16 class impl : public interface {
17 public:
57
73 impl(std::shared_ptr<logging::log> logger,
76 std::shared_ptr<broker::interface> broker,
78 parameter_type param,
79 exec_callback_type result_callback,
80 broker::lock_type initial_lock_type,
81 bool is_readonly_run,
82 std::shared_ptr<secp256k1_context> secp,
83 std::shared_ptr<thread_pool> t_pool);
84
86 ~impl() override;
87
88 impl(const impl&) = delete;
89 auto operator=(const impl&) -> impl& = delete;
90 impl(impl&&) = delete;
91 auto operator=(impl&&) -> impl& = delete;
92
95 auto exec() -> bool override;
96
100 auto get_ticket_number() const
101 -> std::optional<ticket_machine::ticket_number_type>;
102
105 auto get_state() const -> state;
106
107 private:
108 std::shared_ptr<logging::log> m_log;
109 const cbdc::parsec::config m_cfg;
110 runner::interface::factory_type m_runner_factory;
111 std::shared_ptr<broker::interface> m_broker;
112 std::optional<ticket_machine::ticket_number_type> m_ticket_number;
113 std::optional<exec_return_type> m_result;
114 std::unique_ptr<runner::interface> m_runner;
115 state m_state{state::init};
116 bool m_permanent_error{false};
117 mutable std::recursive_mutex m_mut;
118 broker::lock_type m_initial_lock_type;
119 bool m_is_readonly_run;
120 std::shared_ptr<secp256k1_context> m_secp;
121 std::shared_ptr<thread_pool> m_threads;
122 std::optional<hash_t> m_tx_id;
123 bool m_wounded{false};
124 broker::held_locks_set_type m_requested_locks{};
125 bool m_restarted{false};
126
128
129 void
130 handle_function(const broker::interface::try_lock_return_type& res);
131
132 void handle_run(const runner::interface::run_return_type& res);
133
134 void handle_commit(broker::interface::commit_return_type res);
135
136 void do_start();
137
138 void do_result();
139
140 void do_finish();
141
142 void do_runner(broker::value_type v);
143
144 void do_rollback(bool finish);
145
146 void do_commit();
147
150 [[nodiscard]] auto
151 do_try_lock_request(broker::key_type key,
152 broker::lock_type locktype,
154 -> bool;
155
156 void
157 handle_rollback(broker::interface::rollback_return_type rollback_res);
158
159 void handle_finish(broker::interface::finish_return_type finish_res);
160
161 void handle_try_lock_response(
164 };
165}
166
167#endif
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Implementation of an agent.
state
States for a ticket managed by this agent.
@ begin_sent
Begin request sent to broker.
@ function_get_failed
Function bytecode lock request failed.
@ commit_error
Broker error during commit request.
@ function_get_error
Broker error during function bytecode lock.
@ rollback_failed
Rollback request failed.
@ function_get_sent
Function bytecode lock sent to broker.
@ function_started
Function execution started.
@ commit_failed
Commit request failed.
@ finish_failed
Finish request failed.
@ function_exception
Function error during execution.
@ finish_complete
Finish complete.
@ commit_sent
Commit request sent to broker.
@ rollback_sent
Rollback request sent to broker.
@ rollback_complete
Rollback complete.
@ finish_sent
Finish request sent to broker.
@ begin_failed
Begin request failed.
@ function_failed
Function execution failed.
auto exec() -> bool override
Initiates function execution.
auto get_state() const -> state
Return the state of the ticket.
impl(std::shared_ptr< logging::log > logger, cbdc::parsec::config cfg, runner::interface::factory_type runner_factory, std::shared_ptr< broker::interface > broker, runtime_locking_shard::key_type function, parameter_type param, exec_callback_type result_callback, broker::lock_type initial_lock_type, bool is_readonly_run, std::shared_ptr< secp256k1_context > secp, std::shared_ptr< thread_pool > t_pool)
Constructor.
auto operator=(const impl &) -> impl &=delete
impl(const impl &)=delete
~impl() override
Ensures function execution is complete before destruction.
auto get_ticket_number() const -> std::optional< ticket_machine::ticket_number_type >
Returns the ticket number associated with this agent, if available.
auto operator=(impl &&) -> impl &=delete
std::variant< return_type, error_code > exec_return_type
Return type from function execution.
std::function< void(exec_return_type)> exec_callback_type
Callback function type with function execution result.
std::function< std::unique_ptr< interface >( std::shared_ptr< logging::log > logger, const cbdc::parsec::config &cfg, runtime_locking_shard::value_type function, parameter_type param, bool is_readonly_run, runner::interface::run_callback_type result_callback, runner::interface::try_lock_callback_type try_lock_callback, std::shared_ptr< secp256k1_context >, std::shared_ptr< thread_pool > t_pool, ticket_number_type ticket_number)> factory_type
Factory function type for instantiating new runners.
std::variant< runtime_locking_shard::state_update_type, error_code > run_return_type
Return type from executing a function.
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.
std::optional< error_code > finish_return_type
Return type from a finish operation.
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::key_type key_type
Shard key type.
std:: unordered_map< key_type, lock_type, hashing::const_sip_hash< key_type > > held_locks_set_type
Set of held locks.
runtime_locking_shard::lock_type lock_type
Shard lock type.
Configuration parameters for a phase two system.