6#ifndef OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_INTERFACE_H_
7#define OPENCBDC_TX_SRC_PARSEC_RUNTIME_LOCKING_SHARD_INTERFACE_H_
14#include <unordered_map>
28 unordered_map<key_type, value_type, hashing::const_sip_hash<key_type>>;
218 = std::unordered_map<ticket_number_type, ticket_state>;
222 = std::variant<get_tickets_success_type, error_code>;
Buffer to store and retrieve byte data.
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.
virtual ~interface()=default
interface(interface &&)=delete
std::optional< shard_error > prepare_return_type
Return type from a prepare operation. An error, if applicable.
virtual auto rollback(ticket_number_type ticket_number, rollback_callback_type result_callback) -> bool=0
Releases any locks held by a ticket and returns it to a clean state.
std::optional< shard_error > commit_return_type
Return type from a commit operation. An error code, if applicable.
std::optional< shard_error > finish_return_type
Return type from a finish operation. An error code, if applicable.
interface(const interface &)=delete
virtual auto get_tickets(broker_id_type broker_id, get_tickets_callback_type result_callback) -> bool=0
Returns all unfinished tickets managed with the given broker ID.
std::unordered_map< ticket_number_type, ticket_state > get_tickets_success_type
Return type from a successful get tickets operation.
virtual auto commit(ticket_number_type ticket_number, commit_callback_type result_callback) -> bool=0
Commits the state updates from a previously prepared ticket.
virtual 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=0
Requests a lock on the given key and returns the value associated with the key.
std::function< void(get_tickets_return_type)> get_tickets_callback_type
Callback function type for the result of a get tickets operation.
auto operator=(const interface &) -> interface &=delete
virtual auto finish(ticket_number_type ticket_number, finish_callback_type result_callback) -> bool=0
Removes a ticket from the shard's internal state.
auto operator=(interface &&) -> interface &=delete
std::variant< value_type, shard_error > try_lock_return_type
Return type from a try lock operation.
std::optional< shard_error > rollback_return_type
Return type from a rollback operation.
std::function< void(rollback_return_type)> rollback_callback_type
Callback function type for the result of a rollback operation.
virtual auto prepare(ticket_number_type ticket_number, broker_id_type broker_id, state_update_type state_update, prepare_callback_type result_callback) -> bool=0
Prepares a ticket with the given state updates to be applied if the ticket is subsequently committed.
std::function< void(finish_return_type)> finish_callback_type
Callback function type for the result of a finish operation.
std::variant< get_tickets_success_type, error_code > get_tickets_return_type
Return type from a get tickets 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.
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.
error_code
Error codes returned by methods on shards.
@ wounded
Request invalid because ticket is in the wounded state.
@ lock_not_held
Cannot apply requested state update because the ticket does not hold a write lock on the given key.
@ internal_error
Request failed because of a transient internal error.
@ not_committed
Request invalid because ticket is not in the committed state.
@ lock_held
The ticket already holds the requested lock.
@ lock_queued
The requested lock is already queued for the given ticket.
@ prepared
Request invalid because ticket is in the prepared state.
@ state_update_with_read_lock
Cannot apply requested state update because the ticket only holds a read lock on the given key.
@ not_prepared
Cannot commit the ticket because the ticket has not been prepared.
@ unknown_ticket
The given ticket number is not known to this shard.
@ committed
Request invalid because ticket is in the committed state.
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.
@ read
Read lock. Multiple readers can hold a lock for the same key.
@ write
Write lock. Only one ticket can hold this lock at a time.
uint64_t ticket_number_type
Type alias for a ticket number.
@ buffer
A singular RLP value (byte array)
error_code m_error_code
The error code.
std::optional< wounded_details > m_wounded_details
Optional details about the wounded error code.
Details about wounded error code.
key_type m_wounding_key
The key that triggered the other ticket to wound.
ticket_number_type m_wounding_ticket
The ticket that caused wounding.