6#ifndef OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_IMPL_H_
7#define OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_IMPL_H_
16#include <unordered_map>
17#include <unordered_set>
26 explicit impl(std::shared_ptr<logging::log> logger);
96 struct lock_queue_element_type {
101 struct rw_lock_type {
102 std::optional<ticket_number_type> m_writer;
103 std::unordered_set<ticket_number_type> m_readers;
104 std::map<ticket_number_type, lock_queue_element_type> m_queue;
107 struct state_element_type {
113 = std::unordered_set<key_type, hashing::const_sip_hash<key_type>>;
115 struct ticket_state_type {
121 key_set_type m_queued_locks;
124 std::optional<wounded_details> m_wounded_details{};
127 struct pending_callback_element_type {
133 using pending_callbacks_list_type
134 = std::vector<pending_callback_element_type>;
136 mutable std::mutex m_mut;
137 std::shared_ptr<logging::log> m_log;
143 std::unordered_map<ticket_number_type, ticket_state_type> m_tickets;
147 const std::vector<ticket_number_type>& blocking_tickets,
149 -> pending_callbacks_list_type;
154 -> std::vector<ticket_number_type>;
157 ticket_state_type& ticket)
158 -> std::pair<pending_callbacks_list_type, key_set_type>;
160 auto acquire_locks(
const key_set_type& keys)
161 -> pending_callbacks_list_type;
163 auto acquire_lock(
const key_type& key,
164 pending_callbacks_list_type& callbacks) -> bool;
Buffer to store and retrieve byte data.
Implementation of a runtime locking shard.
auto rollback(ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool override
Rolls back an uncommitted ticket.
auto recover(const replicated_shard::state_type &state, const replicated_shard::tickets_type &tickets) -> bool
Restores the state of another shard instance.
auto finish(ticket_number_type ticket_number, finish_callback_type result_callback) -> bool override
Deletes a committed or rolled-back ticket.
auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_update_type state_update, prepare_callback_type result_callback) -> bool override
Prepares a ticket with the given state updates.
auto commit(ticket_number_type ticket_number, commit_callback_type result_callback) -> bool override
Commits a previously prepared ticket.
auto try_lock(ticket_number_type ticket_number, broker_id_type broker_id, key_type key, lock_type locktype, bool first_lock, try_lock_callback_type result_callback) -> bool override
Locks the given key for a ticket and returns the associated value.
auto get_tickets(broker_id_type broker_id, get_tickets_callback_type result_callback) -> bool override
Returns tickets managed by the given broker.
impl(std::shared_ptr< logging::log > logger)
Constructor.
Interface for a runtime locking shard.
std::function< void(prepare_return_type)> prepare_callback_type
Callback function type for the result of a prepare operation.
std::function< void(get_tickets_return_type)> get_tickets_callback_type
Callback function type for the result of a get tickets operation.
std::variant< value_type, shard_error > try_lock_return_type
Return type from a try lock operation.
std::function< void(rollback_return_type)> rollback_callback_type
Callback function type for the result of a rollback operation.
std::function< void(finish_return_type)> finish_callback_type
Callback function type for the result of a finish operation.
std::function< void(try_lock_return_type)> try_lock_callback_type
Function type for try lock operation results.
std::function< void(commit_return_type)> commit_callback_type
Callback function type for the result of a commit operation.
std::unordered_map< ticket_number_type, ticket_type > tickets_type
Type for the tickets list returned by the state machine.
std::unordered_map< key_type, value_type, hashing::const_sip_hash< key_type > > state_type
Type for state updates to a shard.
buffer key_type
Type for keys held by shards.
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.
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.
ticket_state
Ticket states returned by shards for broker recovery purposes.
@ begun
Begun, may still hold locks or be rolled-back.
lock_type
Types of key lock supported by shards.
SipHash function to generate STL data structure hash keys for system IDs.