6#ifndef OPENCBDC_TX_SRC_COORDINATOR_DISTRIBUTED_TX_H_
7#define OPENCBDC_TX_SRC_COORDINATOR_DISTRIBUTED_TX_H_
33 std::vector<std::shared_ptr<locking_shard::interface>> shards,
34 std::shared_ptr<logging::log> logger);
41 [[nodiscard]]
auto execute() -> std::optional<std::vector<bool>>;
56 = std::function<bool(
const hash_t&,
57 const std::vector<bool>&,
58 const std::vector<std::vector<uint64_t>>&)>;
60 = std::function<bool(
const hash_t&,
61 const std::vector<transaction::compact_tx>&)>;
113 const std::vector<std::vector<uint64_t>>& tx_idxs);
121 [[nodiscard]]
auto size() const ->
size_t;
148 [[nodiscard]] auto prepare() -> std::optional<std::vector<
bool>>;
150 [[nodiscard]] auto
commit(const std::vector<
bool>& complete_txs)
153 auto discard() ->
bool;
156 std::vector<std::shared_ptr<locking_shard::
interface>> m_shards;
157 std::vector<std::vector<locking_shard::tx>> m_txs;
158 std::vector<transaction::compact_tx> m_full_txs;
159 std::vector<std::vector<uint64_t>> m_tx_idxs;
165 std::vector<bool> m_complete_txs;
166 std::shared_ptr<logging::log> m_logger;
Class to manage a single distributed transaction (dtx) batch between shards.
std::function< bool(const hash_t &)> discard_cb_t
void set_commit_cb(const commit_cb_t &cb)
Registers a callback to be called before starting the commit phase of the dtx.
auto size() const -> size_t
Returns the number of transactions in the dtx.
auto get_id() const -> hash_t
Returns the dtx ID associated with this coordinator instance.
void recover_commit(const std::vector< bool > &complete_txs, const std::vector< std::vector< uint64_t > > &tx_idxs)
Sets the state of the dtx to commit and sets the state from the end of the prepare phase so that exec...
auto execute() -> std::optional< std::vector< bool > >
Executes the dtx batch to completion or failure, either from start, or an intermediate state if one o...
void set_discard_cb(const discard_cb_t &cb)
Registers a callback to be called before the discard phase of the dtx is started.
@ failed
dtx was interrupted and needs recovery.
@ done
dtx has completed fully
@ start
dtx initial state, no action has been performed yet
@ commit
dtx is calling commit on shards
void recover_discard()
Sets the state of the dtx to discard so that execute() will start from the discard phase.
auto add_tx(const transaction::compact_tx &tx) -> size_t
Adds a TX to the batch managed by this coordinator and dtx ID.
void recover_prepare(const std::vector< transaction::compact_tx > &txs)
Sets the state of the dtx to prepare and re-adds all the txs included in the batch.
std::function< bool(const hash_t &, const std::vector< transaction::compact_tx > &)> prepare_cb_t
std::function< bool(const hash_t &, const std::vector< bool > &, const std::vector< std::vector< uint64_t > > &)> commit_cb_t
auto get_state() const -> dtx_state
Returns the current state of the dtx.
distributed_tx(const hash_t &dtx_id, std::vector< std::shared_ptr< locking_shard::interface > > shards, std::shared_ptr< logging::log > logger)
Constructs a new transaction coordinator instance.
void set_prepare_cb(const prepare_cb_t &cb)
Registers a callback to be called before starting the prepare phase of the dtx.
std::function< bool(const hash_t &)> done_cb_t
void set_done_cb(const done_cb_t &cb)
Registers a callback to be called before the done phase of the dtx is started.
Interface for a coordinator.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Pseudorandom number generator (PRNG) for generating random data from a given entropy source.
A condensed, hash-only transaction representation.