CCF
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ccf::kv::Store Class Reference

#include <store.h>

Inherits ccf::kv::AbstractStore, ccf::kv::StoreState, ccf::kv::ExecutionWrapperStore, and ccf::kv::ReadOnlyStore.

Public Member Functions

 Store (bool strict_versions_=true, bool is_historical_=false)
 
 Store (const Store &that)=delete
 
std::shared_ptr< Consensusget_consensus () override
 
void set_consensus (const std::shared_ptr< Consensus > &consensus_)
 
std::shared_ptr< TxHistoryget_history () override
 
void set_history (const std::shared_ptr< TxHistory > &history_)
 
std::shared_ptr< ILedgerChunkerget_chunker () override
 
void set_chunker (const std::shared_ptr< ILedgerChunker > &chunker_)
 
void set_encryptor (const EncryptorPtr &encryptor_)
 
EncryptorPtr get_encryptor () override
 
void set_snapshotter (const SnapshotterPtr &snapshotter_)
 
std::shared_ptr< AbstractMapget_map (ccf::kv::Version v, const std::string &map_name) override
 
std::shared_ptr< AbstractMapget_map_unsafe (ccf::kv::Version v, const std::string &map_name) override
 
std::shared_ptr< ccf::kv::untyped::Mapget_map_internal (ccf::kv::Version v, const std::string &map_name)
 
void add_dynamic_map (ccf::kv::Version v, const std::shared_ptr< AbstractMap > &map_) override
 
std::unique_ptr< AbstractSnapshotsnapshot_unsafe_maps (Version v) override
 
void lock_maps () override
 
void unlock_maps () override
 
std::vector< uint8_t > serialise_snapshot (std::unique_ptr< AbstractSnapshot > snapshot) override
 
ApplyResult deserialise_snapshot (const uint8_t *data, size_t size, ccf::kv::ConsensusHookPtrs &hooks, std::vector< Version > *view_history=nullptr, bool public_only=false) override
 
void compact (Version v) override
 
void rollback (const TxID &tx_id, Term term_of_next_version_) override
 
void initialise_term (Term t) override
 
bool fill_maps (const std::vector< uint8_t > &data, bool public_only, ccf::kv::Version &v, ccf::kv::Term &view, ccf::kv::EntryFlags &entry_flags, OrderedChanges &changes, MapCollection &new_maps, ccf::ClaimsDigest &claims_digest, std::optional< ccf::crypto::Sha256Hash > &commit_evidence_digest, bool ignore_strict_versions=false) override
 
std::unique_ptr< ccf::kv::AbstractExecutionWrapperdeserialize (const std::vector< uint8_t > &data, bool public_only=false, const std::optional< TxID > &expected_txid=std::nullopt) override
 
bool operator== (const Store &that) const
 
Version current_version () override
 
ccf::kv::TxID current_txid () override
 
ccf::TxID get_txid () override
 
std::pair< TxID, Termcurrent_txid_and_commit_term () override
 
Version compacted_version () override
 
Term commit_view () override
 
CommitResult commit (const TxID &txid, std::unique_ptr< PendingTx > pending_tx, bool globally_committable) override
 
bool should_create_ledger_chunk (Version version) override
 
bool should_create_ledger_chunk_unsafe (Version version) override
 
void lock_map_set () override
 
void unlock_map_set () override
 
bool check_rollback_count (Version count) override
 
std::tuple< Version, Versionnext_version (bool commit_new_map) override
 
Version next_version () override
 
TxID next_txid () override
 
size_t committable_gap () override
 
void swap_private_maps (Store &store)
 
void set_map_hook (const std::string &map_name, const ccf::kv::untyped::Map::MapHook &hook)
 
void unset_map_hook (const std::string &map_name)
 
void set_global_hook (const std::string &map_name, const ccf::kv::untyped::Map::CommitHook &hook)
 
void unset_global_hook (const std::string &map_name)
 
ReadOnlyTx create_read_only_tx () override
 
std::unique_ptr< ReadOnlyTxcreate_read_only_tx_ptr () override
 
