CCF
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
ccf::historical::StateCache Class Reference

#include <historical_queries.h>

Inherits ccf::historical::StateCacheImpl, and ccf::historical::AbstractStateCache.

Public Member Functions

template<typename... Ts>
 StateCache (Ts &&... ts)
 
ccf::kv::ReadOnlyStorePtr get_store_at (RequestHandle handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry) override
 
ccf::kv::ReadOnlyStorePtr get_store_at (RequestHandle handle, ccf::SeqNo seqno) override
 
StatePtr get_state_at (RequestHandle handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry) override
 
StatePtr get_state_at (RequestHandle handle, ccf::SeqNo seqno) override
 
std::vector< ccf::kv::ReadOnlyStorePtrget_store_range (RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, ExpiryDuration seconds_until_expiry) override
 
std::vector< ccf::kv::ReadOnlyStorePtrget_store_range (RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) override
 
std::vector< StatePtrget_state_range (RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, ExpiryDuration seconds_until_expiry) override
 
std::vector< StatePtrget_state_range (RequestHandle handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno) override
 
std::vector< ccf::kv::ReadOnlyStorePtrget_stores_for (RequestHandle handle, const SeqNoCollection &seqnos, ExpiryDuration seconds_until_expiry) override
 
std::vector< ccf::kv::ReadOnlyStorePtrget_stores_for (RequestHandle handle, const SeqNoCollection &seqnos) override
 
std::vector< StatePtrget_states_for (RequestHandle handle, const SeqNoCollection &seqnos, ExpiryDuration seconds_until_expiry) override
 
std::vector< StatePtrget_states_for (RequestHandle handle, const SeqNoCollection &seqnos) override
 
void set_default_expiry_duration (ExpiryDuration duration) override
 
void set_soft_cache_limit (CacheSize cache_limit) override
 
void track_deletes_on_missing_keys (bool track) override
 
bool drop_cached_states (RequestHandle handle) override
 
- Public Member Functions inherited from ccf::historical::StateCacheImpl
 StateCacheImpl (ccf::kv::Store &store, const std::shared_ptr< ccf::LedgerSecrets > &secrets, const ringbuffer::WriterPtr &host_writer)
 
ccf::kv::ReadOnlyStorePtr get_store_at (const CompoundHandle &handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry)
 
ccf::kv::ReadOnlyStorePtr get_store_at (const CompoundHandle &handle, ccf::SeqNo seqno)
 
StatePtr get_state_at (const CompoundHandle &handle, ccf::SeqNo seqno, ExpiryDuration seconds_until_expiry)
 
StatePtr get_state_at (const CompoundHandle &handle, ccf::SeqNo seqno)
 
std::vector< ccf::kv::ReadOnlyStorePtrget_store_range (const CompoundHandle &handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, ExpiryDuration seconds_until_expiry)
 
std::vector< ccf::kv::ReadOnlyStorePtrget_store_range (const CompoundHandle &handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno)
 
std::vector< StatePtrget_state_range (const CompoundHandle &handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno, ExpiryDuration seconds_until_expiry)
 
std::vector< StatePtrget_state_range (const CompoundHandle &handle, ccf::SeqNo start_seqno, ccf::SeqNo end_seqno)
 
std::vector< ccf::kv::ReadOnlyStorePtrget_stores_for (const CompoundHandle &handle, const SeqNoCollection &seqnos, ExpiryDuration seconds_until_expiry)
 
std::vector< ccf::kv::ReadOnlyStorePtrget_stores_for (const CompoundHandle &handle, const SeqNoCollection &seqnos)
 
std::vector< StatePtrget_states_for (const CompoundHandle &handle, const SeqNoCollection &seqnos, ExpiryDuration seconds_until_expiry)
 
std::vector< StatePtrget_states_for (const CompoundHandle &handle, const SeqNoCollection &seqnos)
 
void set_default_expiry_duration (ExpiryDuration duration)
 
void set_soft_cache_limit (CacheSize cache_limit)
 