TxDiff create_tx_diff () override
 
CommittableTx create_tx ()
 
std::unique_ptr< CommittableTxcreate_tx_ptr ()
 
ReservedTx create_reserved_tx (const TxID &tx_id)
 
virtual void set_flag (StoreFlag f) override
 
virtual void unset_flag (StoreFlag f) override
 
virtual bool flag_enabled (StoreFlag f) override
 
virtual void set_flag_unsafe (StoreFlag f) override
 
virtual void unset_flag_unsafe (StoreFlag f) override
 
virtual bool flag_enabled_unsafe (StoreFlag f) const override
 
- Public Member Functions inherited from ccf::kv::AbstractStore
virtual ~AbstractStore ()
 
- Public Member Functions inherited from ccf::kv::StoreState
void clear ()
 
- Public Member Functions inherited from ccf::kv::ReadOnlyStore
virtual ~ReadOnlyStore ()=default
 

Additional Inherited Members

- Public Types inherited from ccf::kv::AbstractStore
enum class  StoreFlag : uint8_t { SNAPSHOT_AT_NEXT_SIGNATURE = 0x02 }
 
- Protected Types inherited from ccf::kv::StoreState
using Maps = std::map< std::string, std::pair< ccf::kv::Version, std::shared_ptr< untyped::Map > > >
 
- Protected Attributes inherited from ccf::kv::StoreState
ccf::pal::Mutex maps_lock
 
Maps maps
 
ccf::pal::Mutex version_lock
 
std::atomic< Versionversion = 0
 
Version last_new_map = ccf::kv::NoVersion
 
std::atomic< Versioncompacted = 0
 
ccf::pal::Mutex commit_lock
 
std::atomic< Termterm_of_next_version = 0
 
Term term_of_last_version = 0
 
Version last_replicated = 0
 
Version last_committable = 0
 
Version rollback_count = 0
 
std::unordered_map< Version, std::tuple< std::unique_ptr< PendingTx >, bool > > pending_txs
 

Constructor & Destructor Documentation

◆ Store() [1/2]

ccf::kv::Store::Store ( bool  strict_versions_ = true,
bool  is_historical_ = false 
)
inline

◆ Store() [2/2]

ccf::kv::Store::Store ( const Store that)
delete

Member Function Documentation

◆ add_dynamic_map()

void ccf::kv::Store::add_dynamic_map ( ccf::kv::Version  v,
const std::shared_ptr< AbstractMap > &  map_ 
)
inlineoverridevirtual

Transfer ownership of a dynamically created map to this Store.

Should be called as part of the commit process, once a transaction is known to be conflict-free and has been assigned a unique Version. This publishes dynamically created Maps so they can be retrieved via get_map in future transactions.

Parameters
vVersion at which map is being committed/created
map_Map to add

Implements ccf::kv::AbstractStore.

◆ check_rollback_count()

bool ccf::kv::Store::check_rollback_count ( Version  count)
inlineoverridevirtual

◆ commit()

CommitResult ccf::kv::Store::commit ( const TxID txid,
std::unique_ptr< PendingTx pending_tx,
bool  globally_committable 
)
inlineoverridevirtual

◆ commit_view()

Term ccf::kv::Store::commit_view ( )
inlineoverridevirtual

◆ committable_gap()

size_t ccf::kv::Store::committable_gap ( )
inlineoverridevirtual

◆ compact()

void ccf::kv::Store::compact ( Version  v)
inlineoverridevirtual

◆ compacted_version()

Version ccf::kv::Store::compacted_version ( )
inlineoverridevirtual

◆ create_read_only_tx()

ReadOnlyTx ccf::kv::Store::create_read_only_tx ( )
inlineoverridevirtual

◆ create_read_only_tx_ptr()

std::unique_ptr< ReadOnlyTx > ccf::kv::Store::create_read_only_tx_ptr ( )
inlineoverridevirtual

◆ create_reserved_tx()

ReservedTx ccf::kv::Store::create_reserved_tx ( const TxID tx_id)
inline

◆ create_tx()

CommittableTx ccf::kv::Store::create_tx ( )
inline

◆ create_tx_diff()

TxDiff ccf::kv::Store::create_tx_diff ( )
inlineoverridevirtual

◆ create_tx_ptr()

std::unique_ptr< CommittableTx > ccf::kv::Store::create_tx_ptr ( )
inline

◆ current_txid()

ccf::kv::TxID ccf::kv::Store::current_txid ( )
inlineoverridevirtual

◆ current_txid_and_commit_term()

std::pair< TxID, Term > ccf::kv::Store::current_txid_and_commit_term ( )
inlineoverridevirtual

◆ current_version()

Version ccf::kv::Store::current_version ( )
inlineoverridevirtual

◆ deserialise_snapshot()

ApplyResult ccf::kv::Store::deserialise_snapshot ( const uint8_t *  data,
size_t  size,
ccf::kv::ConsensusHookPtrs hooks,
std::vector< Version > *  view_history = nullptr,
bool  public_only = false 
)
inlineoverridevirtual

◆ deserialize()

std::unique_ptr< ccf::kv::AbstractExecutionWrapper > ccf::kv::Store::deserialize ( const std::vector< uint8_t > &  data,
bool  public_only = false,
const std::optional< TxID > &  expected_txid = std::nullopt 
)
inlineoverridevirtual

◆ fill_maps()

bool ccf::kv::Store::fill_maps ( const std::vector< uint8_t > &  data,
bool  public_only,
ccf::kv::Version v,
ccf::kv::Term view,
ccf::kv::EntryFlags entry_flags,
OrderedChanges changes,
MapCollection new_maps,
ccf::ClaimsDigest claims_digest,
std::optional< ccf::crypto::Sha256Hash > &  commit_evidence_digest,
bool  ignore_strict_versions = false 
)
inlineoverridevirtual

◆ flag_enabled()

virtual bool ccf::kv::Store::flag_enabled ( StoreFlag  f)
inlineoverridevirtual

◆ flag_enabled_unsafe()

virtual bool ccf::kv::Store::flag_enabled_unsafe ( StoreFlag  f) const
inlineoverridevirtual

◆ get_chunker()

std::shared_ptr< ILedgerChunker > ccf::kv::Store::get_chunker ( )
inlineoverridevirtual

◆ get_consensus()

std::shared_ptr< Consensus > ccf::kv::Store::get_consensus ( )
inlineoverridevirtual

◆ get_encryptor()

EncryptorPtr ccf::kv::Store::get_encryptor ( )
inlineoverridevirtual

◆ get_history()

std::shared_ptr< TxHistory > ccf::kv::Store::get_history ( )
inlineoverridevirtual

◆ get_map()

std::shared_ptr< AbstractMap > ccf::kv::Store::get_map ( ccf::kv::Version  v,
const std::string &  map_name 
)
inlineoverridevirtual

Get a map by name, iff it exists at the given version.

This means a prior transaction must have created the map, and successfully committed at a version <= v. If this has not happened (the map has never been created, or never been committed, or committed at a later version) this will return nullptr.

Parameters
vVersion at which the map must exist
map_nameName of requested map
Returns
Abstract shared-owning pointer to requested map, or nullptr if no such map exists

Implements ccf::kv::AbstractStore.

◆ get_map_internal()

std::shared_ptr< ccf::kv::untyped::Map > ccf::kv::Store::get_map_internal ( ccf::kv::Version  v,
const std::string &  map_name 
)
inline

◆ get_map_unsafe()

std::shared_ptr< AbstractMap > ccf::kv::Store::get_map_unsafe ( ccf::kv::Version  v,
const std::string &  map_name 
)
inlineoverridevirtual

◆ get_txid()

ccf::TxID ccf::kv::Store::get_txid ( )
inlineoverridevirtual

◆ initialise_term()

void ccf::kv::Store::initialise_term ( Term  t)
inlineoverridevirtual

◆ lock_map_set()

void ccf::kv::Store::lock_map_set ( )
inlineoverridevirtual