void track_deletes_on_missing_keys (bool track)
 
bool drop_cached_states (const CompoundHandle &handle)
 
bool handle_ledger_entry (ccf::SeqNo seqno, const std::vector< uint8_t > &data)
 
bool handle_ledger_entry (ccf::SeqNo seqno, const uint8_t *data, size_t size)
 
bool handle_ledger_entries (ccf::SeqNo from_seqno, ccf::SeqNo to_seqno, const LedgerEntry &data)
 
bool handle_ledger_entries (ccf::SeqNo from_seqno, ccf::SeqNo to_seqno, const uint8_t *data, size_t size)
 
void handle_no_entry (ccf::SeqNo seqno)
 
void handle_no_entry_range (ccf::SeqNo from_seqno, ccf::SeqNo to_seqno)
 
ccf::kv::StorePtr deserialise_ledger_entry (ccf::SeqNo seqno, const uint8_t *data, size_t size, ccf::kv::ApplyResult &result, ccf::ClaimsDigest &claims_digest, bool &has_commit_evidence)
 
void tick (const std::chrono::milliseconds &elapsed_ms)
 
- Public Member Functions inherited from ccf::historical::AbstractStateCache
virtual ~AbstractStateCache ()=default
 
- Public Member Functions inherited from ccf::AbstractNodeSubSystem
virtual ~AbstractNodeSubSystem ()=default
 

Protected Member Functions

CompoundHandle make_compound_handle (RequestHandle rh)
 
- Protected Member Functions inherited from ccf::historical::StateCacheImpl
void update_earliest_known_ledger_secret ()
 
void add_request_ref (SeqNo seq, CompoundHandle handle)
 
void add_request_refs (CompoundHandle handle)
 
void remove_request_ref (SeqNo seq, CompoundHandle handle)
 
void remove_request_refs (CompoundHandle handle)
 
void lru_promote (CompoundHandle handle)
 
void lru_shrink_to_fit (size_t threshold)
 
void lru_evict (CompoundHandle handle)
 
void update_store_raw_size (SeqNo seq, size_t new_size)
 
void fetch_entry_at (ccf::SeqNo seqno)
 
void fetch_entries_range (ccf::SeqNo from, ccf::SeqNo to)
 
std::optional< ccf::SeqNofetch_supporting_secret_if_needed (ccf::SeqNo seqno)
 
void process_deserialised_store (const StoreDetailsPtr &details, const ccf::kv::StorePtr &store, const ccf::crypto::Sha256Hash &entry_digest, ccf::SeqNo seqno, bool is_signature, ccf::ClaimsDigest &&claims_digest, bool has_commit_evidence)
 
bool handle_encrypted_past_ledger_secret (const ccf::kv::StorePtr &store, LedgerSecretPtr encrypting_secret)
 
SeqNoCollection collection_from_single_range (ccf::SeqNo start_seqno, ccf::SeqNo end_seqno)
 
std::vector< StatePtrget_states_internal (const CompoundHandle &handle, const SeqNoCollection &seqnos, ExpiryDuration seconds_until_expiry, bool include_receipts)
 
void delete_all_interested_requests (ccf::SeqNo seqno)
 
std::vector< ccf::kv::ReadOnlyStorePtrstates_to_stores (const std::vector< StatePtr > &states)
 

Additional Inherited Members

- Static Public Member Functions inherited from ccf::historical::AbstractStateCache
static char const * get_subsystem_name ()
 
- Protected Types inherited from ccf::historical::StateCacheImpl
enum class  StoreStage { Fetching , Trusted }
 
using LedgerEntry = std::vector< uint8_t >
 
using StoreDetailsPtr = std::shared_ptr< StoreDetails >
 
using RequestedStores = std::map< ccf::SeqNo, StoreDetailsPtr >
 
using WeakStoreDetailsPtr = std::weak_ptr< StoreDetails >
 
using AllRequestedStores = std::map< ccf::SeqNo, WeakStoreDetailsPtr >
 
- Protected Attributes inherited from ccf::historical::StateCacheImpl
ccf::kv::Storesource_store
 
std::shared_ptr< ccf::LedgerSecretssource_ledger_secrets
 
ringbuffer::WriterPtr to_host
 
std::shared_ptr< ccf::LedgerSecretshistorical_ledger_secrets
 
std::shared_ptr< ccf::NodeEncryptorhistorical_encryptor
 
bool track_deletes_on_missing_keys_v = false
 
VersionedSecret earliest_secret_ = {}
 
StoreDetailsPtr next_secret_fetch_handle = nullptr
 
ccf::pal::Mutex requests_lock
 
std::map< CompoundHandle, Requestrequests
 
AllRequestedStores all_stores
 
ExpiryDuration default_expiry_duration = std::chrono::seconds(1800)
 
std::list< CompoundHandlelru_requests
 
std::map< CompoundHandle, std::list< CompoundHandle >::iterator > lru_lookup
 
std::unordered_map< SeqNo, std::set< CompoundHandle > > store_to_requests
 
std::unordered_map< ccf::SeqNo, size_t > raw_store_sizes {}
 
CacheSize soft_store_cache_limit {std::numeric_limits<size_t>::max()}
 
CacheSize soft_store_cache_limit_raw
 
CacheSize estimated_store_cache_size {0}
 

Constructor & Destructor Documentation

◆ StateCache()

template<typename... Ts>
ccf::historical::StateCache::StateCache ( Ts &&...  ts)
inline

Member Function Documentation

◆ drop_cached_states()

bool ccf::historical::StateCache::drop_cached_states ( RequestHandle  handle)
inlineoverridevirtual

Drop state for the given handle.

May be used to free up space once a historical query has been resolved, more aggressively than waiting for the states to expire.

Implements ccf::historical::AbstractStateCache.

◆ get_state_at() [1/2]

StatePtr ccf::historical::StateCache::get_state_at ( RequestHandle  handle,
ccf::SeqNo  seqno 
)
inlineoverridevirtual

Same as get_state_at but uses default expiry value.

See also
get_state_at

Implements ccf::historical::AbstractStateCache.

◆ get_state_at() [2/2]

StatePtr ccf::historical::StateCache::get_state_at ( RequestHandle  handle,
ccf::SeqNo  seqno,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve a full state at a given seqno, including the Store, the TxID assigned by consensus, and an offline-verifiable receipt for the Tx.

Implements ccf::historical::AbstractStateCache.

◆ get_state_range() [1/2]

std::vector< StatePtr > ccf::historical::StateCache::get_state_range ( RequestHandle  handle,
ccf::SeqNo  start_seqno,
ccf::SeqNo  end_seqno 
)
inlineoverridevirtual

Same as get_state_range but uses default expiry value.

See also
get_state_range

Implements ccf::historical::AbstractStateCache.

◆ get_state_range() [2/2]

std::vector< StatePtr > ccf::historical::StateCache::get_state_range ( RequestHandle  handle,
ccf::SeqNo  start_seqno,
ccf::SeqNo  end_seqno,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve a range of states at the given indices, including the Store, the TxID assigned by consensus, and an offline-verifiable receipt for the Tx.

Implements ccf::historical::AbstractStateCache.

◆ get_states_for() [1/2]

std::vector< StatePtr > ccf::historical::StateCache::get_states_for ( RequestHandle  handle,
const SeqNoCollection seqnos 
)
inlineoverridevirtual

◆ get_states_for() [2/2]

std::vector< StatePtr > ccf::historical::StateCache::get_states_for ( RequestHandle  handle,
const SeqNoCollection seqnos,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve states for a set of given indices.

Implements ccf::historical::AbstractStateCache.

◆ get_store_at() [1/2]

ccf::kv::ReadOnlyStorePtr ccf::historical::StateCache::get_store_at ( RequestHandle  handle,
ccf::SeqNo  seqno 
)
inlineoverridevirtual

Same as get_store_at but uses default expiry value.

See also
get_store_at

Implements ccf::historical::AbstractStateCache.

◆ get_store_at() [2/2]

ccf::kv::ReadOnlyStorePtr ccf::historical::StateCache::get_store_at ( RequestHandle  handle,
ccf::SeqNo  seqno,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve a Store containing the state written at the given seqno.

See get_store_range for a description of the caching behaviour. This is equivalent to get_store_at(handle, seqno, seqno), but returns nullptr if the state is currently unavailable.

Implements ccf::historical::AbstractStateCache.

◆ get_store_range() [1/2]

std::vector< ccf::kv::ReadOnlyStorePtr > ccf::historical::StateCache::get_store_range ( RequestHandle  handle,
ccf::SeqNo  start_seqno,
ccf::SeqNo  end_seqno 
)
inlineoverridevirtual

Same as get_store_range but uses default expiry value.

See also
get_store_range

Implements ccf::historical::AbstractStateCache.

◆ get_store_range() [2/2]

std::vector< ccf::kv::ReadOnlyStorePtr > ccf::historical::StateCache::get_store_range ( RequestHandle  handle,
ccf::SeqNo  start_seqno,
ccf::SeqNo  end_seqno,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve a range of Stores containing the state written at the given indices.

If this is not currently available, this function returns an empty vector and begins fetching the ledger entry asynchronously. This will generally be true for the first call for a given seqno, and it may take some time to completely fetch and validate. The call should be repeated later with the same arguments to retrieve the requested entries. This state is kept until it is deleted for one of the following reasons:

  • A call to drop_cached_states
  • seconds_until_expiry seconds elapse without calling this function
  • This handle is used to request a different seqno or range

The range is inclusive of both start_seqno and end_seqno. If a non-empty vector is returned, it will always contain the full requested range; the vector will be of length (end_seqno - start_seqno + 1) and will contain no nullptrs.

Implements ccf::historical::AbstractStateCache.

◆ get_stores_for() [1/2]

std::vector< ccf::kv::ReadOnlyStorePtr > ccf::historical::StateCache::get_stores_for ( RequestHandle  handle,
const SeqNoCollection seqnos 
)
inlineoverridevirtual

◆ get_stores_for() [2/2]

std::vector< ccf::kv::ReadOnlyStorePtr > ccf::historical::StateCache::get_stores_for ( RequestHandle  handle,
const SeqNoCollection seqnos,
ExpiryDuration  seconds_until_expiry 
)
inlineoverridevirtual

Retrieve stores for a set of given indices.

Implements ccf::historical::AbstractStateCache.

◆ make_compound_handle()

CompoundHandle ccf::historical::StateCache::make_compound_handle ( RequestHandle  rh)
inlineprotected

◆ set_default_expiry_duration()

void ccf::historical::StateCache::set_default_expiry_duration ( ExpiryDuration  seconds_until_expiry)
inlineoverridevirtual

Set the default time after which a request's state will be deleted, and will not be accessible without retrieving it again from the ledger. Any call to get_store_XXX which doesn't pass an explicit seconds_until_expiry will reset the timer to this default duration.

Implements ccf::historical::AbstractStateCache.

◆ set_soft_cache_limit()

void ccf::historical::StateCache::set_soft_cache_limit ( CacheSize  cache_limit)
inlineoverridevirtual

Set the cache limit (in bytes) to evict least recently used requests from the cache after its size grows beyond this limit. The limit is not strict. It is estimated based on serialized states' sizes approximation and is checked once per tick, and so it can overflow for a short time.

Implements ccf::historical::AbstractStateCache.

◆ track_deletes_on_missing_keys()

void ccf::historical::StateCache::track_deletes_on_missing_keys ( bool  track)
inlineoverridevirtual

EXPERIMENTAL: Set the tracking of deletes on missing keys for historical queries.

This is experimental but setting this to true ensures that the tx_diff available in index handlers can observe deleted values.

Implements ccf::historical::AbstractStateCache.


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