◆ lock_maps()

void ccf::kv::Store::lock_maps ( )
inlineoverridevirtual

◆ next_txid()

TxID ccf::kv::Store::next_txid ( )
inlineoverridevirtual

◆ next_version() [1/2]

Version ccf::kv::Store::next_version ( )
inlineoverridevirtual

◆ next_version() [2/2]

std::tuple< Version, Version > ccf::kv::Store::next_version ( bool  commit_new_map)
inlineoverridevirtual

◆ operator==()

bool ccf::kv::Store::operator== ( const Store that) const
inline

◆ rollback()

void ccf::kv::Store::rollback ( const TxID tx_id,
Term  term_of_next_version_ 
)
inlineoverridevirtual

◆ serialise_snapshot()

std::vector< uint8_t > ccf::kv::Store::serialise_snapshot ( std::unique_ptr< AbstractSnapshot snapshot)
inlineoverridevirtual

◆ set_chunker()

void ccf::kv::Store::set_chunker ( const std::shared_ptr< ILedgerChunker > &  chunker_)
inline

◆ set_consensus()

void ccf::kv::Store::set_consensus ( const std::shared_ptr< Consensus > &  consensus_)
inline

◆ set_encryptor()

void ccf::kv::Store::set_encryptor ( const EncryptorPtr encryptor_)
inline

◆ set_flag()

virtual void ccf::kv::Store::set_flag ( StoreFlag  f)
inlineoverridevirtual

◆ set_flag_unsafe()

virtual void ccf::kv::Store::set_flag_unsafe ( StoreFlag  f)
inlineoverridevirtual

◆ set_global_hook()

void ccf::kv::Store::set_global_hook ( const std::string &  map_name,
const ccf::kv::untyped::Map::CommitHook hook 
)
inline

◆ set_history()

void ccf::kv::Store::set_history ( const std::shared_ptr< TxHistory > &  history_)
inline

◆ set_map_hook()

void ccf::kv::Store::set_map_hook ( const std::string &  map_name,
const ccf::kv::untyped::Map::MapHook hook 
)
inline

◆ set_snapshotter()

void ccf::kv::Store::set_snapshotter ( const SnapshotterPtr snapshotter_)
inline

◆ should_create_ledger_chunk()

bool ccf::kv::Store::should_create_ledger_chunk ( Version  version)
inlineoverridevirtual

◆ should_create_ledger_chunk_unsafe()

bool ccf::kv::Store::should_create_ledger_chunk_unsafe ( Version  version)
inlineoverridevirtual

◆ snapshot_unsafe_maps()

std::unique_ptr< AbstractSnapshot > ccf::kv::Store::snapshot_unsafe_maps ( Version  v)
inlineoverridevirtual

◆ swap_private_maps()

void ccf::kv::Store::swap_private_maps ( Store store)
inline

This is only safe in very restricted circumstances, and is only meant to be used during catastrophic recovery, between a KV with public-state only and a KV with full state, to swap in the private state from the latter into the former.

It's also important to note that swapping in private state may result in previously uncompacted writes becoming effectively compacted, from a user's perspective (they would not be internally compacted until the next compact() however). So it is important to make sure that the private state being swapped in is fully compacted before the swap.

◆ unlock_map_set()

void ccf::kv::Store::unlock_map_set ( )
inlineoverridevirtual

◆ unlock_maps()

void ccf::kv::Store::unlock_maps ( )
inlineoverridevirtual

◆ unset_flag()

virtual void ccf::kv::Store::unset_flag ( StoreFlag  f)
inlineoverridevirtual

◆ unset_flag_unsafe()

virtual void ccf::kv::Store::unset_flag_unsafe ( StoreFlag  f)
inlineoverridevirtual

◆ unset_global_hook()

void ccf::kv::Store::unset_global_hook ( const std::string &  map_name)
inline

◆ unset_map_hook()

void ccf::kv::Store::unset_map_hook ( const std::string &  map_name)
inline

The documentation for this class was generated from the following file: